xref: /dpdk/app/test-compress-perf/comp_perf_options_parse.c (revision 72c64a3492ba7b41bc1074e016684643c30be04d)
1e0b6287cSTomasz Jozwiak /* SPDX-License-Identifier: BSD-3-Clause
2e0b6287cSTomasz Jozwiak  * Copyright(c) 2018 Intel Corporation
3e0b6287cSTomasz Jozwiak  */
4e0b6287cSTomasz Jozwiak 
5e0b6287cSTomasz Jozwiak #include <getopt.h>
6e0b6287cSTomasz Jozwiak #include <stdint.h>
7e0b6287cSTomasz Jozwiak #include <stdio.h>
8e0b6287cSTomasz Jozwiak #include <string.h>
9e0b6287cSTomasz Jozwiak #include <inttypes.h>
10e0b6287cSTomasz Jozwiak #include <stdlib.h>
11e0b6287cSTomasz Jozwiak #include <errno.h>
12e0b6287cSTomasz Jozwiak 
13e0b6287cSTomasz Jozwiak #include <rte_string_fns.h>
14e0b6287cSTomasz Jozwiak #include <rte_comp.h>
15e0b6287cSTomasz Jozwiak 
16e0b6287cSTomasz Jozwiak #include "comp_perf_options.h"
17e0b6287cSTomasz Jozwiak 
181a9b0f35STomasz Jozwiak #define CPERF_PTEST_TYPE	("ptest")
19e0b6287cSTomasz Jozwiak #define CPERF_DRIVER_NAME	("driver-name")
20e0b6287cSTomasz Jozwiak #define CPERF_TEST_FILE		("input-file")
21e0b6287cSTomasz Jozwiak #define CPERF_SEG_SIZE		("seg-sz")
22e0b6287cSTomasz Jozwiak #define CPERF_BURST_SIZE	("burst-sz")
23e0b6287cSTomasz Jozwiak #define CPERF_EXTENDED_SIZE	("extended-input-sz")
24e0b6287cSTomasz Jozwiak #define CPERF_POOL_SIZE		("pool-sz")
25e0b6287cSTomasz Jozwiak #define CPERF_MAX_SGL_SEGS	("max-num-sgl-segs")
26e0b6287cSTomasz Jozwiak #define CPERF_NUM_ITER		("num-iter")
27e0b6287cSTomasz Jozwiak #define CPERF_OPTYPE		("operation")
28*72c64a34SMichael Baum #define CPERF_ALGO		("algo")
29e0b6287cSTomasz Jozwiak #define CPERF_HUFFMAN_ENC	("huffman-enc")
30*72c64a34SMichael Baum #define CPERF_LZ4_FLAGS		("lz4-flags")
31e0b6287cSTomasz Jozwiak #define CPERF_LEVEL		("compress-level")
32e0b6287cSTomasz Jozwiak #define CPERF_WINDOW_SIZE	("window-sz")
33c02e33b0SAdam Dybkowski #define CPERF_EXTERNAL_MBUFS	("external-mbufs")
34e0b6287cSTomasz Jozwiak 
352695db95SArtur Trybula /* cyclecount-specific options */
362695db95SArtur Trybula #define CPERF_CYCLECOUNT_DELAY_US ("cc-delay-us")
372695db95SArtur Trybula 
38e0b6287cSTomasz Jozwiak struct name_id_map {
39e0b6287cSTomasz Jozwiak 	const char *name;
40e0b6287cSTomasz Jozwiak 	uint32_t id;
41e0b6287cSTomasz Jozwiak };
42e0b6287cSTomasz Jozwiak 
43e0b6287cSTomasz Jozwiak static void
usage(char * progname)44e0b6287cSTomasz Jozwiak usage(char *progname)
45e0b6287cSTomasz Jozwiak {
46e0b6287cSTomasz Jozwiak 	printf("%s [EAL options] --\n"
472695db95SArtur Trybula 		" --ptest throughput / verify / pmd-cyclecount\n"
48e0b6287cSTomasz Jozwiak 		" --driver-name NAME: compress driver to use\n"
49e0b6287cSTomasz Jozwiak 		" --input-file NAME: file to compress and decompress\n"
50e0b6287cSTomasz Jozwiak 		" --extended-input-sz N: extend file data up to this size (default: no extension)\n"
51e0b6287cSTomasz Jozwiak 		" --seg-sz N: size of segment to store the data (default: 2048)\n"
52e0b6287cSTomasz Jozwiak 		" --burst-sz N: compress operation burst size\n"
53e0b6287cSTomasz Jozwiak 		" --pool-sz N: mempool size for compress operations/mbufs\n"
54e0b6287cSTomasz Jozwiak 		"		(default: 8192)\n"
55e0b6287cSTomasz Jozwiak 		" --max-num-sgl-segs N: maximum number of segments for each mbuf\n"
56e0b6287cSTomasz Jozwiak 		"		(default: 16)\n"
57e0b6287cSTomasz Jozwiak 		" --num-iter N: number of times the file will be\n"
58e0b6287cSTomasz Jozwiak 		"		compressed/decompressed (default: 10000)\n"
59e0b6287cSTomasz Jozwiak 		" --operation [comp/decomp/comp_and_decomp]: perform test on\n"
60e0b6287cSTomasz Jozwiak 		"		compression, decompression or both operations\n"
61*72c64a34SMichael Baum 		" --algo [null/deflate/lzs/lz4]: perform test on algorithm\n"
62*72c64a34SMichael Baum 		"		null(DMA), deflate, lzs or lz4 (default: deflate)\n"
63fedfef43STomasz Jozwiak 		" --huffman-enc [fixed/dynamic/default]: Huffman encoding\n"
64fedfef43STomasz Jozwiak 		"		(default: dynamic)\n"
65*72c64a34SMichael Baum 		" --lz4-flags N: flags to configure LZ4 algorithm (default: 0)\n"
66e0b6287cSTomasz Jozwiak 		" --compress-level N: compression level, which could be a single value, list or range\n"
67e0b6287cSTomasz Jozwiak 		"		(default: range between 1 and 9)\n"
68e0b6287cSTomasz Jozwiak 		" --window-sz N: base two log value of compression window size\n"
69e0b6287cSTomasz Jozwiak 		"		(e.g.: 15 => 32k, default: max supported by PMD)\n"
70c02e33b0SAdam Dybkowski 		" --external-mbufs: use memzones as external buffers instead of\n"
71c02e33b0SAdam Dybkowski 		"		keeping the data directly in mbuf area\n"
722695db95SArtur Trybula 		" --cc-delay-us N: delay between enqueue and dequeue operations in microseconds\n"
732695db95SArtur Trybula 		"		valid only for cyclecount perf test (default: 500 us)\n"
74e0b6287cSTomasz Jozwiak 		" -h: prints this help\n",
75e0b6287cSTomasz Jozwiak 		progname);
76e0b6287cSTomasz Jozwiak }
77e0b6287cSTomasz Jozwiak 
78e0b6287cSTomasz Jozwiak static int
get_str_key_id_mapping(struct name_id_map * map,unsigned int map_len,const char * str_key)79e0b6287cSTomasz Jozwiak get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len,
80e0b6287cSTomasz Jozwiak 		const char *str_key)
81e0b6287cSTomasz Jozwiak {
82e0b6287cSTomasz Jozwiak 	unsigned int i;
83e0b6287cSTomasz Jozwiak 
84e0b6287cSTomasz Jozwiak 	for (i = 0; i < map_len; i++) {
85e0b6287cSTomasz Jozwiak 
86e0b6287cSTomasz Jozwiak 		if (strcmp(str_key, map[i].name) == 0)
87e0b6287cSTomasz Jozwiak 			return map[i].id;
88e0b6287cSTomasz Jozwiak 	}
89e0b6287cSTomasz Jozwiak 
90e0b6287cSTomasz Jozwiak 	return -1;
91e0b6287cSTomasz Jozwiak }
92e0b6287cSTomasz Jozwiak 
93e0b6287cSTomasz Jozwiak static int
parse_cperf_test_type(struct comp_test_data * test_data,const char * arg)941a9b0f35STomasz Jozwiak parse_cperf_test_type(struct comp_test_data *test_data, const char *arg)
951a9b0f35STomasz Jozwiak {
961a9b0f35STomasz Jozwiak 	struct name_id_map cperftest_namemap[] = {
971a9b0f35STomasz Jozwiak 		{
982695db95SArtur Trybula 			comp_perf_test_type_strs[CPERF_TEST_TYPE_THROUGHPUT],
992695db95SArtur Trybula 			CPERF_TEST_TYPE_THROUGHPUT
1001a9b0f35STomasz Jozwiak 		},
1011a9b0f35STomasz Jozwiak 		{
1024fba6df9SLavanya Govindarajan 			comp_perf_test_type_strs[CPERF_TEST_TYPE_VERIFY],
1031a9b0f35STomasz Jozwiak 			CPERF_TEST_TYPE_VERIFY
1042695db95SArtur Trybula 		},
1052695db95SArtur Trybula 		{
1062695db95SArtur Trybula 			comp_perf_test_type_strs[CPERF_TEST_TYPE_PMDCC],
1072695db95SArtur Trybula 			CPERF_TEST_TYPE_PMDCC
1081a9b0f35STomasz Jozwiak 		}
1091a9b0f35STomasz Jozwiak 	};
1101a9b0f35STomasz Jozwiak 
1111a9b0f35STomasz Jozwiak 	int id = get_str_key_id_mapping(
1121a9b0f35STomasz Jozwiak 			(struct name_id_map *)cperftest_namemap,
1131a9b0f35STomasz Jozwiak 			RTE_DIM(cperftest_namemap), arg);
1141a9b0f35STomasz Jozwiak 	if (id < 0) {
1151a9b0f35STomasz Jozwiak 		RTE_LOG(ERR, USER1, "failed to parse test type");
1161a9b0f35STomasz Jozwiak 		return -1;
1171a9b0f35STomasz Jozwiak 	}
1181a9b0f35STomasz Jozwiak 
1198c7a3131SArtur Trybula 	test_data->test = (enum cperf_test_type)id;
1201a9b0f35STomasz Jozwiak 
1211a9b0f35STomasz Jozwiak 	return 0;
1221a9b0f35STomasz Jozwiak }
1231a9b0f35STomasz Jozwiak 
1241a9b0f35STomasz Jozwiak static int
parse_uint32_t(uint32_t * value,const char * arg)125e0b6287cSTomasz Jozwiak parse_uint32_t(uint32_t *value, const char *arg)
126e0b6287cSTomasz Jozwiak {
127e0b6287cSTomasz Jozwiak 	char *end = NULL;
128e0b6287cSTomasz Jozwiak 	unsigned long n = strtoul(arg, &end, 10);
129e0b6287cSTomasz Jozwiak 
130e0b6287cSTomasz Jozwiak 	if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
131e0b6287cSTomasz Jozwiak 		return -1;
132e0b6287cSTomasz Jozwiak 
133e0b6287cSTomasz Jozwiak 	if (n > UINT32_MAX)
134e0b6287cSTomasz Jozwiak 		return -ERANGE;
135e0b6287cSTomasz Jozwiak 
136e0b6287cSTomasz Jozwiak 	*value = (uint32_t) n;
137e0b6287cSTomasz Jozwiak 
138e0b6287cSTomasz Jozwiak 	return 0;
139e0b6287cSTomasz Jozwiak }
140e0b6287cSTomasz Jozwiak 
141e0b6287cSTomasz Jozwiak static int
parse_uint16_t(uint16_t * value,const char * arg)142e0b6287cSTomasz Jozwiak parse_uint16_t(uint16_t *value, const char *arg)
143e0b6287cSTomasz Jozwiak {
144e0b6287cSTomasz Jozwiak 	uint32_t val = 0;
145e0b6287cSTomasz Jozwiak 	int ret = parse_uint32_t(&val, arg);
146e0b6287cSTomasz Jozwiak 
147e0b6287cSTomasz Jozwiak 	if (ret < 0)
148e0b6287cSTomasz Jozwiak 		return ret;
149e0b6287cSTomasz Jozwiak 
150e0b6287cSTomasz Jozwiak 	if (val > UINT16_MAX)
151e0b6287cSTomasz Jozwiak 		return -ERANGE;
152e0b6287cSTomasz Jozwiak 
153e0b6287cSTomasz Jozwiak 	*value = (uint16_t) val;
154e0b6287cSTomasz Jozwiak 
155e0b6287cSTomasz Jozwiak 	return 0;
156e0b6287cSTomasz Jozwiak }
157e0b6287cSTomasz Jozwiak 
158e0b6287cSTomasz Jozwiak static int
parse_uint8_t(uint8_t * value,const char * arg)159*72c64a34SMichael Baum parse_uint8_t(uint8_t *value, const char *arg)
160*72c64a34SMichael Baum {
161*72c64a34SMichael Baum 	uint32_t val = 0;
162*72c64a34SMichael Baum 	int ret = parse_uint32_t(&val, arg);
163*72c64a34SMichael Baum 
164*72c64a34SMichael Baum 	if (ret < 0)
165*72c64a34SMichael Baum 		return ret;
166*72c64a34SMichael Baum 
167*72c64a34SMichael Baum 	if (val > UINT8_MAX)
168*72c64a34SMichael Baum 		return -ERANGE;
169*72c64a34SMichael Baum 
170*72c64a34SMichael Baum 	*value = (uint8_t) val;
171*72c64a34SMichael Baum 
172*72c64a34SMichael Baum 	return 0;
173*72c64a34SMichael Baum }
174*72c64a34SMichael Baum 
175*72c64a34SMichael Baum static int
parse_range(const char * arg,uint8_t * min,uint8_t * max,uint8_t * inc)176e0b6287cSTomasz Jozwiak parse_range(const char *arg, uint8_t *min, uint8_t *max, uint8_t *inc)
177e0b6287cSTomasz Jozwiak {
178e0b6287cSTomasz Jozwiak 	char *token;
179e0b6287cSTomasz Jozwiak 	uint8_t number;
180e0b6287cSTomasz Jozwiak 
181e0b6287cSTomasz Jozwiak 	char *copy_arg = strdup(arg);
182e0b6287cSTomasz Jozwiak 
183e0b6287cSTomasz Jozwiak 	if (copy_arg == NULL)
184e0b6287cSTomasz Jozwiak 		return -1;
185e0b6287cSTomasz Jozwiak 
186e0b6287cSTomasz Jozwiak 	errno = 0;
187e0b6287cSTomasz Jozwiak 	token = strtok(copy_arg, ":");
188e0b6287cSTomasz Jozwiak 
189e0b6287cSTomasz Jozwiak 	/* Parse minimum value */
190e0b6287cSTomasz Jozwiak 	if (token != NULL) {
191e0b6287cSTomasz Jozwiak 		number = strtoul(token, NULL, 10);
192e0b6287cSTomasz Jozwiak 
193e0b6287cSTomasz Jozwiak 		if (errno == EINVAL || errno == ERANGE)
194e0b6287cSTomasz Jozwiak 			goto err_range;
195e0b6287cSTomasz Jozwiak 
196e0b6287cSTomasz Jozwiak 		*min = number;
197e0b6287cSTomasz Jozwiak 	} else
198e0b6287cSTomasz Jozwiak 		goto err_range;
199e0b6287cSTomasz Jozwiak 
200e0b6287cSTomasz Jozwiak 	token = strtok(NULL, ":");
201e0b6287cSTomasz Jozwiak 
202e0b6287cSTomasz Jozwiak 	/* Parse increment value */
203e0b6287cSTomasz Jozwiak 	if (token != NULL) {
204e0b6287cSTomasz Jozwiak 		number = strtoul(token, NULL, 10);
205e0b6287cSTomasz Jozwiak 
206e0b6287cSTomasz Jozwiak 		if (errno == EINVAL || errno == ERANGE ||
207e0b6287cSTomasz Jozwiak 				number == 0)
208e0b6287cSTomasz Jozwiak 			goto err_range;
209e0b6287cSTomasz Jozwiak 
210e0b6287cSTomasz Jozwiak 		*inc = number;
211e0b6287cSTomasz Jozwiak 	} else
212e0b6287cSTomasz Jozwiak 		goto err_range;
213e0b6287cSTomasz Jozwiak 
214e0b6287cSTomasz Jozwiak 	token = strtok(NULL, ":");
215e0b6287cSTomasz Jozwiak 
216e0b6287cSTomasz Jozwiak 	/* Parse maximum value */
217e0b6287cSTomasz Jozwiak 	if (token != NULL) {
218e0b6287cSTomasz Jozwiak 		number = strtoul(token, NULL, 10);
219e0b6287cSTomasz Jozwiak 
220e0b6287cSTomasz Jozwiak 		if (errno == EINVAL || errno == ERANGE ||
221e0b6287cSTomasz Jozwiak 				number < *min)
222e0b6287cSTomasz Jozwiak 			goto err_range;
223e0b6287cSTomasz Jozwiak 
224e0b6287cSTomasz Jozwiak 		*max = number;
225e0b6287cSTomasz Jozwiak 	} else
226e0b6287cSTomasz Jozwiak 		goto err_range;
227e0b6287cSTomasz Jozwiak 
228e0b6287cSTomasz Jozwiak 	if (strtok(NULL, ":") != NULL)
229e0b6287cSTomasz Jozwiak 		goto err_range;
230e0b6287cSTomasz Jozwiak 
231e0b6287cSTomasz Jozwiak 	free(copy_arg);
232e0b6287cSTomasz Jozwiak 	return 0;
233e0b6287cSTomasz Jozwiak 
234e0b6287cSTomasz Jozwiak err_range:
235e0b6287cSTomasz Jozwiak 	free(copy_arg);
236e0b6287cSTomasz Jozwiak 	return -1;
237e0b6287cSTomasz Jozwiak }
238e0b6287cSTomasz Jozwiak 
239e0b6287cSTomasz Jozwiak static int
parse_list(const char * arg,uint8_t * list,uint8_t * min,uint8_t * max)240e0b6287cSTomasz Jozwiak parse_list(const char *arg, uint8_t *list, uint8_t *min, uint8_t *max)
241e0b6287cSTomasz Jozwiak {
242e0b6287cSTomasz Jozwiak 	char *token;
243e0b6287cSTomasz Jozwiak 	uint32_t number;
244e0b6287cSTomasz Jozwiak 	uint8_t count = 0;
245e0b6287cSTomasz Jozwiak 	uint32_t temp_min;
246e0b6287cSTomasz Jozwiak 	uint32_t temp_max;
247e0b6287cSTomasz Jozwiak 
248e0b6287cSTomasz Jozwiak 	char *copy_arg = strdup(arg);
249e0b6287cSTomasz Jozwiak 
250e0b6287cSTomasz Jozwiak 	if (copy_arg == NULL)
251e0b6287cSTomasz Jozwiak 		return -1;
252e0b6287cSTomasz Jozwiak 
253e0b6287cSTomasz Jozwiak 	errno = 0;
254e0b6287cSTomasz Jozwiak 	token = strtok(copy_arg, ",");
255e0b6287cSTomasz Jozwiak 
256e0b6287cSTomasz Jozwiak 	/* Parse first value */
257e0b6287cSTomasz Jozwiak 	if (token != NULL) {
258e0b6287cSTomasz Jozwiak 		number = strtoul(token, NULL, 10);
259e0b6287cSTomasz Jozwiak 
260e0b6287cSTomasz Jozwiak 		if (errno == EINVAL || errno == ERANGE)
261e0b6287cSTomasz Jozwiak 			goto err_list;
262e0b6287cSTomasz Jozwiak 
263e0b6287cSTomasz Jozwiak 		list[count++] = number;
264e0b6287cSTomasz Jozwiak 		temp_min = number;
265e0b6287cSTomasz Jozwiak 		temp_max = number;
266e0b6287cSTomasz Jozwiak 	} else
267e0b6287cSTomasz Jozwiak 		goto err_list;
268e0b6287cSTomasz Jozwiak 
269e0b6287cSTomasz Jozwiak 	token = strtok(NULL, ",");
270e0b6287cSTomasz Jozwiak 
271e0b6287cSTomasz Jozwiak 	while (token != NULL) {
272e0b6287cSTomasz Jozwiak 		if (count == MAX_LIST) {
273e0b6287cSTomasz Jozwiak 			RTE_LOG(WARNING, USER1,
274e0b6287cSTomasz Jozwiak 				"Using only the first %u sizes\n",
275e0b6287cSTomasz Jozwiak 					MAX_LIST);
276e0b6287cSTomasz Jozwiak 			break;
277e0b6287cSTomasz Jozwiak 		}
278e0b6287cSTomasz Jozwiak 
279e0b6287cSTomasz Jozwiak 		number = strtoul(token, NULL, 10);
280e0b6287cSTomasz Jozwiak 
281e0b6287cSTomasz Jozwiak 		if (errno == EINVAL || errno == ERANGE)
282e0b6287cSTomasz Jozwiak 			goto err_list;
283e0b6287cSTomasz Jozwiak 
284e0b6287cSTomasz Jozwiak 		list[count++] = number;
285e0b6287cSTomasz Jozwiak 
286e0b6287cSTomasz Jozwiak 		if (number < temp_min)
287e0b6287cSTomasz Jozwiak 			temp_min = number;
288e0b6287cSTomasz Jozwiak 		if (number > temp_max)
289e0b6287cSTomasz Jozwiak 			temp_max = number;
290e0b6287cSTomasz Jozwiak 
291e0b6287cSTomasz Jozwiak 		token = strtok(NULL, ",");
292e0b6287cSTomasz Jozwiak 	}
293e0b6287cSTomasz Jozwiak 
294e0b6287cSTomasz Jozwiak 	if (min)
295e0b6287cSTomasz Jozwiak 		*min = temp_min;
296e0b6287cSTomasz Jozwiak 	if (max)
297e0b6287cSTomasz Jozwiak 		*max = temp_max;
298e0b6287cSTomasz Jozwiak 
299e0b6287cSTomasz Jozwiak 	free(copy_arg);
300e0b6287cSTomasz Jozwiak 	return count;
301e0b6287cSTomasz Jozwiak 
302e0b6287cSTomasz Jozwiak err_list:
303e0b6287cSTomasz Jozwiak 	free(copy_arg);
304e0b6287cSTomasz Jozwiak 	return -1;
305e0b6287cSTomasz Jozwiak }
306e0b6287cSTomasz Jozwiak 
307e0b6287cSTomasz Jozwiak static int
parse_num_iter(struct comp_test_data * test_data,const char * arg)308e0b6287cSTomasz Jozwiak parse_num_iter(struct comp_test_data *test_data, const char *arg)
309e0b6287cSTomasz Jozwiak {
310e0b6287cSTomasz Jozwiak 	int ret = parse_uint32_t(&test_data->num_iter, arg);
311e0b6287cSTomasz Jozwiak 
312e0b6287cSTomasz Jozwiak 	if (ret) {
313e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Failed to parse total iteration count\n");
314e0b6287cSTomasz Jozwiak 		return -1;
315e0b6287cSTomasz Jozwiak 	}
316e0b6287cSTomasz Jozwiak 
317e0b6287cSTomasz Jozwiak 	if (test_data->num_iter == 0) {
318e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1,
319e0b6287cSTomasz Jozwiak 				"Total number of iterations must be higher than 0\n");
320e0b6287cSTomasz Jozwiak 		return -1;
321e0b6287cSTomasz Jozwiak 	}
322e0b6287cSTomasz Jozwiak 
323e0b6287cSTomasz Jozwiak 	return ret;
324e0b6287cSTomasz Jozwiak }
325e0b6287cSTomasz Jozwiak 
326e0b6287cSTomasz Jozwiak static int
parse_pool_sz(struct comp_test_data * test_data,const char * arg)327e0b6287cSTomasz Jozwiak parse_pool_sz(struct comp_test_data *test_data, const char *arg)
328e0b6287cSTomasz Jozwiak {
329e0b6287cSTomasz Jozwiak 	int ret = parse_uint32_t(&test_data->pool_sz, arg);
330e0b6287cSTomasz Jozwiak 
331e0b6287cSTomasz Jozwiak 	if (ret) {
332e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Failed to parse pool size");
333e0b6287cSTomasz Jozwiak 		return -1;
334e0b6287cSTomasz Jozwiak 	}
335e0b6287cSTomasz Jozwiak 
336e0b6287cSTomasz Jozwiak 	if (test_data->pool_sz == 0) {
337e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Pool size must be higher than 0\n");
338e0b6287cSTomasz Jozwiak 		return -1;
339e0b6287cSTomasz Jozwiak 	}
340e0b6287cSTomasz Jozwiak 
341e0b6287cSTomasz Jozwiak 	return ret;
342e0b6287cSTomasz Jozwiak }
343e0b6287cSTomasz Jozwiak 
344e0b6287cSTomasz Jozwiak static int
parse_burst_sz(struct comp_test_data * test_data,const char * arg)345e0b6287cSTomasz Jozwiak parse_burst_sz(struct comp_test_data *test_data, const char *arg)
346e0b6287cSTomasz Jozwiak {
347e0b6287cSTomasz Jozwiak 	int ret = parse_uint16_t(&test_data->burst_sz, arg);
348e0b6287cSTomasz Jozwiak 
349e0b6287cSTomasz Jozwiak 	if (ret) {
350e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Failed to parse burst size/s\n");
351e0b6287cSTomasz Jozwiak 		return -1;
352e0b6287cSTomasz Jozwiak 	}
353e0b6287cSTomasz Jozwiak 
354e0b6287cSTomasz Jozwiak 	if (test_data->burst_sz == 0) {
355e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Burst size must be higher than 0\n");
356e0b6287cSTomasz Jozwiak 		return -1;
357e0b6287cSTomasz Jozwiak 	}
358e0b6287cSTomasz Jozwiak 
359e0b6287cSTomasz Jozwiak 	return 0;
360e0b6287cSTomasz Jozwiak }
361e0b6287cSTomasz Jozwiak 
362e0b6287cSTomasz Jozwiak static int
parse_extended_input_sz(struct comp_test_data * test_data,const char * arg)363e0b6287cSTomasz Jozwiak parse_extended_input_sz(struct comp_test_data *test_data, const char *arg)
364e0b6287cSTomasz Jozwiak {
365e0b6287cSTomasz Jozwiak 	uint32_t tmp;
366e0b6287cSTomasz Jozwiak 	int ret = parse_uint32_t(&tmp, arg);
367e0b6287cSTomasz Jozwiak 
368e0b6287cSTomasz Jozwiak 	if (ret) {
369e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Failed to parse extended input size\n");
370e0b6287cSTomasz Jozwiak 		return -1;
371e0b6287cSTomasz Jozwiak 	}
372e0b6287cSTomasz Jozwiak 	test_data->input_data_sz = tmp;
373e0b6287cSTomasz Jozwiak 
374e0b6287cSTomasz Jozwiak 	if (tmp == 0) {
375e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1,
376e0b6287cSTomasz Jozwiak 			"Extended file size must be higher than 0\n");
377e0b6287cSTomasz Jozwiak 		return -1;
378e0b6287cSTomasz Jozwiak 	}
379e0b6287cSTomasz Jozwiak 	return 0;
380e0b6287cSTomasz Jozwiak }
381e0b6287cSTomasz Jozwiak 
382e0b6287cSTomasz Jozwiak static int
parse_seg_sz(struct comp_test_data * test_data,const char * arg)383e0b6287cSTomasz Jozwiak parse_seg_sz(struct comp_test_data *test_data, const char *arg)
384e0b6287cSTomasz Jozwiak {
385e0b6287cSTomasz Jozwiak 	int ret = parse_uint16_t(&test_data->seg_sz, arg);
386e0b6287cSTomasz Jozwiak 
387e0b6287cSTomasz Jozwiak 	if (ret) {
388e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Failed to parse segment size\n");
389e0b6287cSTomasz Jozwiak 		return -1;
390e0b6287cSTomasz Jozwiak 	}
391e0b6287cSTomasz Jozwiak 
39227cee417STomasz Jozwiak 	if (test_data->seg_sz < MIN_COMPRESSED_BUF_SIZE) {
39327cee417STomasz Jozwiak 		RTE_LOG(ERR, USER1, "Segment size must be higher than %d\n",
39427cee417STomasz Jozwiak 			MIN_COMPRESSED_BUF_SIZE - 1);
39527cee417STomasz Jozwiak 		return -1;
39627cee417STomasz Jozwiak 	}
39727cee417STomasz Jozwiak 
39827cee417STomasz Jozwiak 	if (test_data->seg_sz > MAX_SEG_SIZE) {
39927cee417STomasz Jozwiak 		RTE_LOG(ERR, USER1, "Segment size must be lower than %d\n",
40027cee417STomasz Jozwiak 			MAX_SEG_SIZE + 1);
401e0b6287cSTomasz Jozwiak 		return -1;
402e0b6287cSTomasz Jozwiak 	}
403e0b6287cSTomasz Jozwiak 
404e0b6287cSTomasz Jozwiak 	return 0;
405e0b6287cSTomasz Jozwiak }
406e0b6287cSTomasz Jozwiak 
407e0b6287cSTomasz Jozwiak static int
parse_max_num_sgl_segs(struct comp_test_data * test_data,const char * arg)408e0b6287cSTomasz Jozwiak parse_max_num_sgl_segs(struct comp_test_data *test_data, const char *arg)
409e0b6287cSTomasz Jozwiak {
410e0b6287cSTomasz Jozwiak 	int ret = parse_uint16_t(&test_data->max_sgl_segs, arg);
411e0b6287cSTomasz Jozwiak 
412e0b6287cSTomasz Jozwiak 	if (ret) {
413e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1,
414e0b6287cSTomasz Jozwiak 			"Failed to parse max number of segments per mbuf chain\n");
415e0b6287cSTomasz Jozwiak 		return -1;
416e0b6287cSTomasz Jozwiak 	}
417e0b6287cSTomasz Jozwiak 
418e0b6287cSTomasz Jozwiak 	if (test_data->max_sgl_segs == 0) {
419e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Max number of segments per mbuf chain "
420e0b6287cSTomasz Jozwiak 			"must be higher than 0\n");
421e0b6287cSTomasz Jozwiak 		return -1;
422e0b6287cSTomasz Jozwiak 	}
423e0b6287cSTomasz Jozwiak 
424e0b6287cSTomasz Jozwiak 	return 0;
425e0b6287cSTomasz Jozwiak }
426e0b6287cSTomasz Jozwiak 
427e0b6287cSTomasz Jozwiak static int
parse_window_sz(struct comp_test_data * test_data,const char * arg)428e0b6287cSTomasz Jozwiak parse_window_sz(struct comp_test_data *test_data, const char *arg)
429e0b6287cSTomasz Jozwiak {
4301f04178dSArtur Trybula 	uint16_t tmp;
4311f04178dSArtur Trybula 	int ret = parse_uint16_t(&tmp, arg);
432e0b6287cSTomasz Jozwiak 
433e0b6287cSTomasz Jozwiak 	if (ret) {
434e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Failed to parse window size\n");
435e0b6287cSTomasz Jozwiak 		return -1;
436e0b6287cSTomasz Jozwiak 	}
4371f04178dSArtur Trybula 	test_data->window_sz = (int)tmp;
438e0b6287cSTomasz Jozwiak 
439e0b6287cSTomasz Jozwiak 	return 0;
440e0b6287cSTomasz Jozwiak }
441e0b6287cSTomasz Jozwiak 
442e0b6287cSTomasz Jozwiak static int
parse_driver_name(struct comp_test_data * test_data,const char * arg)443e0b6287cSTomasz Jozwiak parse_driver_name(struct comp_test_data *test_data, const char *arg)
444e0b6287cSTomasz Jozwiak {
445e0b6287cSTomasz Jozwiak 	if (strlen(arg) > (sizeof(test_data->driver_name) - 1))
446e0b6287cSTomasz Jozwiak 		return -1;
447e0b6287cSTomasz Jozwiak 
4486e37913fSThomas Monjalon 	strlcpy(test_data->driver_name, arg,
449e0b6287cSTomasz Jozwiak 			sizeof(test_data->driver_name));
450e0b6287cSTomasz Jozwiak 
451e0b6287cSTomasz Jozwiak 	return 0;
452e0b6287cSTomasz Jozwiak }
453e0b6287cSTomasz Jozwiak 
454e0b6287cSTomasz Jozwiak static int
parse_test_file(struct comp_test_data * test_data,const char * arg)455e0b6287cSTomasz Jozwiak parse_test_file(struct comp_test_data *test_data, const char *arg)
456e0b6287cSTomasz Jozwiak {
457e0b6287cSTomasz Jozwiak 	if (strlen(arg) > (sizeof(test_data->input_file) - 1))
458e0b6287cSTomasz Jozwiak 		return -1;
459e0b6287cSTomasz Jozwiak 
4606e37913fSThomas Monjalon 	strlcpy(test_data->input_file, arg, sizeof(test_data->input_file));
461e0b6287cSTomasz Jozwiak 
462e0b6287cSTomasz Jozwiak 	return 0;
463e0b6287cSTomasz Jozwiak }
464e0b6287cSTomasz Jozwiak 
465e0b6287cSTomasz Jozwiak static int
parse_op_type(struct comp_test_data * test_data,const char * arg)466e0b6287cSTomasz Jozwiak parse_op_type(struct comp_test_data *test_data, const char *arg)
467e0b6287cSTomasz Jozwiak {
468e0b6287cSTomasz Jozwiak 	struct name_id_map optype_namemap[] = {
469e0b6287cSTomasz Jozwiak 		{
470e0b6287cSTomasz Jozwiak 			"comp",
47183cc3b90SMichael Baum 			COMPRESS
472e0b6287cSTomasz Jozwiak 		},
473e0b6287cSTomasz Jozwiak 		{
474e0b6287cSTomasz Jozwiak 			"decomp",
47583cc3b90SMichael Baum 			DECOMPRESS
476e0b6287cSTomasz Jozwiak 		},
477e0b6287cSTomasz Jozwiak 		{
478e0b6287cSTomasz Jozwiak 			"comp_and_decomp",
479e0b6287cSTomasz Jozwiak 			COMPRESS_DECOMPRESS
480e0b6287cSTomasz Jozwiak 		}
481e0b6287cSTomasz Jozwiak 	};
482e0b6287cSTomasz Jozwiak 
483e0b6287cSTomasz Jozwiak 	int id = get_str_key_id_mapping(optype_namemap,
484e0b6287cSTomasz Jozwiak 			RTE_DIM(optype_namemap), arg);
485e0b6287cSTomasz Jozwiak 	if (id < 0) {
486e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Invalid operation type specified\n");
487e0b6287cSTomasz Jozwiak 		return -1;
488e0b6287cSTomasz Jozwiak 	}
489e0b6287cSTomasz Jozwiak 
490e0b6287cSTomasz Jozwiak 	test_data->test_op = (enum comp_operation)id;
491e0b6287cSTomasz Jozwiak 
492e0b6287cSTomasz Jozwiak 	return 0;
493e0b6287cSTomasz Jozwiak }
494e0b6287cSTomasz Jozwiak 
495e0b6287cSTomasz Jozwiak static int
parse_algo(struct comp_test_data * test_data,const char * arg)496*72c64a34SMichael Baum parse_algo(struct comp_test_data *test_data, const char *arg)
497*72c64a34SMichael Baum {
498*72c64a34SMichael Baum 	struct name_id_map algo_namemap[] = {
499*72c64a34SMichael Baum 		{
500*72c64a34SMichael Baum 			"null",
501*72c64a34SMichael Baum 			RTE_COMP_ALGO_NULL
502*72c64a34SMichael Baum 		},
503*72c64a34SMichael Baum 		{
504*72c64a34SMichael Baum 			"deflate",
505*72c64a34SMichael Baum 			RTE_COMP_ALGO_DEFLATE
506*72c64a34SMichael Baum 		},
507*72c64a34SMichael Baum 		{
508*72c64a34SMichael Baum 			"lzs",
509*72c64a34SMichael Baum 			RTE_COMP_ALGO_LZS
510*72c64a34SMichael Baum 		},
511*72c64a34SMichael Baum 		{
512*72c64a34SMichael Baum 			"lz4",
513*72c64a34SMichael Baum 			RTE_COMP_ALGO_LZ4
514*72c64a34SMichael Baum 		}
515*72c64a34SMichael Baum 	};
516*72c64a34SMichael Baum 
517*72c64a34SMichael Baum 	int id = get_str_key_id_mapping(algo_namemap,
518*72c64a34SMichael Baum 			RTE_DIM(algo_namemap), arg);
519*72c64a34SMichael Baum 	if (id < 0) {
520*72c64a34SMichael Baum 		RTE_LOG(ERR, USER1, "Invalid algorithm specified\n");
521*72c64a34SMichael Baum 		return -1;
522*72c64a34SMichael Baum 	}
523*72c64a34SMichael Baum 
524*72c64a34SMichael Baum 	test_data->test_algo = (enum rte_comp_algorithm)id;
525*72c64a34SMichael Baum 
526*72c64a34SMichael Baum 	return 0;
527*72c64a34SMichael Baum }
528*72c64a34SMichael Baum 
529*72c64a34SMichael Baum static int
parse_huffman_enc(struct comp_test_data * test_data,const char * arg)530e0b6287cSTomasz Jozwiak parse_huffman_enc(struct comp_test_data *test_data, const char *arg)
531e0b6287cSTomasz Jozwiak {
532e0b6287cSTomasz Jozwiak 	struct name_id_map huffman_namemap[] = {
533e0b6287cSTomasz Jozwiak 		{
534e0b6287cSTomasz Jozwiak 			"default",
535e0b6287cSTomasz Jozwiak 			RTE_COMP_HUFFMAN_DEFAULT
536e0b6287cSTomasz Jozwiak 		},
537e0b6287cSTomasz Jozwiak 		{
538e0b6287cSTomasz Jozwiak 			"fixed",
539e0b6287cSTomasz Jozwiak 			RTE_COMP_HUFFMAN_FIXED
540fedfef43STomasz Jozwiak 		},
541fedfef43STomasz Jozwiak 		{
542fedfef43STomasz Jozwiak 			"dynamic",
543fedfef43STomasz Jozwiak 			RTE_COMP_HUFFMAN_DYNAMIC
544e0b6287cSTomasz Jozwiak 		}
545e0b6287cSTomasz Jozwiak 	};
546e0b6287cSTomasz Jozwiak 
547e0b6287cSTomasz Jozwiak 	int id = get_str_key_id_mapping(huffman_namemap,
548e0b6287cSTomasz Jozwiak 			RTE_DIM(huffman_namemap), arg);
549e0b6287cSTomasz Jozwiak 	if (id < 0) {
5501643fc9bSMichael Baum 		RTE_LOG(ERR, USER1, "Invalid Huffman encoding specified\n");
551e0b6287cSTomasz Jozwiak 		return -1;
552e0b6287cSTomasz Jozwiak 	}
553e0b6287cSTomasz Jozwiak 
554e0b6287cSTomasz Jozwiak 	test_data->huffman_enc = (enum rte_comp_huffman)id;
555e0b6287cSTomasz Jozwiak 
556e0b6287cSTomasz Jozwiak 	return 0;
557e0b6287cSTomasz Jozwiak }
558e0b6287cSTomasz Jozwiak 
559e0b6287cSTomasz Jozwiak static int
parse_lz4_flags(struct comp_test_data * test_data,const char * arg)560*72c64a34SMichael Baum parse_lz4_flags(struct comp_test_data *test_data, const char *arg)
561*72c64a34SMichael Baum {
562*72c64a34SMichael Baum 	int ret = parse_uint8_t(&test_data->lz4_flags, arg);
563*72c64a34SMichael Baum 
564*72c64a34SMichael Baum 	if (ret) {
565*72c64a34SMichael Baum 		RTE_LOG(ERR, USER1, "Failed to parse LZ4 flags\n");
566*72c64a34SMichael Baum 		return -1;
567*72c64a34SMichael Baum 	}
568*72c64a34SMichael Baum 
569*72c64a34SMichael Baum 	return 0;
570*72c64a34SMichael Baum }
571*72c64a34SMichael Baum 
572*72c64a34SMichael Baum static int
parse_level(struct comp_test_data * test_data,const char * arg)573e0b6287cSTomasz Jozwiak parse_level(struct comp_test_data *test_data, const char *arg)
574e0b6287cSTomasz Jozwiak {
575e0b6287cSTomasz Jozwiak 	int ret;
576e0b6287cSTomasz Jozwiak 
577e0b6287cSTomasz Jozwiak 	/*
578e0b6287cSTomasz Jozwiak 	 * Try parsing the argument as a range, if it fails,
5791643fc9bSMichael Baum 	 * parse it as a list
580e0b6287cSTomasz Jozwiak 	 */
581424dd6c8STomasz Jozwiak 	if (parse_range(arg, &test_data->level_lst.min,
582424dd6c8STomasz Jozwiak 			&test_data->level_lst.max,
583424dd6c8STomasz Jozwiak 			&test_data->level_lst.inc) < 0) {
584424dd6c8STomasz Jozwiak 		ret = parse_list(arg, test_data->level_lst.list,
585424dd6c8STomasz Jozwiak 					&test_data->level_lst.min,
586424dd6c8STomasz Jozwiak 					&test_data->level_lst.max);
587e0b6287cSTomasz Jozwiak 		if (ret < 0) {
588e0b6287cSTomasz Jozwiak 			RTE_LOG(ERR, USER1,
589e0b6287cSTomasz Jozwiak 				"Failed to parse compression level/s\n");
590e0b6287cSTomasz Jozwiak 			return -1;
591e0b6287cSTomasz Jozwiak 		}
592424dd6c8STomasz Jozwiak 		test_data->level_lst.count = ret;
593e0b6287cSTomasz Jozwiak 
594424dd6c8STomasz Jozwiak 		if (test_data->level_lst.max > RTE_COMP_LEVEL_MAX) {
595e0b6287cSTomasz Jozwiak 			RTE_LOG(ERR, USER1, "Level cannot be higher than %u\n",
596e0b6287cSTomasz Jozwiak 					RTE_COMP_LEVEL_MAX);
597e0b6287cSTomasz Jozwiak 			return -1;
598e0b6287cSTomasz Jozwiak 		}
599e0b6287cSTomasz Jozwiak 	}
600e0b6287cSTomasz Jozwiak 
601e0b6287cSTomasz Jozwiak 	return 0;
602e0b6287cSTomasz Jozwiak }
603e0b6287cSTomasz Jozwiak 
604c02e33b0SAdam Dybkowski static int
parse_external_mbufs(struct comp_test_data * test_data,const char * arg __rte_unused)605c02e33b0SAdam Dybkowski parse_external_mbufs(struct comp_test_data *test_data,
606c02e33b0SAdam Dybkowski 		     const char *arg __rte_unused)
607c02e33b0SAdam Dybkowski {
608c02e33b0SAdam Dybkowski 	test_data->use_external_mbufs = 1;
609c02e33b0SAdam Dybkowski 	return 0;
610c02e33b0SAdam Dybkowski }
611c02e33b0SAdam Dybkowski 
6122695db95SArtur Trybula static int
parse_cyclecount_delay_us(struct comp_test_data * test_data,const char * arg)6132695db95SArtur Trybula parse_cyclecount_delay_us(struct comp_test_data *test_data,
6142695db95SArtur Trybula 			const char *arg)
6152695db95SArtur Trybula {
6162695db95SArtur Trybula 	int ret = parse_uint32_t(&(test_data->cyclecount_delay), arg);
6172695db95SArtur Trybula 
6182695db95SArtur Trybula 	if (ret) {
6192695db95SArtur Trybula 		RTE_LOG(ERR, USER1, "Failed to parse cyclecount delay\n");
6202695db95SArtur Trybula 		return -1;
6212695db95SArtur Trybula 	}
6222695db95SArtur Trybula 	return 0;
6232695db95SArtur Trybula }
6242695db95SArtur Trybula 
625e0b6287cSTomasz Jozwiak typedef int (*option_parser_t)(struct comp_test_data *test_data,
626e0b6287cSTomasz Jozwiak 		const char *arg);
627e0b6287cSTomasz Jozwiak 
628e0b6287cSTomasz Jozwiak struct long_opt_parser {
629e0b6287cSTomasz Jozwiak 	const char *lgopt_name;
630e0b6287cSTomasz Jozwiak 	option_parser_t parser_fn;
631e0b6287cSTomasz Jozwiak };
632e0b6287cSTomasz Jozwiak 
633e0b6287cSTomasz Jozwiak static struct option lgopts[] = {
6341a9b0f35STomasz Jozwiak 	{ CPERF_PTEST_TYPE, required_argument, 0, 0 },
635e0b6287cSTomasz Jozwiak 	{ CPERF_DRIVER_NAME, required_argument, 0, 0 },
636e0b6287cSTomasz Jozwiak 	{ CPERF_TEST_FILE, required_argument, 0, 0 },
637e0b6287cSTomasz Jozwiak 	{ CPERF_SEG_SIZE, required_argument, 0, 0 },
638e0b6287cSTomasz Jozwiak 	{ CPERF_BURST_SIZE, required_argument, 0, 0 },
639e0b6287cSTomasz Jozwiak 	{ CPERF_EXTENDED_SIZE, required_argument, 0, 0 },
640e0b6287cSTomasz Jozwiak 	{ CPERF_POOL_SIZE, required_argument, 0, 0 },
641e0b6287cSTomasz Jozwiak 	{ CPERF_MAX_SGL_SEGS, required_argument, 0, 0},
642e0b6287cSTomasz Jozwiak 	{ CPERF_NUM_ITER, required_argument, 0, 0 },
643e0b6287cSTomasz Jozwiak 	{ CPERF_OPTYPE,	required_argument, 0, 0 },
644*72c64a34SMichael Baum 	{ CPERF_ALGO, required_argument, 0, 0 },
645e0b6287cSTomasz Jozwiak 	{ CPERF_HUFFMAN_ENC, required_argument, 0, 0 },
646*72c64a34SMichael Baum 	{ CPERF_LZ4_FLAGS, required_argument, 0, 0 },
647e0b6287cSTomasz Jozwiak 	{ CPERF_LEVEL, required_argument, 0, 0 },
648e0b6287cSTomasz Jozwiak 	{ CPERF_WINDOW_SIZE, required_argument, 0, 0 },
649c02e33b0SAdam Dybkowski 	{ CPERF_EXTERNAL_MBUFS, 0, 0, 0 },
6502695db95SArtur Trybula 	{ CPERF_CYCLECOUNT_DELAY_US, required_argument, 0, 0 },
651e0b6287cSTomasz Jozwiak 	{ NULL, 0, 0, 0 }
652e0b6287cSTomasz Jozwiak };
653c02e33b0SAdam Dybkowski 
654e0b6287cSTomasz Jozwiak static int
comp_perf_opts_parse_long(int opt_idx,struct comp_test_data * test_data)655e0b6287cSTomasz Jozwiak comp_perf_opts_parse_long(int opt_idx, struct comp_test_data *test_data)
656e0b6287cSTomasz Jozwiak {
657e0b6287cSTomasz Jozwiak 	struct long_opt_parser parsermap[] = {
6581a9b0f35STomasz Jozwiak 		{ CPERF_PTEST_TYPE,	parse_cperf_test_type },
659e0b6287cSTomasz Jozwiak 		{ CPERF_DRIVER_NAME,	parse_driver_name },
660e0b6287cSTomasz Jozwiak 		{ CPERF_TEST_FILE,	parse_test_file },
661e0b6287cSTomasz Jozwiak 		{ CPERF_SEG_SIZE,	parse_seg_sz },
662e0b6287cSTomasz Jozwiak 		{ CPERF_BURST_SIZE,	parse_burst_sz },
663e0b6287cSTomasz Jozwiak 		{ CPERF_EXTENDED_SIZE,	parse_extended_input_sz },
664e0b6287cSTomasz Jozwiak 		{ CPERF_POOL_SIZE,	parse_pool_sz },
665e0b6287cSTomasz Jozwiak 		{ CPERF_MAX_SGL_SEGS,	parse_max_num_sgl_segs },
666e0b6287cSTomasz Jozwiak 		{ CPERF_NUM_ITER,	parse_num_iter },
667e0b6287cSTomasz Jozwiak 		{ CPERF_OPTYPE,		parse_op_type },
668*72c64a34SMichael Baum 		{ CPERF_ALGO,		parse_algo },
669e0b6287cSTomasz Jozwiak 		{ CPERF_HUFFMAN_ENC,	parse_huffman_enc },
670*72c64a34SMichael Baum 		{ CPERF_LZ4_FLAGS,	parse_lz4_flags },
671e0b6287cSTomasz Jozwiak 		{ CPERF_LEVEL,		parse_level },
672e0b6287cSTomasz Jozwiak 		{ CPERF_WINDOW_SIZE,	parse_window_sz },
673c02e33b0SAdam Dybkowski 		{ CPERF_EXTERNAL_MBUFS,	parse_external_mbufs },
6742695db95SArtur Trybula 		{ CPERF_CYCLECOUNT_DELAY_US,	parse_cyclecount_delay_us },
675e0b6287cSTomasz Jozwiak 	};
676e0b6287cSTomasz Jozwiak 	unsigned int i;
677e0b6287cSTomasz Jozwiak 
678e0b6287cSTomasz Jozwiak 	for (i = 0; i < RTE_DIM(parsermap); i++) {
679e0b6287cSTomasz Jozwiak 		if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
680e0b6287cSTomasz Jozwiak 				strlen(lgopts[opt_idx].name)) == 0)
681e0b6287cSTomasz Jozwiak 			return parsermap[i].parser_fn(test_data, optarg);
682e0b6287cSTomasz Jozwiak 	}
683e0b6287cSTomasz Jozwiak 
684e0b6287cSTomasz Jozwiak 	return -EINVAL;
685e0b6287cSTomasz Jozwiak }
686e0b6287cSTomasz Jozwiak 
687e0b6287cSTomasz Jozwiak int
comp_perf_options_parse(struct comp_test_data * test_data,int argc,char ** argv)688e0b6287cSTomasz Jozwiak comp_perf_options_parse(struct comp_test_data *test_data, int argc, char **argv)
689e0b6287cSTomasz Jozwiak {
690e0b6287cSTomasz Jozwiak 	int opt, retval, opt_idx;
691e0b6287cSTomasz Jozwiak 
692e0b6287cSTomasz Jozwiak 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
693e0b6287cSTomasz Jozwiak 		switch (opt) {
694e0b6287cSTomasz Jozwiak 		case 'h':
695e0b6287cSTomasz Jozwiak 			usage(argv[0]);
696487cfc24SThomas Monjalon 			exit(EXIT_SUCCESS);
697e0b6287cSTomasz Jozwiak 			break;
698e0b6287cSTomasz Jozwiak 		/* long options */
699e0b6287cSTomasz Jozwiak 		case 0:
700e0b6287cSTomasz Jozwiak 			retval = comp_perf_opts_parse_long(opt_idx, test_data);
701e0b6287cSTomasz Jozwiak 			if (retval != 0)
702e0b6287cSTomasz Jozwiak 				return retval;
703e0b6287cSTomasz Jozwiak 
704e0b6287cSTomasz Jozwiak 			break;
705e0b6287cSTomasz Jozwiak 
706e0b6287cSTomasz Jozwiak 		default:
707e0b6287cSTomasz Jozwiak 			usage(argv[0]);
708e0b6287cSTomasz Jozwiak 			return -EINVAL;
709e0b6287cSTomasz Jozwiak 		}
710e0b6287cSTomasz Jozwiak 	}
711e0b6287cSTomasz Jozwiak 
712e0b6287cSTomasz Jozwiak 	return 0;
713e0b6287cSTomasz Jozwiak }
714e0b6287cSTomasz Jozwiak 
715e0b6287cSTomasz Jozwiak void
comp_perf_options_default(struct comp_test_data * test_data)716e0b6287cSTomasz Jozwiak comp_perf_options_default(struct comp_test_data *test_data)
717e0b6287cSTomasz Jozwiak {
718e0b6287cSTomasz Jozwiak 	test_data->seg_sz = 2048;
719e0b6287cSTomasz Jozwiak 	test_data->burst_sz = 32;
720e0b6287cSTomasz Jozwiak 	test_data->pool_sz = 8192;
721b68a8242STomasz Jozwiak 	test_data->max_sgl_segs = 16;
722e0b6287cSTomasz Jozwiak 	test_data->num_iter = 10000;
723*72c64a34SMichael Baum 	test_data->lz4_flags = 0;
724fedfef43STomasz Jozwiak 	test_data->huffman_enc = RTE_COMP_HUFFMAN_DYNAMIC;
725e0b6287cSTomasz Jozwiak 	test_data->test_op = COMPRESS_DECOMPRESS;
726*72c64a34SMichael Baum 	test_data->test_algo = RTE_COMP_ALGO_DEFLATE;
727e0b6287cSTomasz Jozwiak 	test_data->window_sz = -1;
7288c7a3131SArtur Trybula 	test_data->level_lst.min = RTE_COMP_LEVEL_MIN;
7298c7a3131SArtur Trybula 	test_data->level_lst.max = RTE_COMP_LEVEL_MAX;
730424dd6c8STomasz Jozwiak 	test_data->level_lst.inc = 1;
7312695db95SArtur Trybula 	test_data->test = CPERF_TEST_TYPE_THROUGHPUT;
732c02e33b0SAdam Dybkowski 	test_data->use_external_mbufs = 0;
7332695db95SArtur Trybula 	test_data->cyclecount_delay = 500;
734e0b6287cSTomasz Jozwiak }
735e0b6287cSTomasz Jozwiak 
736e0b6287cSTomasz Jozwiak int
comp_perf_options_check(struct comp_test_data * test_data)737e0b6287cSTomasz Jozwiak comp_perf_options_check(struct comp_test_data *test_data)
738e0b6287cSTomasz Jozwiak {
739e0b6287cSTomasz Jozwiak 	if (test_data->driver_name[0] == '\0') {
740e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Driver name has to be set\n");
741e0b6287cSTomasz Jozwiak 		return -1;
742e0b6287cSTomasz Jozwiak 	}
743e0b6287cSTomasz Jozwiak 
744e0b6287cSTomasz Jozwiak 	if (test_data->input_file[0] == '\0') {
745e0b6287cSTomasz Jozwiak 		RTE_LOG(ERR, USER1, "Input file name has to be set\n");
746e0b6287cSTomasz Jozwiak 		return -1;
747e0b6287cSTomasz Jozwiak 	}
748e0b6287cSTomasz Jozwiak 
749e0b6287cSTomasz Jozwiak 	return 0;
750e0b6287cSTomasz Jozwiak }
751