2013-12-05 09:40:49 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2013-12-09 14:28:27 +08:00
|
|
|
#define THREAD_DATA 0x72b65c10
|
2013-12-05 09:40:49 +08:00
|
|
|
|
|
|
|
typedef unsigned int data_t;
|
|
|
|
|
2013-12-09 12:52:21 +08:00
|
|
|
static bool data_cleanup_executed;
|
|
|
|
|
2013-12-05 09:40:49 +08:00
|
|
|
void
|
|
|
|
data_cleanup(void *arg)
|
|
|
|
{
|
|
|
|
data_t *data = (data_t *)arg;
|
|
|
|
|
2013-12-09 12:52:21 +08:00
|
|
|
assert_x_eq(*data, THREAD_DATA,
|
|
|
|
"Argument passed into cleanup function should match tsd value");
|
|
|
|
data_cleanup_executed = true;
|
2013-12-05 09:40:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
malloc_tsd_protos(, data, data_t)
|
|
|
|
malloc_tsd_externs(data, data_t)
|
2013-12-09 14:28:27 +08:00
|
|
|
#define DATA_INIT 0x12345678
|
2013-12-05 09:40:49 +08:00
|
|
|
malloc_tsd_data(, data, data_t, DATA_INIT)
|
|
|
|
malloc_tsd_funcs(, data, data_t, DATA_INIT, data_cleanup)
|
|
|
|
|
|
|
|
void *
|
|
|
|
je_thread_start(void *arg)
|
|
|
|
{
|
2013-12-09 12:52:21 +08:00
|
|
|
data_t d = (data_t)(uintptr_t)arg;
|
|
|
|
assert_x_eq(*data_tsd_get(), DATA_INIT,
|
|
|
|
"Initial tsd get should return initialization value");
|
2013-12-05 09:40:49 +08:00
|
|
|
|
|
|
|
data_tsd_set(&d);
|
2013-12-09 12:52:21 +08:00
|
|
|
assert_x_eq(*data_tsd_get(), d,
|
|
|
|
"After tsd set, tsd get should return value that was set");
|
2013-12-05 09:40:49 +08:00
|
|
|
|
|
|
|
d = 0;
|
2013-12-09 12:52:21 +08:00
|
|
|
assert_x_eq(*data_tsd_get(), (data_t)(uintptr_t)arg,
|
|
|
|
"Resetting local data should have no effect on tsd");
|
2013-12-05 09:40:49 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-12-09 12:52:21 +08:00
|
|
|
TEST_BEGIN(test_tsd_main_thread)
|
2013-12-05 09:40:49 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
je_thread_start((void *) 0xa5f3e329);
|
2013-12-09 12:52:21 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
2013-12-05 09:40:49 +08:00
|
|
|
|
2013-12-09 12:52:21 +08:00
|
|
|
TEST_BEGIN(test_tsd_sub_thread)
|
|
|
|
{
|
|
|
|
je_thread_t thread;
|
|
|
|
|
|
|
|
data_cleanup_executed = false;
|
2013-12-05 09:40:49 +08:00
|
|
|
je_thread_create(&thread, je_thread_start, (void *) THREAD_DATA);
|
|
|
|
je_thread_join(thread, NULL);
|
2013-12-09 12:52:21 +08:00
|
|
|
assert_true(data_cleanup_executed,
|
|
|
|
"Cleanup function should have executed");
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
data_tsd_boot();
|
2013-12-05 09:40:49 +08:00
|
|
|
|
2013-12-09 12:52:21 +08:00
|
|
|
return (test(
|
|
|
|
test_tsd_main_thread,
|
|
|
|
test_tsd_sub_thread));
|
2013-12-05 09:40:49 +08:00
|
|
|
}
|