Skip to content
Merged
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
20 changes: 6 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,22 @@ jobs:
echo "::endgroup::"
}

make_platform stm32f4discovery
make_platform nucleo-f767zi
make_platform nucleo-f207zg
export -f make_platform
tests --list-platforms | grep -v "mps2" | xargs -I {} bash -c 'make_platform "$@"' _ {}

- name: Build for emulation on QEMU
shell: nix develop .#ci -c bash -e {0}
run: |
output=$(make emulate) && true
if [[ $? != 0 ]]; then
echo "::error title={Build failed}::$output" 1>&2
fi
- name: Functional test
id: func_test
shell: nix develop .#ci -c bash -e {0}
run: |
tests func -v mps2-an386
tests-qemu func
- name: Speed test
id: speed_test
shell: nix develop .#ci -c bash -e {0}
if: |
success()
|| steps.func_test.conclusion == 'failure'
run: |
tests speed -v mps2-an386
tests-qemu speed
- name: Stack test
id: stack_test
shell: nix develop .#ci -c bash -e {0}
Expand All @@ -67,7 +59,7 @@ jobs:
|| steps.func_test.conclusion == 'failure'
|| steps.speed_test.conclusion == 'failure'
run: |
tests stack -v mps2-an386
tests-qemu stack
- name: Nistkat test
shell: nix develop .#ci -c bash -e {0}
if: |
Expand All @@ -76,4 +68,4 @@ jobs:
|| steps.speed_test.conclusion == 'failure'
|| steps.stack_test.conclusion == 'failure'
run: |
tests nistkat -v mps2-an386
tests-qemu nistkat
15 changes: 1 addition & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# SPDX-License-Identifier: Apache-2.0
# temporary Makefile to be replaced by Arm cross-compilation

.PHONY: all

Expand All @@ -19,21 +18,9 @@ nistkat: $(foreach scheme,$(KEM_SCHEMES),$(scheme)-nistkat)

.PHONY: emulate clean

emulate%: PLATFORM = mps2-an386
emulate%: NTESTS = 10
emulate%: override RNG = NOTRAND

emulate\ nistkat: override RNG = NISTKAT

# emulate for test, speed, stack
emulate%:
$(Q)$(MAKE) PLATFORM=$(PLATFORM) NTESTS=$(NTESTS) RNG=$(RNG) $*

emulate\ run: PLATFORM=mps2-an386
emulate\ run:
emulate:
$(Q)qemu-system-arm -machine $(PLATFORM) -nographic -semihosting -kernel $(ELF_FILE)


clean:
$(Q)rm -rf elf/
$(Q)rm -rf bin/
Expand Down
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,17 @@ For further details, please refer to [scripts/README.md](scripts/README.md)

## Running tests and benchmarks

The build system compiles tests and benchmarks for each mlkem parameter set on specified platform, currently supported platform includes `stm32f4discovery` and `mps2-an386` (could be simulated with the `QEMU` simulator).
The build system compiles tests and benchmarks for each mlkem parameter set on specified platform, supported platform can be found by running `tests --list-platforms`.
The PLATFORM configuration is optional, with the default platform set to `stm32f4discovery`.

For example,
- `make [PLATFORM=<PLATFORM_NAME>] bin/mlkem768-test.hex` assembles the `mlkem768` binary performing functional tests.
- `make [PLATFORM=<PLATFORM_NAME>] bin/mlkem1024-speed.hex` assembles the `mlkem-1024` speed benchmark binary.
- `make [PLATFORM=<PLATFORM_NAME>] test` assembles all binaries for functional tests.
- `make [PLATFORM=<PLATFORM_NAME>] speed` assembles all binaries for speed benchmarking
- `make [PLATFORM=<PLATFORM_NAME>] stack` assembles all binaries for stack benchmarking
- `make [PLATFORM=<PLATFORM_NAME>] [RNG=HAL|NOTRAND] test` assembles all binaries for functional tests.
- `make [PLATFORM=<PLATFORM_NAME>] [RNG=HAL|NOTRAND] speed` assembles all binaries for speed benchmarking
- `make [PLATFORM=<PLATFORM_NAME>] [RNG=HAL|NOTRAND] stack` assembles all binaries for stack benchmarking
- `make [PLATFORM=<PLATFORM_NAME>] RNG=NISTKAT nistkat` assembles all binaries for nistkat
- `make [PLATFORM=<PLATFORM_NAME>] (all)` assembles all the above targets for all parameter sets.

- `make emulate` build binaries for emulating `mps2-an386` on `QEMU` of test, speed, stack
- `make "emulate [test|speed|stack|nistkat]"` build binaries of test, speed, stack or nistkat for emulating `mps2-an386` on `QEMU`
- `make "emulate run" ELF_FILE=<ELF_FILE_NAME>` run emulatation for the file on `QEMU`
- `make emulate` run emulatation for the binary file on `QEMU`
- `make clean` cleans up intermediate artifacts

### Manual testing on board
Expand All @@ -104,6 +100,7 @@ Make sure to run `make clean` between running tests on QEMU or on board or runni
Usage: tests [OPTIONS] COMMAND [ARGS]...

Options:
--list-platforms List the supported platforms
--help Show this message and exit.

Commands:
Expand All @@ -119,13 +116,14 @@ func/speed tests depends on the iteration parameter, which is passed to the test

```
▶ tests func --help
Usage: tests func [OPTIONS]
Usage: tests func [OPTIONS] {stm32f4discovery|mps2-an386|nucleo-f767zi|mps2-an
500|nucleo-f207zg|mps2-an385}

Options:
-cfg, --platform-cfg PATH Configuration file of the specified platform
[default: hal/stm32f4discovery.cfg]
-v, --verbose Show verbose output or not
-e, --emulate Emulate on the QEMU or not
-i, --iterations INTEGER Number of tests [default: 1]
--help Show this message and exit.
-v, --verbose Show verbose output or not
-u, --uart PATH TTY serial device for UART, default to the 1st
serial device connected to your board or an empty
string
-i, --iterations INTEGER Number of tests [default: 1]
--help Show this message and exit.
```
6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
libopencm3 = pkgs.callPackage ./libopencm3.nix {
targets = [ "stm32/f2" "stm32/f4" "stm32/f7" ];
};
mbed-os = pkgs.callPackage ./mbed-os.nix {
targets = [ "TARGET_MPS2_M3" "TARGET_MPS2_M4" "TARGET_MPS2_M7" ];
};
core = builtins.attrValues {
libopencm3 = libopencm3;
mbed-os = mbed-os;

inherit (pkgs)
# formatter & linters
Expand Down Expand Up @@ -56,6 +60,7 @@

shellHook = ''
export OPENCM3_DIR=${libopencm3}
export MBED_OS_DIR=${mbed-os}
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
eval "$(_TESTS_COMPLETE=bash_source tests)"
'';
Expand All @@ -66,6 +71,7 @@

shellHook = ''
export OPENCM3_DIR=${libopencm3}
export MBED_OS_DIR=${mbed-os}
export PATH=$PWD/scripts:$PWD/scripts/ci:$PATH
'';
};
Expand Down
8 changes: 8 additions & 0 deletions hal/hal-mps2.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
#include <hal.h>
#if defined(MPS2_AN385)
#include <CMSDK_CM3.h>
#elif defined(MPS2_AN386)
#include <CMSDK_CM4.h>
#elif defined(MPS2_AN500)
#include <CMSDK_CM7.h>
#else
#error Unsupported mps2 board
#endif

#define BAUD 38400

Expand Down
2 changes: 1 addition & 1 deletion hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>
#include <stdlib.h>

#if !defined(MPS2_AN386)
#if !defined(MPS2)
#define SERIAL_MARKER() {\
hal_send_str("$");\
}
Expand Down
Loading