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

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



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


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 f69235bf
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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) {
+12 −2
Original line number Diff line number Diff line
@@ -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;
+28 −18
Original line number Diff line number Diff line
@@ -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) {
		if (op == 'w') {
			workload_type = optarg;
		} else if (op == '?') {
			usage(argv[0]);
			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 = atoi(optarg);
				g_queue_depth = val;
				break;
			case 's':
			g_io_size_bytes = atoi(optarg);
				g_io_size_bytes = val;
				break;
			case 't':
			g_time_in_sec = atoi(optarg);
			break;
		case 'w':
			workload_type = optarg;
				g_time_in_sec = val;
				break;
			case 'M':
			g_rw_percentage = atoi(optarg);
				g_rw_percentage = val;
				mix_specified = true;
				break;
			default:
				usage(argv[0]);
			return 1;
				return -EINVAL;
			}
		}
	}