|
Packit |
345191 |
#include "test/jemalloc_test.h"
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void
|
|
Packit |
345191 |
mallctl_bool_get(const char *name, bool expected, const char *func, int line) {
|
|
Packit |
345191 |
bool old;
|
|
Packit |
345191 |
size_t sz;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
sz = sizeof(old);
|
|
Packit |
345191 |
assert_d_eq(mallctl(name, (void *)&old, &sz, NULL, 0), 0,
|
|
Packit |
345191 |
"%s():%d: Unexpected mallctl failure reading %s", func, line, name);
|
|
Packit |
345191 |
assert_b_eq(old, expected, "%s():%d: Unexpected %s value", func, line,
|
|
Packit |
345191 |
name);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void
|
|
Packit |
345191 |
mallctl_bool_set(const char *name, bool old_expected, bool val_new,
|
|
Packit |
345191 |
const char *func, int line) {
|
|
Packit |
345191 |
bool old;
|
|
Packit |
345191 |
size_t sz;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
sz = sizeof(old);
|
|
Packit |
345191 |
assert_d_eq(mallctl(name, (void *)&old, &sz, (void *)&val_new,
|
|
Packit |
345191 |
sizeof(val_new)), 0,
|
|
Packit |
345191 |
"%s():%d: Unexpected mallctl failure reading/writing %s", func,
|
|
Packit |
345191 |
line, name);
|
|
Packit |
345191 |
assert_b_eq(old, old_expected, "%s():%d: Unexpected %s value", func,
|
|
Packit |
345191 |
line, name);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void
|
|
Packit |
345191 |
mallctl_prof_active_get_impl(bool prof_active_old_expected, const char *func,
|
|
Packit |
345191 |
int line) {
|
|
Packit |
345191 |
mallctl_bool_get("prof.active", prof_active_old_expected, func, line);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
#define mallctl_prof_active_get(a) \
|
|
Packit |
345191 |
mallctl_prof_active_get_impl(a, __func__, __LINE__)
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void
|
|
Packit |
345191 |
mallctl_prof_active_set_impl(bool prof_active_old_expected,
|
|
Packit |
345191 |
bool prof_active_new, const char *func, int line) {
|
|
Packit |
345191 |
mallctl_bool_set("prof.active", prof_active_old_expected,
|
|
Packit |
345191 |
prof_active_new, func, line);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
#define mallctl_prof_active_set(a, b) \
|
|
Packit |
345191 |
mallctl_prof_active_set_impl(a, b, __func__, __LINE__)
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void
|
|
Packit |
345191 |
mallctl_thread_prof_active_get_impl(bool thread_prof_active_old_expected,
|
|
Packit |
345191 |
const char *func, int line) {
|
|
Packit |
345191 |
mallctl_bool_get("thread.prof.active", thread_prof_active_old_expected,
|
|
Packit |
345191 |
func, line);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
#define mallctl_thread_prof_active_get(a) \
|
|
Packit |
345191 |
mallctl_thread_prof_active_get_impl(a, __func__, __LINE__)
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void
|
|
Packit |
345191 |
mallctl_thread_prof_active_set_impl(bool thread_prof_active_old_expected,
|
|
Packit |
345191 |
bool thread_prof_active_new, const char *func, int line) {
|
|
Packit |
345191 |
mallctl_bool_set("thread.prof.active", thread_prof_active_old_expected,
|
|
Packit |
345191 |
thread_prof_active_new, func, line);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
#define mallctl_thread_prof_active_set(a, b) \
|
|
Packit |
345191 |
mallctl_thread_prof_active_set_impl(a, b, __func__, __LINE__)
|
|
Packit |
345191 |
|
|
Packit |
345191 |
static void
|
|
Packit |
345191 |
prof_sampling_probe_impl(bool expect_sample, const char *func, int line) {
|
|
Packit |
345191 |
void *p;
|
|
Packit |
345191 |
size_t expected_backtraces = expect_sample ? 1 : 0;
|
|
Packit |
345191 |
|
|
Packit |
345191 |
assert_zu_eq(prof_bt_count(), 0, "%s():%d: Expected 0 backtraces", func,
|
|
Packit |
345191 |
line);
|
|
Packit |
345191 |
p = mallocx(1, 0);
|
|
Packit |
345191 |
assert_ptr_not_null(p, "Unexpected mallocx() failure");
|
|
Packit |
345191 |
assert_zu_eq(prof_bt_count(), expected_backtraces,
|
|
Packit |
345191 |
"%s():%d: Unexpected backtrace count", func, line);
|
|
Packit |
345191 |
dallocx(p, 0);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
#define prof_sampling_probe(a) \
|
|
Packit |
345191 |
prof_sampling_probe_impl(a, __func__, __LINE__)
|
|
Packit |
345191 |
|
|
Packit |
345191 |
TEST_BEGIN(test_prof_active) {
|
|
Packit |
345191 |
test_skip_if(!config_prof);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
mallctl_prof_active_get(true);
|
|
Packit |
345191 |
mallctl_thread_prof_active_get(false);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
mallctl_prof_active_set(true, true);
|
|
Packit |
345191 |
mallctl_thread_prof_active_set(false, false);
|
|
Packit |
345191 |
/* prof.active, !thread.prof.active. */
|
|
Packit |
345191 |
prof_sampling_probe(false);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
mallctl_prof_active_set(true, false);
|
|
Packit |
345191 |
mallctl_thread_prof_active_set(false, false);
|
|
Packit |
345191 |
/* !prof.active, !thread.prof.active. */
|
|
Packit |
345191 |
prof_sampling_probe(false);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
mallctl_prof_active_set(false, false);
|
|
Packit |
345191 |
mallctl_thread_prof_active_set(false, true);
|
|
Packit |
345191 |
/* !prof.active, thread.prof.active. */
|
|
Packit |
345191 |
prof_sampling_probe(false);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
mallctl_prof_active_set(false, true);
|
|
Packit |
345191 |
mallctl_thread_prof_active_set(true, true);
|
|
Packit |
345191 |
/* prof.active, thread.prof.active. */
|
|
Packit |
345191 |
prof_sampling_probe(true);
|
|
Packit |
345191 |
|
|
Packit |
345191 |
/* Restore settings. */
|
|
Packit |
345191 |
mallctl_prof_active_set(true, true);
|
|
Packit |
345191 |
mallctl_thread_prof_active_set(true, false);
|
|
Packit |
345191 |
}
|
|
Packit |
345191 |
TEST_END
|
|
Packit |
345191 |
|
|
Packit |
345191 |
int
|
|
Packit |
345191 |
main(void) {
|
|
Packit |
345191 |
return test_no_reentrancy(
|
|
Packit |
345191 |
test_prof_active);
|
|
Packit |
345191 |
}
|