blob: 1724aed0bd1170686055fad6326b19cd31dfa01b [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 Peskine33406b62023-11-02 18:48:39 +010037
38#include <stdio.h>
39#include <string.h>
40
Gilles Peskine102aea22023-11-03 18:05:38 +010041#if defined(MBEDTLS_THREADING_C)
42#include <mbedtls/threading.h>
43#endif
44
Gilles Peskinef5dd0022023-11-03 17:01:32 +010045/* C99 feature missing from older versions of MSVC */
46#if (defined(_MSC_VER) && (_MSC_VER <= 1900))
47#define /*no-check-names*/ __func__ __FUNCTION__
48#endif
49
Gilles Peskine33406b62023-11-02 18:48:39 +010050
Gilles Peskine69e8db02023-11-02 19:52:32 +010051/* This is an external variable, so the compiler doesn't know that we're never
52 * changing its value.
Gilles Peskine69e8db02023-11-02 19:52:32 +010053 */
Gilles Peskined2fa6982023-11-09 21:46:24 +010054volatile int false_but_the_compiler_does_not_know = 0;
55
Gilles Peskine7a715c42023-11-21 13:42:40 +010056/* Hide calls to calloc/free from static checkers such as
57 * `gcc-12 -Wuse-after-free`, to avoid compile-time complaints about
58 * code where we do mean to cause a runtime error. */
59void * (* volatile calloc_but_the_compiler_does_not_know)(size_t, size_t) = mbedtls_calloc;
60void(*volatile free_but_the_compiler_does_not_know)(void *) = mbedtls_free;
61
Gilles Peskined2fa6982023-11-09 21:46:24 +010062/* Set n bytes at the address p to all-bits-zero, in such a way that
63 * the compiler should not know that p is all-bits-zero. */
Gilles Peskineda6e7a22023-11-10 10:09:27 +010064static void set_to_zero_but_the_compiler_does_not_know(volatile void *p, size_t n)
Gilles Peskined2fa6982023-11-09 21:46:24 +010065{
Gilles Peskineda6e7a22023-11-10 10:09:27 +010066 memset((void *) p, false_but_the_compiler_does_not_know, n);
Gilles Peskined2fa6982023-11-09 21:46:24 +010067}
Gilles Peskine69e8db02023-11-02 19:52:32 +010068
Gilles Peskine895ebc32023-11-23 12:33:39 +010069/* Simulate an access to the given object, to avoid compiler optimizations
70 * in code that prepares or consumes the object. */
71static void do_nothing_with_object(void *p)
72{
73 (void) p;
74}
75void(*volatile do_nothing_with_object_but_the_compiler_does_not_know)(void *) =
76 do_nothing_with_object;
77
Gilles Peskine69e8db02023-11-02 19:52:32 +010078
Gilles Peskine33406b62023-11-02 18:48:39 +010079/****************************************************************/
Gilles Peskinef309fbf2023-11-02 18:49:52 +010080/* Test framework features */
81/****************************************************************/
82
83void meta_test_fail(const char *name)
84{
85 (void) name;
86 mbedtls_test_fail("Forced test failure", __LINE__, __FILE__);
87}
88
89
90/****************************************************************/
Gilles Peskine80ba8322023-11-02 19:23:26 +010091/* Platform features */
92/****************************************************************/
93
94void null_pointer_dereference(const char *name)
95{
96 (void) name;
Gilles Peskineda6e7a22023-11-10 10:09:27 +010097 volatile char *volatile p;
Gilles Peskined2fa6982023-11-09 21:46:24 +010098 set_to_zero_but_the_compiler_does_not_know(&p, sizeof(p));
Gilles Peskine2f40cc02023-11-16 15:11:44 +010099 /* Undefined behavior (read from null data pointer) */
Gilles Peskine69e8db02023-11-02 19:52:32 +0100100 mbedtls_printf("%p -> %u\n", p, (unsigned) *p);
Gilles Peskine80ba8322023-11-02 19:23:26 +0100101}
102
103void null_pointer_call(const char *name)
104{
105 (void) name;
Gilles Peskineda6e7a22023-11-10 10:09:27 +0100106 unsigned(*volatile p)(void);
Gilles Peskined2fa6982023-11-09 21:46:24 +0100107 set_to_zero_but_the_compiler_does_not_know(&p, sizeof(p));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100108 /* Undefined behavior (execute null function pointer) */
Gilles Peskinef0d5cf92023-11-03 10:58:57 +0100109 /* The pointer representation may be truncated, but we don't care:
110 * the only point of printing it is to have some use of the pointer
111 * to dissuade the compiler from optimizing it away. */
112 mbedtls_printf("%lx() -> %u\n", (unsigned long) (uintptr_t) p, p());
Gilles Peskine80ba8322023-11-02 19:23:26 +0100113}
114
115
116/****************************************************************/
Gilles Peskine102aea22023-11-03 18:05:38 +0100117/* Memory */
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100118/****************************************************************/
119
120void read_after_free(const char *name)
121{
122 (void) name;
Gilles Peskine7a715c42023-11-21 13:42:40 +0100123 volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100124 *p = 'a';
Gilles Peskine7a715c42023-11-21 13:42:40 +0100125 free_but_the_compiler_does_not_know((void *) p);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100126 /* Undefined behavior (read after free) */
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100127 mbedtls_printf("%u\n", (unsigned) *p);
128}
129
130void double_free(const char *name)
131{
132 (void) name;
Gilles Peskine7a715c42023-11-21 13:42:40 +0100133 volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100134 *p = 'a';
Gilles Peskine7a715c42023-11-21 13:42:40 +0100135 free_but_the_compiler_does_not_know((void *) p);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100136 /* Undefined behavior (double free) */
Gilles Peskine7a715c42023-11-21 13:42:40 +0100137 free_but_the_compiler_does_not_know((void *) p);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100138}
139
140void read_uninitialized_stack(const char *name)
141{
142 (void) name;
Gilles Peskineccb12152023-11-10 11:35:36 +0100143 char buf[1];
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100144 if (false_but_the_compiler_does_not_know) {
145 buf[0] = '!';
146 }
Gilles Peskineccb12152023-11-10 11:35:36 +0100147 char *volatile p = buf;
148 if (*p != 0) {
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100149 /* Unspecified result (read from uninitialized memory) */
Gilles Peskineccb12152023-11-10 11:35:36 +0100150 mbedtls_printf("%u\n", (unsigned) *p);
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100151 }
152}
153
154void memory_leak(const char *name)
155{
156 (void) name;
Gilles Peskine7a715c42023-11-21 13:42:40 +0100157 volatile char *p = calloc_but_the_compiler_does_not_know(1, 1);
Gilles Peskined2fa6982023-11-09 21:46:24 +0100158 mbedtls_printf("%u\n", (unsigned) *p);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100159 /* Leak of a heap object */
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100160}
161
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100162/* name = "test_memory_poison_%(start)_%(offset)_%(count)_%(direction)"
Gilles Peskined29cce92023-11-02 20:49:34 +0100163 * Poison a region starting at start from an 8-byte aligned origin,
164 * encompassing count bytes. Access the region at offset from the start.
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100165 * %(start), %(offset) and %(count) are decimal integers.
166 * %(direction) is either the character 'r' for read or 'w' for write.
Gilles Peskined29cce92023-11-02 20:49:34 +0100167 */
168void test_memory_poison(const char *name)
169{
170 size_t start = 0, offset = 0, count = 0;
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100171 char direction = 'r';
Gilles Peskinee0acf872023-11-03 19:41:44 +0100172 if (sscanf(name,
173 "%*[^0-9]%" MBEDTLS_PRINTF_SIZET
174 "%*[^0-9]%" MBEDTLS_PRINTF_SIZET
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100175 "%*[^0-9]%" MBEDTLS_PRINTF_SIZET
176 "_%c",
177 &start, &offset, &count, &direction) != 4) {
Gilles Peskined29cce92023-11-02 20:49:34 +0100178 mbedtls_fprintf(stderr, "%s: Bad name format: %s\n", __func__, name);
179 return;
180 }
181
182 union {
183 long long ll;
184 unsigned char buf[32];
185 } aligned;
186 memset(aligned.buf, 'a', sizeof(aligned.buf));
187
188 if (start > sizeof(aligned.buf)) {
Gilles Peskinee0acf872023-11-03 19:41:44 +0100189 mbedtls_fprintf(stderr,
190 "%s: start=%" MBEDTLS_PRINTF_SIZET
191 " > size=%" MBEDTLS_PRINTF_SIZET,
192 __func__, start, sizeof(aligned.buf));
Gilles Peskined29cce92023-11-02 20:49:34 +0100193 return;
194 }
195 if (start + count > sizeof(aligned.buf)) {
Gilles Peskinee0acf872023-11-03 19:41:44 +0100196 mbedtls_fprintf(stderr,
197 "%s: start+count=%" MBEDTLS_PRINTF_SIZET
198 " > size=%" MBEDTLS_PRINTF_SIZET,
199 __func__, start + count, sizeof(aligned.buf));
Gilles Peskined29cce92023-11-02 20:49:34 +0100200 return;
201 }
202 if (offset >= count) {
Gilles Peskinee0acf872023-11-03 19:41:44 +0100203 mbedtls_fprintf(stderr,
204 "%s: offset=%" MBEDTLS_PRINTF_SIZET
205 " >= count=%" MBEDTLS_PRINTF_SIZET,
206 __func__, offset, count);
Gilles Peskined29cce92023-11-02 20:49:34 +0100207 return;
208 }
209
210 MBEDTLS_TEST_MEMORY_POISON(aligned.buf + start, count);
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100211
212 if (direction == 'w') {
213 aligned.buf[start + offset] = 'b';
Gilles Peskine895ebc32023-11-23 12:33:39 +0100214 do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100215 } else {
Gilles Peskine895ebc32023-11-23 12:33:39 +0100216 do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100217 mbedtls_printf("%u\n", (unsigned) aligned.buf[start + offset]);
218 }
Gilles Peskined29cce92023-11-02 20:49:34 +0100219}
220
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100221
222/****************************************************************/
Gilles Peskine102aea22023-11-03 18:05:38 +0100223/* Threading */
224/****************************************************************/
225
226void mutex_lock_not_initialized(const char *name)
227{
228 (void) name;
Gilles Peskinead2a17e2023-11-16 15:09:48 +0100229#if defined(MBEDTLS_THREADING_C)
Gilles Peskine102aea22023-11-03 18:05:38 +0100230 mbedtls_threading_mutex_t mutex;
231 memset(&mutex, 0, sizeof(mutex));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100232 /* This mutex usage error is detected by our test framework's mutex usage
233 * verification framework. See tests/src/threading_helpers.c. Other
234 * threading implementations (e.g. pthread without our instrumentation)
235 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100236 TEST_ASSERT(mbedtls_mutex_lock(&mutex) == 0);
237exit:
238 ;
239#endif
240}
241
242void mutex_unlock_not_initialized(const char *name)
243{
244 (void) name;
Gilles Peskine102aea22023-11-03 18:05:38 +0100245#if defined(MBEDTLS_THREADING_C)
246 mbedtls_threading_mutex_t mutex;
247 memset(&mutex, 0, sizeof(mutex));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100248 /* This mutex usage error is detected by our test framework's mutex usage
249 * verification framework. See tests/src/threading_helpers.c. Other
250 * threading implementations (e.g. pthread without our instrumentation)
251 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100252 TEST_ASSERT(mbedtls_mutex_unlock(&mutex) == 0);
253exit:
254 ;
255#endif
256}
257
258void mutex_free_not_initialized(const char *name)
259{
260 (void) name;
Gilles Peskine102aea22023-11-03 18:05:38 +0100261#if defined(MBEDTLS_THREADING_C)
262 mbedtls_threading_mutex_t mutex;
263 memset(&mutex, 0, sizeof(mutex));
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100264 /* This mutex usage error is detected by our test framework's mutex usage
265 * verification framework. See tests/src/threading_helpers.c. Other
266 * threading implementations (e.g. pthread without our instrumentation)
267 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100268 mbedtls_mutex_free(&mutex);
269#endif
270}
271
272void mutex_double_init(const char *name)
273{
274 (void) name;
275#if defined(MBEDTLS_THREADING_C)
276 mbedtls_threading_mutex_t mutex;
277 mbedtls_mutex_init(&mutex);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100278 /* This mutex usage error is detected by our test framework's mutex usage
279 * verification framework. See tests/src/threading_helpers.c. Other
280 * threading implementations (e.g. pthread without our instrumentation)
281 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100282 mbedtls_mutex_init(&mutex);
283 mbedtls_mutex_free(&mutex);
284#endif
285}
286
287void mutex_double_free(const char *name)
288{
289 (void) name;
290#if defined(MBEDTLS_THREADING_C)
291 mbedtls_threading_mutex_t mutex;
292 mbedtls_mutex_init(&mutex);
293 mbedtls_mutex_free(&mutex);
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100294 /* This mutex usage error is detected by our test framework's mutex usage
295 * verification framework. See tests/src/threading_helpers.c. Other
296 * threading implementations (e.g. pthread without our instrumentation)
297 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100298 mbedtls_mutex_free(&mutex);
299#endif
300}
301
302void mutex_leak(const char *name)
303{
304 (void) name;
Gilles Peskinead2a17e2023-11-16 15:09:48 +0100305#if defined(MBEDTLS_THREADING_C)
Gilles Peskine102aea22023-11-03 18:05:38 +0100306 mbedtls_threading_mutex_t mutex;
307 mbedtls_mutex_init(&mutex);
308#endif
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100309 /* This mutex usage error is detected by our test framework's mutex usage
310 * verification framework. See tests/src/threading_helpers.c. Other
311 * threading implementations (e.g. pthread without our instrumentation)
312 * might consider this normal usage. */
Gilles Peskine102aea22023-11-03 18:05:38 +0100313}
314
315
316/****************************************************************/
Gilles Peskine33406b62023-11-02 18:48:39 +0100317/* Command line entry point */
318/****************************************************************/
319
320typedef struct {
Gilles Peskinecce00122023-11-10 15:36:15 +0100321 /** Command line argument that will trigger that metatest.
322 *
323 * Conventionally matches "[a-z0-9_]+". */
Gilles Peskine33406b62023-11-02 18:48:39 +0100324 const char *name;
Gilles Peskinecce00122023-11-10 15:36:15 +0100325
326 /** Platform under which that metatest is valid.
327 *
328 * - "any": should work anywhere.
329 * - "asan": triggers ASan (Address Sanitizer).
330 * - "msan": triggers MSan (Memory Sanitizer).
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100331 * - "pthread": requires MBEDTLS_THREADING_PTHREAD and MBEDTLS_TEST_HOOKS,
332 * which enables MBEDTLS_TEST_MUTEX_USAGE internally in the test
333 * framework (see tests/src/threading_helpers.c).
Gilles Peskinecce00122023-11-10 15:36:15 +0100334 */
Gilles Peskine33406b62023-11-02 18:48:39 +0100335 const char *platform;
Gilles Peskinecce00122023-11-10 15:36:15 +0100336
337 /** Function that performs the metatest.
338 *
339 * The function receives the name as an argument. This allows using the
340 * same function to perform multiple variants of a test based on the name.
341 *
342 * When executed on a conforming platform, the function is expected to
343 * either cause a test failure (mbedtls_test_fail()), or cause the
344 * program to abort in some way (e.g. by causing a segfault or by
345 * triggering a sanitizer).
346 *
347 * When executed on a non-conforming platform, the function may return
348 * normally or may have unpredictable behavior.
349 */
Gilles Peskine33406b62023-11-02 18:48:39 +0100350 void (*entry_point)(const char *name);
351} metatest_t;
352
Gilles Peskinecce00122023-11-10 15:36:15 +0100353/* The list of availble meta-tests. Remember to register new functions here!
354 *
355 * Note that we always compile all the functions, so that `metatest --list`
356 * will always list all the available meta-tests.
Gilles Peskine2f40cc02023-11-16 15:11:44 +0100357 *
358 * See the documentation of metatest_t::platform for the meaning of
359 * platform values.
Gilles Peskinecce00122023-11-10 15:36:15 +0100360 */
Gilles Peskine33406b62023-11-02 18:48:39 +0100361metatest_t metatests[] = {
Gilles Peskinef309fbf2023-11-02 18:49:52 +0100362 { "test_fail", "any", meta_test_fail },
Gilles Peskine80ba8322023-11-02 19:23:26 +0100363 { "null_dereference", "any", null_pointer_dereference },
364 { "null_call", "any", null_pointer_call },
Gilles Peskineb0f0a642023-11-02 19:42:13 +0100365 { "read_after_free", "asan", read_after_free },
366 { "double_free", "asan", double_free },
367 { "read_uninitialized_stack", "msan", read_uninitialized_stack },
368 { "memory_leak", "asan", memory_leak },
Gilles Peskineef0f01f2023-11-22 18:22:07 +0100369 { "test_memory_poison_0_0_8_r", "asan", test_memory_poison },
370 { "test_memory_poison_0_0_8_w", "asan", test_memory_poison },
371 { "test_memory_poison_0_7_8_r", "asan", test_memory_poison },
372 { "test_memory_poison_0_7_8_w", "asan", test_memory_poison },
373 { "test_memory_poison_0_0_1_r", "asan", test_memory_poison },
374 { "test_memory_poison_0_0_1_w", "asan", test_memory_poison },
375 { "test_memory_poison_0_1_2_r", "asan", test_memory_poison },
376 { "test_memory_poison_0_1_2_w", "asan", test_memory_poison },
377 { "test_memory_poison_7_0_8_r", "asan", test_memory_poison },
378 { "test_memory_poison_7_0_8_w", "asan", test_memory_poison },
379 { "test_memory_poison_7_7_8_r", "asan", test_memory_poison },
380 { "test_memory_poison_7_7_8_w", "asan", test_memory_poison },
381 { "test_memory_poison_7_0_1_r", "asan", test_memory_poison },
382 { "test_memory_poison_7_0_1_w", "asan", test_memory_poison },
383 { "test_memory_poison_7_1_2_r", "asan", test_memory_poison },
384 { "test_memory_poison_7_1_2_w", "asan", test_memory_poison },
Gilles Peskine102aea22023-11-03 18:05:38 +0100385 { "mutex_lock_not_initialized", "pthread", mutex_lock_not_initialized },
386 { "mutex_unlock_not_initialized", "pthread", mutex_unlock_not_initialized },
387 { "mutex_free_not_initialized", "pthread", mutex_free_not_initialized },
388 { "mutex_double_init", "pthread", mutex_double_init },
389 { "mutex_double_free", "pthread", mutex_double_free },
390 { "mutex_leak", "pthread", mutex_leak },
Gilles Peskine33406b62023-11-02 18:48:39 +0100391 { NULL, NULL, NULL }
392};
393
394static void help(FILE *out, const char *argv0)
395{
396 mbedtls_fprintf(out, "Usage: %s list|TEST\n", argv0);
397 mbedtls_fprintf(out, "Run a meta-test that should cause a test failure.\n");
398 mbedtls_fprintf(out, "With 'list', list the available tests and their platform requirement.\n");
399}
400
401int main(int argc, char *argv[])
402{
403 const char *argv0 = argc > 0 ? argv[0] : "metatest";
404 if (argc != 2) {
405 help(stderr, argv0);
406 mbedtls_exit(MBEDTLS_EXIT_FAILURE);
407 }
408
409 /* Support "-help", "--help", "--list", etc. */
410 const char *command = argv[1];
411 while (*command == '-') {
412 ++command;
413 }
414
415 if (strcmp(argv[1], "help") == 0) {
416 help(stdout, argv0);
417 mbedtls_exit(MBEDTLS_EXIT_SUCCESS);
418 }
419 if (strcmp(argv[1], "list") == 0) {
420 for (const metatest_t *p = metatests; p->name != NULL; p++) {
421 mbedtls_printf("%s %s\n", p->name, p->platform);
422 }
423 mbedtls_exit(MBEDTLS_EXIT_SUCCESS);
424 }
425
Gilles Peskine102aea22023-11-03 18:05:38 +0100426#if defined(MBEDTLS_TEST_MUTEX_USAGE)
427 mbedtls_test_mutex_usage_init();
428#endif
429
Gilles Peskine33406b62023-11-02 18:48:39 +0100430 for (const metatest_t *p = metatests; p->name != NULL; p++) {
431 if (strcmp(argv[1], p->name) == 0) {
432 mbedtls_printf("Running metatest %s...\n", argv[1]);
433 p->entry_point(argv[1]);
Gilles Peskine102aea22023-11-03 18:05:38 +0100434#if defined(MBEDTLS_TEST_MUTEX_USAGE)
435 mbedtls_test_mutex_usage_check();
436#endif
Gilles Peskine33406b62023-11-02 18:48:39 +0100437 mbedtls_printf("Running metatest %s... done, result=%d\n",
438 argv[1], (int) mbedtls_test_info.result);
439 mbedtls_exit(mbedtls_test_info.result == MBEDTLS_TEST_RESULT_SUCCESS ?
440 MBEDTLS_EXIT_SUCCESS :
441 MBEDTLS_EXIT_FAILURE);
442 }
443 }
444
445 mbedtls_fprintf(stderr, "%s: FATAL: No such metatest: %s\n",
446 argv0, command);
447 mbedtls_exit(MBEDTLS_EXIT_FAILURE);
448}