summaryrefslogtreecommitdiff
path: root/examples/redis-unstable/deps/jemalloc/test/unit/prof_sys_thread_name.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:40:55 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:40:55 +0100
commit5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda (patch)
tree1acdfa5220cd13b7be43a2a01368e80d306473ca /examples/redis-unstable/deps/jemalloc/test/unit/prof_sys_thread_name.c
parentc7ab12bba64d9c20ccd79b132dac475f7bc3923e (diff)
downloadcrep-5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda.tar.gz
Add Redis source code for testing
Diffstat (limited to 'examples/redis-unstable/deps/jemalloc/test/unit/prof_sys_thread_name.c')
-rw-r--r--examples/redis-unstable/deps/jemalloc/test/unit/prof_sys_thread_name.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/jemalloc/test/unit/prof_sys_thread_name.c b/examples/redis-unstable/deps/jemalloc/test/unit/prof_sys_thread_name.c
new file mode 100644
index 0000000..affc788
--- /dev/null
+++ b/examples/redis-unstable/deps/jemalloc/test/unit/prof_sys_thread_name.c
@@ -0,0 +1,77 @@
+#include "test/jemalloc_test.h"
+
+#include "jemalloc/internal/prof_sys.h"
+
+static const char *test_thread_name = "test_name";
+
+static int
+test_prof_sys_thread_name_read_error(char *buf, size_t limit) {
+ return ENOSYS;
+}
+
+static int
+test_prof_sys_thread_name_read(char *buf, size_t limit) {
+ assert(strlen(test_thread_name) < limit);
+ strncpy(buf, test_thread_name, limit);
+ return 0;
+}
+
+static int
+test_prof_sys_thread_name_read_clear(char *buf, size_t limit) {
+ assert(limit > 0);
+ buf[0] = '\0';
+ return 0;
+}
+
+TEST_BEGIN(test_prof_sys_thread_name) {
+ test_skip_if(!config_prof);
+
+ bool oldval;
+ size_t sz = sizeof(oldval);
+ assert_d_eq(mallctl("opt.prof_sys_thread_name", &oldval, &sz, NULL, 0),
+ 0, "mallctl failed");
+ assert_true(oldval, "option was not set correctly");
+
+ const char *thread_name;
+ sz = sizeof(thread_name);
+ assert_d_eq(mallctl("thread.prof.name", &thread_name, &sz, NULL, 0), 0,
+ "mallctl read for thread name should not fail");
+ expect_str_eq(thread_name, "", "Initial thread name should be empty");
+
+ thread_name = test_thread_name;
+ assert_d_eq(mallctl("thread.prof.name", NULL, NULL, &thread_name, sz),
+ ENOENT, "mallctl write for thread name should fail");
+ assert_ptr_eq(thread_name, test_thread_name,
+ "Thread name should not be touched");
+
+ prof_sys_thread_name_read = test_prof_sys_thread_name_read_error;
+ void *p = malloc(1);
+ free(p);
+ assert_d_eq(mallctl("thread.prof.name", &thread_name, &sz, NULL, 0), 0,
+ "mallctl read for thread name should not fail");
+ assert_str_eq(thread_name, "",
+ "Thread name should stay the same if the system call fails");
+
+ prof_sys_thread_name_read = test_prof_sys_thread_name_read;
+ p = malloc(1);
+ free(p);
+ assert_d_eq(mallctl("thread.prof.name", &thread_name, &sz, NULL, 0), 0,
+ "mallctl read for thread name should not fail");
+ assert_str_eq(thread_name, test_thread_name,
+ "Thread name should be changed if the system call succeeds");
+
+ prof_sys_thread_name_read = test_prof_sys_thread_name_read_clear;
+ p = malloc(1);
+ free(p);
+ assert_d_eq(mallctl("thread.prof.name", &thread_name, &sz, NULL, 0), 0,
+ "mallctl read for thread name should not fail");
+ expect_str_eq(thread_name, "", "Thread name should be updated if the "
+ "system call returns a different name");
+}
+TEST_END
+
+int
+main(void) {
+ return test(
+ test_prof_sys_thread_name);
+}