Add a multithreaded test for prof_sys_thread_name.
Verified that this catches the issue being fixed in 5fd5583
.
This commit is contained in:
parent
5266152d79
commit
6cab460a45
@ -3,6 +3,7 @@
|
|||||||
#include "jemalloc/internal/prof_sys.h"
|
#include "jemalloc/internal/prof_sys.h"
|
||||||
|
|
||||||
static const char *test_thread_name = "test_name";
|
static const char *test_thread_name = "test_name";
|
||||||
|
static const char *dump_filename = "/dev/null";
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_prof_sys_thread_name_read_error(char *buf, size_t limit) {
|
test_prof_sys_thread_name_read_error(char *buf, size_t limit) {
|
||||||
@ -25,6 +26,7 @@ test_prof_sys_thread_name_read_clear(char *buf, size_t limit) {
|
|||||||
|
|
||||||
TEST_BEGIN(test_prof_sys_thread_name) {
|
TEST_BEGIN(test_prof_sys_thread_name) {
|
||||||
test_skip_if(!config_prof);
|
test_skip_if(!config_prof);
|
||||||
|
test_skip_if(!opt_prof_sys_thread_name);
|
||||||
|
|
||||||
bool oldval;
|
bool oldval;
|
||||||
size_t sz = sizeof(oldval);
|
size_t sz = sizeof(oldval);
|
||||||
@ -44,6 +46,8 @@ TEST_BEGIN(test_prof_sys_thread_name) {
|
|||||||
assert_ptr_eq(thread_name, test_thread_name,
|
assert_ptr_eq(thread_name, test_thread_name,
|
||||||
"Thread name should not be touched");
|
"Thread name should not be touched");
|
||||||
|
|
||||||
|
prof_sys_thread_name_read_t *orig_prof_sys_thread_name_read =
|
||||||
|
prof_sys_thread_name_read;
|
||||||
prof_sys_thread_name_read = test_prof_sys_thread_name_read_error;
|
prof_sys_thread_name_read = test_prof_sys_thread_name_read_error;
|
||||||
void *p = malloc(1);
|
void *p = malloc(1);
|
||||||
free(p);
|
free(p);
|
||||||
@ -67,11 +71,55 @@ TEST_BEGIN(test_prof_sys_thread_name) {
|
|||||||
"mallctl read for thread name should not fail");
|
"mallctl read for thread name should not fail");
|
||||||
expect_str_eq(thread_name, "", "Thread name should be updated if the "
|
expect_str_eq(thread_name, "", "Thread name should be updated if the "
|
||||||
"system call returns a different name");
|
"system call returns a different name");
|
||||||
|
|
||||||
|
prof_sys_thread_name_read = orig_prof_sys_thread_name_read;
|
||||||
}
|
}
|
||||||
TEST_END
|
TEST_END
|
||||||
|
|
||||||
|
#define ITER (16*1024)
|
||||||
|
static void *
|
||||||
|
thd_start(void *unused) {
|
||||||
|
/* Triggering samples which loads thread names. */
|
||||||
|
for (unsigned i = 0; i < ITER; i++) {
|
||||||
|
void *p = mallocx(4096, 0);
|
||||||
|
assert_ptr_not_null(p, "Unexpected mallocx() failure");
|
||||||
|
dallocx(p, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_BEGIN(test_prof_sys_thread_name_mt) {
|
||||||
|
test_skip_if(!config_prof);
|
||||||
|
test_skip_if(!opt_prof_sys_thread_name);
|
||||||
|
|
||||||
|
#define NTHREADS 4
|
||||||
|
thd_t thds[NTHREADS];
|
||||||
|
unsigned thd_args[NTHREADS];
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < NTHREADS; i++) {
|
||||||
|
thd_args[i] = i;
|
||||||
|
thd_create(&thds[i], thd_start, (void *)&thd_args[i]);
|
||||||
|
}
|
||||||
|
/* Prof dump which reads the thread names. */
|
||||||
|
for (i = 0; i < ITER; i++) {
|
||||||
|
expect_d_eq(mallctl("prof.dump", NULL, NULL,
|
||||||
|
(void *)&dump_filename, sizeof(dump_filename)), 0,
|
||||||
|
"Unexpected mallctl failure while dumping");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < NTHREADS; i++) {
|
||||||
|
thd_join(thds[i], NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef NTHREADS
|
||||||
|
#undef ITER
|
||||||
|
TEST_END
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void) {
|
main(void) {
|
||||||
return test(
|
return test(
|
||||||
test_prof_sys_thread_name);
|
test_prof_sys_thread_name,
|
||||||
|
test_prof_sys_thread_name_mt);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user