xref: /dpdk/app/test-eventdev/evt_main.c (revision b25a66c49e8df8bd0976d0b70ef36352bed29eff)
153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
253a3b7e8SJerin Jacob  * Copyright(c) 2017 Cavium, Inc
36d1729deSJerin Jacob  */
46d1729deSJerin Jacob 
56d1729deSJerin Jacob #include <stdio.h>
672b452c5SDmitry Kozlyuk #include <stdlib.h>
76d1729deSJerin Jacob #include <unistd.h>
86d1729deSJerin Jacob #include <signal.h>
96d1729deSJerin Jacob 
106d1729deSJerin Jacob #include <rte_debug.h>
116d1729deSJerin Jacob #include <rte_eal.h>
126d1729deSJerin Jacob #include <rte_eventdev.h>
136d1729deSJerin Jacob 
143f3872b1SJerin Jacob #include "evt_options.h"
153f3872b1SJerin Jacob #include "evt_test.h"
163f3872b1SJerin Jacob 
173f3872b1SJerin Jacob struct evt_options opt;
183f3872b1SJerin Jacob struct evt_test *test;
193f3872b1SJerin Jacob 
202b0bf13cSJerin Jacob static void
signal_handler(int signum)212b0bf13cSJerin Jacob signal_handler(int signum)
222b0bf13cSJerin Jacob {
23a734e738SPavan Nikhilesh 	if (signum == SIGINT || signum == SIGTERM) {
24685bb577SPavan Nikhilesh 		if (test != NULL) {
252b0bf13cSJerin Jacob 			/* request all lcores to exit from the main loop */
262b0bf13cSJerin Jacob 			*(int *)test->test_priv = true;
272b0bf13cSJerin Jacob 			rte_wmb();
28685bb577SPavan Nikhilesh 		}
292b0bf13cSJerin Jacob 	}
302b0bf13cSJerin Jacob }
313f3872b1SJerin Jacob 
323f3872b1SJerin Jacob static inline void
evt_options_dump_all(struct evt_test * test,struct evt_options * opts)333f3872b1SJerin Jacob evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
343f3872b1SJerin Jacob {
353f3872b1SJerin Jacob 	evt_options_dump(opts);
363f3872b1SJerin Jacob 	if (test->ops.opt_dump)
373f3872b1SJerin Jacob 		test->ops.opt_dump(opts);
383f3872b1SJerin Jacob }
393f3872b1SJerin Jacob 
406d1729deSJerin Jacob int
main(int argc,char ** argv)416d1729deSJerin Jacob main(int argc, char **argv)
426d1729deSJerin Jacob {
436d1729deSJerin Jacob 	uint8_t evdevs;
446d1729deSJerin Jacob 	int ret;
456d1729deSJerin Jacob 
462b0bf13cSJerin Jacob 	signal(SIGINT, signal_handler);
472b0bf13cSJerin Jacob 	signal(SIGTERM, signal_handler);
482b0bf13cSJerin Jacob 
496d1729deSJerin Jacob 	ret = rte_eal_init(argc, argv);
506d1729deSJerin Jacob 	if (ret < 0)
516d1729deSJerin Jacob 		rte_panic("invalid EAL arguments\n");
526d1729deSJerin Jacob 	argc -= ret;
536d1729deSJerin Jacob 	argv += ret;
546d1729deSJerin Jacob 
556d1729deSJerin Jacob 	evdevs = rte_event_dev_count();
566d1729deSJerin Jacob 	if (!evdevs)
576d1729deSJerin Jacob 		rte_panic("no eventdev devices found\n");
586d1729deSJerin Jacob 
593f3872b1SJerin Jacob 	/* Populate the default values of the options */
603f3872b1SJerin Jacob 	evt_options_default(&opt);
613f3872b1SJerin Jacob 
623f3872b1SJerin Jacob 	/* Parse the command line arguments */
633f3872b1SJerin Jacob 	ret = evt_options_parse(&opt, argc, argv);
643f3872b1SJerin Jacob 	if (ret) {
6520841a25SRashmi Shetty 		evt_err("parsing one or more user options failed");
663f3872b1SJerin Jacob 		goto error;
673f3872b1SJerin Jacob 	}
683f3872b1SJerin Jacob 
693f3872b1SJerin Jacob 	/* Get struct evt_test *test from name */
703f3872b1SJerin Jacob 	test = evt_test_get(opt.test_name);
713f3872b1SJerin Jacob 	if (test == NULL) {
723f3872b1SJerin Jacob 		evt_err("failed to find requested test: %s", opt.test_name);
733f3872b1SJerin Jacob 		goto error;
743f3872b1SJerin Jacob 	}
753f3872b1SJerin Jacob 
763f3872b1SJerin Jacob 	if (test->ops.test_result == NULL) {
773f3872b1SJerin Jacob 		evt_err("%s: ops.test_result not found", opt.test_name);
783f3872b1SJerin Jacob 		goto error;
793f3872b1SJerin Jacob 	}
803f3872b1SJerin Jacob 
813f3872b1SJerin Jacob 	/* Verify the command line options */
823f3872b1SJerin Jacob 	if (opt.dev_id >= rte_event_dev_count()) {
833f3872b1SJerin Jacob 		evt_err("invalid event device %d", opt.dev_id);
843f3872b1SJerin Jacob 		goto error;
853f3872b1SJerin Jacob 	}
863f3872b1SJerin Jacob 	if (test->ops.opt_check) {
873f3872b1SJerin Jacob 		if (test->ops.opt_check(&opt)) {
883f3872b1SJerin Jacob 			evt_err("invalid command line argument");
893f3872b1SJerin Jacob 			evt_options_dump_all(test, &opt);
903f3872b1SJerin Jacob 			goto error;
913f3872b1SJerin Jacob 		}
923f3872b1SJerin Jacob 	}
933f3872b1SJerin Jacob 
943f3872b1SJerin Jacob 	/* Check the eventdev capability before proceeding */
953f3872b1SJerin Jacob 	if (test->ops.cap_check) {
963f3872b1SJerin Jacob 		if (test->ops.cap_check(&opt) == false) {
973f3872b1SJerin Jacob 			evt_info("unsupported test: %s", opt.test_name);
983f3872b1SJerin Jacob 			evt_options_dump_all(test, &opt);
993f3872b1SJerin Jacob 			ret = EVT_TEST_UNSUPPORTED;
1003f3872b1SJerin Jacob 			goto nocap;
1013f3872b1SJerin Jacob 		}
1023f3872b1SJerin Jacob 	}
1033f3872b1SJerin Jacob 
1043f3872b1SJerin Jacob 	/* Dump the options */
1053f3872b1SJerin Jacob 	if (opt.verbose_level)
1063f3872b1SJerin Jacob 		evt_options_dump_all(test, &opt);
1073f3872b1SJerin Jacob 
1083f3872b1SJerin Jacob 	/* Test specific setup */
1093f3872b1SJerin Jacob 	if (test->ops.test_setup) {
1103f3872b1SJerin Jacob 		if (test->ops.test_setup(test, &opt))  {
1113f3872b1SJerin Jacob 			evt_err("failed to setup test: %s", opt.test_name);
1123f3872b1SJerin Jacob 			goto error;
1133f3872b1SJerin Jacob 
1143f3872b1SJerin Jacob 		}
1153f3872b1SJerin Jacob 	}
1163f3872b1SJerin Jacob 
1173f3872b1SJerin Jacob 	/* Test specific mempool setup */
1183f3872b1SJerin Jacob 	if (test->ops.mempool_setup) {
1193f3872b1SJerin Jacob 		if (test->ops.mempool_setup(test, &opt)) {
1203f3872b1SJerin Jacob 			evt_err("%s: mempool setup failed", opt.test_name);
1213f3872b1SJerin Jacob 			goto test_destroy;
1223f3872b1SJerin Jacob 		}
1233f3872b1SJerin Jacob 	}
1243f3872b1SJerin Jacob 
1253f3872b1SJerin Jacob 	/* Test specific ethdev setup */
1263f3872b1SJerin Jacob 	if (test->ops.ethdev_setup) {
1273f3872b1SJerin Jacob 		if (test->ops.ethdev_setup(test, &opt)) {
1283f3872b1SJerin Jacob 			evt_err("%s: ethdev setup failed", opt.test_name);
1293f3872b1SJerin Jacob 			goto mempool_destroy;
1303f3872b1SJerin Jacob 		}
1313f3872b1SJerin Jacob 	}
1323f3872b1SJerin Jacob 
133de2bc16eSShijith Thotton 	/* Test specific cryptodev setup */
134de2bc16eSShijith Thotton 	if (test->ops.cryptodev_setup) {
135de2bc16eSShijith Thotton 		if (test->ops.cryptodev_setup(test, &opt)) {
136de2bc16eSShijith Thotton 			evt_err("%s: cryptodev setup failed", opt.test_name);
137de2bc16eSShijith Thotton 			goto ethdev_destroy;
138de2bc16eSShijith Thotton 		}
139de2bc16eSShijith Thotton 	}
140de2bc16eSShijith Thotton 
141*b25a66c4SAmit Prakash Shukla 	/* Test specific dmadev setup */
142*b25a66c4SAmit Prakash Shukla 	if (test->ops.dmadev_setup) {
143*b25a66c4SAmit Prakash Shukla 		if (test->ops.dmadev_setup(test, &opt)) {
144*b25a66c4SAmit Prakash Shukla 			evt_err("%s: dmadev setup failed", opt.test_name);
145*b25a66c4SAmit Prakash Shukla 			goto dmadev_destroy;
146*b25a66c4SAmit Prakash Shukla 		}
147*b25a66c4SAmit Prakash Shukla 	}
148*b25a66c4SAmit Prakash Shukla 
1493f3872b1SJerin Jacob 	/* Test specific eventdev setup */
1503f3872b1SJerin Jacob 	if (test->ops.eventdev_setup) {
1513f3872b1SJerin Jacob 		if (test->ops.eventdev_setup(test, &opt)) {
1523f3872b1SJerin Jacob 			evt_err("%s: eventdev setup failed", opt.test_name);
153de2bc16eSShijith Thotton 			goto cryptodev_destroy;
1543f3872b1SJerin Jacob 		}
1553f3872b1SJerin Jacob 	}
1563f3872b1SJerin Jacob 
1573f3872b1SJerin Jacob 	/* Launch lcores */
1583f3872b1SJerin Jacob 	if (test->ops.launch_lcores) {
1593f3872b1SJerin Jacob 		if (test->ops.launch_lcores(test, &opt)) {
1603f3872b1SJerin Jacob 			evt_err("%s: failed to launch lcores", opt.test_name);
1613f3872b1SJerin Jacob 			goto eventdev_destroy;
1623f3872b1SJerin Jacob 		}
1633f3872b1SJerin Jacob 	}
1643f3872b1SJerin Jacob 
165a734e738SPavan Nikhilesh 	if (test->ops.ethdev_rx_stop)
166a734e738SPavan Nikhilesh 		test->ops.ethdev_rx_stop(test, &opt);
167a734e738SPavan Nikhilesh 
1683f3872b1SJerin Jacob 	rte_eal_mp_wait_lcore();
1693f3872b1SJerin Jacob 
170a734e738SPavan Nikhilesh 	if (test->ops.test_result)
171a734e738SPavan Nikhilesh 		test->ops.test_result(test, &opt);
172a734e738SPavan Nikhilesh 
173a734e738SPavan Nikhilesh 	if (test->ops.ethdev_destroy)
174a734e738SPavan Nikhilesh 		test->ops.ethdev_destroy(test, &opt);
175a734e738SPavan Nikhilesh 
176a734e738SPavan Nikhilesh 	if (test->ops.eventdev_destroy)
177a734e738SPavan Nikhilesh 		test->ops.eventdev_destroy(test, &opt);
178a734e738SPavan Nikhilesh 
17967f22707SShijith Thotton 	if (test->ops.cryptodev_destroy)
18067f22707SShijith Thotton 		test->ops.cryptodev_destroy(test, &opt);
18167f22707SShijith Thotton 
182*b25a66c4SAmit Prakash Shukla 	if (test->ops.dmadev_destroy)
183*b25a66c4SAmit Prakash Shukla 		test->ops.dmadev_destroy(test, &opt);
184*b25a66c4SAmit Prakash Shukla 
185a734e738SPavan Nikhilesh 	if (test->ops.mempool_destroy)
186a734e738SPavan Nikhilesh 		test->ops.mempool_destroy(test, &opt);
187a734e738SPavan Nikhilesh 
188a734e738SPavan Nikhilesh 	if (test->ops.test_destroy)
189a734e738SPavan Nikhilesh 		test->ops.test_destroy(test, &opt);
190a734e738SPavan Nikhilesh 
1913f3872b1SJerin Jacob nocap:
1923f3872b1SJerin Jacob 	if (ret == EVT_TEST_SUCCESS) {
1933f3872b1SJerin Jacob 		printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
1943f3872b1SJerin Jacob 	} else if (ret == EVT_TEST_FAILED) {
1953f3872b1SJerin Jacob 		printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
1963f3872b1SJerin Jacob 		return EXIT_FAILURE;
1973f3872b1SJerin Jacob 	} else if (ret == EVT_TEST_UNSUPPORTED) {
1983f3872b1SJerin Jacob 		printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
1993f3872b1SJerin Jacob 	}
2003f3872b1SJerin Jacob 
2016d1729deSJerin Jacob 	return 0;
2023f3872b1SJerin Jacob eventdev_destroy:
2033f3872b1SJerin Jacob 	if (test->ops.eventdev_destroy)
2043f3872b1SJerin Jacob 		test->ops.eventdev_destroy(test, &opt);
2053f3872b1SJerin Jacob 
206de2bc16eSShijith Thotton cryptodev_destroy:
207de2bc16eSShijith Thotton 	if (test->ops.cryptodev_destroy)
208de2bc16eSShijith Thotton 		test->ops.cryptodev_destroy(test, &opt);
209de2bc16eSShijith Thotton 
210*b25a66c4SAmit Prakash Shukla dmadev_destroy:
211*b25a66c4SAmit Prakash Shukla 	if (test->ops.dmadev_destroy)
212*b25a66c4SAmit Prakash Shukla 		test->ops.dmadev_destroy(test, &opt);
213*b25a66c4SAmit Prakash Shukla 
2143f3872b1SJerin Jacob ethdev_destroy:
2153f3872b1SJerin Jacob 	if (test->ops.ethdev_destroy)
2163f3872b1SJerin Jacob 		test->ops.ethdev_destroy(test, &opt);
2173f3872b1SJerin Jacob 
2183f3872b1SJerin Jacob mempool_destroy:
2193f3872b1SJerin Jacob 	if (test->ops.mempool_destroy)
2203f3872b1SJerin Jacob 		test->ops.mempool_destroy(test, &opt);
2213f3872b1SJerin Jacob 
2223f3872b1SJerin Jacob test_destroy:
2233f3872b1SJerin Jacob 	if (test->ops.test_destroy)
2243f3872b1SJerin Jacob 		test->ops.test_destroy(test, &opt);
2253f3872b1SJerin Jacob error:
2263f3872b1SJerin Jacob 	return EXIT_FAILURE;
2276d1729deSJerin Jacob }
228