4 * Copyright(c) 2010-2012 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.
37 #include <cmdline_parse.h>
41 #ifndef RTE_EXEC_ENV_BAREMETAL
46 #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>
71 #include <rte_mempool.h>
73 #include <rte_fbk_hash.h>
75 #include <rte_string_fns.h>
79 #define launch_proc(ARGV) process_dup(ARGV, \
80 sizeof(ARGV)/(sizeof(ARGV[0])), __func__)
83 * This function is called in the primary i.e. main test, to spawn off secondary
84 * processes to run actual mp tests. Uses fork() and exec pair
87 run_secondary_instances(void)
92 /* good case, using secondary */
93 const char *argv1[] = {
94 prgname, "-c", coremask, "--proc-type=secondary"
96 /* good case, using auto */
97 const char *argv2[] = {
98 prgname, "-c", coremask, "--proc-type=auto"
100 /* bad case, using invalid type */
101 const char *argv3[] = {
102 prgname, "-c", coremask, "--proc-type=ERROR"
104 /* bad case, using invalid file prefix */
105 const char *argv4[] = {
106 prgname, "-c", coremask, "--proc-type=secondary",
107 "--file-prefix=ERROR"
110 rte_snprintf(coremask, sizeof(coremask), "%x", \
111 (1 << rte_get_master_lcore()));
113 ret |= launch_proc(argv1);
114 ret |= launch_proc(argv2);
116 ret |= !(launch_proc(argv3));
117 ret |= !(launch_proc(argv4));
123 * This function is run in the secondary instance to test that creation of
124 * objects fails in a secondary
127 run_object_creation_tests(void)
129 const unsigned flags = 0;
130 const unsigned size = 1024;
131 const unsigned elt_size = 64;
132 const unsigned cache_size = 64;
133 const unsigned priv_data_size = 32;
135 printf("### Testing object creation - expect lots of mz reserve errors!\n");
138 if (rte_memzone_reserve("test_mz", size, rte_socket_id(), flags) != NULL
139 || rte_errno != E_RTE_SECONDARY){
140 printf("Error: unexpected return value from rte_memzone_reserve\n");
143 printf("# Checked rte_memzone_reserve() OK\n");
146 if (rte_ring_create("test_rng", size, rte_socket_id(), flags) != NULL
147 || rte_errno != E_RTE_SECONDARY){
148 printf("Error: unexpected return value from rte_ring_create()\n");
151 printf("# Checked rte_ring_create() OK\n");
155 if (rte_mempool_create("test_mp", size, elt_size, cache_size,
156 priv_data_size, NULL, NULL, NULL, NULL,
157 rte_socket_id(), flags) != NULL
158 || rte_errno != E_RTE_SECONDARY){
159 printf("Error: unexpected return value from rte_ring_create()\n");
162 printf("# Checked rte_mempool_create() OK\n");
164 const struct rte_hash_parameters hash_params = { .name = "test_mp_hash" };
166 if (rte_hash_create(&hash_params) != NULL
167 || rte_errno != E_RTE_SECONDARY){
168 printf("Error: unexpected return value from rte_ring_create()\n");
171 printf("# Checked rte_hash_create() OK\n");
173 const struct rte_fbk_hash_params fbk_params = { .name = "test_mp_hash" };
175 if (rte_fbk_hash_create(&fbk_params) != NULL
176 || rte_errno != E_RTE_SECONDARY){
177 printf("Error: unexpected return value from rte_ring_create()\n");
180 printf("# Checked rte_fbk_hash_create() OK\n");
183 if (rte_lpm_create("test_lpm", size, rte_socket_id(), RTE_LPM_HEAP) != NULL
184 || rte_errno != E_RTE_SECONDARY){
185 printf("Error: unexpected return value from rte_ring_create()\n");
188 printf("# Checked rte_lpm_create() OK\n");
190 /* Run a test_pci call */
191 if (test_pci() != 0) {
192 printf("PCI scan failed in secondary\n");
193 if (getuid() == 0) /* pci scans can fail as non-root */
196 printf("PCI scan succeeded in secondary\n");
201 /* if called in a primary process, just spawns off a secondary process to
202 * run validation tests - which brings us right back here again...
203 * if called in a secondary process, this runs a series of API tests to check
204 * how things run in a secondary instance.
207 test_mp_secondary(void)
209 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
211 printf("=== Running pre-requisite test of test_pci\n");
213 printf("=== Requisite test done\n");
215 return run_secondary_instances();
218 printf("IN SECONDARY PROCESS\n");
220 return run_object_creation_tests();
226 * Multiprocess not applicable, so just return 0 always
229 test_mp_secondary(void)
231 printf("Multi-process not applicable for baremetal\n");