Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(lib_random_workspace)

add_subdirectory(examples)
add_subdirectory(tests)
3 changes: 3 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pipeline {
dir("examples") {
xcoreBuild()
}
dir("tests") {
xcoreBuild()
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(lib_random_tests)

add_subdirectory(test_lib_random)
62 changes: 62 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# lib_random Tests

This directory contains xCore tests for the lib_random library.

## Test Coverage

The test suite covers all public API functions:

### Pseudo-Random Number Generation
- `random_create_generator_from_seed()` - Tests deterministic seed behavior
- `random_get_random_number()` - Tests number generation and state changes
- `random_get_random_bytes()` - Tests byte array generation

### Hardware-Based Random Generation
- `random_create_generator_from_hw_seed()` - Tests hardware seed initialization
- `random_ro_init()` - Tests ring oscillator initialization
- `random_ro_get_bit()` - Tests individual bit generation
- `random_ro_uninit()` - Tests ring oscillator cleanup

### Statistical Properties
- Basic distribution tests for generated values
- Uniqueness tests for generated sequences
- Edge case testing

## Building and Running

### xCore Testing (requires XMOS XTC Tools)

To build the tests for xCore hardware:

```bash
cd tests
cmake -G "Unix Makefiles" -B build
xmake -C build
```

To run the tests on simulator:

```bash
xsim build/bin/test_lib_random.xe
```

### Host Testing (for basic validation)

For basic testing without XMOS tools (some tests will be mocked):

```bash
cd tests/test_lib_random
cmake -f CMakeLists_host.txt -B build_host
make -C build_host
./build_host/test_lib_random_host
```

Note: Host testing mocks the hardware-specific ring oscillator functions.

## Test Results

The test suite outputs PASS/FAIL for each individual test and provides a summary at the end. A return code of 0 indicates all tests passed.

## Continuous Integration

Tests are automatically built and verified in the Jenkins CI pipeline alongside the examples.
1 change: 1 addition & 0 deletions tests/deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(APP_DEPENDENT_MODULES "lib_random")
11 changes: 11 additions & 0 deletions tests/test_lib_random/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(test_lib_random)

set(APP_HW_TARGET XK-EVK-XU316)

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)

XMOS_REGISTER_APP()
29 changes: 29 additions & 0 deletions tests/test_lib_random/CMakeLists_host.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Host Test Build (for basic validation without XMOS tools)

if(NOT DEFINED ENV{XMOS_CMAKE_PATH})
message(WARNING "XMOS_CMAKE_PATH not set, building host test version")

cmake_minimum_required(VERSION 3.21)
project(test_lib_random_host)

# Create host-compatible version for basic testing
add_executable(test_lib_random_host
src/main.c
../../lib_random/src/pr_random.c
)

target_include_directories(test_lib_random_host PRIVATE
../../lib_random/api
../../lib_random/src
)

# Mock XMOS-specific functions for host testing
target_compile_definitions(test_lib_random_host PRIVATE
-DHOST_TEST_BUILD=1
)

message(STATUS "Built host test version - some tests may be skipped")
else()
# Use the normal XMOS build when tools are available
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)
endif()
Loading