mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 21:23:06 +00:00
Refactor tests.
Refactor tests to use explicit testing assertions, rather than diff'ing test output. This makes the test code a bit shorter, more explicitly encodes testing intent, and makes test failure diagnosis more straightforward.
This commit is contained in:
@@ -4,12 +4,16 @@
|
||||
|
||||
typedef unsigned int data_t;
|
||||
|
||||
static bool data_cleanup_executed;
|
||||
|
||||
void
|
||||
data_cleanup(void *arg)
|
||||
{
|
||||
data_t *data = (data_t *)arg;
|
||||
|
||||
malloc_printf("Cleanup for data %x.\n", *data);
|
||||
assert_x_eq(*data, THREAD_DATA,
|
||||
"Argument passed into cleanup function should match tsd value");
|
||||
data_cleanup_executed = true;
|
||||
}
|
||||
|
||||
malloc_tsd_protos(, data, data_t)
|
||||
@@ -21,34 +25,47 @@ malloc_tsd_funcs(, data, data_t, DATA_INIT, data_cleanup)
|
||||
void *
|
||||
je_thread_start(void *arg)
|
||||
{
|
||||
data_t d = (data_t)(uintptr_t) arg;
|
||||
malloc_printf("Initial tsd_get returns %x. Expected %x.\n",
|
||||
*data_tsd_get(), DATA_INIT);
|
||||
data_t d = (data_t)(uintptr_t)arg;
|
||||
assert_x_eq(*data_tsd_get(), DATA_INIT,
|
||||
"Initial tsd get should return initialization value");
|
||||
|
||||
data_tsd_set(&d);
|
||||
malloc_printf("After tsd_set: %x. Expected %x.\n",
|
||||
*data_tsd_get(), d);
|
||||
assert_x_eq(*data_tsd_get(), d,
|
||||
"After tsd set, tsd get should return value that was set");
|
||||
|
||||
d = 0;
|
||||
malloc_printf("After resetting local data: %x. Expected %x.\n",
|
||||
*data_tsd_get(), (data_t)(uintptr_t) arg);
|
||||
assert_x_eq(*data_tsd_get(), (data_t)(uintptr_t)arg,
|
||||
"Resetting local data should have no effect on tsd");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
TEST_BEGIN(test_tsd_main_thread)
|
||||
{
|
||||
|
||||
je_thread_start((void *) 0xa5f3e329);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_tsd_sub_thread)
|
||||
{
|
||||
je_thread_t thread;
|
||||
|
||||
malloc_printf("Test begin\n");
|
||||
|
||||
data_tsd_boot();
|
||||
je_thread_start((void *) 0xa5f3e329);
|
||||
|
||||
data_cleanup_executed = false;
|
||||
je_thread_create(&thread, je_thread_start, (void *) THREAD_DATA);
|
||||
je_thread_join(thread, NULL);
|
||||
|
||||
malloc_printf("Test end\n");
|
||||
return (0);
|
||||
assert_true(data_cleanup_executed,
|
||||
"Cleanup function should have executed");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
data_tsd_boot();
|
||||
|
||||
return (test(
|
||||
test_tsd_main_thread,
|
||||
test_tsd_sub_thread));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user