-
Notifications
You must be signed in to change notification settings - Fork 9
/
tests
executable file
·260 lines (235 loc) · 6.41 KB
/
tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
import platform
import os
import sys
import click
from functools import reduce
sys.path.append(f"{os.path.join(os.path.dirname(__file__), 'lib')}")
from mlkem_test import *
"""
Click interface configuration
"""
def __callback(n):
def callback(ctx, param, value):
state = ctx.ensure_object(Options)
state.__dict__[n] = value
return value
return callback
def add_options(options):
"""Shortcurt for adding multiple options for Click command"""
return lambda func: reduce(lambda f, o: o(f), reversed(options), func)
_shared_options = [
click.option(
"-v",
"--verbose",
expose_value=False,
is_flag=True,
show_default=True,
default=False,
type=bool,
help="Show verbose output or not",
callback=__callback("verbose"),
),
click.option(
"-cp",
"--cross-prefix",
expose_value=False,
default="",
show_default=True,
nargs=1,
help="Cross prefix for compilation",
callback=__callback("cross_prefix"),
),
click.option(
"--cflags",
expose_value=False,
nargs=1,
help="Extra cflags to passed in (e.g. '-mcpu=cortex-a72')",
callback=__callback("cflags"),
),
click.option(
"--arch-flags",
expose_value=False,
nargs=1,
help="Extra arch flags to passed in (e.g. '-march=armv8')",
callback=__callback("arch_flags"),
),
click.option(
"--auto/--no-auto",
expose_value=False,
is_flag=True,
show_default=True,
default=True,
help="Allow makefile to auto configure system specific preprocessor",
callback=__callback("auto"),
),
click.option(
"--opt",
expose_value=False,
nargs=1,
type=click.Choice(["ALL", "OPT", "NO_OPT"], case_sensitive=False),
show_default=True,
default="ALL",
help="Determine whether to compile/run the opt/no_opt binary or both",
callback=__callback("opt"),
),
click.option(
"--compile/--no-compile",
expose_value=False,
is_flag=True,
show_default=True,
default=True,
help="Determine to compile the binary or not",
callback=__callback("compile"),
),
click.option(
"--run/--no-run",
expose_value=False,
is_flag=True,
show_default=True,
default=True,
help="Determine to run the compiled binary or not",
callback=__callback("run"),
),
]
_bench_options = [
click.option(
"-c",
"--cycles",
nargs=1,
type=click.Choice(["NO", "PMU", "PERF", "M1"]),
show_default=True,
default="NO",
help="Method for counting clock cycles. PMU requires (user-space) access to the Arm Performance Monitor Unit (PMU). PERF requires a kernel with perf support. M1 only works on Apple silicon.",
),
click.option(
"-o",
"--output",
nargs=1,
help="Path to output file in json format",
),
click.option(
"-r",
"--run-as-root",
is_flag=True,
show_default=True,
default=False,
type=bool,
help="Benchmarking binary is run with sudo.",
),
click.option(
"-w",
"--exec-wrapper",
help="Run the benchmark binary with the user-customized wrapper.",
),
click.option(
"-t",
"--mac-taskpolicy",
nargs=1,
type=click.Choice(["utility", "background", "maintenance"]),
hidden=platform.system() != "Darwin",
show_default=True,
default=None,
help="Run the program using the specified QoS clamp. Applies to MacOS only. Setting this flag to 'background' guarantees running on E-cores. This is an abbreviation of --exec-wrapper 'taskpolicy -c {mac_taskpolicy}'.",
),
click.option(
"--components",
is_flag=True,
type=bool,
show_default=True,
default=False,
help="Benchmark low-level components",
),
]
@click.group(invoke_without_command=True)
def cli():
pass
@cli.command(
short_help="Run the functional tests for all parameter sets",
context_settings={"show_default": True},
)
@add_options(_shared_options)
@click.make_pass_decorator(Options, ensure=True)
def func(opts: Options):
Tests(opts).func()
@cli.command(
short_help="Run the nistkat tests for all parameter sets",
context_settings={"show_default": True},
)
@add_options(_shared_options)
@click.make_pass_decorator(Options, ensure=True)
def nistkat(opts: Options):
Tests(opts).nistkat()
@cli.command(
short_help="Run the kat tests for all parameter sets",
context_settings={"show_default": True},
)
@add_options(_shared_options)
@click.make_pass_decorator(Options, ensure=True)
def kat(opts: Options):
Tests(opts).kat()
@cli.command(
short_help="Run the benchmarks for all parameter sets",
context_settings={"show_default": True},
)
@add_options(_shared_options)
@add_options(_bench_options)
@click.make_pass_decorator(Options, ensure=True)
def bench(
opts: Options,
cycles: str,
output,
run_as_root: bool,
exec_wrapper: str,
mac_taskpolicy,
components,
):
Tests(opts).bench(
cycles,
output,
run_as_root,
exec_wrapper,
mac_taskpolicy,
components,
)
@cli.command(
short_help="Run all tests (except benchmark for now)",
context_settings={"show_default": True},
)
@add_options(_shared_options)
@add_options(
[
click.option(
"--func/--no-func",
is_flag=True,
show_default=True,
default=True,
help="Determine whether to run func test or not",
),
click.option(
"--kat/--no-kat",
is_flag=True,
show_default=True,
default=True,
help="Determine whether to run kat test or not",
),
click.option(
"--nistkat/--no-nistkat",
is_flag=True,
show_default=True,
default=True,
help="Determine whether to run nistkat test or not",
),
]
)
@click.make_pass_decorator(Options, ensure=True)
def all(
opts: Options,
func: bool,
kat: bool,
nistkat: bool,
):
Tests(opts).all(func, kat, nistkat)
if __name__ == "__main__":
cli()