blob: 79c57d17469555a5f06f8b059581100136bae43b [file] [log] [blame]
Gilles Peskine33406b62023-11-02 18:48:39 +01001/** \file metatest.c
2 *
3 * \brief Test features of the test framework.
Gilles Peskinecce00122023-11-10 15:36:15 +01004 *
5 * When you run this program, it runs a single "meta-test". A meta-test
6 * performs an operation which should be caught as a failure by our
7 * test framework. The meta-test passes if this program calls `exit` with
8 * a nonzero status, or aborts, or is terminated by a signal, or if the
9 * framework running the program considers the run an error (this happens
10 * with Valgrind for a memory leak). The non-success of the meta-test
11 * program means that the test failure has been caught correctly.
12 *
13 * Some failures are purely functional: the logic of the code causes the
14 * test result to be set to FAIL. Other failures come from extra
15 * instrumentation which is not present in a normal build; for example,
16 * Asan or Valgrind to detect memory leaks. This is reflected by the
17 * "platform" associated with each meta-test.
18 *
19 * Use the companion script `tests/scripts/run-metatests.sh` to run all
20 * the meta-tests for a given platform and validate that they trigger a
21 * detected failure as expected.
Gilles Peskine33406b62023-11-02 18:48:39 +010022 */
23
24/*
25 * Copyright The Mbed TLS Contributors
26 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
27 */
28
29#define MBEDTLS_ALLOW_PRIVATE_ACCESS
30
Gilles Peskinee0acf872023-11-03 19:41:44 +010031#include <mbedtls/debug.h>
Gilles Peskine33406b62023-11-02 18:48:39 +010032#include <mbedtls/platform.h>
Gilles Peskine69e8db02023-11-02 19:52:32 +010033#include <mbedtls/platform_util.h>
Gilles Peskine33406b62023-11-02 18:48:39 +010034#include "test/helpers.h"
Gilles Peskine102aea22023-11-03 18:05:38 +010035#include "test/macros.h"
Gilles Peskined29cce92023-11-02 20:49:34 +010036#include "test/memory.h"
Gilles Peskine6f8ca292023-11-29 19:42:43 +010037#include "common.h"
Gilles Peskine33406b62023-11-02 18:48:39 +010038
39#include <stdio.h>
40#include <string.h>
41
Gilles Peskine102aea22023-11-03 18:05:38 +010042#if defined(MBEDTLS_THREADING_C)
43#include <mbedtls/threading.h>
44#endif
45
Gilles Peskine33406b62023-11-02 18:48:39 +010046
Gilles Peskine69e8db02023-11-02 19:52:32 +010047/* This is an external variable, so the compiler doesn't know that we're never
48 * changing its value.
Gilles Peskine69e8db02023-11-02 19:52:32 +010049 */
Gilles Peskined2fa6982023-11-09 21:46:24 +010050volatile int false_but_the_compiler_does_not_know = 0;
51
Gilles Peskine7a715c42023-11-21 13:42:40 +010052/* Hide calls to calloc/free from static checkers such as
53 * `gcc-12 -Wuse-after-free`, to avoid compile-time complaints about
54 * code where we do mean to cause a runtime error. */
55void * (* volatile calloc_but_the_compiler_does_not_know)(size_t, size_t) = mbedtls_calloc;
56void(*volatile free_but_the_compiler_does_not_know)(void *) = mbedtls_free;
57
Gilles Peskined2fa6982023-11-09 21:46:24 +010058/* Set n bytes at the address p to all-bits-zero, in such a way that
59 * the compiler should not know that p is all-bits-zero. */
Gilles Peskineda6e7a22023-11-10 10:09:27 +010060static void set_to_zero_but_the_compiler_does_not_know(volatile void *p, size_t n)
Gilles Peskined2fa6982023-11-09 21:46:24 +010061{
Gilles Peskineda6e7a22023-11-10 10:09:27 +010062 memset((void *) p, false_but_the_compiler_does_not_know, n);
Gilles Peskined2fa6982023-11-09 21:46:24 +010063}
Gilles Peskine69e8db02023-11-02 19:52:32 +010064
Gilles Peskine895ebc32023-11-23 12:33:39 +010065/* Simulate an access to the given object, to avoid compiler optimizations
66 * in code that prepares or consumes the object. */
67static void do_nothing_with_object(void *p)
68{
69 (void) p;
70}
71void(*volatile do_nothing_with_object_but_the_compiler_does_not_know)(void *) =
72 do_nothing_with_object;
73
Gilles Peskine69e8db02023-11-02 19:52:32 +010074
Gilles Peskine33406b62023-11-02 18:48:39 +010075/****************************************************************/
Gilles Peskinef309fbf2023-11-02 18:49:52 +010076/* Test framework features */
77/****************************************************************/
78
79void meta_test_fail(const char *name)
80{
81 (void) name;
82 mbedtls_test_fail("Forced test failure", __LINE__, __FILE__);
83}
84
85
86/****************************************************************/
Gilles Peskine80ba8322023-11-02 19:23:26 +010087/* Platform features */
88/****************************************************************/
89
90void null_pointer_dereference(const char *name)
91{
92 (void) name;
Gilles Peskineda6e7a22023-11-10 10:09:27 +010093 volatile char *volatile p;
Gilles Peskined2fa6982023-11-09 21:46:24 +010094 set_to_zero_but_the_compiler_does_not_know(&p, sizeof(p));
Gilles Peskine2f40cc02023-11-16 15:11:44 +010095 /* Undefined behavior (read from null data pointer) */
Gilles Peskine69e8db02023-11-02 19:52:32 +010096 mbedtls_printf("%p -> %u\n", p, (unsigned) *p);
Gilles Peskine80ba8322023-11-02 19:23:26 +010097}
98
99void null_pointer_call(const char *name)
100{
101 (void) name;
Gilles Peskineda6e7a22023-11-10 10:09:27 +0100102 unsigned(*volatile p)(void);
Gilles Peskined2fa6982023-11-09 21:46:24 +0100103 set_to_zero_but_the_compiler_does_not_know(&p, sizeof(p));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100104 /* Undefined behavior (execute null function pointer) */
Gilles Peskinef0d5cf92023-11-03 10:58:57 +0100105 /* The pointer representation may be truncated, but we don't care:
106 * the only point of printing it is to have some use of the pointer
107 * to dissuade the compiler from optimizing it away. */
108 mbedtls_printf("%lx() -> %u\n", (unsigned long) (uintptr_t) p, p());
Gilles Peskine80ba8322023-11-02 19:23:26 +0100109}
110
111
112/****************************************************************/
Gilles Peskine102aea22023-11-03 18:05:38 +0100113/* Memory */
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100114/****************************************************************/
115
116void read_after_free(const char *name)
117{
118 (void) name;
Gilles Peskine7a715c42023-11-21 13:42:40 +0100119 volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100120 *p = 'a';
Gilles Peskine7a715c42023-11-21 13:42:40 +0100121 free_but_the_compiler_does_not_know((void *) p);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100122 /* Undefined behavior (read after free) */
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100123 mbedtls_printf("%u\n", (unsigned) *p);
124}
125
126void double_free(const char *name)
127{
128 (void) name;
Gilles Peskine7a715c42023-11-21 13:42:40 +0100129 volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100130 *p = 'a';
Gilles Peskine7a715c42023-11-21 13:42:40 +0100131 free_but_the_compiler_does_not_know((void *) p);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100132 /* Undefined behavior (double free) */
Gilles Peskine7a715c42023-11-21 13:42:40 +0100133 free_but_the_compiler_does_not_know((void *) p);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100134}
135
136void read_uninitialized_stack(const char *name)
137{
138 (void) name;
Gilles Peskineccb12152023-11-10 11:35:36 +0100139 char buf[1];
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100140 if (false_but_the_compiler_does_not_know) {
141 buf[0] = '!';
142 }
Gilles Peskineccb12152023-11-10 11:35:36 +0100143 char *volatile p = buf;
144 if (*p != 0) {
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100145 /* Unspecified result (read from uninitialized memory) */
Gilles Peskineccb12152023-11-10 11:35:36 +0100146 mbedtls_printf("%u\n", (unsigned) *p);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100147 }
148}
149
150void memory_leak(const char *name)
151{
152 (void) name;
Gilles Peskine7a715c42023-11-21 13:42:40 +0100153 volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
Gilles Peskined2fa6982023-11-09 21:46:24 +0100154 mbedtls_printf("%u\n", (unsigned) *p);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100155 /* Leak of a heap object */
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100156}
157
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100158/* name = "test_memory_poison_%(start)_%(offset)_%(count)_%(direction)"
Gilles Peskined29cce92023-11-02 20:49:34 +0100159 * Poison a region starting at start from an 8-byte aligned origin,
160 * encompassing count bytes. Access the region at offset from the start.
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100161 * %(start), %(offset) and %(count) are decimal integers.
162 * %(direction) is either the character 'r' for read or 'w' for write.
Gilles Peskined29cce92023-11-02 20:49:34 +0100163 */
164void test_memory_poison(const char *name)
165{
166 size_t start = 0, offset = 0, count = 0;
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100167 char direction = 'r';
Gilles Peskinee0acf872023-11-03 19:41:44 +0100168 if (sscanf(name,
169 "%*[^0-9]%" MBEDTLS_PRINTF_SIZET
170 "%*[^0-9]%" MBEDTLS_PRINTF_SIZET
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100171 "%*[^0-9]%" MBEDTLS_PRINTF_SIZET
172 "_%c",
173 &start, &offset, &count, &direction) != 4) {
Gilles Peskined29cce92023-11-02 20:49:34 +0100174 mbedtls_fprintf(stderr, "%s: Bad name format: %s\n", __func__, name);
175 return;
176 }
177
178 union {
179 long long ll;
180 unsigned char buf[32];
181 } aligned;
182 memset(aligned.buf, 'a', sizeof(aligned.buf));
183
184 if (start > sizeof(aligned.buf)) {
Gilles Peskinee0acf872023-11-03 19:41:44 +0100185 mbedtls_fprintf(stderr,
186 "%s: start=%" MBEDTLS_PRINTF_SIZET
187 " > size=%" MBEDTLS_PRINTF_SIZET,
188 __func__, start, sizeof(aligned.buf));
Gilles Peskined29cce92023-11-02 20:49:34 +0100189 return;
190 }
191 if (start + count > sizeof(aligned.buf)) {
Gilles Peskinee0acf872023-11-03 19:41:44 +0100192 mbedtls_fprintf(stderr,
193 "%s: start+count=%" MBEDTLS_PRINTF_SIZET
194 " > size=%" MBEDTLS_PRINTF_SIZET,
195 __func__, start + count, sizeof(aligned.buf));
Gilles Peskined29cce92023-11-02 20:49:34 +0100196 return;
197 }
198 if (offset >= count) {
Gilles Peskinee0acf872023-11-03 19:41:44 +0100199 mbedtls_fprintf(stderr,
200 "%s: offset=%" MBEDTLS_PRINTF_SIZET
201 " >= count=%" MBEDTLS_PRINTF_SIZET,
202 __func__, offset, count);
Gilles Peskined29cce92023-11-02 20:49:34 +0100203 return;
204 }
205
206 MBEDTLS_TEST_MEMORY_POISON(aligned.buf + start, count);
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100207
208 if (direction == 'w') {
209 aligned.buf[start + offset] = 'b';
Gilles Peskine895ebc32023-11-23 12:33:39 +0100210 do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100211 } else {
Gilles Peskine895ebc32023-11-23 12:33:39 +0100212 do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100213 mbedtls_printf("%u\n", (unsigned) aligned.buf[start + offset]);
214 }
Gilles Peskined29cce92023-11-02 20:49:34 +0100215}
216
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100217
218/****************************************************************/
Gilles Peskine102aea22023-11-03 18:05:38 +0100219/* Threading */
220/****************************************************************/
221
222void mutex_lock_not_initialized(const char *name)
223{
224 (void) name;
Gilles Peskinead2a17e2023-11-16 15:09:48 +0100225#if defined(MBEDTLS_THREADING_C)
Gilles Peskine102aea22023-11-03 18:05:38 +0100226 mbedtls_threading_mutex_t mutex;
227 memset(&mutex, 0, sizeof(mutex));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100228 /* This mutex usage error is detected by our test framework's mutex usage
229 * verification framework. See tests/src/threading_helpers.c. Other
230 * threading implementations (e.g. pthread without our instrumentation)
231 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100232 TEST_ASSERT(mbedtls_mutex_lock(&mutex) == 0);
233exit:
234 ;
235#endif
236}
237
238void mutex_unlock_not_initialized(const char *name)
239{
240 (void) name;
Gilles Peskine102aea22023-11-03 18:05:38 +0100241#if defined(MBEDTLS_THREADING_C)
242 mbedtls_threading_mutex_t mutex;
243 memset(&mutex, 0, sizeof(mutex));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100244 /* This mutex usage error is detected by our test framework's mutex usage
245 * verification framework. See tests/src/threading_helpers.c. Other
246 * threading implementations (e.g. pthread without our instrumentation)
247 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100248 TEST_ASSERT(mbedtls_mutex_unlock(&mutex) == 0);
249exit:
250 ;
251#endif
252}
253
254void mutex_free_not_initialized(const char *name)
255{
256 (void) name;
Gilles Peskine102aea22023-11-03 18:05:38 +0100257#if defined(MBEDTLS_THREADING_C)
258 mbedtls_threading_mutex_t mutex;
259 memset(&mutex, 0, sizeof(mutex));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100260 /* This mutex usage error is detected by our test framework's mutex usage
261 * verification framework. See tests/src/threading_helpers.c. Other
262 * threading implementations (e.g. pthread without our instrumentation)
263 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100264 mbedtls_mutex_free(&mutex);
265#endif
266}
267
268void mutex_double_init(const char *name)
269{
270 (void) name;
271#if defined(MBEDTLS_THREADING_C)
272 mbedtls_threading_mutex_t mutex;
273 mbedtls_mutex_init(&mutex);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100274 /* This mutex usage error is detected by our test framework's mutex usage
275 * verification framework. See tests/src/threading_helpers.c. Other
276 * threading implementations (e.g. pthread without our instrumentation)
277 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100278 mbedtls_mutex_init(&mutex);
279 mbedtls_mutex_free(&mutex);
280#endif
281}
282
283void mutex_double_free(const char *name)
284{
285 (void) name;
286#if defined(MBEDTLS_THREADING_C)
287 mbedtls_threading_mutex_t mutex;
288 mbedtls_mutex_init(&mutex);
289 mbedtls_mutex_free(&mutex);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100290 /* This mutex usage error is detected by our test framework's mutex usage
291 * verification framework. See tests/src/threading_helpers.c. Other
292 * threading implementations (e.g. pthread without our instrumentation)
293 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100294 mbedtls_mutex_free(&mutex);
295#endif
296}
297
298void mutex_leak(const char *name)
299{
300 (void) name;
Gilles Peskinead2a17e2023-11-16 15:09:48 +0100301#if defined(MBEDTLS_THREADING_C)
Gilles Peskine102aea22023-11-03 18:05:38 +0100302 mbedtls_threading_mutex_t mutex;
303 mbedtls_mutex_init(&mutex);
304#endif
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100305 /* This mutex usage error is detected by our test framework's mutex usage
306 * verification framework. See tests/src/threading_helpers.c. Other
307 * threading implementations (e.g. pthread without our instrumentation)
308 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100309}
310
311
312/****************************************************************/
Gilles Peskine33406b62023-11-02 18:48:39 +0100313/* Command line entry point */
314/****************************************************************/
315
316typedef struct {
Gilles Peskinecce00122023-11-10 15:36:15 +0100317 /** Command line argument that will trigger that metatest.
318 *
319 * Conventionally matches "[a-z0-9_]+". */
Gilles Peskine33406b62023-11-02 18:48:39 +0100320 const char *name;
Gilles Peskinecce00122023-11-10 15:36:15 +0100321
322 /** Platform under which that metatest is valid.
323 *
324 * - "any": should work anywhere.
325 * - "asan": triggers ASan (Address Sanitizer).
326 * - "msan": triggers MSan (Memory Sanitizer).
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100327 * - "pthread": requires MBEDTLS_THREADING_PTHREAD and MBEDTLS_TEST_HOOKS,
328 * which enables MBEDTLS_TEST_MUTEX_USAGE internally in the test
329 * framework (see tests/src/threading_helpers.c).
Gilles Peskinecce00122023-11-10 15:36:15 +0100330 */
Gilles Peskine33406b62023-11-02 18:48:39 +0100331 const char *platform;
Gilles Peskinecce00122023-11-10 15:36:15 +0100332
333 /** Function that performs the metatest.
334 *
335 * The function receives the name as an argument. This allows using the
336 * same function to perform multiple variants of a test based on the name.
337 *
338 * When executed on a conforming platform, the function is expected to
339 * either cause a test failure (mbedtls_test_fail()), or cause the
340 * program to abort in some way (e.g. by causing a segfault or by
341 * triggering a sanitizer).
342 *
343 * When executed on a non-conforming platform, the function may return
344 * normally or may have unpredictable behavior.
345 */
Gilles Peskine33406b62023-11-02 18:48:39 +0100346 void (*entry_point)(const char *name);
347} metatest_t;
348
Gilles Peskinecce00122023-11-10 15:36:15 +0100349/* The list of availble meta-tests. Remember to register new functions here!
350 *
351 * Note that we always compile all the functions, so that `metatest --list`
352 * will always list all the available meta-tests.
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100353 *
354 * See the documentation of metatest_t::platform for the meaning of
355 * platform values.
Gilles Peskinecce00122023-11-10 15:36:15 +0100356 */
Gilles Peskine33406b62023-11-02 18:48:39 +0100357metatest_t metatests[] = {
Gilles Peskinef309fbf2023-11-02 18:49:52 +0100358 { "test_fail", "any", meta_test_fail },
Gilles Peskine80ba8322023-11-02 19:23:26 +0100359 { "null_dereference", "any", null_pointer_dereference },
360 { "null_call", "any", null_pointer_call },
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100361 { "read_after_free", "asan", read_after_free },
362 { "double_free", "asan", double_free },
363 { "read_uninitialized_stack", "msan", read_uninitialized_stack },
364 { "memory_leak", "asan", memory_leak },
David Horstmann9de6edd2024-01-17 14:53:08 +0000365 { "test_memory_poison_0_0_8_r", "poison", test_memory_poison },
366 { "test_memory_poison_0_0_8_w", "poison", test_memory_poison },
367 { "test_memory_poison_0_7_8_r", "poison", test_memory_poison },
368 { "test_memory_poison_0_7_8_w", "poison", test_memory_poison },
369 { "test_memory_poison_0_0_1_r", "poison", test_memory_poison },
370 { "test_memory_poison_0_0_1_w", "poison", test_memory_poison },
371 { "test_memory_poison_0_1_2_r", "poison", test_memory_poison },
372 { "test_memory_poison_0_1_2_w", "poison", test_memory_poison },
373 { "test_memory_poison_7_0_8_r", "poison", test_memory_poison },
374 { "test_memory_poison_7_0_8_w", "poison", test_memory_poison },
375 { "test_memory_poison_7_7_8_r", "poison", test_memory_poison },
376 { "test_memory_poison_7_7_8_w", "poison", test_memory_poison },
377 { "test_memory_poison_7_0_1_r", "poison", test_memory_poison },
378 { "test_memory_poison_7_0_1_w", "poison", test_memory_poison },
379 { "test_memory_poison_7_1_2_r", "poison", test_memory_poison },
380 { "test_memory_poison_7_1_2_w", "poison", test_memory_poison },
Gilles Peskine102aea22023-11-03 18:05:38 +0100381 { "mutex_lock_not_initialized", "pthread", mutex_lock_not_initialized },
382 { "mutex_unlock_not_initialized", "pthread", mutex_unlock_not_initialized },
383 { "mutex_free_not_initialized", "pthread", mutex_free_not_initialized },
384 { "mutex_double_init", "pthread", mutex_double_init },
385 { "mutex_double_free", "pthread", mutex_double_free },
386 { "mutex_leak", "pthread", mutex_leak },
Gilles Peskine33406b62023-11-02 18:48:39 +0100387 { NULL, NULL, NULL }
388};
389
390static void help(FILE *out, const char *argv0)
391{
392 mbedtls_fprintf(out, "Usage: %s list|TEST\n", argv0);
393 mbedtls_fprintf(out, "Run a meta-test that should cause a test failure.\n");
394 mbedtls_fprintf(out, "With 'list', list the available tests and their platform requirement.\n");
395}
396
397int main(int argc, char *argv[])
398{
399 const char *argv0 = argc > 0 ? argv[0] : "metatest";
400 if (argc != 2) {
401 help(stderr, argv0);
402 mbedtls_exit(MBEDTLS_EXIT_FAILURE);
403 }
404
405 /* Support "-help", "--help", "--list", etc. */
406 const char *command = argv[1];
407 while (*command == '-') {
408 ++command;
409 }
410
411 if (strcmp(argv[1], "help") == 0) {
412 help(stdout, argv0);
413 mbedtls_exit(MBEDTLS_EXIT_SUCCESS);
414 }
415 if (strcmp(argv[1], "list") == 0) {
416 for (const metatest_t *p = metatests; p->name != NULL; p++) {
417 mbedtls_printf("%s %s\n", p->name, p->platform);
418 }
419 mbedtls_exit(MBEDTLS_EXIT_SUCCESS);
420 }
421
Gilles Peskine102aea22023-11-03 18:05:38 +0100422#if defined(MBEDTLS_TEST_MUTEX_USAGE)
423 mbedtls_test_mutex_usage_init();
424#endif
425
Gilles Peskine33406b62023-11-02 18:48:39 +0100426 for (const metatest_t *p = metatests; p->name != NULL; p++) {
427 if (strcmp(argv[1], p->name) == 0) {
428 mbedtls_printf("Running metatest %s...\n", argv[1]);
429 p->entry_point(argv[1]);
Gilles Peskine102aea22023-11-03 18:05:38 +0100430#if defined(MBEDTLS_TEST_MUTEX_USAGE)
431 mbedtls_test_mutex_usage_check();
432#endif
Gilles Peskine33406b62023-11-02 18:48:39 +0100433 mbedtls_printf("Running metatest %s... done, result=%d\n",
434 argv[1], (int) mbedtls_test_info.result);
435 mbedtls_exit(mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SUCCESS ?
436 MBEDTLS_EXIT_SUCCESS :
437 MBEDTLS_EXIT_FAILURE);
438 }
439 }
440
441 mbedtls_fprintf(stderr, "%s: FATAL: No such metatest: %s\n",
442 argv0, command);
443 mbedtls_exit(MBEDTLS_EXIT_FAILURE);
444}