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