test/nvme: Improve error check of input parsing by spdk_strtol

Change-Id: I7ad159f7e7033e0249779a39faed92f94857aae7
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/441642
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com>
This commit is contained in:
Shuhei Matsumoto 2019-01-23 10:57:05 +09:00 committed by Darek Stojaczyk
parent f69235bf3a
commit 9c8941f973
3 changed files with 48 additions and 21 deletions

View File

@ -36,6 +36,7 @@
#include "spdk/log.h"
#include "spdk/nvme.h"
#include "spdk/env.h"
#include "spdk/string.h"
#define MAX_DEVS 64
@ -303,6 +304,7 @@ static int
parse_args(int argc, char **argv)
{
int op, rc;
long int val;
g_trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
snprintf(g_trid.subnqn, sizeof(g_trid.subnqn), "%s", SPDK_NVMF_DISCOVERY_NQN);
@ -310,7 +312,12 @@ parse_args(int argc, char **argv)
while ((op = getopt(argc, argv, "n:r:HL:T")) != -1) {
switch (op) {
case 'n':
expected_ns_test = atoi(optarg);
val = spdk_strtol(optarg, 10);
if (val < 0) {
fprintf(stderr, "Invalid NS attribute notice ID\n");
return val;
}
expected_ns_test = (uint32_t)val;
break;
case 'r':
if (spdk_nvme_transport_id_parse(&g_trid, optarg) != 0) {

View File

@ -545,6 +545,7 @@ static int
parse_args(int argc, char **argv)
{
int op;
long int val;
/* default value */
g_io_size_bytes = 0;
@ -557,10 +558,19 @@ parse_args(int argc, char **argv)
exit(0);
break;
case 's':
g_io_size_bytes = atoi(optarg);
val = spdk_strtol(optarg, 10);
if (val < 0) {
fprintf(stderr, "Invalid io size\n");
return val;
}
g_io_size_bytes = (uint32_t)val;
break;
case 't':
g_time_in_sec = atoi(optarg);
g_time_in_sec = spdk_strtol(optarg, 10);
if (g_time_in_sec < 0) {
fprintf(stderr, "Invalid run time\n");
return g_time_in_sec;
}
break;
case 'H':
g_enable_histogram = true;

View File

@ -382,6 +382,7 @@ parse_args(int argc, char **argv)
const char *workload_type;
int op;
bool mix_specified = false;
long int val;
/* default value */
g_queue_depth = 0;
@ -391,26 +392,35 @@ parse_args(int argc, char **argv)
g_rw_percentage = -1;
while ((op = getopt(argc, argv, "m:q:s:t:w:M:")) != -1) {
switch (op) {
case 'q':
g_queue_depth = atoi(optarg);
break;
case 's':
g_io_size_bytes = atoi(optarg);
break;
case 't':
g_time_in_sec = atoi(optarg);
break;
case 'w':
if (op == 'w') {
workload_type = optarg;
break;
case 'M':
g_rw_percentage = atoi(optarg);
mix_specified = true;
break;
default:
} else if (op == '?') {
usage(argv[0]);
return 1;
return -EINVAL;
} else {
val = spdk_strtol(optarg, 10);
if (val < 0) {
fprintf(stderr, "Converting a string to integer failed\n");
return val;
}
switch (op) {
case 'q':
g_queue_depth = val;
break;
case 's':
g_io_size_bytes = val;
break;
case 't':
g_time_in_sec = val;
break;
case 'M':
g_rw_percentage = val;
mix_specified = true;
break;
default:
usage(argv[0]);
return -EINVAL;
}
}
}