test/overhead: print error and exit if no device found

While here, do some additional cleanup:

1) add -h option to print help and exit
2) parse args before initializing the environment - this
   allows "overhead -h" to immediately show a usage message
   without having to wait for DPDK to initialize.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I1021f9f7f7f2b03e34c0fd40714ce8f3db849cb2

Reviewed-on: https://review.gerrithub.io/374508
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2017-08-16 08:34:03 -07:00 committed by Daniel Verkamp
parent bfb1ddba7a
commit ced2c57b67

View File

@ -541,8 +541,12 @@ parse_args(int argc, char **argv)
g_io_size_bytes = 0;
g_time_in_sec = 0;
while ((op = getopt(argc, argv, "s:t:H")) != -1) {
while ((op = getopt(argc, argv, "hs:t:H")) != -1) {
switch (op) {
case 'h':
usage(argv[0]);
exit(0);
break;
case 's':
g_io_size_bytes = atoi(optarg);
break;
@ -610,6 +614,11 @@ register_controllers(void)
return 1;
}
if (g_ns == NULL) {
fprintf(stderr, "no NVMe controller found - check that device is bound to uio/vfio\n");
return 1;
}
return 0;
}
@ -618,17 +627,17 @@ int main(int argc, char **argv)
int rc;
struct spdk_env_opts opts;
rc = parse_args(argc, argv);
if (rc != 0) {
return rc;
}
spdk_env_opts_init(&opts);
opts.name = "overhead";
opts.core_mask = "0x1";
opts.shm_id = 0;
spdk_env_init(&opts);
rc = parse_args(argc, argv);
if (rc != 0) {
return rc;
}
g_task = spdk_dma_zmalloc(sizeof(struct perf_task), 0, NULL);
if (g_task == NULL) {
fprintf(stderr, "g_task alloc failed\n");