From 31a907891f4392a937ad4222ff9f24df1db1ed01 Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Thu, 30 Jul 2026 15:54:44 +0100 Subject: [PATCH 01/11] Bug fix and two basic tests --- lib_random/src/pr_random.c | 2 +- tests/CMakeLists.txt | 7 +++++++ tests/conftest.py | 17 +++++++++++++++++ tests/requirements.txt | 37 ++++++++++++++++++++++++++++++++++++ tests/test_hw.py | 34 +++++++++++++++++++++++++++++++++ tests/test_pr/CMakeLists.txt | 17 +++++++++++++++++ tests/test_pr/src/main.c | 27 ++++++++++++++++++++++++++ tests/test_ro/CMakeLists.txt | 17 +++++++++++++++++ tests/test_ro/src/main.c | 36 +++++++++++++++++++++++++++++++++++ tests/test_xsim.py | 19 ++++++++++++++++++ 10 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/conftest.py create mode 100644 tests/requirements.txt create mode 100644 tests/test_hw.py create mode 100644 tests/test_pr/CMakeLists.txt create mode 100644 tests/test_pr/src/main.c create mode 100644 tests/test_ro/CMakeLists.txt create mode 100644 tests/test_ro/src/main.c create mode 100644 tests/test_xsim.py diff --git a/lib_random/src/pr_random.c b/lib_random/src/pr_random.c index 7032917..cc0b457 100644 --- a/lib_random/src/pr_random.c +++ b/lib_random/src/pr_random.c @@ -4,7 +4,7 @@ #include "random.h" #include "random_internal.h" -#define crc32(a,b,c) asm("crc32 %0, %1, %2" : "+r" (a) : "r" (c), "r" (b)) +#define crc32(a,b,c) asm("crc32 %0, %1, %2" : "+r" (a) : "r" (b), "r" (c)) static const unsigned random_poly = 0xEDB88320; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..a57af69 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.21) +include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake) +project(lib_crypto_tests) + +add_subdirectory(test_pr) +add_subdirectory(test_ro) + diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..dde5eab --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +# Copyright 2025 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. +import pytest + +@pytest.fixture +def level(request): + return request.config.getoption("--level") + +def pytest_addoption(parser): + + parser.addoption( + "--level", + action="store", + default="smoke", + choices=["smoke", "default", "extended"], + help="Test coverage level", + ) diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..16d1980 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,37 @@ +# python_version 3.12.1 +# pip_version 24.* +# +# The parse_version_from_requirements() function in the installPipfile.groovy +# file of the Jenkins Shared Library uses the python_version comment to set +# the version of python used. + +# Distributed (released) dependencies +# +# The python modules listed below specify a known working combination required +# by the python code in this repository. The procedure used to set up a +# suitable python environment for it installs the version of each module in +# the list. Using a specific version ensures a controlled infrastructure for +# development, testing and release of this repository. +# +# Another repository might depend on python code defined in this one. The +# procedure to set up a suitable python environment for that repository may +# pip-install this one as editable using this repository's setup.py file. The +# same modules should appear in the setup.py list as given below. +pytest==8.3.3 +pytest-xdist==3.6.1 +filelock==3.19.1 + +# Development dependencies +# +# Each link listed below specifies the path to a setup.py file which are +# installed in editable mode with '-e $PATH' (without the quotes). +# +# If python code in this repository depends on python code under development +# in another repository, then an entry for that other respository should +# appear in this list instead of the released dependencies list. +# +# If this repository uses the setup functionality (e.g., script entry points) +# of its own setup.py file, then this list must include an entry for that +# setup.py file, e.g., '-e .' or '-e ./python' (without the quotes). + +-e git+ssh://git@github.com/xmos/test_support.git@v2.0.0#egg=test_support diff --git a/tests/test_hw.py b/tests/test_hw.py new file mode 100644 index 0000000..dc4da26 --- /dev/null +++ b/tests/test_hw.py @@ -0,0 +1,34 @@ +# Copyright 2025 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. +import re +import pytest +from pathlib import Path +from filelock import FileLock +import subprocess +import shutil +import sys + +""" +This test runs the hardware tests - none at present. Placeholder. +""" + +def test_ro(request): + test_name = "test_ro_hw" + + cwd = Path(request.fspath).parent + binary = Path(f'{cwd}/{test_name}/bin/{test_name}.xe') + outfile= Path(f'{cwd}/{test_name}/bin/out.bin') + + assert Path(binary).exists(), f"Cannot find {binary}" + + # Ensure we don't spin up two HW instances at the same time + with FileLock("xrun.lock"): + run_cmd = f'xrun --id 0 --io --args {binary} {outfile}' + print("Running cmd: ", run_cmd) + stdout = subprocess.check_output(run_cmd, shell = True) + + print('<', stdout, '>') + with open(outfile, "rb") as fd: + xrun_output = fd.read() + print(xrun_output, file=sys.stderr) + assert(b'PASS' == xrun_output) diff --git a/tests/test_pr/CMakeLists.txt b/tests/test_pr/CMakeLists.txt new file mode 100644 index 0000000..43bb4b4 --- /dev/null +++ b/tests/test_pr/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.21) +include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake) + +project(test_pr) + +set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..) + +set(APP_HW_TARGET XK-EVK-XU316) + +set(APP_DEPENDENT_MODULES "lib_random") + +set(APP_COMPILER_FLAGS -Werror -O2 -fcmdline-buffer-bytes=1024) + +set(APP_INCLUDES src) + + +XMOS_REGISTER_APP() diff --git a/tests/test_pr/src/main.c b/tests/test_pr/src/main.c new file mode 100644 index 0000000..f6cc7aa --- /dev/null +++ b/tests/test_pr/src/main.c @@ -0,0 +1,27 @@ +// Copyright 2025 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#include +#include +#include +#include +#include +#include +#include +#include +#include "random.h" + +int main(int argc, char *argv[]) { + random_generator_t g = 0x12345678; + + unsigned first = random_get_random_number(&g); + for(int i = 0; i < 100000; i++) { + unsigned x = random_get_random_number(&g); + if (x == first) { + printf("FAIL %d %08x %08x\n", i, first, x); + exit(1); + } + } + printf("PASS\n"); + return 0; +} diff --git a/tests/test_ro/CMakeLists.txt b/tests/test_ro/CMakeLists.txt new file mode 100644 index 0000000..a635966 --- /dev/null +++ b/tests/test_ro/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.21) +include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake) + +project(test_ro) + +set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..) + +set(APP_HW_TARGET XK-EVK-XU316) + +set(APP_DEPENDENT_MODULES "lib_random") + +set(APP_COMPILER_FLAGS -Werror -O2 -fcmdline-buffer-bytes=1024 -mcmodel=large) + +set(APP_INCLUDES src) + + +XMOS_REGISTER_APP() diff --git a/tests/test_ro/src/main.c b/tests/test_ro/src/main.c new file mode 100644 index 0000000..d428ce5 --- /dev/null +++ b/tests/test_ro/src/main.c @@ -0,0 +1,36 @@ +// Copyright 2025 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#include +#include +#include +#include +#include +#include +#include +#include +#include "random.h" + +#define N 128000 + +unsigned int data[N]; + +int main(int argc, char *argv[]) { + random_ro_init(); + for(int i = 0; i < N; i++) { + int j = 0; + unsigned int bits = 0; + do { + int bit = random_ro_get_bit(); + if (bit >= 0) { + bits = bits << 1; + j++; + } + } while (j != 32); + data[i] = bits; + } + FILE *fd = fopen(argv[1], "wb"); + fwrite(data, sizeof(data), 1, fd); + fclose(fd); + return 0; +} diff --git a/tests/test_xsim.py b/tests/test_xsim.py new file mode 100644 index 0000000..8e774c1 --- /dev/null +++ b/tests/test_xsim.py @@ -0,0 +1,19 @@ +# Copyright 2025 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. + +from pathlib import Path +import subprocess +import sys + +def test_xsim_sha2(): + bin_path = Path(__file__).parent / "test_pr" / "bin" + outfile = bin_path / "out.bin" + data = message.encode() + with open(infile, "wb") as fd: + fd.write(data) + run_cmd = "xsim " + "--args " + str(bin_path) + f"/test_pr.xe " + str(infile) + " " + str(outfile) + stdout = subprocess.check_output(run_cmd, cwd = bin_path, shell = True) + with open(outfile, "rb") as fd: + pass_str = fd.read() + print(stdout) + assert(b'PASS' == pass_str) From bf02f58f52bc149a176102dd3a9380c659bfd50b Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Fri, 31 Jul 2026 14:45:21 +0100 Subject: [PATCH 02/11] Modified Jenkinsfile to build entropy software --- .gitignore | 4 + .gitmodules | 3 + Jenkinsfile | 211 ++++++++++++++++++------- README.rst | 2 +- submodules/SP800-90B_EntropyAssessment | 1 + tests/test_hw.py | 17 +- tests/test_ro/src/main.c | 22 ++- tests/test_xsim.py | 12 +- 8 files changed, 196 insertions(+), 76 deletions(-) create mode 100644 .gitmodules create mode 160000 submodules/SP800-90B_EntropyAssessment diff --git a/.gitignore b/.gitignore index 06ab964..541f8de 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,7 @@ # Built documentation doc/_build/pdf/*.pdf **/doc/pdf/*.pdf + + +tests/pytest_result.xml +tests/xrun.lock diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..34b883b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/--depth=1"] + path = submodules/SP800-90B_EntropyAssessment + url = git@github.com:xmos/SP800-90B_EntropyAssessment.git diff --git a/Jenkinsfile b/Jenkinsfile index 0f0c1f3..fc88ed8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,66 +1,167 @@ -@Library('xmos_jenkins_shared_library@v0.34.0') _ +// This file relates to internal XMOS infrastructure and should be ignored by external users -getApproval() +@Library('xmos_jenkins_shared_library@v0.42.0') _ +getApproval() pipeline { - agent { - label 'x86_64 && linux' - } - environment { - REPO = 'lib_random' - } - options { - buildDiscarder(xmosDiscardBuildSettings()) - skipDefaultCheckout() - timestamps() - } - parameters { - string( - name: 'TOOLS_VERSION', - defaultValue: '15.3.0', - description: 'The XTC tools version' - ) - string( - name: 'XMOSDOC_VERSION', - defaultValue: 'v6.1.3', - description: 'The xmosdoc version' - ) - } - stages { - stage('Build') { - steps { - dir("lib_random") { - checkout scm + agent none - withTools(params.TOOLS_VERSION) { - dir("examples") { - sh 'cmake -G "Unix Makefiles" -B build' - sh 'xmake -C build' - } - } - } - } - } // Build + parameters { + string( + name: 'TOOLS_VERSION', + defaultValue: '15.3.1', + description: 'XTC tools version' + ) + string( + name: 'XMOSDOC_VERSION', + defaultValue: 'v7.4.0', + description: 'xmosdoc version' + ) + string( + name: 'INFR_APPS_VERSION', + defaultValue: 'v3.1.1', + description: 'The infr_apps version' + ) + } - stage('Library checks') { - steps { - runLibraryChecks("${WORKSPACE}/${REPO}", "v2.0.1") - } + options { + skipDefaultCheckout() + timestamps() + buildDiscarder(xmosDiscardBuildSettings(onlyArtifacts = false)) } - stage('Documentation') { - steps { - dir("${REPO}") { - buildDocs() + stages { + stage('🏗️ Build & Test') { + parallel { + stage('🏗️ Build and sim tests') { + agent { label 'x86_64 && linux && documentation' } + stages { + stage('Checkout') { + steps { + println "Stage running on ${env.NODE_NAME}" + script { + def (server, user, repo) = extractFromScmUrl() + env.REPO_NAME = repo + } + dir(REPO_NAME) { + checkoutScmShallow() + } + } + } + + stage('Examples build') { + steps { + dir("${REPO_NAME}/examples") { + xcoreBuild() + } + } + } + + stage('Repo checks') { + steps { + warnError("Repo checks failed") { + runRepoChecks("${WORKSPACE}/${REPO_NAME}") + } + } + } + + stage('Doc build') { + steps { + dir(REPO_NAME) { + buildDocs() + } + } + } + + stage('Sim tests') { + steps { + dir("${REPO_NAME}/tests") { + withTools(params.TOOLS_VERSION) { + createVenv(reqFile: "requirements.txt") + withVenv { + xcoreBuild(archiveBins: false) + sh "pytest -k _xsim -vv -n auto --junitxml=pytest_result.xml" + } + } + } + junit "${REPO_NAME}/tests/**/pytest_*.xml" + } + } + + stage("Archive sandbox") { + steps { + archiveSandbox(REPO_NAME) + } + } + } + post { + cleanup { + xcoreCleanSandbox() + } + } + } // stage Build and test + + stage('🏗️ Build and hardware tests') { + agent { label 'xcore.ai' } + stages { + stage('Checkout') { + steps { + println "Stage running on ${env.NODE_NAME}" + script { + def (server, user, repo) = extractFromScmUrl() + env.REPO_NAME = repo + } + dir(REPO_NAME) { + checkoutScmShallow() + } + } + } + stage('Analysis SW') { + steps { + dir("${REPO_NAME}/submodules/SP800-90B_EntropyAssessment") { + sh "make" + } + } + } + + stage('HW tests') { + steps { + dir("${REPO_NAME}/tests") { + withTools(params.TOOLS_VERSION) { + createVenv(reqFile: "requirements.txt") + withVenv { + xcoreBuild(archiveBins: false) + sh "pytest -k _hw -vv -s test_hw.py --junitxml=pytest_result.xml" + } + } + } + junit "${REPO_NAME}/tests/**/pytest_*.xml" + } + } + + stage("Archive sandbox") { + steps { + archiveSandbox(REPO_NAME) + } + } + } + post { + cleanup { + xcoreCleanSandbox() + } + } + } // stage Test HW + } // parallel } - } - } - } // stages - post { - cleanup { - xcoreCleanSandbox() + stage('🚀 Release') { + when { + expression { triggerRelease.isReleasable() } + } + steps { + triggerRelease() + } + } } - } -} +} // pipeline diff --git a/README.rst b/README.rst index 23675ad..6ed703d 100644 --- a/README.rst +++ b/README.rst @@ -27,7 +27,7 @@ Features * Example application demonstrating usage ************ -Known Issues +Known issues ************ * None diff --git a/submodules/SP800-90B_EntropyAssessment b/submodules/SP800-90B_EntropyAssessment new file mode 160000 index 0000000..87c104d --- /dev/null +++ b/submodules/SP800-90B_EntropyAssessment @@ -0,0 +1 @@ +Subproject commit 87c104d0ed4cbc96103e7b8b38d6f2c7e0a6b289 diff --git a/tests/test_hw.py b/tests/test_hw.py index dc4da26..657a39e 100644 --- a/tests/test_hw.py +++ b/tests/test_hw.py @@ -13,7 +13,7 @@ """ def test_ro(request): - test_name = "test_ro_hw" + test_name = "test_ro" cwd = Path(request.fspath).parent binary = Path(f'{cwd}/{test_name}/bin/{test_name}.xe') @@ -25,10 +25,17 @@ def test_ro(request): with FileLock("xrun.lock"): run_cmd = f'xrun --id 0 --io --args {binary} {outfile}' print("Running cmd: ", run_cmd) - stdout = subprocess.check_output(run_cmd, shell = True) +# stdout = subprocess.check_output(run_cmd, shell = True) - print('<', stdout, '>') + with open(outfile, "rb") as fd: xrun_output = fd.read() - print(xrun_output, file=sys.stderr) - assert(b'PASS' == xrun_output) + + run_cmd = f'../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid {outfile}' + test_output = subprocess.check_output(run_cmd, shell = True) + + assert(b'Warning' not in test_output) + assert(b'Passed chi square tests' in test_output) + assert(b'Passed length of longest repeated substring test' in test_output) + assert(b'Passed IID permutation tests' in test_output) + diff --git a/tests/test_ro/src/main.c b/tests/test_ro/src/main.c index d428ce5..2e32542 100644 --- a/tests/test_ro/src/main.c +++ b/tests/test_ro/src/main.c @@ -1,21 +1,23 @@ // Copyright 2025 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. +// This program collects 1,000,000 random bits +// These are stored compressed, and then written to a file as single bits in a byte file +// These can then be analysed off-line for randomness. + #include #include #include #include -#include #include -#include -#include #include "random.h" -#define N 128000 +#define N 1000000/32 unsigned int data[N]; int main(int argc, char *argv[]) { + int t0 = get_reference_time(); random_ro_init(); for(int i = 0; i < N; i++) { int j = 0; @@ -23,14 +25,22 @@ int main(int argc, char *argv[]) { do { int bit = random_ro_get_bit(); if (bit >= 0) { - bits = bits << 1; + bits |= bit << j; j++; } } while (j != 32); data[i] = bits; } + int t1 = get_reference_time(); + printf("%d %d\n", t1 - t0, (t1-t0)/(N*32)); FILE *fd = fopen(argv[1], "wb"); - fwrite(data, sizeof(data), 1, fd); + for(int i = 0; i < N; i++) { + unsigned char output_data[32]; + for(int j = 0; j < 32; j++) { + output_data[j] = (data[i] >> j)&1; + } + fwrite(output_data, sizeof(output_data), 1, fd); + } fclose(fd); return 0; } diff --git a/tests/test_xsim.py b/tests/test_xsim.py index 8e774c1..001a299 100644 --- a/tests/test_xsim.py +++ b/tests/test_xsim.py @@ -5,15 +5,9 @@ import subprocess import sys -def test_xsim_sha2(): +def test_xsim(request): bin_path = Path(__file__).parent / "test_pr" / "bin" - outfile = bin_path / "out.bin" - data = message.encode() - with open(infile, "wb") as fd: - fd.write(data) - run_cmd = "xsim " + "--args " + str(bin_path) + f"/test_pr.xe " + str(infile) + " " + str(outfile) + run_cmd = "xsim " + "--args " + str(bin_path) + f"/test_pr.xe" stdout = subprocess.check_output(run_cmd, cwd = bin_path, shell = True) - with open(outfile, "rb") as fd: - pass_str = fd.read() print(stdout) - assert(b'PASS' == pass_str) + assert(b'PASS\n' == stdout) From e757c6ce72ef25cf13a02dd23b51da345f34129d Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:08:02 +0100 Subject: [PATCH 03/11] Fix Jenkinsfile --- .gitmodules | 2 +- CHANGELOG.rst | 11 +++++++++++ Dockerfile | 5 +++++ Jenkinsfile | 19 ++++++++++++++----- README.rst | 28 +++++++++++++++++----------- examples/app_random/src/main.c | 4 +++- lib_random/api/random.h | 2 +- lib_random/lib_build_info.cmake | 11 +++++++++-- lib_random/module_build_info | 4 ++-- lib_random/src/pr_random.c | 4 ++-- lib_random/src/random_init.c | 2 +- lib_random/src/random_internal.h | 2 +- lib_random/src/ro_random.c | 10 +++++----- settings.yml | 2 +- tests/conftest.py | 2 +- tests/test_hw.py | 13 +++++++++---- tests/test_pr/src/main.c | 4 +++- tests/test_ro/src/main.c | 2 +- tests/test_xsim.py | 2 +- 19 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 Dockerfile diff --git a/.gitmodules b/.gitmodules index 34b883b..9132ac5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "submodules/--depth=1"] +[submodule "submodules/SP800-90B_EntropyAssessment"] path = submodules/SP800-90B_EntropyAssessment url = git@github.com:xmos/SP800-90B_EntropyAssessment.git diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7119070..1624701 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,17 @@ lib_random change log ===================== +1.3.1 +----- + + * FIXED: Compiler warnings with -Wconversion compiler flag. + +1.3.0 +----- + + * FIXED: HW-based random number generation for xs2 and xs3 devices + * ADDED: Ring oscillator bit generation API + 1.2.0 ----- diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d2ccf66 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM gcc:15-bookworm + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libbz2-dev libdivsufsort-dev libjsoncpp-dev libssl-dev libmpfr-dev diff --git a/Jenkinsfile b/Jenkinsfile index fc88ed8..83665de 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,6 @@ // This file relates to internal XMOS infrastructure and should be ignored by external users - -@Library('xmos_jenkins_shared_library@v0.42.0') _ + +@Library('xmos_jenkins_shared_library@v0.43.0') _ getApproval() pipeline { @@ -114,13 +114,22 @@ pipeline { } dir(REPO_NAME) { checkoutScmShallow() - } + sh 'git submodule update --init --recursive --depth 1' + } } } stage('Analysis SW') { + agent { + dockerfile { + filename "${REPO_NAME}/Dockerfile" + reuseNode true + } + } steps { - dir("${REPO_NAME}/submodules/SP800-90B_EntropyAssessment") { - sh "make" + dir("${REPO_NAME}/submodules/SP800-90B_EntropyAssessment/cpp") { + sh 'ls -l /lib/x86_64-linux-gnu/libdivsu*' + sh 'make -k CXXFLAGS="-std=c++11 -fopenmp -O2 -ffloat-store -march=native -I/usr/include/jsoncpp -static"' + sh 'ldd ./ea_iid' } } } diff --git a/README.rst b/README.rst index 6ed703d..6702265 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ lib_random: Random Number Generation #################################### :vendor: XMOS -:version: 1.2.0 +:version: 1.3.1 :scope: General Use :description: Random number generation :category: General Purpose @@ -22,35 +22,41 @@ This library provides random number generation. Features ******** - * Software and hardware based randomness - * Single single value and array generation - * Example application demonstrating usage +* Software and hardware based randomness +* Single single value and array generation +* Example application demonstrating usage ************ Known issues ************ - * None +* None + +**************** +Development repo +**************** + +* `lib_random `_ ************** -Required Tools +Required tools ************** - * XMOS XTC Tools: 15.3.0 +* XMOS XTC Tools: 15.3.0 ********************************* -Required Libraries (dependencies) +Required libraries (dependencies) ********************************* - * None +* None ************************* -Related Application Notes +Related application notes ************************* The following application notes use this library: - * None +* None ******* Support diff --git a/examples/app_random/src/main.c b/examples/app_random/src/main.c index 47256c6..db8717b 100644 --- a/examples/app_random/src/main.c +++ b/examples/app_random/src/main.c @@ -1,4 +1,4 @@ -// Copyright 2016-2025 XMOS LIMITED. +// Copyright 2016-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include @@ -26,6 +26,7 @@ int main() { printuintln(rand_buf[idx]); } + random_ro_init(); for (int i = 0; i < 10; ++i) { int bit; do { @@ -34,6 +35,7 @@ int main() { } while(bit < 0); printint(bit); } + random_ro_uninit(); printstr(" Done\n"); return 0; diff --git a/lib_random/api/random.h b/lib_random/api/random.h index 18b80e1..18b6bbc 100644 --- a/lib_random/api/random.h +++ b/lib_random/api/random.h @@ -1,4 +1,4 @@ -// Copyright 2016-2025 XMOS LIMITED. +// Copyright 2016-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _RANDOM_H_ #define _RANDOM_H_ diff --git a/lib_random/lib_build_info.cmake b/lib_random/lib_build_info.cmake index 5bbca63..9ba958a 100644 --- a/lib_random/lib_build_info.cmake +++ b/lib_random/lib_build_info.cmake @@ -1,7 +1,14 @@ set(LIB_NAME lib_random) -set(LIB_VERSION 1.2.0) +set(LIB_VERSION 1.3.1) set(LIB_DEPENDENT_MODULES "") set(LIB_INCLUDES api) -set(LIB_COMPILER_FLAGS -g -Os) +set(LIB_COMPILER_FLAGS -g -Os + -Wall + -Wextra + -Werror + -Wconversion + -Wdiv-by-zero + -Wfloat-equal + -Wsign-compare) XMOS_REGISTER_MODULE() diff --git a/lib_random/module_build_info b/lib_random/module_build_info index f1f9030..ad33747 100644 --- a/lib_random/module_build_info +++ b/lib_random/module_build_info @@ -9,6 +9,6 @@ # # You can also set MODULE_XCC_C_FLAGS, MODULE_XCC_XC_FLAGS etc.. -MODULE_XCC_FLAGS = -g -Os +MODULE_XCC_FLAGS = -g -Os -Wall -Wextra -Werror -VERSION = 1.2.0 +VERSION = 1.3.1 diff --git a/lib_random/src/pr_random.c b/lib_random/src/pr_random.c index cc0b457..567a879 100644 --- a/lib_random/src/pr_random.c +++ b/lib_random/src/pr_random.c @@ -1,4 +1,4 @@ -// Copyright 2016-2025 XMOS LIMITED. +// Copyright 2016-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include "random.h" @@ -16,7 +16,7 @@ unsigned random_get_random_number(random_generator_t *g) void random_get_random_bytes(random_generator_t *g, uint8_t in_buffer[], size_t byte_count) { - for (int i=0; i < byte_count; i++) + for (unsigned i=0; i < byte_count; i++) { in_buffer[i] = (uint8_t)random_get_random_number(g); } diff --git a/lib_random/src/random_init.c b/lib_random/src/random_init.c index 0771dd9..bf526c4 100644 --- a/lib_random/src/random_init.c +++ b/lib_random/src/random_init.c @@ -1,4 +1,4 @@ -// Copyright 2016-2025 XMOS LIMITED. +// Copyright 2016-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include "random.h" diff --git a/lib_random/src/random_internal.h b/lib_random/src/random_internal.h index 9018b56..a5de866 100644 --- a/lib_random/src/random_internal.h +++ b/lib_random/src/random_internal.h @@ -1,4 +1,4 @@ -// Copyright 2024-2025 XMOS LIMITED. +// Copyright 2024-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __random_internal_h__ diff --git a/lib_random/src/ro_random.c b/lib_random/src/ro_random.c index 6e3ff21..89a45d7 100644 --- a/lib_random/src/ro_random.c +++ b/lib_random/src/ro_random.c @@ -1,11 +1,11 @@ -// Copyright 2018-2025 XMOS LIMITED. +// Copyright 2018-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include #include "random.h" #include "random_internal.h" -static int last_time = 0; +static unsigned last_time = 0; void random_ro_init() { last_time = get_reference_time(); @@ -17,10 +17,10 @@ void random_ro_uninit() { } int random_ro_get_bit() { - int time, ro; + unsigned ro, time; time = get_reference_time(); - int diff = time - last_time; + unsigned diff = time - last_time; if (diff > RANDOM_RO_MIN_TIME_FOR_ONE_BIT) { random_ro_off(); @@ -29,5 +29,5 @@ int random_ro_get_bit() { last_time = time; return ro & 1; } - return -diff-1; + return -(int)diff-1; } diff --git a/settings.yml b/settings.yml index a529c3f..c03fe86 100644 --- a/settings.yml +++ b/settings.yml @@ -3,7 +3,7 @@ lib_name: lib_random project: '{{lib_name}}' title: '{{lib_name}}: Random number generation' -version: 1.2.0 +version: 1.3.1 documentation: exclude_patterns_path: doc/exclude_patterns.inc diff --git a/tests/conftest.py b/tests/conftest.py index dde5eab..7c54b8b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,4 @@ -# Copyright 2025 XMOS LIMITED. +# Copyright 2025-2026 XMOS LIMITED. # This Software is subject to the terms of the XMOS Public Licence: Version 1. import pytest diff --git a/tests/test_hw.py b/tests/test_hw.py index 657a39e..866ee6e 100644 --- a/tests/test_hw.py +++ b/tests/test_hw.py @@ -1,4 +1,4 @@ -# Copyright 2025 XMOS LIMITED. +# Copyright 2025-2026 XMOS LIMITED. # This Software is subject to the terms of the XMOS Public Licence: Version 1. import re import pytest @@ -27,12 +27,17 @@ def test_ro(request): print("Running cmd: ", run_cmd) # stdout = subprocess.check_output(run_cmd, shell = True) - - with open(outfile, "rb") as fd: - xrun_output = fd.read() + run_cmd = f'ldd ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' + test_output = subprocess.run(run_cmd, shell = True) + print(test_output) + + run_cmd = f'../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' + test_output = subprocess.run(run_cmd, shell = True) + print(test_output) run_cmd = f'../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid {outfile}' test_output = subprocess.check_output(run_cmd, shell = True) + print(test_output) assert(b'Warning' not in test_output) assert(b'Passed chi square tests' in test_output) diff --git a/tests/test_pr/src/main.c b/tests/test_pr/src/main.c index f6cc7aa..d41479a 100644 --- a/tests/test_pr/src/main.c +++ b/tests/test_pr/src/main.c @@ -1,6 +1,8 @@ -// Copyright 2025 XMOS LIMITED. +// Copyright 2025-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. +// This is a smoke test - just tests that there is no repeats in the first 100000 numbers. + #include #include #include diff --git a/tests/test_ro/src/main.c b/tests/test_ro/src/main.c index 2e32542..9a143ab 100644 --- a/tests/test_ro/src/main.c +++ b/tests/test_ro/src/main.c @@ -1,4 +1,4 @@ -// Copyright 2025 XMOS LIMITED. +// Copyright 2025-2026 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. // This program collects 1,000,000 random bits diff --git a/tests/test_xsim.py b/tests/test_xsim.py index 001a299..fadd82c 100644 --- a/tests/test_xsim.py +++ b/tests/test_xsim.py @@ -1,4 +1,4 @@ -# Copyright 2025 XMOS LIMITED. +# Copyright 2025-2026 XMOS LIMITED. # This Software is subject to the terms of the XMOS Public Licence: Version 1. from pathlib import Path From f9496577708c20dd057a7f003e1a528a4eeb615a Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:14:02 +0100 Subject: [PATCH 04/11] Fix Jenkinsfile --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 83665de..b94b0d4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -127,9 +127,10 @@ pipeline { } steps { dir("${REPO_NAME}/submodules/SP800-90B_EntropyAssessment/cpp") { - sh 'ls -l /lib/x86_64-linux-gnu/libdivsu*' - sh 'make -k CXXFLAGS="-std=c++11 -fopenmp -O2 -ffloat-store -march=native -I/usr/include/jsoncpp -static"' + sh '(cd /lib/x86_64-linux-gnu; tar cf - libdivsu*) | tar xf -' + sh 'make -k CXXFLAGS="-std=c++11 -fopenmp -O2 -ffloat-store -march=native -I/usr/include/jsoncpp -L$cwd"' sh 'ldd ./ea_iid' + sh 'ls -l' } } } From 7afad8c93dc1541d7a9a4ed0022eb1ce26ad5ca3 Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:23:39 +0100 Subject: [PATCH 05/11] Merge cnfl --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b94b0d4..bdbeb11 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -128,7 +128,7 @@ pipeline { steps { dir("${REPO_NAME}/submodules/SP800-90B_EntropyAssessment/cpp") { sh '(cd /lib/x86_64-linux-gnu; tar cf - libdivsu*) | tar xf -' - sh 'make -k CXXFLAGS="-std=c++11 -fopenmp -O2 -ffloat-store -march=native -I/usr/include/jsoncpp -L$cwd"' + sh 'make -k CXXFLAGS="-std=c++11 -fopenmp -O2 -ffloat-store -march=native -I/usr/include/jsoncpp -L$PWD"' sh 'ldd ./ea_iid' sh 'ls -l' } From ba4a776fe0ed0e3842da30941ec77445675bfb44 Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:29:22 +0100 Subject: [PATCH 06/11] Merge cnfl --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index bdbeb11..0990fc8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -129,7 +129,7 @@ pipeline { dir("${REPO_NAME}/submodules/SP800-90B_EntropyAssessment/cpp") { sh '(cd /lib/x86_64-linux-gnu; tar cf - libdivsu*) | tar xf -' sh 'make -k CXXFLAGS="-std=c++11 -fopenmp -O2 -ffloat-store -march=native -I/usr/include/jsoncpp -L$PWD"' - sh 'ldd ./ea_iid' + sh 'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ldd ./ea_iid' sh 'ls -l' } } From e3bb664a2046980d09cd32f32b561ac05fe64d94 Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:32:43 +0100 Subject: [PATCH 07/11] Fix Jenkinsfile --- tests/test_hw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_hw.py b/tests/test_hw.py index 866ee6e..b44095a 100644 --- a/tests/test_hw.py +++ b/tests/test_hw.py @@ -27,15 +27,15 @@ def test_ro(request): print("Running cmd: ", run_cmd) # stdout = subprocess.check_output(run_cmd, shell = True) - run_cmd = f'ldd ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' + run_cmd = f'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ldd ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' test_output = subprocess.run(run_cmd, shell = True) print(test_output) - run_cmd = f'../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' + run_cmd = f'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' test_output = subprocess.run(run_cmd, shell = True) print(test_output) - run_cmd = f'../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid {outfile}' + run_cmd = f'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid {outfile}' test_output = subprocess.check_output(run_cmd, shell = True) print(test_output) From 04607fae7663044a7fd05913e42488a3fe53c81b Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:48:37 +0100 Subject: [PATCH 08/11] Fix Jenkinsfile --- tests/test_hw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_hw.py b/tests/test_hw.py index b44095a..8dd5dc9 100644 --- a/tests/test_hw.py +++ b/tests/test_hw.py @@ -27,15 +27,15 @@ def test_ro(request): print("Running cmd: ", run_cmd) # stdout = subprocess.check_output(run_cmd, shell = True) - run_cmd = f'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ldd ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' + run_cmd = f'LD_LIBRARY_PATH=../submodules/SP800-90B_EntropyAssessment/cpp:$LD_LIBRARY_PATH ldd ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' test_output = subprocess.run(run_cmd, shell = True) print(test_output) - run_cmd = f'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' + run_cmd = f'LD_LIBRARY_PATH=../submodules/SP800-90B_EntropyAssessment/cpp:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' test_output = subprocess.run(run_cmd, shell = True) print(test_output) - run_cmd = f'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid {outfile}' + run_cmd = f'LD_LIBRARY_PATH=../submodules/SP800-90B_EntropyAssessment/cpp:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid {outfile}' test_output = subprocess.check_output(run_cmd, shell = True) print(test_output) From 8fec73f7d7221e317cca30bb23d4455a31170d53 Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:52:03 +0100 Subject: [PATCH 09/11] Fix Jenkinsfile --- tests/test_hw.py | 10 +--------- tests/test_ro/src/main.c | 3 ++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/test_hw.py b/tests/test_hw.py index 8dd5dc9..251d704 100644 --- a/tests/test_hw.py +++ b/tests/test_hw.py @@ -25,15 +25,7 @@ def test_ro(request): with FileLock("xrun.lock"): run_cmd = f'xrun --id 0 --io --args {binary} {outfile}' print("Running cmd: ", run_cmd) -# stdout = subprocess.check_output(run_cmd, shell = True) - - run_cmd = f'LD_LIBRARY_PATH=../submodules/SP800-90B_EntropyAssessment/cpp:$LD_LIBRARY_PATH ldd ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' - test_output = subprocess.run(run_cmd, shell = True) - print(test_output) - - run_cmd = f'LD_LIBRARY_PATH=../submodules/SP800-90B_EntropyAssessment/cpp:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid' - test_output = subprocess.run(run_cmd, shell = True) - print(test_output) + stdout = subprocess.check_output(run_cmd, shell = True) run_cmd = f'LD_LIBRARY_PATH=../submodules/SP800-90B_EntropyAssessment/cpp:$LD_LIBRARY_PATH ../submodules/SP800-90B_EntropyAssessment/cpp/ea_iid {outfile}' test_output = subprocess.check_output(run_cmd, shell = True) diff --git a/tests/test_ro/src/main.c b/tests/test_ro/src/main.c index 9a143ab..eb01153 100644 --- a/tests/test_ro/src/main.c +++ b/tests/test_ro/src/main.c @@ -12,7 +12,8 @@ #include #include "random.h" -#define N 1000000/32 +//#define N 1000000/32 +#define N 1024/32 unsigned int data[N]; From 648dd0154a764f83336a1a0cb7ca78740b98cf00 Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 14:55:11 +0100 Subject: [PATCH 10/11] Finalise test count --- tests/test_ro/src/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_ro/src/main.c b/tests/test_ro/src/main.c index eb01153..9a143ab 100644 --- a/tests/test_ro/src/main.c +++ b/tests/test_ro/src/main.c @@ -12,8 +12,7 @@ #include #include "random.h" -//#define N 1000000/32 -#define N 1024/32 +#define N 1000000/32 unsigned int data[N]; From a20c9361645da4aa8361587f097a39f7a04ad722 Mon Sep 17 00:00:00 2001 From: Henk Muller Date: Mon, 3 Aug 2026 15:16:44 +0100 Subject: [PATCH 11/11] Cleaning up --- Jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0990fc8..5006a93 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -118,7 +118,7 @@ pipeline { } } } - stage('Analysis SW') { + stage('Build Analysis SW') { agent { dockerfile { filename "${REPO_NAME}/Dockerfile" @@ -128,14 +128,12 @@ pipeline { steps { dir("${REPO_NAME}/submodules/SP800-90B_EntropyAssessment/cpp") { sh '(cd /lib/x86_64-linux-gnu; tar cf - libdivsu*) | tar xf -' - sh 'make -k CXXFLAGS="-std=c++11 -fopenmp -O2 -ffloat-store -march=native -I/usr/include/jsoncpp -L$PWD"' - sh 'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ldd ./ea_iid' - sh 'ls -l' + sh 'make -k' } } } - stage('HW tests') { + stage('Verif HW random') { steps { dir("${REPO_NAME}/tests") { withTools(params.TOOLS_VERSION) {