summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2013-12-05 01:40:49 (GMT)
committerJason Evans <je@fb.com>2013-12-05 01:40:49 (GMT)
commit72284f03357d6fb4a7ff82542dd1a41d567b0bb2 (patch)
treeebcb6a05766ab11bfd18528fe95c93c167f418c8
parent95424fc1884112d6b90193481e8ad26247463b4b (diff)
downloadjemalloc-72284f03357d6fb4a7ff82542dd1a41d567b0bb2.zip
jemalloc-72284f03357d6fb4a7ff82542dd1a41d567b0bb2.tar.gz
jemalloc-72284f03357d6fb4a7ff82542dd1a41d567b0bb2.tar.bz2
Add tsd test.
Submitted by Mike Hommey.
-rw-r--r--.gitignore6
-rw-r--r--Makefile.in3
-rw-r--r--test/unit/tsd.c54
-rw-r--r--test/unit/tsd.exp9
4 files changed, 68 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 0a9ca18..afde57a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,19 +37,19 @@
test/include/test/jemalloc_test.h
/test/integration/[A-Za-z]*
-!/test/integration/*.*
+!/test/integration/[A-Za-z]*.*
/test/integration/*.[od]
/test/integration/*.out
/test/src/*.[od]
/test/stress/[A-Za-z]*
-!/test/stress/*.*
+!/test/stress/[A-Za-z]*.*
/test/stress/*.[od]
/test/stress/*.out
/test/unit/[A-Za-z]*
-!/test/unit/*.*
+!/test/unit/[A-Za-z]*.*
/test/unit/*.[od]
/test/unit/*.out
diff --git a/Makefile.in b/Makefile.in
index 8d3e22a..ab6662c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -104,7 +104,8 @@ DOCS_MAN3 := $(DOCS_XML:$(objroot)%.xml=$(srcroot)%.3)
DOCS := $(DOCS_HTML) $(DOCS_MAN3)
C_TESTLIB_SRCS := $(srcroot)test/src/test.c $(srcroot)test/src/thread.c
C_UTIL_INTEGRATION_SRCS := $(srcroot)src/util.c
-TESTS_UNIT := $(srcroot)test/unit/bitmap.c
+TESTS_UNIT := $(srcroot)test/unit/bitmap.c \
+ $(srcroot)test/unit/tsd.c
TESTS_INTEGRATION := $(srcroot)test/integration/aligned_alloc.c \
$(srcroot)test/integration/allocated.c \
$(srcroot)test/integration/ALLOCM_ARENA.c \
diff --git a/test/unit/tsd.c b/test/unit/tsd.c
new file mode 100644
index 0000000..dacddff
--- /dev/null
+++ b/test/unit/tsd.c
@@ -0,0 +1,54 @@
+#include "test/jemalloc_test.h"
+
+#define THREAD_DATA 0x72b65c10
+
+typedef unsigned int data_t;
+
+void
+data_cleanup(void *arg)
+{
+ data_t *data = (data_t *)arg;
+
+ malloc_printf("Cleanup for data %x.\n", *data);
+}
+
+malloc_tsd_protos(, data, data_t)
+malloc_tsd_externs(data, data_t)
+#define DATA_INIT 0x12345678
+malloc_tsd_data(, data, data_t, DATA_INIT)
+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_tsd_set(&d);
+ malloc_printf("After tsd_set: %x. Expected %x.\n",
+ *data_tsd_get(), d);
+
+ d = 0;
+ malloc_printf("After resetting local data: %x. Expected %x.\n",
+ *data_tsd_get(), (data_t)(uintptr_t) arg);
+
+ return NULL;
+}
+
+int
+main(void)
+{
+ je_thread_t thread;
+
+ malloc_printf("Test begin\n");
+
+ data_tsd_boot();
+ je_thread_start((void *) 0xa5f3e329);
+
+ je_thread_create(&thread, je_thread_start, (void *) THREAD_DATA);
+ je_thread_join(thread, NULL);
+
+ malloc_printf("Test end\n");
+ return (0);
+}
diff --git a/test/unit/tsd.exp b/test/unit/tsd.exp
new file mode 100644
index 0000000..b4abedc
--- /dev/null
+++ b/test/unit/tsd.exp
@@ -0,0 +1,9 @@
+Test begin
+Initial tsd_get returns 12345678. Expected 12345678.
+After tsd_set: a5f3e329. Expected a5f3e329.
+After resetting local data: a5f3e329. Expected a5f3e329.
+Initial tsd_get returns 12345678. Expected 12345678.
+After tsd_set: 72b65c10. Expected 72b65c10.
+After resetting local data: 72b65c10. Expected 72b65c10.
+Cleanup for data 72b65c10.
+Test end