4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #ifndef RTE_EXEC_ENV_BAREMETAL
43 #include <sys/queue.h>
56 #include <rte_common.h>
57 #include <rte_memory.h>
58 #include <rte_memzone.h>
59 #include <rte_tailq.h>
61 #include <rte_launch.h>
62 #include <rte_per_lcore.h>
63 #include <rte_lcore.h>
64 #include <rte_errno.h>
65 #include <rte_branch_prediction.h>
66 #include <rte_atomic.h>
68 #include <rte_debug.h>
70 #include <rte_mempool.h>
72 #ifdef RTE_LIBRTE_HASH
74 #include <rte_fbk_hash.h>
75 #endif /* RTE_LIBRTE_HASH */
79 #endif /* RTE_LIBRTE_LPM */
81 #include <rte_string_fns.h>
85 #define launch_proc(ARGV) process_dup(ARGV, \
86 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
89 get_current_prefix(char * prefix, int size)
91 char path[PATH_MAX] = {0};
92 char buf[PATH_MAX] = {0};
94 /* get file for config (fd is always 3) */
95 snprintf(path, sizeof(path), "/proc/self/fd/%d", 3);
97 /* return NULL on error */
98 if (readlink(path, buf, sizeof(buf)) == -1)
101 /* get the basename */
102 snprintf(buf, sizeof(buf), "%s", basename(buf));
104 /* copy string all the way from second char up to start of _config */
105 snprintf(prefix, size, "%.*s",
106 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")),
113 * This function is called in the primary i.e. main test, to spawn off secondary
114 * processes to run actual mp tests. Uses fork() and exec pair
117 run_secondary_instances(void)
122 char tmp[PATH_MAX] = {0};
123 char prefix[PATH_MAX] = {0};
125 get_current_prefix(tmp, sizeof(tmp));
127 snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
129 /* good case, using secondary */
130 const char *argv1[] = {
131 prgname, "-c", coremask, "--proc-type=secondary",
134 /* good case, using auto */
135 const char *argv2[] = {
136 prgname, "-c", coremask, "--proc-type=auto",
139 /* bad case, using invalid type */
140 const char *argv3[] = {
141 prgname, "-c", coremask, "--proc-type=ERROR",
144 /* bad case, using invalid file prefix */
145 const char *argv4[] = {
146 prgname, "-c", coremask, "--proc-type=secondary",
147 "--file-prefix=ERROR"
150 snprintf(coremask, sizeof(coremask), "%x", \
151 (1 << rte_get_master_lcore()));
153 ret |= launch_proc(argv1);
154 ret |= launch_proc(argv2);
156 ret |= !(launch_proc(argv3));
157 ret |= !(launch_proc(argv4));
163 * This function is run in the secondary instance to test that creation of
164 * objects fails in a secondary
167 run_object_creation_tests(void)
169 const unsigned flags = 0;
170 const unsigned size = 1024;
171 const unsigned elt_size = 64;
172 const unsigned cache_size = 64;
173 const unsigned priv_data_size = 32;
175 printf("### Testing object creation - expect lots of mz reserve errors!\n");
178 if ((rte_memzone_reserve("test_mz", size, rte_socket_id(),
180 (rte_memzone_lookup("test_mz") == NULL)) {
181 printf("Error: unexpected return value from rte_memzone_reserve\n");
184 printf("# Checked rte_memzone_reserve() OK\n");
187 if ((rte_ring_create(
188 "test_ring", size, rte_socket_id(), flags) == NULL) &&
189 (rte_ring_lookup("test_ring") == NULL)){
190 printf("Error: unexpected return value from rte_ring_create()\n");
193 printf("# Checked rte_ring_create() OK\n");
196 if ((rte_mempool_create("test_mp", size, elt_size, cache_size,
197 priv_data_size, NULL, NULL, NULL, NULL,
198 rte_socket_id(), flags) == NULL) &&
199 (rte_mempool_lookup("test_mp") == NULL)){
200 printf("Error: unexpected return value from rte_mempool_create()\n");
203 printf("# Checked rte_mempool_create() OK\n");
205 #ifdef RTE_LIBRTE_HASH
206 const struct rte_hash_parameters hash_params = { .name = "test_mp_hash" };
208 if ((rte_hash_create(&hash_params) != NULL) &&
209 (rte_hash_find_existing(hash_params.name) == NULL)){
210 printf("Error: unexpected return value from rte_hash_create()\n");
213 printf("# Checked rte_hash_create() OK\n");
215 const struct rte_fbk_hash_params fbk_params = { .name = "test_fbk_mp_hash" };
217 if ((rte_fbk_hash_create(&fbk_params) != NULL) &&
218 (rte_fbk_hash_find_existing(fbk_params.name) == NULL)){
219 printf("Error: unexpected return value from rte_fbk_hash_create()\n");
222 printf("# Checked rte_fbk_hash_create() OK\n");
225 #ifdef RTE_LIBRTE_LPM
227 if ((rte_lpm_create("test_lpm", size, rte_socket_id(), 0) != NULL) &&
228 (rte_lpm_find_existing("test_lpm") == NULL)){
229 printf("Error: unexpected return value from rte_lpm_create()\n");
232 printf("# Checked rte_lpm_create() OK\n");
235 /* Run a test_pci call */
236 if (test_pci() != 0) {
237 printf("PCI scan failed in secondary\n");
238 if (getuid() == 0) /* pci scans can fail as non-root */
241 printf("PCI scan succeeded in secondary\n");
246 /* if called in a primary process, just spawns off a secondary process to
247 * run validation tests - which brings us right back here again...
248 * if called in a secondary process, this runs a series of API tests to check
249 * how things run in a secondary instance.
252 test_mp_secondary(void)
254 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
256 printf("=== Running pre-requisite test of test_pci\n");
258 printf("=== Requisite test done\n");
260 return run_secondary_instances();
263 printf("IN SECONDARY PROCESS\n");
265 return run_object_creation_tests();
271 * Multiprocess not applicable, so just return 0 always
274 test_mp_secondary(void)
276 printf("Multi-process not applicable for baremetal\n");