1 #include "test/jemalloc_test.h"
4 mallctl_thread_name_get_impl(const char *thread_name_expected
, const char *func
,
7 const char *thread_name_old
;
10 sz
= sizeof(thread_name_old
);
11 assert_d_eq(mallctl("thread.prof.name", (void *)&thread_name_old
, &sz
,
13 "%s():%d: Unexpected mallctl failure reading thread.prof.name",
15 assert_str_eq(thread_name_old
, thread_name_expected
,
16 "%s():%d: Unexpected thread.prof.name value", func
, line
);
18 #define mallctl_thread_name_get(a) \
19 mallctl_thread_name_get_impl(a, __func__, __LINE__)
22 mallctl_thread_name_set_impl(const char *thread_name
, const char *func
,
26 assert_d_eq(mallctl("thread.prof.name", NULL
, NULL
,
27 (void *)&thread_name
, sizeof(thread_name
)), 0,
28 "%s():%d: Unexpected mallctl failure reading thread.prof.name",
30 mallctl_thread_name_get_impl(thread_name
, func
, line
);
32 #define mallctl_thread_name_set(a) \
33 mallctl_thread_name_set_impl(a, __func__, __LINE__)
35 TEST_BEGIN(test_prof_thread_name_validation
)
37 const char *thread_name
;
39 test_skip_if(!config_prof
);
41 mallctl_thread_name_get("");
42 mallctl_thread_name_set("hi there");
44 /* NULL input shouldn't be allowed. */
46 assert_d_eq(mallctl("thread.prof.name", NULL
, NULL
,
47 (void *)&thread_name
, sizeof(thread_name
)), EFAULT
,
48 "Unexpected mallctl result writing \"%s\" to thread.prof.name",
51 /* '\n' shouldn't be allowed. */
52 thread_name
= "hi\nthere";
53 assert_d_eq(mallctl("thread.prof.name", NULL
, NULL
,
54 (void *)&thread_name
, sizeof(thread_name
)), EFAULT
,
55 "Unexpected mallctl result writing \"%s\" to thread.prof.name",
58 /* Simultaneous read/write shouldn't be allowed. */
60 const char *thread_name_old
;
63 sz
= sizeof(thread_name_old
);
64 assert_d_eq(mallctl("thread.prof.name",
65 (void *)&thread_name_old
, &sz
, (void *)&thread_name
,
66 sizeof(thread_name
)), EPERM
,
67 "Unexpected mallctl result writing \"%s\" to "
68 "thread.prof.name", thread_name
);
71 mallctl_thread_name_set("");
80 unsigned thd_ind
= *(unsigned *)varg
;
81 char thread_name
[16] = "";
84 malloc_snprintf(thread_name
, sizeof(thread_name
), "thread %u", thd_ind
);
86 mallctl_thread_name_get("");
87 mallctl_thread_name_set(thread_name
);
89 for (i
= 0; i
< NRESET
; i
++) {
90 assert_d_eq(mallctl("prof.reset", NULL
, NULL
, NULL
, 0), 0,
91 "Unexpected error while resetting heap profile data");
92 mallctl_thread_name_get(thread_name
);
95 mallctl_thread_name_set(thread_name
);
96 mallctl_thread_name_set("");
101 TEST_BEGIN(test_prof_thread_name_threaded
)
103 thd_t thds
[NTHREADS
];
104 unsigned thd_args
[NTHREADS
];
107 test_skip_if(!config_prof
);
109 for (i
= 0; i
< NTHREADS
; i
++) {
111 thd_create(&thds
[i
], thd_start
, (void *)&thd_args
[i
]);
113 for (i
= 0; i
< NTHREADS
; i
++)
114 thd_join(thds
[i
], NULL
);
125 test_prof_thread_name_validation
,
126 test_prof_thread_name_threaded
));