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
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
yq;

inherit (pkgs.python311Packages)
black
pyserial# 3.5
click;
};
Expand Down
9 changes: 8 additions & 1 deletion scripts/ci/lint
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ checkerr()

if [[ ${#1} != 0 ]]; then
echo "$1" | while read -r file line; do
echo "::error file={$file},line={${line:-1}},title={Format error}::$file require to be formatted"
echo "::error file=$file,line=${line:-1},title=Format error::$file require to be formatted"
done
SUCCESS=false
fi
Expand All @@ -35,6 +35,13 @@ echo "::group::Linting shell scripts with shfmt"
checkerr "$(shfmt -s -l -i 2 -ci -fn $(shfmt -f $(git grep -l '' :/)))"
echo "::endgroup::"

echo "::group::Linting python scripts with black"
if ! diff=$(black --check --diff -q --include scripts/tests "$ROOT"); then
echo "::error title=Format error::$diff"
SUCCESS=false
fi
echo "::endgroup::"

echo "::group::Linting c files with astyle"
checkerr "$(astyle $(git ls-files ":/*.c" ":/*.h") --options="$ROOT/.astylerc" --dry-run --formatted | awk '{print $2}')"
echo "::endgroup::"
Expand Down
3 changes: 3 additions & 0 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ nixpkgs-fmt "$ROOT"
info "Formatting shell scripts"
shfmt -s -w -l -i 2 -ci -fn $(shfmt -f $(git grep -l '' :/))

info "Formatting python scripts"
black --include scripts/tests "$ROOT"

info "Formatting c files"
astyle $(git ls-files ":/*.c" ":/*.h") --options="$ROOT/.astylerc" --formatted | awk '{print $2}'

Expand Down
38 changes: 26 additions & 12 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ def serial_ports():
return ports


def usbdev():
port = next(iter(serial_ports()), None)
def default_serial_port():
return next(iter(serial_ports()), None)

if port is None:

def usbdev(uart):
if uart is None:
raise DeviceError("No available usb device")

dev = serial.Serial(port, 38400)
dev = serial.Serial(uart, 38400)
return dev


Expand Down Expand Up @@ -118,7 +120,6 @@ class PLATFORM(Enum):


class RecursiveNamespace(SimpleNamespace):

@staticmethod
def map_entry(entry):
if isinstance(entry, dict):
Expand Down Expand Up @@ -159,6 +160,7 @@ def base_test(
expect_proc,
actual_proc,
verbose,
uart,
):
"""
test_type: test, speed, stack, nistkat
Expand Down Expand Up @@ -206,7 +208,7 @@ def base_test(
logging.info(f"Check {file} passed")

if platform_cfg is not None:
dev = usbdev()
dev = usbdev(uart)

for scheme in ["mlkem512", "mlkem768", "mlkem1024"]:
file = f"elf/{scheme}-{test_type}.elf"
Expand Down Expand Up @@ -246,6 +248,14 @@ _shared_options = [
type=bool,
help="Show verbose output or not",
),
click.option(
"-u",
"--uart",
type=click.Path(),
show_default=True,
default=default_serial_port(),
help="TTY serial device for UART, default to the 1st serial device connected to your board or an empty string",
),
click.argument(
"platform",
nargs=1,
Expand All @@ -269,9 +279,9 @@ def add_options(options):
type=click.Path(),
help="The binary hex file that you wanted to test.",
)
def run(platform, bin, verbose):
def run(platform, bin, verbose, uart):
config_logger(True)
dev = usbdev()
dev = usbdev(uart)

try:
result = asyncio.run(
Expand All @@ -289,7 +299,7 @@ def run(platform, bin, verbose):
)
@add_options(_shared_options)
@click.option("-i", "--iterations", default=1, type=int, help="Number of tests")
def func(platform, iterations, verbose):
def func(platform, iterations, verbose, uart):
try:
base_test(
TEST_TYPE.TEST,
Expand All @@ -298,6 +308,7 @@ def func(platform, iterations, verbose):
lambda _: iterations * 3,
lambda output: count(output, "OK"),
verbose,
uart,
)
except asyncio.CancelledError:
pass
Expand All @@ -306,7 +317,7 @@ def func(platform, iterations, verbose):
@click.command(short_help="Run speed tests", context_settings={"show_default": True})
@add_options(_shared_options)
@click.option("-i", "--iterations", default=1, type=int, help="Number of tests")
def speed(platform, iterations, verbose):
def speed(platform, iterations, verbose, uart):
try:
base_test(
TEST_TYPE.SPEED,
Expand All @@ -315,14 +326,15 @@ def speed(platform, iterations, verbose):
lambda _: 1,
lambda output: count(output, "OK"),
verbose,
uart,
)
except asyncio.CancelledError:
pass


@click.command(short_help="Run stack tests", context_settings={"show_default": True})
@add_options(_shared_options)
def stack(platform, verbose):
def stack(platform, verbose, uart):
try:
base_test(
TEST_TYPE.STACK,
Expand All @@ -331,14 +343,15 @@ def stack(platform, verbose):
lambda _: 1,
lambda output: count(output, "OK"),
verbose,
uart,
)
except asyncio.CancelledError:
pass


@click.command(short_help="Run nistkat tests", context_settings={"show_default": True})
@add_options(_shared_options)
def nistkat(platform, verbose):
def nistkat(platform, verbose, uart):
def scheme_hash(scheme):
result = subprocess.run(
[
Expand All @@ -364,6 +377,7 @@ def nistkat(platform, verbose):
scheme_hash,
lambda output: str(output, encoding="utf-8").strip().lower(),
verbose,
uart,
)
except asyncio.CancelledError:
pass
Expand Down