Commit b252a13a authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Darek Stojaczyk
Browse files

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



Change-Id: I18900c9c066834f02ba721bdaa0c833789755b0f
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/441643


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarwuzhouhui <wuzhouhui@kingsoft.com>
parent 9c8941f9
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include "spdk/event.h"
#include "spdk_internal/event.h"
#include "spdk/log.h"
#include "spdk/string.h"

static uint64_t g_tsc_rate;
static uint64_t g_tsc_us_rate;
@@ -153,7 +154,11 @@ main(int argc, char **argv)
			opts.reactor_mask = optarg;
			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;
		default:
			usage(argv[0]);
+3 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "spdk/stdinc.h"

#include "spdk/event.h"
#include "spdk/string.h"
#include "spdk/thread.h"

static int g_time_in_sec;
@@ -123,7 +124,7 @@ main(int argc, char **argv)
	while ((op = getopt(argc, argv, "t:")) != -1) {
		switch (op) {
		case 't':
			g_time_in_sec = atoi(optarg);
			g_time_in_sec = spdk_strtol(optarg, 10);
			break;
		default:
			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]);
		exit(1);
	}
+14 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@

#include "spdk/env.h"
#include "spdk/event.h"
#include "spdk/string.h"
#include "spdk/thread.h"

static int g_time_in_sec;
@@ -102,6 +103,7 @@ main(int argc, char **argv)
	struct spdk_app_opts opts;
	int op;
	int rc;
	long int val;

	spdk_app_opts_init(&opts);
	opts.name = "reactor_perf";
@@ -111,15 +113,24 @@ main(int argc, char **argv)
	g_queue_depth = 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) {
		case 'd':
			opts.max_delay_us = atoi(optarg);
			opts.max_delay_us = (uint64_t)val;
			break;
		case 'q':
			g_queue_depth = atoi(optarg);
			g_queue_depth = val;
			break;
		case 't':
			g_time_in_sec = atoi(optarg);
			g_time_in_sec = val;
			break;
		default:
			usage(argv[0]);