Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2020 Marvell International Ltd.
3 : : */
4 : :
5 : : #include <rte_eal_trace.h>
6 : : #include <rte_lcore.h>
7 : : #include <rte_random.h>
8 : : #include <rte_trace.h>
9 : :
10 : : #include "test.h"
11 : : #include "test_trace.h"
12 : :
13 : : int app_dpdk_test_tp_count;
14 : :
15 : : #ifdef RTE_EXEC_ENV_WINDOWS
16 : :
17 : : static int
18 : : test_trace(void)
19 : : {
20 : : printf("trace not supported on Windows, skipping test\n");
21 : : return TEST_SKIPPED;
22 : : }
23 : :
24 : : #else
25 : :
26 : : static int32_t
27 : 2 : test_trace_point_globbing(void)
28 : : {
29 : : int rc;
30 : :
31 : 2 : rc = rte_trace_pattern("app.dpdk.test*", false);
32 [ - + ]: 2 : if (rc != 1)
33 : 0 : goto failed;
34 : :
35 [ - + ]: 2 : if (rte_trace_point_is_enabled(&__app_dpdk_test_tp))
36 : 0 : goto failed;
37 : :
38 : 2 : rc = rte_trace_pattern("app.dpdk.test*", true);
39 [ - + ]: 2 : if (rc != 1)
40 : 0 : goto failed;
41 : :
42 [ - + ]: 2 : if (!rte_trace_point_is_enabled(&__app_dpdk_test_tp))
43 : 0 : goto failed;
44 : :
45 : 2 : rc = rte_trace_pattern("invalid_testpoint.*", true);
46 [ - + ]: 2 : if (rc != 0)
47 : 0 : goto failed;
48 : :
49 : : return TEST_SUCCESS;
50 : :
51 : : failed:
52 : : return TEST_FAILED;
53 : : }
54 : :
55 : : static int32_t
56 : 2 : test_trace_point_regex(void)
57 : : {
58 : : int rc;
59 : :
60 : 2 : rc = rte_trace_regexp("app.dpdk.test*", false);
61 [ - + ]: 2 : if (rc != 1)
62 : 0 : goto failed;
63 : :
64 [ - + ]: 2 : if (rte_trace_point_is_enabled(&__app_dpdk_test_tp))
65 : 0 : goto failed;
66 : :
67 : 2 : rc = rte_trace_regexp("app.dpdk.test*", true);
68 [ - + ]: 2 : if (rc != 1)
69 : 0 : goto failed;
70 : :
71 [ - + ]: 2 : if (!rte_trace_point_is_enabled(&__app_dpdk_test_tp))
72 : 0 : goto failed;
73 : :
74 : 2 : rc = rte_trace_regexp("invalid_testpoint.*", true);
75 [ - + ]: 2 : if (rc != 0)
76 : 0 : goto failed;
77 : :
78 : : return TEST_SUCCESS;
79 : :
80 : : failed:
81 : : return TEST_FAILED;
82 : : }
83 : :
84 : : static int32_t
85 : 2 : test_trace_point_disable_enable(void)
86 : : {
87 : : int expected;
88 : : int rc;
89 : :
90 : : /* At tp registration, the associated counter increases once. */
91 : : expected = 1;
92 [ - + ]: 2 : TEST_ASSERT_EQUAL(app_dpdk_test_tp_count, expected,
93 : : "Expecting %d, but got %d for app_dpdk_test_tp_count",
94 : : expected, app_dpdk_test_tp_count);
95 : :
96 : 2 : rc = rte_trace_point_disable(&__app_dpdk_test_tp);
97 [ - + ]: 2 : if (rc < 0)
98 : 0 : goto failed;
99 : :
100 [ - + ]: 2 : if (rte_trace_point_is_enabled(&__app_dpdk_test_tp))
101 : 0 : goto failed;
102 : :
103 : : /* No emission expected */
104 : : app_dpdk_test_tp("app.dpdk.test.tp");
105 [ - + ]: 2 : TEST_ASSERT_EQUAL(app_dpdk_test_tp_count, expected,
106 : : "Expecting %d, but got %d for app_dpdk_test_tp_count",
107 : : expected, app_dpdk_test_tp_count);
108 : :
109 : 2 : rc = rte_trace_point_enable(&__app_dpdk_test_tp);
110 [ - + ]: 2 : if (rc < 0)
111 : 0 : goto failed;
112 : :
113 [ - + ]: 2 : if (!rte_trace_point_is_enabled(&__app_dpdk_test_tp))
114 : 0 : goto failed;
115 : :
116 : : /* Emit the trace */
117 : : app_dpdk_test_tp("app.dpdk.test.tp");
118 : : expected++;
119 [ - + ]: 2 : TEST_ASSERT_EQUAL(app_dpdk_test_tp_count, expected,
120 : : "Expecting %d, but got %d for app_dpdk_test_tp_count",
121 : : expected, app_dpdk_test_tp_count);
122 : :
123 : : return TEST_SUCCESS;
124 : :
125 : : failed:
126 : : return TEST_FAILED;
127 : : }
128 : :
129 : : static int
130 : 2 : test_trace_mode(void)
131 : : {
132 : : enum rte_trace_mode current;
133 : :
134 : 2 : current = rte_trace_mode_get();
135 : :
136 : 2 : rte_trace_mode_set(RTE_TRACE_MODE_DISCARD);
137 [ - + ]: 2 : if (rte_trace_mode_get() != RTE_TRACE_MODE_DISCARD)
138 : 0 : goto failed;
139 : :
140 : 2 : rte_trace_mode_set(RTE_TRACE_MODE_OVERWRITE);
141 [ - + ]: 2 : if (rte_trace_mode_get() != RTE_TRACE_MODE_OVERWRITE)
142 : 0 : goto failed;
143 : :
144 : 2 : rte_trace_mode_set(current);
145 : 2 : return TEST_SUCCESS;
146 : :
147 : : failed:
148 : : return TEST_FAILED;
149 : :
150 : : }
151 : :
152 : : static int
153 : 2 : test_trace_points_lookup(void)
154 : : {
155 : : rte_trace_point_t *trace;
156 : :
157 : 2 : trace = rte_trace_point_lookup("app.dpdk.test.tp");
158 [ - + ]: 2 : if (trace == NULL)
159 : 0 : goto fail;
160 : 2 : trace = rte_trace_point_lookup("this_trace_point_does_not_exist");
161 [ - + ]: 2 : if (trace != NULL)
162 : 0 : goto fail;
163 : :
164 : : return TEST_SUCCESS;
165 : : fail:
166 : : return TEST_FAILED;
167 : : }
168 : :
169 : : static int
170 : 2 : test_fp_trace_points(void)
171 : : {
172 : : /* Emit the FP trace */
173 : : app_dpdk_test_fp();
174 : :
175 : 2 : return TEST_SUCCESS;
176 : : }
177 : :
178 : : static int
179 : 2 : test_generic_trace_points(void)
180 : : {
181 : : uint8_t arr[RTE_TRACE_BLOB_LEN_MAX];
182 : : int tmp;
183 : : int i;
184 : :
185 [ + + ]: 130 : for (i = 0; i < RTE_TRACE_BLOB_LEN_MAX; i++)
186 : 128 : arr[i] = i;
187 : :
188 : : rte_eal_trace_generic_void();
189 [ + + ]: 2 : rte_eal_trace_generic_u64(0x10000000000000);
190 [ + + ]: 2 : rte_eal_trace_generic_u32(0x10000000);
191 [ + + ]: 2 : rte_eal_trace_generic_u16(0xffee);
192 [ + + ]: 2 : rte_eal_trace_generic_u8(0xc);
193 [ + + ]: 2 : rte_eal_trace_generic_i64(-1234);
194 [ + + ]: 2 : rte_eal_trace_generic_i32(-1234567);
195 [ + + ]: 2 : rte_eal_trace_generic_i16(12);
196 [ + + ]: 2 : rte_eal_trace_generic_i8(-3);
197 [ + + ]: 2 : rte_eal_trace_generic_int(3333333);
198 [ + + ]: 2 : rte_eal_trace_generic_long(333);
199 [ + + ]: 2 : rte_eal_trace_generic_float(20.45);
200 [ + + ]: 2 : rte_eal_trace_generic_double(20000.5000004);
201 [ + + ]: 2 : rte_eal_trace_generic_ptr(&tmp);
202 : : rte_eal_trace_generic_str("my string");
203 [ + + ]: 2 : rte_eal_trace_generic_size_t(sizeof(void *));
204 [ + + ]: 2 : rte_eal_trace_generic_blob(arr, 0);
205 [ + + ]: 2 : rte_eal_trace_generic_blob(arr, 17);
206 : 2 : rte_eal_trace_generic_blob(arr, RTE_TRACE_BLOB_LEN_MAX);
207 [ + + + + ]: 3 : rte_eal_trace_generic_blob(arr, rte_rand() %
208 : : RTE_TRACE_BLOB_LEN_MAX);
209 : : RTE_EAL_TRACE_GENERIC_FUNC;
210 : :
211 : 2 : return TEST_SUCCESS;
212 : : }
213 : :
214 : : static int
215 : 2 : test_trace_dump(void)
216 : : {
217 : 2 : rte_trace_dump(stdout);
218 : 2 : return 0;
219 : : }
220 : :
221 : : static int
222 : 2 : test_trace_metadata_dump(void)
223 : : {
224 : 2 : return rte_trace_metadata_dump(stdout);
225 : : }
226 : :
227 : : static struct unit_test_suite trace_tests = {
228 : : .suite_name = "trace autotest",
229 : : .setup = NULL,
230 : : .teardown = NULL,
231 : : .unit_test_cases = {
232 : : TEST_CASE(test_trace_mode),
233 : : TEST_CASE(test_generic_trace_points),
234 : : TEST_CASE(test_fp_trace_points),
235 : : TEST_CASE(test_trace_point_disable_enable),
236 : : TEST_CASE(test_trace_point_globbing),
237 : : TEST_CASE(test_trace_point_regex),
238 : : TEST_CASE(test_trace_points_lookup),
239 : : TEST_CASE(test_trace_dump),
240 : : TEST_CASE(test_trace_metadata_dump),
241 : : TEST_CASES_END()
242 : : }
243 : : };
244 : :
245 : : static int
246 : 2 : test_trace(void)
247 : : {
248 : : if (!rte_trace_feature_is_enabled()) {
249 : : printf("Trace omitted at build-time, skipping test\n");
250 : : return TEST_SKIPPED;
251 : : }
252 : 2 : return unit_test_suite_runner(&trace_tests);
253 : : }
254 : :
255 : : #endif /* !RTE_EXEC_ENV_WINDOWS */
256 : :
257 : 252 : REGISTER_FAST_TEST(trace_autotest, true, true, test_trace);
|