Avoid dladdr() in ztest

Under Linux, at least, dladdr() doesn't reliably work for functions which
aren't in a DSO.  Add the function name to ztest_info[].

Signed-off-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3130
This commit is contained in:
Tim Chase 2015-02-24 12:53:31 -06:00 committed by Brian Behlendorf
parent 8bdcfb5396
commit fdc5d98253

View File

@ -119,7 +119,6 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <umem.h> #include <umem.h>
#include <dlfcn.h>
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include <sys/fs/zfs.h> #include <sys/fs/zfs.h>
@ -297,6 +296,7 @@ typedef struct ztest_info {
ztest_func_t *zi_func; /* test function */ ztest_func_t *zi_func; /* test function */
uint64_t zi_iters; /* iterations per execution */ uint64_t zi_iters; /* iterations per execution */
uint64_t *zi_interval; /* execute every <interval> seconds */ uint64_t *zi_interval; /* execute every <interval> seconds */
const char *zi_funcname; /* name of test function */
} ztest_info_t; } ztest_info_t;
typedef struct ztest_shared_callstate { typedef struct ztest_shared_callstate {
@ -308,9 +308,6 @@ typedef struct ztest_shared_callstate {
static ztest_shared_callstate_t *ztest_shared_callstate; static ztest_shared_callstate_t *ztest_shared_callstate;
#define ZTEST_GET_SHARED_CALLSTATE(c) (&ztest_shared_callstate[c]) #define ZTEST_GET_SHARED_CALLSTATE(c) (&ztest_shared_callstate[c])
/*
* Note: these aren't static because we want dladdr() to work.
*/
ztest_func_t ztest_dmu_read_write; ztest_func_t ztest_dmu_read_write;
ztest_func_t ztest_dmu_write_parallel; ztest_func_t ztest_dmu_write_parallel;
ztest_func_t ztest_dmu_object_alloc_free; ztest_func_t ztest_dmu_object_alloc_free;
@ -347,40 +344,44 @@ uint64_t zopt_often = 1ULL * NANOSEC; /* every second */
uint64_t zopt_sometimes = 10ULL * NANOSEC; /* every 10 seconds */ uint64_t zopt_sometimes = 10ULL * NANOSEC; /* every 10 seconds */
uint64_t zopt_rarely = 60ULL * NANOSEC; /* every 60 seconds */ uint64_t zopt_rarely = 60ULL * NANOSEC; /* every 60 seconds */
#define ZTI_INIT(func, iters, interval) \
{ .zi_func = (func), \
.zi_iters = (iters), \
.zi_interval = (interval), \
.zi_funcname = # func }
ztest_info_t ztest_info[] = { ztest_info_t ztest_info[] = {
{ ztest_dmu_read_write, 1, &zopt_always }, ZTI_INIT(ztest_dmu_read_write, 1, &zopt_always),
{ ztest_dmu_write_parallel, 10, &zopt_always }, ZTI_INIT(ztest_dmu_write_parallel, 10, &zopt_always),
{ ztest_dmu_object_alloc_free, 1, &zopt_always }, ZTI_INIT(ztest_dmu_object_alloc_free, 1, &zopt_always),
{ ztest_dmu_commit_callbacks, 1, &zopt_always }, ZTI_INIT(ztest_dmu_commit_callbacks, 1, &zopt_always),
{ ztest_zap, 30, &zopt_always }, ZTI_INIT(ztest_zap, 30, &zopt_always),
{ ztest_zap_parallel, 100, &zopt_always }, ZTI_INIT(ztest_zap_parallel, 100, &zopt_always),
{ ztest_split_pool, 1, &zopt_always }, ZTI_INIT(ztest_split_pool, 1, &zopt_always),
{ ztest_zil_commit, 1, &zopt_incessant }, ZTI_INIT(ztest_zil_commit, 1, &zopt_incessant),
{ ztest_zil_remount, 1, &zopt_sometimes }, ZTI_INIT(ztest_zil_remount, 1, &zopt_sometimes),
{ ztest_dmu_read_write_zcopy, 1, &zopt_often }, ZTI_INIT(ztest_dmu_read_write_zcopy, 1, &zopt_often),
{ ztest_dmu_objset_create_destroy, 1, &zopt_often }, ZTI_INIT(ztest_dmu_objset_create_destroy, 1, &zopt_often),
{ ztest_dsl_prop_get_set, 1, &zopt_often }, ZTI_INIT(ztest_dsl_prop_get_set, 1, &zopt_often),
{ ztest_spa_prop_get_set, 1, &zopt_sometimes }, ZTI_INIT(ztest_spa_prop_get_set, 1, &zopt_sometimes),
#if 0 #if 0
{ ztest_dmu_prealloc, 1, &zopt_sometimes }, ZTI_INIT(ztest_dmu_prealloc, 1, &zopt_sometimes),
#endif #endif
{ ztest_fzap, 1, &zopt_sometimes }, ZTI_INIT(ztest_fzap, 1, &zopt_sometimes),
{ ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes }, ZTI_INIT(ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes),
{ ztest_spa_create_destroy, 1, &zopt_sometimes }, ZTI_INIT(ztest_spa_create_destroy, 1, &zopt_sometimes),
{ ztest_fault_inject, 1, &zopt_sometimes }, ZTI_INIT(ztest_fault_inject, 1, &zopt_sometimes),
{ ztest_ddt_repair, 1, &zopt_sometimes }, ZTI_INIT(ztest_ddt_repair, 1, &zopt_sometimes),
{ ztest_dmu_snapshot_hold, 1, &zopt_sometimes }, ZTI_INIT(ztest_dmu_snapshot_hold, 1, &zopt_sometimes),
{ ztest_reguid, 1, &zopt_rarely }, ZTI_INIT(ztest_reguid, 1, &zopt_rarely),
{ ztest_spa_rename, 1, &zopt_rarely }, ZTI_INIT(ztest_spa_rename, 1, &zopt_rarely),
{ ztest_scrub, 1, &zopt_rarely }, ZTI_INIT(ztest_scrub, 1, &zopt_rarely),
{ ztest_spa_upgrade, 1, &zopt_rarely }, ZTI_INIT(ztest_spa_upgrade, 1, &zopt_rarely),
{ ztest_dsl_dataset_promote_busy, 1, &zopt_rarely }, ZTI_INIT(ztest_dsl_dataset_promote_busy, 1, &zopt_rarely),
{ ztest_vdev_attach_detach, 1, &zopt_sometimes }, ZTI_INIT(ztest_vdev_attach_detach, 1, &zopt_sometimes),
{ ztest_vdev_LUN_growth, 1, &zopt_rarely }, ZTI_INIT(ztest_vdev_LUN_growth, 1, &zopt_rarely),
{ ztest_vdev_add_remove, 1, ZTI_INIT(ztest_vdev_add_remove, 1, &ztest_opts.zo_vdevtime),
&ztest_opts.zo_vdevtime }, ZTI_INIT(ztest_vdev_aux_add_remove, 1, &ztest_opts.zo_vdevtime),
{ ztest_vdev_aux_add_remove, 1,
&ztest_opts.zo_vdevtime },
}; };
#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t)) #define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))
@ -5583,12 +5584,9 @@ ztest_execute(int test, ztest_info_t *zi, uint64_t id)
atomic_add_64(&zc->zc_count, 1); atomic_add_64(&zc->zc_count, 1);
atomic_add_64(&zc->zc_time, functime); atomic_add_64(&zc->zc_time, functime);
if (ztest_opts.zo_verbose >= 4) { if (ztest_opts.zo_verbose >= 4)
Dl_info dli;
(void) dladdr((void *)zi->zi_func, &dli);
(void) printf("%6.2f sec in %s\n", (void) printf("%6.2f sec in %s\n",
(double)functime / NANOSEC, dli.dli_sname); (double)functime / NANOSEC, zi->zi_funcname);
}
} }
static void * static void *
@ -6490,15 +6488,12 @@ main(int argc, char **argv)
(void) printf("%7s %9s %s\n", (void) printf("%7s %9s %s\n",
"-----", "----", "--------"); "-----", "----", "--------");
for (f = 0; f < ZTEST_FUNCS; f++) { for (f = 0; f < ZTEST_FUNCS; f++) {
Dl_info dli;
zi = &ztest_info[f]; zi = &ztest_info[f];
zc = ZTEST_GET_SHARED_CALLSTATE(f); zc = ZTEST_GET_SHARED_CALLSTATE(f);
print_time(zc->zc_time, timebuf); print_time(zc->zc_time, timebuf);
(void) dladdr((void *)zi->zi_func, &dli);
(void) printf("%7llu %9s %s\n", (void) printf("%7llu %9s %s\n",
(u_longlong_t)zc->zc_count, timebuf, (u_longlong_t)zc->zc_count, timebuf,
dli.dli_sname); zi->zi_funcname);
} }
(void) printf("\n"); (void) printf("\n");
} }