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, RTE_DIM(ARGV), __func__)
53 * This function is called in the primary i.e. main test, to spawn off secondary
54 * processes to run actual mp tests. Uses fork() and exec pair
57 run_secondary_instances(void)
62 #ifdef RTE_EXEC_ENV_LINUX
63 char tmp[PATH_MAX] = {0};
64 char prefix[PATH_MAX] = {0};
66 get_current_prefix(tmp, sizeof(tmp));
68 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
70 const char *prefix = "";
73 /* good case, using secondary */
74 const char *argv1[] = {
75 prgname, "-c", coremask, "--proc-type=secondary",
78 /* good case, using auto */
79 const char *argv2[] = {
80 prgname, "-c", coremask, "--proc-type=auto",
83 /* bad case, using invalid type */
84 const char *argv3[] = {
85 prgname, "-c", coremask, "--proc-type=ERROR",
88 #ifdef RTE_EXEC_ENV_LINUX
89 /* bad case, using invalid file prefix */
90 const char *argv4[] = {
91 prgname, "-c", coremask, "--proc-type=secondary",
96 snprintf(coremask, sizeof(coremask), "%x", \
97 (1 << rte_get_master_lcore()));
99 ret |= launch_proc(argv1);
100 ret |= launch_proc(argv2);
102 ret |= !(launch_proc(argv3));
103 #ifdef RTE_EXEC_ENV_LINUX
104 ret |= !(launch_proc(argv4));
111 * This function is run in the secondary instance to test that creation of
112 * objects fails in a secondary
115 run_object_creation_tests(void)
117 const unsigned flags = 0;
118 const unsigned size = 1024;
119 const unsigned elt_size = 64;
120 const unsigned cache_size = 64;
121 const unsigned priv_data_size = 32;
123 printf("### Testing object creation - expect lots of mz reserve errors!\n");
126 if ((rte_memzone_reserve("test_mz", size, rte_socket_id(),
128 (rte_memzone_lookup("test_mz") == NULL)) {
129 printf("Error: unexpected return value from rte_memzone_reserve\n");
132 printf("# Checked rte_memzone_reserve() OK\n");
135 if ((rte_ring_create(
136 "test_ring", size, rte_socket_id(), flags) == NULL) &&
137 (rte_ring_lookup("test_ring") == NULL)){
138 printf("Error: unexpected return value from rte_ring_create()\n");
141 printf("# Checked rte_ring_create() OK\n");
144 if ((rte_mempool_create("test_mp", size, elt_size, cache_size,
145 priv_data_size, NULL, NULL, NULL, NULL,
146 rte_socket_id(), flags) == NULL) &&
147 (rte_mempool_lookup("test_mp") == NULL)){
148 printf("Error: unexpected return value from rte_mempool_create()\n");
151 printf("# Checked rte_mempool_create() OK\n");
153 #ifdef RTE_LIBRTE_HASH
154 const struct rte_hash_parameters hash_params = { .name = "test_mp_hash" };
156 if ((rte_hash_create(&hash_params) != NULL) &&
157 (rte_hash_find_existing(hash_params.name) == NULL)){
158 printf("Error: unexpected return value from rte_hash_create()\n");
161 printf("# Checked rte_hash_create() OK\n");
163 const struct rte_fbk_hash_params fbk_params = { .name = "test_fbk_mp_hash" };
165 if ((rte_fbk_hash_create(&fbk_params) != NULL) &&
166 (rte_fbk_hash_find_existing(fbk_params.name) == NULL)){
167 printf("Error: unexpected return value from rte_fbk_hash_create()\n");
170 printf("# Checked rte_fbk_hash_create() OK\n");
173 #ifdef RTE_LIBRTE_LPM
175 struct rte_lpm_config config;
177 config.max_rules = rte_socket_id();
178 config.number_tbl8s = 256;
180 if ((rte_lpm_create("test_lpm", size, &config) != NULL) &&
181 (rte_lpm_find_existing("test_lpm") == NULL)){
182 printf("Error: unexpected return value from rte_lpm_create()\n");
185 printf("# Checked rte_lpm_create() OK\n");
191 /* if called in a primary process, just spawns off a secondary process to
192 * run validation tests - which brings us right back here again...
193 * if called in a secondary process, this runs a series of API tests to check
194 * how things run in a secondary instance.
197 test_mp_secondary(void)
199 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
200 return run_secondary_instances();
203 printf("IN SECONDARY PROCESS\n");
205 return run_object_creation_tests();
208 REGISTER_TEST_COMMAND(multiprocess_autotest, test_mp_secondary);