summaryrefslogtreecommitdiffstats
path: root/test/unit/prof_reset.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/prof_reset.c')
-rw-r--r--test/unit/prof_reset.c63
1 files changed, 25 insertions, 38 deletions
diff --git a/test/unit/prof_reset.c b/test/unit/prof_reset.c
index 87b0d0c..7cce42d 100644
--- a/test/unit/prof_reset.c
+++ b/test/unit/prof_reset.c
@@ -1,39 +1,34 @@
#include "test/jemalloc_test.h"
static int
-prof_dump_open_intercept(bool propagate_err, const char *filename)
-{
+prof_dump_open_intercept(bool propagate_err, const char *filename) {
int fd;
fd = open("/dev/null", O_WRONLY);
assert_d_ne(fd, -1, "Unexpected open() failure");
- return (fd);
+ return fd;
}
static void
-set_prof_active(bool active)
-{
-
+set_prof_active(bool active) {
assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active,
sizeof(active)), 0, "Unexpected mallctl failure");
}
static size_t
-get_lg_prof_sample(void)
-{
+get_lg_prof_sample(void) {
size_t lg_prof_sample;
size_t sz = sizeof(size_t);
assert_d_eq(mallctl("prof.lg_sample", (void *)&lg_prof_sample, &sz,
NULL, 0), 0,
"Unexpected mallctl failure while reading profiling sample rate");
- return (lg_prof_sample);
+ return lg_prof_sample;
}
static void
-do_prof_reset(size_t lg_prof_sample)
-{
+do_prof_reset(size_t lg_prof_sample) {
assert_d_eq(mallctl("prof.reset", NULL, NULL,
(void *)&lg_prof_sample, sizeof(size_t)), 0,
"Unexpected mallctl failure while resetting profile data");
@@ -41,8 +36,7 @@ do_prof_reset(size_t lg_prof_sample)
"Expected profile sample rate change");
}
-TEST_BEGIN(test_prof_reset_basic)
-{
+TEST_BEGIN(test_prof_reset_basic) {
size_t lg_prof_sample_orig, lg_prof_sample, lg_prof_sample_next;
size_t sz;
unsigned i;
@@ -91,17 +85,14 @@ bool prof_dump_header_intercepted = false;
prof_cnt_t cnt_all_copy = {0, 0, 0, 0};
static bool
prof_dump_header_intercept(tsdn_t *tsdn, bool propagate_err,
- const prof_cnt_t *cnt_all)
-{
-
+ const prof_cnt_t *cnt_all) {
prof_dump_header_intercepted = true;
memcpy(&cnt_all_copy, cnt_all, sizeof(prof_cnt_t));
- return (false);
+ return false;
}
-TEST_BEGIN(test_prof_reset_cleanup)
-{
+TEST_BEGIN(test_prof_reset_cleanup) {
void *p;
prof_dump_header_t *prof_dump_header_orig;
@@ -139,14 +130,13 @@ TEST_BEGIN(test_prof_reset_cleanup)
}
TEST_END
-#define NTHREADS 4
-#define NALLOCS_PER_THREAD (1U << 13)
-#define OBJ_RING_BUF_COUNT 1531
-#define RESET_INTERVAL (1U << 10)
-#define DUMP_INTERVAL 3677
+#define NTHREADS 4
+#define NALLOCS_PER_THREAD (1U << 13)
+#define OBJ_RING_BUF_COUNT 1531
+#define RESET_INTERVAL (1U << 10)
+#define DUMP_INTERVAL 3677
static void *
-thd_start(void *varg)
-{
+thd_start(void *varg) {
unsigned thd_ind = *(unsigned *)varg;
unsigned i;
void *objs[OBJ_RING_BUF_COUNT];
@@ -186,11 +176,10 @@ thd_start(void *varg)
}
}
- return (NULL);
+ return NULL;
}
-TEST_BEGIN(test_prof_reset)
-{
+TEST_BEGIN(test_prof_reset) {
size_t lg_prof_sample_orig;
thd_t thds[NTHREADS];
unsigned thd_args[NTHREADS];
@@ -213,8 +202,9 @@ TEST_BEGIN(test_prof_reset)
thd_args[i] = i;
thd_create(&thds[i], thd_start, (void *)&thd_args[i]);
}
- for (i = 0; i < NTHREADS; i++)
+ for (i = 0; i < NTHREADS; i++) {
thd_join(thds[i], NULL);
+ }
assert_zu_eq(prof_bt_count(), bt_count,
"Unexpected bactrace count change");
@@ -233,9 +223,8 @@ TEST_END
#undef DUMP_INTERVAL
/* Test sampling at the same allocation site across resets. */
-#define NITER 10
-TEST_BEGIN(test_xallocx)
-{
+#define NITER 10
+TEST_BEGIN(test_xallocx) {
size_t lg_prof_sample_orig;
unsigned i;
void *ptrs[NITER];
@@ -285,15 +274,13 @@ TEST_END
#undef NITER
int
-main(void)
-{
-
+main(void) {
/* Intercept dumping prior to running any tests. */
prof_dump_open = prof_dump_open_intercept;
- return (test(
+ return test_no_reentrancy(
test_prof_reset_basic,
test_prof_reset_cleanup,
test_prof_reset,
- test_xallocx));
+ test_xallocx);
}