Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : :
7 : : #include "test.h"
8 : :
9 : : #include <stdint.h>
10 : : #include <stdlib.h>
11 : : #include <stdarg.h>
12 : : #include <inttypes.h>
13 : : #include <sys/queue.h>
14 : : #include <errno.h>
15 : : #include <string.h>
16 : : #include <unistd.h>
17 : :
18 : : #ifdef RTE_EXEC_ENV_WINDOWS
19 : : int
20 : : test_mp_secondary(void)
21 : : {
22 : : printf("mp_secondary not supported on Windows, skipping test\n");
23 : : return TEST_SKIPPED;
24 : : }
25 : : #else
26 : :
27 : : #include <sys/wait.h>
28 : : #include <libgen.h>
29 : : #include <dirent.h>
30 : : #include <limits.h>
31 : :
32 : : #include <rte_common.h>
33 : : #include <rte_memory.h>
34 : : #include <rte_memzone.h>
35 : : #include <rte_eal.h>
36 : : #include <rte_launch.h>
37 : : #include <rte_per_lcore.h>
38 : : #include <rte_lcore.h>
39 : : #include <rte_errno.h>
40 : : #include <rte_branch_prediction.h>
41 : : #include <rte_ring.h>
42 : : #include <rte_debug.h>
43 : : #include <rte_log.h>
44 : : #include <rte_mempool.h>
45 : :
46 : : #ifdef RTE_LIB_HASH
47 : : #include <rte_hash.h>
48 : : #include <rte_fbk_hash.h>
49 : : #endif /* RTE_LIB_HASH */
50 : :
51 : : #ifdef RTE_LIB_LPM
52 : : #include <rte_lpm.h>
53 : : #endif /* RTE_LIB_LPM */
54 : :
55 : : #include <rte_string_fns.h>
56 : :
57 : : #include "process.h"
58 : :
59 : : #define launch_proc(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
60 : :
61 : : /*
62 : : * This function is called in the primary i.e. main test, to spawn off secondary
63 : : * processes to run actual mp tests. Uses fork() and exec pair
64 : : */
65 : : static int
66 : 1 : run_secondary_instances(void)
67 : : {
68 : : int ret = 0;
69 : : char core_str[10];
70 : : const char *prefix;
71 : :
72 : 1 : prefix = file_prefix_arg();
73 [ + - ]: 1 : if (prefix == NULL)
74 : : return -1;
75 : :
76 : : /* good case, using secondary */
77 : 1 : const char *argv1[] = {
78 : : prgname, "-l", core_str, "--proc-type=secondary",
79 : : prefix
80 : : };
81 : : /* good case, using auto */
82 : 1 : const char *argv2[] = {
83 : : prgname, "-l", core_str, "--proc-type=auto",
84 : : prefix
85 : : };
86 : : /* bad case, using invalid type */
87 : 1 : const char *argv3[] = {
88 : : prgname, "-l", core_str, "--proc-type=ERROR",
89 : : prefix
90 : : };
91 : : #ifdef RTE_EXEC_ENV_LINUX
92 : : /* bad case, using invalid file prefix */
93 : 1 : const char *argv4[] = {
94 : : prgname, "-l", core_str, "--proc-type=secondary",
95 : : "--file-prefix=ERROR"
96 : : };
97 : : #endif
98 : :
99 : 1 : snprintf(core_str, sizeof(core_str), "%u", rte_get_main_lcore());
100 : :
101 : 1 : ret |= launch_proc(argv1);
102 : : printf("### Testing rte_mp_disable() reject:\n");
103 [ - + ]: 1 : if (rte_mp_disable()) {
104 : : printf("Error: rte_mp_disable() has been accepted\n");
105 : : ret |= -1;
106 : : } else {
107 : : printf("# Checked rte_mp_disable() is refused\n");
108 : : }
109 : 1 : ret |= launch_proc(argv2);
110 : :
111 : 1 : ret |= !(launch_proc(argv3));
112 : : #ifdef RTE_EXEC_ENV_LINUX
113 : 1 : ret |= !(launch_proc(argv4));
114 : : #endif
115 : :
116 : 1 : return ret;
117 : : }
118 : :
119 : : /*
120 : : * This function is run in the secondary instance to test that creation of
121 : : * objects fails in a secondary
122 : : */
123 : : static int
124 : 2 : run_object_creation_tests(void)
125 : : {
126 : : const unsigned flags = 0;
127 : : const unsigned size = 1024;
128 : : const unsigned elt_size = 64;
129 : : const unsigned cache_size = 64;
130 : : const unsigned priv_data_size = 32;
131 : :
132 : : printf("### Testing object creation - expect lots of mz reserve errors!\n");
133 : :
134 : 2 : rte_errno = 0;
135 [ + + ]: 2 : if ((rte_memzone_reserve("test_mz", size, rte_socket_id(),
136 [ - + ]: 1 : flags) == NULL) &&
137 : 1 : (rte_memzone_lookup("test_mz") == NULL)) {
138 : : printf("Error: unexpected return value from rte_memzone_reserve\n");
139 : 0 : return -1;
140 : : }
141 : : printf("# Checked rte_memzone_reserve() OK\n");
142 : :
143 : 2 : rte_errno = 0;
144 [ + + ]: 2 : if ((rte_ring_create(
145 [ - + ]: 3 : "test_ring", size, rte_socket_id(), flags) == NULL) &&
146 : 1 : (rte_ring_lookup("test_ring") == NULL)){
147 : : printf("Error: unexpected return value from rte_ring_create()\n");
148 : 0 : return -1;
149 : : }
150 : : printf("# Checked rte_ring_create() OK\n");
151 : :
152 : 2 : rte_errno = 0;
153 [ + + ]: 2 : if ((rte_mempool_create("test_mp", size, elt_size, cache_size,
154 : : priv_data_size, NULL, NULL, NULL, NULL,
155 [ - + ]: 3 : rte_socket_id(), flags) == NULL) &&
156 : 1 : (rte_mempool_lookup("test_mp") == NULL)){
157 : : printf("Error: unexpected return value from rte_mempool_create()\n");
158 : 0 : return -1;
159 : : }
160 : : printf("# Checked rte_mempool_create() OK\n");
161 : :
162 : : #ifdef RTE_LIB_HASH
163 : 2 : const struct rte_hash_parameters hash_params = { .name = "test_mp_hash" };
164 : 2 : rte_errno=0;
165 [ - + - - ]: 2 : if ((rte_hash_create(&hash_params) != NULL) &&
166 : 0 : (rte_hash_find_existing(hash_params.name) == NULL)){
167 : : printf("Error: unexpected return value from rte_hash_create()\n");
168 : 0 : return -1;
169 : : }
170 : : printf("# Checked rte_hash_create() OK\n");
171 : :
172 : 2 : const struct rte_fbk_hash_params fbk_params = { .name = "test_fbk_mp_hash" };
173 : 2 : rte_errno=0;
174 [ - + - - ]: 2 : if ((rte_fbk_hash_create(&fbk_params) != NULL) &&
175 : 0 : (rte_fbk_hash_find_existing(fbk_params.name) == NULL)){
176 : : printf("Error: unexpected return value from rte_fbk_hash_create()\n");
177 : 0 : return -1;
178 : : }
179 : : printf("# Checked rte_fbk_hash_create() OK\n");
180 : : #endif
181 : :
182 : : #ifdef RTE_LIB_LPM
183 : 2 : rte_errno=0;
184 : : struct rte_lpm_config config;
185 : :
186 : 2 : config.max_rules = rte_socket_id();
187 : 2 : config.number_tbl8s = 256;
188 : 2 : config.flags = 0;
189 [ - + - - ]: 2 : if ((rte_lpm_create("test_lpm", size, &config) != NULL) &&
190 : 0 : (rte_lpm_find_existing("test_lpm") == NULL)){
191 : : printf("Error: unexpected return value from rte_lpm_create()\n");
192 : 0 : return -1;
193 : : }
194 : : printf("# Checked rte_lpm_create() OK\n");
195 : : #endif
196 : :
197 : 2 : return 0;
198 : : }
199 : :
200 : : /* if called in a primary process, just spawns off a secondary process to
201 : : * run validation tests - which brings us right back here again...
202 : : * if called in a secondary process, this runs a series of API tests to check
203 : : * how things run in a secondary instance.
204 : : */
205 : : int
206 : 3 : test_mp_secondary(void)
207 : : {
208 [ + + ]: 3 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
209 : 1 : return run_secondary_instances();
210 : : }
211 : :
212 : : printf("IN SECONDARY PROCESS\n");
213 : :
214 : 2 : return run_object_creation_tests();
215 : : }
216 : :
217 : : #endif /* !RTE_EXEC_ENV_WINDOWS */
218 : :
219 : 276 : REGISTER_FAST_TEST(multiprocess_autotest, NOHUGE_SKIP, ASAN_SKIP, test_mp_secondary);
|