From ced2c57b6735aa0a391beb4c548aaa4ff32ccb29 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 16 Aug 2017 08:34:03 -0700 Subject: [PATCH] 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 Change-Id: I1021f9f7f7f2b03e34c0fd40714ce8f3db849cb2 Reviewed-on: https://review.gerrithub.io/374508 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- test/lib/nvme/overhead/overhead.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/lib/nvme/overhead/overhead.c b/test/lib/nvme/overhead/overhead.c index b38fae7ca..d6b91686b 100644 --- a/test/lib/nvme/overhead/overhead.c +++ b/test/lib/nvme/overhead/overhead.c @@ -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");