test/event: Improve error check of input parsing by spdk_strtol
Change-Id: I18900c9c066834f02ba721bdaa0c833789755b0f Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/c/441643 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:
parent
9c8941f973
commit
b252a13a90
@ -37,6 +37,7 @@
|
|||||||
#include "spdk/event.h"
|
#include "spdk/event.h"
|
||||||
#include "spdk_internal/event.h"
|
#include "spdk_internal/event.h"
|
||||||
#include "spdk/log.h"
|
#include "spdk/log.h"
|
||||||
|
#include "spdk/string.h"
|
||||||
|
|
||||||
static uint64_t g_tsc_rate;
|
static uint64_t g_tsc_rate;
|
||||||
static uint64_t g_tsc_us_rate;
|
static uint64_t g_tsc_us_rate;
|
||||||
@ -153,7 +154,11 @@ main(int argc, char **argv)
|
|||||||
opts.reactor_mask = optarg;
|
opts.reactor_mask = optarg;
|
||||||
break;
|
break;
|
||||||
case 't':
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "spdk/stdinc.h"
|
#include "spdk/stdinc.h"
|
||||||
|
|
||||||
#include "spdk/event.h"
|
#include "spdk/event.h"
|
||||||
|
#include "spdk/string.h"
|
||||||
#include "spdk/thread.h"
|
#include "spdk/thread.h"
|
||||||
|
|
||||||
static int g_time_in_sec;
|
static int g_time_in_sec;
|
||||||
@ -123,7 +124,7 @@ main(int argc, char **argv)
|
|||||||
while ((op = getopt(argc, argv, "t:")) != -1) {
|
while ((op = getopt(argc, argv, "t:")) != -1) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case 't':
|
case 't':
|
||||||
g_time_in_sec = atoi(optarg);
|
g_time_in_sec = spdk_strtol(optarg, 10);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
@ -131,7 +132,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_time_in_sec) {
|
if (g_time_in_sec <= 0) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "spdk/env.h"
|
#include "spdk/env.h"
|
||||||
#include "spdk/event.h"
|
#include "spdk/event.h"
|
||||||
|
#include "spdk/string.h"
|
||||||
#include "spdk/thread.h"
|
#include "spdk/thread.h"
|
||||||
|
|
||||||
static int g_time_in_sec;
|
static int g_time_in_sec;
|
||||||
@ -102,6 +103,7 @@ main(int argc, char **argv)
|
|||||||
struct spdk_app_opts opts;
|
struct spdk_app_opts opts;
|
||||||
int op;
|
int op;
|
||||||
int rc;
|
int rc;
|
||||||
|
long int val;
|
||||||
|
|
||||||
spdk_app_opts_init(&opts);
|
spdk_app_opts_init(&opts);
|
||||||
opts.name = "reactor_perf";
|
opts.name = "reactor_perf";
|
||||||
@ -111,15 +113,24 @@ main(int argc, char **argv)
|
|||||||
g_queue_depth = 1;
|
g_queue_depth = 1;
|
||||||
|
|
||||||
while ((op = getopt(argc, argv, "d:q:t:")) != -1) {
|
while ((op = getopt(argc, argv, "d:q:t:")) != -1) {
|
||||||
|
if (op == '?') {
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
val = spdk_strtol(optarg, 10);
|
||||||
|
if (val < 0) {
|
||||||
|
fprintf(stderr, "Converting a string to integer failed\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case 'd':
|
case 'd':
|
||||||
opts.max_delay_us = atoi(optarg);
|
opts.max_delay_us = (uint64_t)val;
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
g_queue_depth = atoi(optarg);
|
g_queue_depth = val;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
g_time_in_sec = atoi(optarg);
|
g_time_in_sec = val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user