1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <sys/queue.h>
22 #include <rte_common.h>
23 #include <rte_memory.h>
24 #include <rte_memzone.h>
26 #include <rte_launch.h>
27 #include <rte_per_lcore.h>
28 #include <rte_lcore.h>
29 #include <rte_errno.h>
30 #include <rte_branch_prediction.h>
32 #include <rte_debug.h>
34 #include <rte_mempool.h>
38 #include <rte_fbk_hash.h>
39 #endif /* RTE_LIB_HASH */
43 #endif /* RTE_LIB_LPM */
45 #include <rte_string_fns.h>
49 #define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
52 * This function is called in the primary i.e. main test, to spawn off secondary
53 * processes to run actual mp tests. Uses fork() and exec pair
56 run_secondary_instances(void)
61 #ifdef RTE_EXEC_ENV_LINUX
62 char tmp[PATH_MAX] = {0};
63 char prefix[PATH_MAX] = {0};
65 get_current_prefix(tmp, sizeof(tmp));
67 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
69 const char *prefix = "";
72 /* good case, using secondary */
73 const char *argv1[] = {
74 prgname, "-c", coremask, "--proc-type=secondary",
77 /* good case, using auto */
78 const char *argv2[] = {
79 prgname, "-c", coremask, "--proc-type=auto",
82 /* bad case, using invalid type */
83 const char *argv3[] = {
84 prgname, "-c", coremask, "--proc-type=ERROR",
87 #ifdef RTE_EXEC_ENV_LINUX
88 /* bad case, using invalid file prefix */
89 const char *argv4[] = {
90 prgname, "-c", coremask, "--proc-type=secondary",
95 snprintf(coremask, sizeof(coremask), "%x", \
96 (1 << rte_get_main_lcore()));
98 ret |= launch_proc(argv1);
99 printf("### Testing rte_mp_disable() reject:\n");
100 if (rte_mp_disable()) {
101 printf("Error: rte_mp_disable() has been accepted\n");
104 printf("# Checked rte_mp_disable() is refused\n");
106 ret |= launch_proc(argv2);
108 ret |= !(launch_proc(argv3));
109 #ifdef RTE_EXEC_ENV_LINUX
110 ret |= !(launch_proc(argv4));
117 * This function is run in the secondary instance to test that creation of
118 * objects fails in a secondary
121 run_object_creation_tests(void)
123 const unsigned flags = 0;
124 const unsigned size = 1024;
125 const unsigned elt_size = 64;
126 const unsigned cache_size = 64;
127 const unsigned priv_data_size = 32;
129 printf("### Testing object creation - expect lots of mz reserve errors!\n");
132 if ((rte_memzone_reserve("test_mz", size, rte_socket_id(),
134 (rte_memzone_lookup("test_mz") == NULL)) {
135 printf("Error: unexpected return value from rte_memzone_reserve\n");
138 printf("# Checked rte_memzone_reserve() OK\n");
141 if ((rte_ring_create(
142 "test_ring", size, rte_socket_id(), flags) == NULL) &&
143 (rte_ring_lookup("test_ring") == NULL)){
144 printf("Error: unexpected return value from rte_ring_create()\n");
147 printf("# Checked rte_ring_create() OK\n");
150 if ((rte_mempool_create("test_mp", size, elt_size, cache_size,
151 priv_data_size, NULL, NULL, NULL, NULL,
152 rte_socket_id(), flags) == NULL) &&
153 (rte_mempool_lookup("test_mp") == NULL)){
154 printf("Error: unexpected return value from rte_mempool_create()\n");
157 printf("# Checked rte_mempool_create() OK\n");
160 const struct rte_hash_parameters hash_params = { .name = "test_mp_hash" };
162 if ((rte_hash_create(&hash_params) != NULL) &&
163 (rte_hash_find_existing(hash_params.name) == NULL)){
164 printf("Error: unexpected return value from rte_hash_create()\n");
167 printf("# Checked rte_hash_create() OK\n");
169 const struct rte_fbk_hash_params fbk_params = { .name = "test_fbk_mp_hash" };
171 if ((rte_fbk_hash_create(&fbk_params) != NULL) &&
172 (rte_fbk_hash_find_existing(fbk_params.name) == NULL)){
173 printf("Error: unexpected return value from rte_fbk_hash_create()\n");
176 printf("# Checked rte_fbk_hash_create() OK\n");
181 struct rte_lpm_config config;
183 config.max_rules = rte_socket_id();
184 config.number_tbl8s = 256;
186 if ((rte_lpm_create("test_lpm", size, &config) != NULL) &&
187 (rte_lpm_find_existing("test_lpm") == NULL)){
188 printf("Error: unexpected return value from rte_lpm_create()\n");
191 printf("# Checked rte_lpm_create() OK\n");
197 /* if called in a primary process, just spawns off a secondary process to
198 * run validation tests - which brings us right back here again...
199 * if called in a secondary process, this runs a series of API tests to check
200 * how things run in a secondary instance.
203 test_mp_secondary(void)
205 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
206 return run_secondary_instances();
209 printf("IN SECONDARY PROCESS\n");
211 return run_object_creation_tests();
214 REGISTER_TEST_COMMAND(multiprocess_autotest, test_mp_secondary);