Run single subtest from a test file

Add mechanism to be able to select a test to run from a test file. The test harness will read the JEMALLOC_TEST_NAME env and, if set, it will only run subtests with that name.
This commit is contained in:
Tony Printezis 2026-02-19 12:42:52 -08:00 committed by Guangli Dai
parent 34ace9169b
commit 0fa27fd28f
2 changed files with 23 additions and 6 deletions

View file

@ -520,12 +520,15 @@ typedef void(test_t)(void);
#define TEST_BEGIN(f) \
static void f(void) { \
p_test_init(#f);
const bool skip_test = p_test_init(#f); \
if (skip_test) { \
goto label_test_end; \
}
#define TEST_END \
goto label_test_end; \
label_test_end: \
p_test_fini(); \
p_test_fini(skip_test); \
}
#define test(...) p_test(__VA_ARGS__, NULL)
@ -552,6 +555,6 @@ void test_fail(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
test_status_t p_test(test_t *t, ...);
test_status_t p_test_no_reentrancy(test_t *t, ...);
test_status_t p_test_no_malloc_init(test_t *t, ...);
void p_test_init(const char *name);
void p_test_fini(void);
bool p_test_init(const char *name);
void p_test_fini(bool skip_test);
void p_test_fail(bool may_abort, const char *prefix, const char *message);

View file

@ -6,6 +6,7 @@ static unsigned test_count = 0;
static test_status_t test_counts[test_status_count] = {0, 0, 0};
static test_status_t test_status = test_status_pass;
static const char *test_name = "";
static const char *selected_test_name = NULL;
/* Reentrancy testing helpers. */
@ -100,15 +101,26 @@ test_status_string(test_status_t current_status) {
}
}
void
bool
p_test_init(const char *name) {
if (selected_test_name != NULL && strcmp(selected_test_name, name)) {
/* skip test */
return true;
}
test_count++;
test_status = test_status_pass;
test_name = name;
return false;
}
void
p_test_fini(void) {
p_test_fini(bool skip_test) {
if (skip_test) {
return;
}
test_counts[test_status]++;
malloc_printf("%s (%s): %s\n", test_name, reentrancy_t_str(reentrancy),
test_status_string(test_status));
@ -130,6 +142,8 @@ check_global_slow(test_status_t *status) {
static test_status_t
p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
selected_test_name = getenv("JEMALLOC_TEST_NAME");
test_status_t ret;
if (do_malloc_init) {