bpf: allow self-xor operation
[dpdk.git] / app / test / test_trace.c
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_trace.h>
8
9 #include "test.h"
10 #include "test_trace.h"
11
12 static int32_t
13 test_trace_point_globbing(void)
14 {
15         int rc;
16
17         rc = rte_trace_pattern("app.dpdk.test*", false);
18         if (rc != 1)
19                 goto failed;
20
21         if (rte_trace_point_is_enabled(&__app_dpdk_test_tp))
22                 goto failed;
23
24         rc = rte_trace_pattern("app.dpdk.test*", true);
25         if (rc != 1)
26                 goto failed;
27
28         if (!rte_trace_point_is_enabled(&__app_dpdk_test_tp))
29                 goto failed;
30
31         rc = rte_trace_pattern("invalid_testpoint.*", true);
32         if (rc != 0)
33                 goto failed;
34
35         return TEST_SUCCESS;
36
37 failed:
38         return TEST_FAILED;
39 }
40
41 static int32_t
42 test_trace_point_regex(void)
43 {
44         int rc;
45
46         rc = rte_trace_regexp("app.dpdk.test*", false);
47         if (rc != 1)
48                 goto failed;
49
50         if (rte_trace_point_is_enabled(&__app_dpdk_test_tp))
51                 goto failed;
52
53         rc = rte_trace_regexp("app.dpdk.test*", true);
54         if (rc != 1)
55                 goto failed;
56
57         if (!rte_trace_point_is_enabled(&__app_dpdk_test_tp))
58                 goto failed;
59
60         rc = rte_trace_regexp("invalid_testpoint.*", true);
61         if (rc != 0)
62                 goto failed;
63
64         return TEST_SUCCESS;
65
66 failed:
67         return TEST_FAILED;
68 }
69
70 static int32_t
71 test_trace_point_disable_enable(void)
72 {
73         int rc;
74
75         rc = rte_trace_point_disable(&__app_dpdk_test_tp);
76         if (rc < 0)
77                 goto failed;
78
79         if (rte_trace_point_is_enabled(&__app_dpdk_test_tp))
80                 goto failed;
81
82         rc = rte_trace_point_enable(&__app_dpdk_test_tp);
83         if (rc < 0)
84                 goto failed;
85
86         if (!rte_trace_point_is_enabled(&__app_dpdk_test_tp))
87                 goto failed;
88
89         /* Emit the trace */
90         app_dpdk_test_tp("app.dpdk.test.tp");
91         return TEST_SUCCESS;
92
93 failed:
94         return TEST_FAILED;
95 }
96
97 static int
98 test_trace_mode(void)
99 {
100         enum rte_trace_mode current;
101
102         current = rte_trace_mode_get();
103
104         if (!rte_trace_is_enabled())
105                 return TEST_SKIPPED;
106
107         rte_trace_mode_set(RTE_TRACE_MODE_DISCARD);
108         if (rte_trace_mode_get() != RTE_TRACE_MODE_DISCARD)
109                 goto failed;
110
111         rte_trace_mode_set(RTE_TRACE_MODE_OVERWRITE);
112         if (rte_trace_mode_get() != RTE_TRACE_MODE_OVERWRITE)
113                 goto failed;
114
115         rte_trace_mode_set(current);
116         return TEST_SUCCESS;
117
118 failed:
119         return TEST_FAILED;
120
121 }
122
123 static int
124 test_trace_points_lookup(void)
125 {
126         rte_trace_point_t *trace;
127
128         trace =  rte_trace_point_lookup("app.dpdk.test.tp");
129         if (trace == NULL)
130                 goto fail;
131         trace = rte_trace_point_lookup("this_trace_point_does_not_exist");
132         if (trace != NULL)
133                 goto fail;
134
135         return TEST_SUCCESS;
136 fail:
137         return TEST_FAILED;
138 }
139
140 static int
141 test_fp_trace_points(void)
142 {
143         /* Emit the FP trace */
144         app_dpdk_test_fp();
145
146         return TEST_SUCCESS;
147 }
148
149 static int
150 test_generic_trace_points(void)
151 {
152         int tmp;
153
154         rte_eal_trace_generic_void();
155         rte_eal_trace_generic_u64(0x10000000000000);
156         rte_eal_trace_generic_u32(0x10000000);
157         rte_eal_trace_generic_u16(0xffee);
158         rte_eal_trace_generic_u8(0xc);
159         rte_eal_trace_generic_i64(-1234);
160         rte_eal_trace_generic_i32(-1234567);
161         rte_eal_trace_generic_i16(12);
162         rte_eal_trace_generic_i8(-3);
163         rte_eal_trace_generic_int(3333333);
164         rte_eal_trace_generic_long(333);
165         rte_eal_trace_generic_float(20.45);
166         rte_eal_trace_generic_double(20000.5000004);
167         rte_eal_trace_generic_ptr(&tmp);
168         rte_eal_trace_generic_str("my string");
169         rte_eal_trace_generic_size_t(sizeof(void *));
170         RTE_EAL_TRACE_GENERIC_FUNC;
171
172         return TEST_SUCCESS;
173 }
174
175 static struct unit_test_suite trace_tests = {
176         .suite_name = "trace autotest",
177         .setup = NULL,
178         .teardown = NULL,
179         .unit_test_cases = {
180                 TEST_CASE(test_trace_mode),
181                 TEST_CASE(test_generic_trace_points),
182                 TEST_CASE(test_fp_trace_points),
183                 TEST_CASE(test_trace_point_disable_enable),
184                 TEST_CASE(test_trace_point_globbing),
185                 TEST_CASE(test_trace_point_regex),
186                 TEST_CASE(test_trace_points_lookup),
187                 TEST_CASES_END()
188         }
189 };
190
191 static int
192 test_trace(void)
193 {
194         return unit_test_suite_runner(&trace_tests);
195 }
196
197 REGISTER_TEST_COMMAND(trace_autotest, test_trace);
198
199 static int
200 test_trace_dump(void)
201 {
202         rte_trace_dump(stdout);
203         return 0;
204 }
205
206 REGISTER_TEST_COMMAND(trace_dump, test_trace_dump);
207
208 static int
209 test_trace_metadata_dump(void)
210 {
211         return rte_trace_metadata_dump(stdout);
212 }
213
214 REGISTER_TEST_COMMAND(trace_metadata_dump, test_trace_metadata_dump);