Skip to content

Commit a2d900d

Browse files
committed
Add alloc test to scripts/tests and CI
Signed-off-by: Hanno Becker <[email protected]>
1 parent d97eb3d commit a2d900d

File tree

7 files changed

+87
-3
lines changed

7 files changed

+87
-3
lines changed

.github/actions/config-variations/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ runs:
6161
opt: ${{ inputs.opt }}
6262
extra_env: 'ASAN_OPTIONS=detect_leaks=1'
6363
examples: false # Some examples use a custom config themselves
64+
alloc: false # Requires custom config
6465
- name: "Custom zeroization (explicit_bzero)"
6566
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'custom-zeroize') }}
6667
uses: ./.github/actions/multi-functest
@@ -74,6 +75,7 @@ runs:
7475
acvp: true
7576
opt: ${{ inputs.opt }}
7677
examples: false # Some examples use a custom config themselves
78+
alloc: false # Requires custom config
7779
- name: "Custom native capability functions (static ON)"
7880
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'native-cap-ON') }}
7981
uses: ./.github/actions/multi-functest
@@ -87,6 +89,7 @@ runs:
8789
acvp: true
8890
opt: ${{ inputs.opt }}
8991
examples: false # Some examples use a custom config themselves
92+
alloc: false # Requires custom config
9093
- name: "Custom native capability functions (static OFF)"
9194
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'native-cap-OFF') }}
9295
uses: ./.github/actions/multi-functest
@@ -100,6 +103,7 @@ runs:
100103
acvp: true
101104
opt: ${{ inputs.opt }}
102105
examples: false # Some examples use a custom config themselves
106+
alloc: false # Requires custom config
103107
- name: "Custom native capability functions (ID_AA64PFR1_EL1 detection)"
104108
if: ${{ (inputs.tests == 'all' || contains(inputs.tests, 'native-cap-ID_AA64PFR1_EL1')) && runner.os == 'Linux' && runner.arch == 'ARM64' }}
105109
uses: ./.github/actions/multi-functest
@@ -113,6 +117,7 @@ runs:
113117
acvp: true
114118
opt: ${{ inputs.opt }}
115119
examples: false # Some examples use a custom config themselves
120+
alloc: false # Requires custom config
116121
- name: "Custom native capability functions (CPUID AVX2 detection)"
117122
if: ${{ (inputs.tests == 'all' || contains(inputs.tests, 'native-cap-CPUID_AVX2')) && runner.os == 'Linux' && runner.arch == 'X64' }}
118123
uses: ./.github/actions/multi-functest
@@ -126,6 +131,7 @@ runs:
126131
acvp: true
127132
opt: ${{ inputs.opt }}
128133
examples: false # Some examples use a custom config themselves
134+
alloc: false # Requires custom config
129135
- name: "No ASM"
130136
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'no-asm') }}
131137
uses: ./.github/actions/multi-functest
@@ -139,6 +145,7 @@ runs:
139145
acvp: true
140146
opt: ${{ inputs.opt }}
141147
examples: false # Some examples use a custom config themselves
148+
alloc: false # Requires custom config
142149
- name: "Serial FIPS202 (no batched Keccak)"
143150
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'serial-fips202') }}
144151
uses: ./.github/actions/multi-functest
@@ -152,6 +159,7 @@ runs:
152159
acvp: true
153160
opt: ${{ inputs.opt }}
154161
examples: false # Some examples use a custom config themselves
162+
alloc: false # Requires custom config
155163
- name: "Custom randombytes"
156164
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'custom-randombytes') }}
157165
uses: ./.github/actions/multi-functest
@@ -165,6 +173,7 @@ runs:
165173
acvp: true
166174
opt: ${{ inputs.opt }}
167175
examples: false # Some examples use a custom config themselves
176+
alloc: false # Requires custom config
168177
- name: "Custom memcpy"
169178
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'custom-memcpy') }}
170179
uses: ./.github/actions/multi-functest
@@ -178,6 +187,7 @@ runs:
178187
acvp: true
179188
opt: ${{ inputs.opt }}
180189
examples: false # Some examples use a custom config themselves
190+
alloc: false # Requires custom config
181191
- name: "Custom memset"
182192
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'custom-memset') }}
183193
uses: ./.github/actions/multi-functest
@@ -191,6 +201,7 @@ runs:
191201
acvp: true
192202
opt: ${{ inputs.opt }}
193203
examples: false # Some examples use a custom config themselves
204+
alloc: false # Requires custom config
194205
- name: "Custom stdlib (memcpy + memset)"
195206
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'custom-stdlib') }}
196207
uses: ./.github/actions/multi-functest
@@ -204,3 +215,4 @@ runs:
204215
acvp: true
205216
opt: ${{ inputs.opt }}
206217
examples: false # Some examples use a custom config themselves
218+
alloc: false # Requires custom config

.github/actions/functest/action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ inputs:
5757
stack:
5858
description: Determine whether to run stack analysis or not
5959
default: "false"
60+
alloc:
61+
description: Determine whether to run alloc tests or not
62+
default: "true"
6063
extra_args:
6164
description: Additional arguments to pass to the tests script
6265
default: ""
@@ -77,6 +80,7 @@ runs:
7780
echo ACVP="${{ inputs.acvp == 'true' && 'acvp' || 'no-acvp' }}" >> $GITHUB_ENV
7881
echo EXAMPLES="${{ inputs.examples == 'true' && 'examples' || 'no-examples' }}" >> $GITHUB_ENV
7982
echo STACK="${{ inputs.stack == 'true' && 'stack' || 'no-stack' }}" >> $GITHUB_ENV
83+
echo ALLOC="${{ inputs.alloc == 'true' && 'alloc' || 'no-alloc' }}" >> $GITHUB_ENV
8084
- name: Setup nix
8185
uses: ./.github/actions/setup-shell
8286
with:
@@ -107,11 +111,11 @@ runs:
107111
- $(python3 --version)
108112
- $(${{ inputs.cross_prefix }}${CC} --version | grep -m1 "")
109113
EOF
110-
- name: ${{ env.MODE }} ${{ inputs.opt }} tests (${{ env.FUNC }}, ${{ env.KAT }}, ${{ env.EXAMPLES }}, ${{ env.STACK }}, ${{ env.UNIT }})
114+
- name: ${{ env.MODE }} ${{ inputs.opt }} tests (${{ env.FUNC }}, ${{ env.KAT }}, ${{ env.EXAMPLES }}, ${{ env.STACK }}, ${{ env.UNIT }}, ${{ env.ALLOC }})
111115
shell: ${{ env.SHELL }}
112116
run: |
113117
make clean
114-
${{ inputs.extra_env }} ./scripts/tests all ${{ inputs.check_namespace == 'true' && '--check-namespace' || ''}} --exec-wrapper="${{ inputs.exec_wrapper }}" --cross-prefix="${{ inputs.cross_prefix }}" --cflags="${{ inputs.cflags }}" --ldflags="${{ inputs.ldflags }}" --opt=${{ inputs.opt }} --${{ env.FUNC }} --${{ env.KAT }} --${{ env.ACVP }} --${{ env.EXAMPLES }} --${{ env.STACK }} --${{ env.UNIT }} -v ${{ inputs.extra_args }}
118+
${{ inputs.extra_env }} ./scripts/tests all ${{ inputs.check_namespace == 'true' && '--check-namespace' || ''}} --exec-wrapper="${{ inputs.exec_wrapper }}" --cross-prefix="${{ inputs.cross_prefix }}" --cflags="${{ inputs.cflags }}" --ldflags="${{ inputs.ldflags }}" --opt=${{ inputs.opt }} --${{ env.FUNC }} --${{ env.KAT }} --${{ env.ACVP }} --${{ env.EXAMPLES }} --${{ env.STACK }} --${{ env.UNIT }} --${{ env.ALLOC }} -v ${{ inputs.extra_args }}
115119
- name: Post ${{ env.MODE }} Tests
116120
shell: ${{ env.SHELL }}
117121
if: success() || failure()

.github/actions/multi-functest/action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ inputs:
5454
stack:
5555
description: Determine whether to run stack analysis or not
5656
default: "false"
57+
alloc:
58+
description: Determine whether to run alloc tests or not
59+
default: "true"
5760
extra_args:
5861
description: Additional arguments to pass to the tests script
5962
default: ""
@@ -82,6 +85,7 @@ runs:
8285
examples: ${{ inputs.examples }}
8386
check_namespace: ${{ inputs.check_namespace }}
8487
stack: ${{ inputs.stack }}
88+
alloc: ${{ inputs.alloc }}
8589
extra_args: ${{ inputs.extra_args }}
8690
extra_env: ${{ inputs.extra_env }}
8791
- name: Cross x86_64 Tests
@@ -105,6 +109,7 @@ runs:
105109
examples: ${{ inputs.examples }}
106110
check_namespace: ${{ inputs.check_namespace }}
107111
stack: ${{ inputs.stack }}
112+
alloc: ${{ inputs.alloc }}
108113
extra_args: ${{ inputs.extra_args }}
109114
extra_env: ${{ inputs.extra_env }}
110115
- name: Cross aarch64 Tests
@@ -128,6 +133,7 @@ runs:
128133
examples: ${{ inputs.examples }}
129134
check_namespace: ${{ inputs.check_namespace }}
130135
stack: ${{ inputs.stack }}
136+
alloc: ${{ inputs.alloc }}
131137
extra_args: ${{ inputs.extra_args }}
132138
extra_env: ${{ inputs.extra_env }}
133139
- name: Cross ppc64le Tests
@@ -151,6 +157,7 @@ runs:
151157
examples: ${{ inputs.examples }}
152158
check_namespace: ${{ inputs.check_namespace }}
153159
stack: ${{ inputs.stack }}
160+
alloc: ${{ inputs.alloc }}
154161
extra_args: ${{ inputs.extra_args }}
155162
extra_env: ${{ inputs.extra_env }}
156163
- name: Cross aarch64_be Tests
@@ -174,6 +181,7 @@ runs:
174181
examples: ${{ inputs.examples }}
175182
check_namespace: ${{ inputs.check_namespace }}
176183
stack: ${{ inputs.stack }}
184+
alloc: ${{ inputs.alloc }}
177185
extra_args: ${{ inputs.extra_args }}
178186
extra_env: ${{ inputs.extra_env }}
179187
- name: Cross riscv64 Tests (RVV, VLEN=128)
@@ -197,6 +205,7 @@ runs:
197205
examples: ${{ inputs.examples }}
198206
check_namespace: ${{ inputs.check_namespace }}
199207
stack: ${{ inputs.stack }}
208+
alloc: ${{ inputs.alloc }}
200209
extra_args: ${{ inputs.extra_args }}
201210
extra_env: ${{ inputs.extra_env }}
202211
- name: Cross riscv64 Tests (RVV, VLEN=256)
@@ -219,6 +228,7 @@ runs:
219228
examples: ${{ inputs.examples }}
220229
check_namespace: ${{ inputs.check_namespace }}
221230
stack: ${{ inputs.stack }}
231+
alloc: ${{ inputs.alloc }}
222232
extra_args: ${{ inputs.extra_args }}
223233
extra_env: ${{ inputs.extra_env }}
224234
- name: Cross riscv64 Tests (RVV, VLEN=512)
@@ -241,6 +251,7 @@ runs:
241251
examples: ${{ inputs.examples }}
242252
check_namespace: ${{ inputs.check_namespace }}
243253
stack: ${{ inputs.stack }}
254+
alloc: ${{ inputs.alloc }}
244255
extra_args: ${{ inputs.extra_args }}
245256
extra_env: ${{ inputs.extra_env }}
246257
- name: Cross riscv64 Tests (RVV, VLEN=1024)
@@ -263,6 +274,7 @@ runs:
263274
examples: ${{ inputs.examples }}
264275
check_namespace: ${{ inputs.check_namespace }}
265276
stack: ${{ inputs.stack }}
277+
alloc: ${{ inputs.alloc }}
266278
extra_args: ${{ inputs.extra_args }}
267279
extra_env: ${{ inputs.extra_env }}
268280
- name: Cross riscv32 Tests
@@ -286,6 +298,7 @@ runs:
286298
examples: ${{ inputs.examples }}
287299
check_namespace: ${{ inputs.check_namespace }}
288300
stack: ${{ inputs.stack }}
301+
alloc: ${{ inputs.alloc }}
289302
extra_args: ${{ inputs.extra_args }}
290303
extra_env: ${{ inputs.extra_env }}
291304

.github/workflows/baremetal.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ jobs:
3535
acvp: true
3636
examples: false
3737
stack: false
38+
alloc: false

scripts/tests

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class TEST_TYPES(Enum):
212212
SIZE = 17
213213
BASIC_DETERMINISTIC = 18
214214
UNIT = 19
215+
ALLOC = 20
215216

216217
def is_benchmark(self):
217218
return self in [TEST_TYPES.BENCH, TEST_TYPES.BENCH_COMPONENTS]
@@ -286,6 +287,8 @@ class TEST_TYPES(Enum):
286287
return "Measurement Code Size"
287288
if self == TEST_TYPES.UNIT:
288289
return "Unit Test"
290+
if self == TEST_TYPES.ALLOC:
291+
return "Alloc Test"
289292

290293
def make_dir(self):
291294
if self == TEST_TYPES.BRING_YOUR_OWN_FIPS202:
@@ -351,6 +354,8 @@ class TEST_TYPES(Enum):
351354
return "size"
352355
if self == TEST_TYPES.UNIT:
353356
return "unit"
357+
if self == TEST_TYPES.ALLOC:
358+
return "alloc"
354359

355360
def make_run_target(self, scheme):
356361
t = self.make_target()
@@ -650,6 +655,19 @@ class Tests:
650655

651656
self.check_fail()
652657

658+
def alloc(self):
659+
def _alloc(opt):
660+
self._compile_schemes(TEST_TYPES.ALLOC, opt)
661+
if self.args.run:
662+
self._run_schemes(TEST_TYPES.ALLOC, opt)
663+
664+
if self.do_no_opt():
665+
_alloc(False)
666+
if self.do_opt():
667+
_alloc(True)
668+
669+
self.check_fail()
670+
653671
def acvp(self):
654672
def _acvp(opt):
655673
self._compile_schemes(TEST_TYPES.ACVP, opt)
@@ -784,6 +802,7 @@ class Tests:
784802
examples = self.args.examples
785803
stack = self.args.stack
786804
unit = self.args.unit
805+
alloc = self.args.alloc
787806

788807
def _all(opt):
789808
if func is True:
@@ -796,6 +815,8 @@ class Tests:
796815
self._compile_schemes(TEST_TYPES.STACK, opt)
797816
if unit is True:
798817
self._compile_schemes(TEST_TYPES.UNIT, opt)
818+
if alloc is True:
819+
self._compile_schemes(TEST_TYPES.ALLOC, opt)
799820

800821
if self.args.check_namespace is True:
801822
p = subprocess.run(
@@ -819,6 +840,8 @@ class Tests:
819840
self._run_schemes(TEST_TYPES.STACK, opt, suppress_output=False)
820841
if unit is True:
821842
self._run_schemes(TEST_TYPES.UNIT, opt)
843+
if alloc is True:
844+
self._run_schemes(TEST_TYPES.ALLOC, opt)
822845

823846
if self.do_no_opt():
824847
_all(False)
@@ -1192,6 +1215,21 @@ def cli():
11921215
help="Do not run stack analysis",
11931216
)
11941217

1218+
alloc_group = all_parser.add_mutually_exclusive_group()
1219+
alloc_group.add_argument(
1220+
"--alloc",
1221+
action="store_true",
1222+
dest="alloc",
1223+
help="Run alloc tests",
1224+
default=True,
1225+
)
1226+
alloc_group.add_argument(
1227+
"--no-alloc",
1228+
action="store_false",
1229+
dest="alloc",
1230+
help="Do not run alloc tests",
1231+
)
1232+
11951233
# acvp arguments
11961234
acvp_parser = cmd_subparsers.add_parser(
11971235
"acvp", help="Run ACVP client", parents=[common_parser]
@@ -1398,6 +1436,13 @@ def cli():
13981436
default=False,
13991437
)
14001438

1439+
# alloc arguments
1440+
alloc_parser = cmd_subparsers.add_parser(
1441+
"alloc",
1442+
help="Run the alloc tests for all parameter sets",
1443+
parents=[common_parser],
1444+
)
1445+
14011446
args = main_parser.parse_args()
14021447

14031448
if not hasattr(args, "mac_taskpolicy"):
@@ -1425,6 +1470,8 @@ def cli():
14251470
Tests(args).kat()
14261471
elif args.cmd == "unit":
14271472
Tests(args).unit()
1473+
elif args.cmd == "alloc":
1474+
Tests(args).alloc()
14281475
elif args.cmd == "stack":
14291476
Tests(args).stack()
14301477
elif args.cmd == "size":

test/configs.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ configs:
401401
description: "Using custom allocation that can be made fail at specific invocation"
402402
defines:
403403
MLD_CONFIG_NAMESPACE_PREFIX: mld
404-
MLD_CONFIG_KEYGEN_PCT: true
404+
MLD_CONFIG_KEYGEN_PCT:
405+
content: |
406+
#if !defined(MLD_CONFIG_KEYGEN_PCT)
407+
#define MLD_CONFIG_KEYGEN_PCT
408+
#endif
405409
MLD_CONFIG_CUSTOM_ALLOC_FREE:
406410
content: |
407411
#define MLD_CONFIG_CUSTOM_ALLOC_FREE

test/test_alloc_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,10 @@ void custom_free(void *p, size_t sz, const char *file, int line,
626626
* key generation.
627627
*
628628
*****************************************************************************/
629+
#if !defined(MLD_CONFIG_KEYGEN_PCT)
629630
#define MLD_CONFIG_KEYGEN_PCT
631+
#endif
632+
630633

631634
/******************************************************************************
632635
* Name: MLD_CONFIG_KEYGEN_PCT_BREAKAGE_TEST

0 commit comments

Comments
 (0)