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>
31 #include <rte_atomic.h>
33 #include <rte_debug.h>
35 #include <rte_mempool.h>
37 #ifdef RTE_LIBRTE_HASH
39 #include <rte_fbk_hash.h>
40 #endif /* RTE_LIBRTE_HASH */
44 #endif /* RTE_LIBRTE_LPM */
46 #include <rte_string_fns.h>
50 #define launch_proc(ARGV) process_dup(ARGV, \
51 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
53 #ifdef RTE_EXEC_ENV_LINUXAPP
55 get_current_prefix(char * prefix, int size)
57 char path[PATH_MAX] = {0};
58 char buf[PATH_MAX] = {0};
60 /* get file for config (fd is always 3) */
61 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
63 /* return NULL on error */
64 if (readlink(path, buf, sizeof(buf)) == -1)
67 /* get the basename */
68 snprintf(buf, sizeof(buf), "%s", basename(buf));
70 /* copy string all the way from second char up to start of _config */
71 snprintf(prefix, size, "%.*s",
72 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
80 * This function is called in the primary i.e. main test, to spawn off secondary
81 * processes to run actual mp tests. Uses fork() and exec pair
84 run_secondary_instances(void)
89 #ifdef RTE_EXEC_ENV_LINUXAPP
90 char tmp[PATH_MAX] = {0};
91 char prefix[PATH_MAX] = {0};
93 get_current_prefix(tmp, sizeof(tmp));
95 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
97 const char *prefix = "";
100 /* good case, using secondary */
101 const char *argv1[] = {
102 prgname, "-c", coremask, "--proc-type=secondary",
105 /* good case, using auto */
106 const char *argv2[] = {
107 prgname, "-c", coremask, "--proc-type=auto",
110 /* bad case, using invalid type */
111 const char *argv3[] = {
112 prgname, "-c", coremask, "--proc-type=ERROR",
115 #ifdef RTE_EXEC_ENV_LINUXAPP
116 /* bad case, using invalid file prefix */
117 const char *argv4[] = {
118 prgname, "-c", coremask, "--proc-type=secondary",
119 "--file-prefix=ERROR"
123 snprintf(coremask, sizeof(coremask), "%x", \
124 (1 << rte_get_master_lcore()));
126 ret |= launch_proc(argv1);
127 ret |= launch_proc(argv2);
129 ret |= !(launch_proc(argv3));
130 #ifdef RTE_EXEC_ENV_LINUXAPP
131 ret |= !(launch_proc(argv4));
138 * This function is run in the secondary instance to test that creation of
139 * objects fails in a secondary
142 run_object_creation_tests(void)
144 const unsigned flags = 0;
145 const unsigned size = 1024;
146 const unsigned elt_size = 64;
147 const unsigned cache_size = 64;
148 const unsigned priv_data_size = 32;
150 printf("### Testing object creation - expect lots of mz reserve errors!\n");
153 if ((rte_memzone_reserve("test_mz", size, rte_socket_id(),
155 (rte_memzone_lookup("test_mz") == NULL)) {
156 printf("Error: unexpected return value from rte_memzone_reserve\n");
159 printf("# Checked rte_memzone_reserve() OK\n");
162 if ((rte_ring_create(
163 "test_ring", size, rte_socket_id(), flags) == NULL) &&
164 (rte_ring_lookup("test_ring") == NULL)){
165 printf("Error: unexpected return value from rte_ring_create()\n");
168 printf("# Checked rte_ring_create() OK\n");
171 if ((rte_mempool_create("test_mp", size, elt_size, cache_size,
172 priv_data_size, NULL, NULL, NULL, NULL,
173 rte_socket_id(), flags) == NULL) &&
174 (rte_mempool_lookup("test_mp") == NULL)){
175 printf("Error: unexpected return value from rte_mempool_create()\n");
178 printf("# Checked rte_mempool_create() OK\n");
180 #ifdef RTE_LIBRTE_HASH
181 const struct rte_hash_parameters hash_params = { .name = "test_mp_hash" };
183 if ((rte_hash_create(&hash_params) != NULL) &&
184 (rte_hash_find_existing(hash_params.name) == NULL)){
185 printf("Error: unexpected return value from rte_hash_create()\n");
188 printf("# Checked rte_hash_create() OK\n");
190 const struct rte_fbk_hash_params fbk_params = { .name = "test_fbk_mp_hash" };
192 if ((rte_fbk_hash_create(&fbk_params) != NULL) &&
193 (rte_fbk_hash_find_existing(fbk_params.name) == NULL)){
194 printf("Error: unexpected return value from rte_fbk_hash_create()\n");
197 printf("# Checked rte_fbk_hash_create() OK\n");
200 #ifdef RTE_LIBRTE_LPM
202 struct rte_lpm_config config;
204 config.max_rules = rte_socket_id();
205 config.number_tbl8s = 256;
207 if ((rte_lpm_create("test_lpm", size, &config) != NULL) &&
208 (rte_lpm_find_existing("test_lpm") == NULL)){
209 printf("Error: unexpected return value from rte_lpm_create()\n");
212 printf("# Checked rte_lpm_create() OK\n");
218 /* if called in a primary process, just spawns off a secondary process to
219 * run validation tests - which brings us right back here again...
220 * if called in a secondary process, this runs a series of API tests to check
221 * how things run in a secondary instance.
224 test_mp_secondary(void)
226 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
227 return run_secondary_instances();
230 printf("IN SECONDARY PROCESS\n");
232 return run_object_creation_tests();
235 REGISTER_TEST_COMMAND(multiprocess_autotest, test_mp_secondary);