Skip to content

Commit b9649e2

Browse files
willieyzmkannwischer
authored andcommitted
Refactor: move basic test source into test/src/
- This commit refactor the test suite by moving the basic functional and test source files into the test/src/ directory. - The changes in this commit are: - The main test list (ALL_TESTS) in test/mk/components.mk is broken down into logical groups (BASIC_TESTS, ACVP_TESTS, BENCH_TESTS). - The build logic is updated to locate the basic tests in test/src/, while still finding acvp and bench tests in their original location. - The include paths within the moved source files (gen_KAT.c, test_mldsa.c, test_unit.c, test_alloc.c) are updated to reflect their new related path. - This commit also prepares for subsequent changes to move benchmarking and ACVP test sources into their own dedicated directories(acvp, bench). Signed-off-by: willieyz <willie.zhao@chelpis.com>
1 parent d426b21 commit b9649e2

File tree

8 files changed

+45
-42
lines changed

8 files changed

+45
-42
lines changed

Makefile.Microsoft_nmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ OPT = 0
3737
@if NOT EXIST $(MLDSA44_BUILD_DIR)\mldsa\fips202 mkdir $(MLDSA44_BUILD_DIR)\mldsa\fips202
3838
$(CC) $(CFLAGS) /D MLD_CONFIG_PARAMETER_SET=44 /c /Fo$(MLDSA44_BUILD_DIR)\mldsa\fips202\ $<
3939

40-
{test}.c{$(MLDSA44_BUILD_DIR)\test}.obj::
40+
{test\src}.c{$(MLDSA44_BUILD_DIR)\test}.obj::
4141
@if NOT EXIST $(MLDSA44_BUILD_DIR)\test mkdir $(MLDSA44_BUILD_DIR)\test
4242
$(CC) $(CFLAGS) /D MLD_CONFIG_PARAMETER_SET=44 /c /Fo$(MLDSA44_BUILD_DIR)\test\ $<
4343

@@ -50,7 +50,7 @@ OPT = 0
5050
@if NOT EXIST $(MLDSA65_BUILD_DIR)\mldsa\fips202 mkdir $(MLDSA65_BUILD_DIR)\mldsa\fips202
5151
$(CC) $(CFLAGS) /D MLD_CONFIG_PARAMETER_SET=65 /c /Fo$(MLDSA65_BUILD_DIR)\mldsa\fips202\ $<
5252

53-
{test}.c{$(MLDSA65_BUILD_DIR)\test}.obj::
53+
{test\src}.c{$(MLDSA65_BUILD_DIR)\test}.obj::
5454
@if NOT EXIST $(MLDSA65_BUILD_DIR)\test mkdir $(MLDSA65_BUILD_DIR)\test
5555
$(CC) $(CFLAGS) /D MLD_CONFIG_PARAMETER_SET=65 /c /Fo$(MLDSA65_BUILD_DIR)\test\ $<
5656

@@ -63,7 +63,7 @@ OPT = 0
6363
@if NOT EXIST $(MLDSA87_BUILD_DIR)\mldsa\fips202 mkdir $(MLDSA87_BUILD_DIR)\mldsa\fips202
6464
$(CC) $(CFLAGS) /D MLD_CONFIG_PARAMETER_SET=87 /c /Fo$(MLDSA87_BUILD_DIR)\mldsa\fips202\ $<
6565

66-
{test}.c{$(MLDSA87_BUILD_DIR)\test}.obj::
66+
{test\src}.c{$(MLDSA87_BUILD_DIR)\test}.obj::
6767
@if NOT EXIST $(MLDSA87_BUILD_DIR)\test mkdir $(MLDSA87_BUILD_DIR)\test
6868
$(CC) $(CFLAGS) /D MLD_CONFIG_PARAMETER_SET=87 /c /Fo$(MLDSA87_BUILD_DIR)\test\ $<
6969

test/mk/components.mk

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ ifeq ($(OPT),1)
1414
CFLAGS += -DMLD_CONFIG_USE_NATIVE_BACKEND_ARITH -DMLD_CONFIG_USE_NATIVE_BACKEND_FIPS202
1515
endif
1616

17-
ALL_TESTS = test_mldsa test_unit acvp_mldsa bench_mldsa bench_components_mldsa gen_KAT test_stack test_alloc test_rng_fail
17+
BASIC_TESTS = test_mldsa gen_KAT test_stack
18+
ACVP_TESTS = acvp_mldsa
19+
BENCH_TESTS = bench_mldsa bench_components_mldsa
20+
UNIT_TESTS = test_unit
21+
ALLOC_TESTS = test_alloc
22+
RNG_FAIL_TESTS = test_rng_fail
23+
ALL_TESTS = $(BASIC_TESTS) $(ACVP_TESTS) $(BENCH_TESTS) $(UNIT_TESTS) $(ALLOC_TESTS) $(RNG_FAIL_TESTS)
1824

1925
MLDSA44_DIR = $(BUILD_DIR)/mldsa44
2026
MLDSA65_DIR = $(BUILD_DIR)/mldsa65
@@ -86,13 +92,13 @@ $(MLDSA44_DIR)/bin/test_stack44: CFLAGS += -Imldsa -fstack-usage
8692
$(MLDSA65_DIR)/bin/test_stack65: CFLAGS += -Imldsa -fstack-usage
8793
$(MLDSA87_DIR)/bin/test_stack87: CFLAGS += -Imldsa -fstack-usage
8894

89-
$(MLDSA44_DIR)/test/test_alloc.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"
90-
$(MLDSA65_DIR)/test/test_alloc.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"
91-
$(MLDSA87_DIR)/test/test_alloc.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"
95+
$(MLDSA44_DIR)/test/src/test_alloc.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"
96+
$(MLDSA65_DIR)/test/src/test_alloc.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"
97+
$(MLDSA87_DIR)/test/src/test_alloc.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_alloc_config.h\"
9298

93-
$(MLDSA44_DIR)/test/test_rng_fail.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_rng_fail_config.h\"
94-
$(MLDSA65_DIR)/test/test_rng_fail.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_rng_fail_config.h\"
95-
$(MLDSA87_DIR)/test/test_rng_fail.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_rng_fail_config.h\"
99+
$(MLDSA44_DIR)/test/src/test_rng_fail.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_rng_fail_config.h\"
100+
$(MLDSA65_DIR)/test/src/test_rng_fail.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_rng_fail_config.h\"
101+
$(MLDSA87_DIR)/test/src/test_rng_fail.c.o: CFLAGS += -DMLD_CONFIG_FILE=\"../test/configs/test_rng_fail_config.h\"
96102

97103
$(MLDSA44_DIR)/bin/test_unit44: CFLAGS += -DMLD_STATIC_TESTABLE= -Wno-missing-prototypes
98104
$(MLDSA65_DIR)/bin/test_unit65: CFLAGS += -DMLD_STATIC_TESTABLE= -Wno-missing-prototypes
@@ -118,43 +124,40 @@ $(MLDSA87_DIR)/bin/%: CFLAGS += -DMLD_CONFIG_PARAMETER_SET=87
118124
# Link tests with respective library (except test_unit which includes sources directly)
119125
define ADD_SOURCE
120126
$(BUILD_DIR)/$(1)/bin/$(2)$(subst mldsa,,$(1)): LDLIBS += -L$(BUILD_DIR) -l$(1)
121-
$(BUILD_DIR)/$(1)/bin/$(2)$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/$(2).c.o $(BUILD_DIR)/lib$(1).a
127+
$(BUILD_DIR)/$(1)/bin/$(2)$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/$(3)$(2).c.o $(BUILD_DIR)/lib$(1).a
122128
endef
123129

124130

125131
# Special rule for test_unit - link against unit libraries with exposed internal functions
126132
define ADD_SOURCE_UNIT
127133
$(BUILD_DIR)/$(1)/bin/test_unit$(subst mldsa,,$(1)): LDLIBS += -L$(BUILD_DIR) -l$(1)_unit
128-
$(BUILD_DIR)/$(1)/bin/test_unit$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/test_unit.c.o $(BUILD_DIR)/lib$(1)_unit.a $(call MAKE_OBJS, $(BUILD_DIR)/$(1), $(wildcard test/notrandombytes/*.c))
134+
$(BUILD_DIR)/$(1)/bin/test_unit$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/src/test_unit.c.o $(BUILD_DIR)/lib$(1)_unit.a $(call MAKE_OBJS, $(BUILD_DIR)/$(1), $(wildcard test/notrandombytes/*.c))
129135
endef
130136

131137
# Special rule for test_alloc - link against alloc libraries with custom alloc config
132138
define ADD_SOURCE_ALLOC
133139
$(BUILD_DIR)/$(1)/bin/test_alloc$(subst mldsa,,$(1)): LDLIBS += -L$(BUILD_DIR) -l$(1)_alloc
134-
$(BUILD_DIR)/$(1)/bin/test_alloc$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/test_alloc.c.o $(BUILD_DIR)/lib$(1)_alloc.a $(call MAKE_OBJS, $(BUILD_DIR)/$(1), $(wildcard test/notrandombytes/*.c))
140+
$(BUILD_DIR)/$(1)/bin/test_alloc$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/src/test_alloc.c.o $(BUILD_DIR)/lib$(1)_alloc.a $(call MAKE_OBJS, $(BUILD_DIR)/$(1), $(wildcard test/notrandombytes/*.c))
135141
endef
136142

137143
# Special rule for test_rng_fail - link against rng_fail libraries with custom randombytes config
138144
define ADD_SOURCE_RNG_FAIL
139145
$(BUILD_DIR)/$(1)/bin/test_rng_fail$(subst mldsa,,$(1)): LDLIBS += -L$(BUILD_DIR) -l$(1)_rng_fail
140-
$(BUILD_DIR)/$(1)/bin/test_rng_fail$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/test_rng_fail.c.o $(BUILD_DIR)/lib$(1)_rng_fail.a
146+
$(BUILD_DIR)/$(1)/bin/test_rng_fail$(subst mldsa,,$(1)): $(BUILD_DIR)/$(1)/test/src/test_rng_fail.c.o $(BUILD_DIR)/lib$(1)_rng_fail.a
141147
endef
142148

143149
$(foreach scheme,mldsa44 mldsa65 mldsa87, \
144-
$(foreach test,$(filter-out test_unit test_alloc test_rng_fail,$(ALL_TESTS)), \
145-
$(eval $(call ADD_SOURCE,$(scheme),$(test))) \
150+
$(foreach test,$(ACVP_TESTS), \
151+
$(eval $(call ADD_SOURCE,$(scheme),$(test),)) \
152+
) \
153+
$(foreach test,$(BENCH_TESTS), \
154+
$(eval $(call ADD_SOURCE,$(scheme),$(test),)) \
155+
) \
156+
$(foreach test,$(BASIC_TESTS), \
157+
$(eval $(call ADD_SOURCE,$(scheme),$(test),src/)) \
146158
) \
147-
)
148-
149-
$(foreach scheme,mldsa44 mldsa65 mldsa87, \
150159
$(eval $(call ADD_SOURCE_UNIT,$(scheme))) \
151-
)
152-
153-
$(foreach scheme,mldsa44 mldsa65 mldsa87, \
154160
$(eval $(call ADD_SOURCE_ALLOC,$(scheme))) \
155-
)
156-
157-
$(foreach scheme,mldsa44 mldsa65 mldsa87, \
158161
$(eval $(call ADD_SOURCE_RNG_FAIL,$(scheme))) \
159162
)
160163

test/gen_KAT.c renamed to test/src/gen_KAT.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include <stddef.h>
77
#include <stdio.h>
88
#include <string.h>
9-
#include "../mldsa/src/fips202/fips202.h"
10-
#include "../mldsa/src/sign.h"
11-
#include "../mldsa/src/sys.h"
12-
#include "notrandombytes/notrandombytes.h"
9+
#include "../../mldsa/src/fips202/fips202.h"
10+
#include "../../mldsa/src/sign.h"
11+
#include "../../mldsa/src/sys.h"
12+
#include "../notrandombytes/notrandombytes.h"
1313

1414
#if defined(MLD_SYS_WINDOWS)
1515
#include <fcntl.h>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
/* Expose declaration of allocator (normally internal) */
1111
#define MLD_BUILD_INTERNAL
12-
#include "../mldsa/mldsa_native.h"
13-
#include "../mldsa/src/common.h"
14-
#include "notrandombytes/notrandombytes.h"
12+
#include "../../mldsa/mldsa_native.h"
13+
#include "../../mldsa/src/common.h"
14+
#include "../notrandombytes/notrandombytes.h"
1515

1616
/*
1717
* This test checks that
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include <stddef.h>
77
#include <stdio.h>
88
#include <string.h>
9-
#include "../mldsa/src/sign.h"
10-
#include "../mldsa/src/sys.h"
11-
#include "notrandombytes/notrandombytes.h"
9+
#include "../../mldsa/src/sign.h"
10+
#include "../../mldsa/src/sys.h"
11+
#include "../notrandombytes/notrandombytes.h"
1212

1313
#ifndef NTESTS
1414
#define NTESTS 100
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
/* Expose declaration of randombytes (normally internal) */
1010
#define MLD_BUILD_INTERNAL
11-
#include "../mldsa/mldsa_native.h"
12-
#include "../mldsa/src/common.h"
13-
#include "notrandombytes/notrandombytes.h"
11+
#include "../../mldsa/mldsa_native.h"
12+
#include "../../mldsa/src/common.h"
13+
#include "../notrandombytes/notrandombytes.h"
1414

1515
/*
1616
* This test checks that we handle randombytes failures correctly by:
File renamed without changes.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include <stddef.h>
77
#include <stdio.h>
88
#include <string.h>
9-
#include "notrandombytes/notrandombytes.h"
9+
#include "../notrandombytes/notrandombytes.h"
1010

11-
#include "../mldsa/src/poly.h"
12-
#include "../mldsa/src/poly_kl.h"
13-
#include "../mldsa/src/polyvec.h"
11+
#include "../../mldsa/src/poly.h"
12+
#include "../../mldsa/src/poly_kl.h"
13+
#include "../../mldsa/src/polyvec.h"
1414

1515
#ifndef NUM_RANDOM_TESTS
1616
#ifdef MLDSA_DEBUG

0 commit comments

Comments
 (0)