1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <rte_cycles.h>
14 #include <rte_meter.h>
16 #define mlog(format, ...) do{\
17 printf("Line %d:",__LINE__);\
18 printf(format, ##__VA_ARGS__);\
22 #define melog(format, ...) do{\
23 printf("Line %d:",__LINE__);\
24 printf(format, ##__VA_ARGS__);\
25 printf(" failed!\n");\
29 #define TM_TEST_SRTCM_CIR_DF 46000000
30 #define TM_TEST_SRTCM_CBS_DF 2048
31 #define TM_TEST_SRTCM_EBS_DF 4096
33 #define TM_TEST_TRTCM_CIR_DF 46000000
34 #define TM_TEST_TRTCM_PIR_DF 69000000
35 #define TM_TEST_TRTCM_CBS_DF 2048
36 #define TM_TEST_TRTCM_PBS_DF 4096
38 static struct rte_meter_srtcm_params sparams
=
39 {.cir
= TM_TEST_SRTCM_CIR_DF
,
40 .cbs
= TM_TEST_SRTCM_CBS_DF
,
41 .ebs
= TM_TEST_SRTCM_EBS_DF
,};
43 static struct rte_meter_trtcm_params tparams
=
44 {.cir
= TM_TEST_TRTCM_CIR_DF
,
45 .pir
= TM_TEST_TRTCM_PIR_DF
,
46 .cbs
= TM_TEST_TRTCM_CBS_DF
,
47 .pbs
= TM_TEST_TRTCM_PBS_DF
,};
50 * functional test for rte_meter_srtcm_config
53 tm_test_srtcm_config(void)
55 #define SRTCM_CFG_MSG "srtcm_config"
56 struct rte_meter_srtcm_profile sp
;
57 struct rte_meter_srtcm_params sparams1
;
59 /* invalid parameter test */
60 if (rte_meter_srtcm_profile_config(NULL
, NULL
) == 0)
62 if (rte_meter_srtcm_profile_config(&sp
, NULL
) == 0)
64 if (rte_meter_srtcm_profile_config(NULL
, &sparams
) == 0)
67 /* cbs and ebs can't both be zero */
71 if (rte_meter_srtcm_profile_config(&sp
, &sparams1
) == 0)
74 /* cir should never be 0 */
77 if (rte_meter_srtcm_profile_config(&sp
, &sparams1
) == 0)
80 /* one of ebs and cbs can be zero, should be successful */
83 if (rte_meter_srtcm_profile_config(&sp
, &sparams1
) != 0)
88 if (rte_meter_srtcm_profile_config(&sp
, &sparams1
) != 0)
91 /* usual parameter, should be successful */
92 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
100 * functional test for rte_meter_trtcm_config
103 tm_test_trtcm_config(void)
105 struct rte_meter_trtcm_profile tp
;
106 struct rte_meter_trtcm_params tparams1
;
107 #define TRTCM_CFG_MSG "trtcm_config"
109 /* invalid parameter test */
110 if (rte_meter_trtcm_profile_config(NULL
, NULL
) == 0)
111 melog(TRTCM_CFG_MSG
);
112 if (rte_meter_trtcm_profile_config(&tp
, NULL
) == 0)
113 melog(TRTCM_CFG_MSG
);
114 if (rte_meter_trtcm_profile_config(NULL
, &tparams
) == 0)
115 melog(TRTCM_CFG_MSG
);
117 /* cir, cbs, pir and pbs never be zero */
120 if (rte_meter_trtcm_profile_config(&tp
, &tparams1
) == 0)
121 melog(TRTCM_CFG_MSG
);
125 if (rte_meter_trtcm_profile_config(&tp
, &tparams1
) == 0)
126 melog(TRTCM_CFG_MSG
);
130 if (rte_meter_trtcm_profile_config(&tp
, &tparams1
) == 0)
131 melog(TRTCM_CFG_MSG
);
135 if (rte_meter_trtcm_profile_config(&tp
, &tparams1
) == 0)
136 melog(TRTCM_CFG_MSG
);
138 /* pir should be greater or equal to cir */
140 tparams1
.pir
= tparams1
.cir
- 1;
141 if (rte_meter_trtcm_profile_config(&tp
, &tparams1
) == 0)
142 melog(TRTCM_CFG_MSG
" pir < cir test");
144 /* usual parameter, should be successful */
145 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
146 melog(TRTCM_CFG_MSG
);
152 * functional test for rte_meter_srtcm_color_blind_check
155 tm_test_srtcm_color_blind_check(void)
157 #define SRTCM_BLIND_CHECK_MSG "srtcm_blind_check"
158 struct rte_meter_srtcm_profile sp
;
159 struct rte_meter_srtcm sm
;
161 uint64_t hz
= rte_get_tsc_hz();
164 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
165 melog(SRTCM_BLIND_CHECK_MSG
);
166 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
167 melog(SRTCM_BLIND_CHECK_MSG
);
168 time
= rte_get_tsc_cycles() + hz
;
169 if (rte_meter_srtcm_color_blind_check(
170 &sm
, &sp
, time
, TM_TEST_SRTCM_CBS_DF
- 1)
171 != e_RTE_METER_GREEN
)
172 melog(SRTCM_BLIND_CHECK_MSG
" GREEN");
175 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
176 melog(SRTCM_BLIND_CHECK_MSG
);
177 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
178 melog(SRTCM_BLIND_CHECK_MSG
);
179 time
= rte_get_tsc_cycles() + hz
;
180 if (rte_meter_srtcm_color_blind_check(
181 &sm
, &sp
, time
, TM_TEST_SRTCM_CBS_DF
+ 1)
182 != e_RTE_METER_YELLOW
)
183 melog(SRTCM_BLIND_CHECK_MSG
" YELLOW");
185 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
186 melog(SRTCM_BLIND_CHECK_MSG
);
187 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
188 melog(SRTCM_BLIND_CHECK_MSG
);
189 time
= rte_get_tsc_cycles() + hz
;
190 if (rte_meter_srtcm_color_blind_check(
191 &sm
, &sp
, time
, (uint32_t)sp
.ebs
- 1) != e_RTE_METER_YELLOW
)
192 melog(SRTCM_BLIND_CHECK_MSG
" YELLOW");
195 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
196 melog(SRTCM_BLIND_CHECK_MSG
);
197 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
198 melog(SRTCM_BLIND_CHECK_MSG
);
199 time
= rte_get_tsc_cycles() + hz
;
200 if (rte_meter_srtcm_color_blind_check(
201 &sm
, &sp
, time
, TM_TEST_SRTCM_EBS_DF
+ 1)
203 melog(SRTCM_BLIND_CHECK_MSG
" RED");
210 * functional test for rte_meter_trtcm_color_blind_check
213 tm_test_trtcm_color_blind_check(void)
215 #define TRTCM_BLIND_CHECK_MSG "trtcm_blind_check"
218 struct rte_meter_trtcm_profile tp
;
219 struct rte_meter_trtcm tm
;
220 uint64_t hz
= rte_get_tsc_hz();
223 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
224 melog(TRTCM_BLIND_CHECK_MSG
);
225 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
226 melog(TRTCM_BLIND_CHECK_MSG
);
227 time
= rte_get_tsc_cycles() + hz
;
228 if (rte_meter_trtcm_color_blind_check(
229 &tm
, &tp
, time
, TM_TEST_TRTCM_CBS_DF
- 1)
230 != e_RTE_METER_GREEN
)
231 melog(TRTCM_BLIND_CHECK_MSG
" GREEN");
234 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
235 melog(TRTCM_BLIND_CHECK_MSG
);
236 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
237 melog(TRTCM_BLIND_CHECK_MSG
);
238 time
= rte_get_tsc_cycles() + hz
;
239 if (rte_meter_trtcm_color_blind_check(
240 &tm
, &tp
, time
, TM_TEST_TRTCM_CBS_DF
+ 1)
241 != e_RTE_METER_YELLOW
)
242 melog(TRTCM_BLIND_CHECK_MSG
" YELLOW");
244 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
245 melog(TRTCM_BLIND_CHECK_MSG
);
246 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
247 melog(TRTCM_BLIND_CHECK_MSG
);
248 time
= rte_get_tsc_cycles() + hz
;
249 if (rte_meter_trtcm_color_blind_check(
250 &tm
, &tp
, time
, TM_TEST_TRTCM_PBS_DF
- 1)
251 != e_RTE_METER_YELLOW
)
252 melog(TRTCM_BLIND_CHECK_MSG
" YELLOW");
255 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
256 melog(TRTCM_BLIND_CHECK_MSG
);
257 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
258 melog(TRTCM_BLIND_CHECK_MSG
);
259 time
= rte_get_tsc_cycles() + hz
;
260 if (rte_meter_trtcm_color_blind_check(
261 &tm
, &tp
, time
, TM_TEST_TRTCM_PBS_DF
+ 1)
263 melog(TRTCM_BLIND_CHECK_MSG
" RED");
270 * @in[4] : the flags packets carries.
271 * @in[4] : the flags function expect to return.
272 * It will do blind check at the time of 1 second from beginning.
273 * At the time, it will use packets length of cbs -1, cbs + 1,
274 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
275 * aware check, expect flag out[0], out[1], out[2] and out[3]
279 tm_test_srtcm_aware_check
280 (enum rte_meter_color in
[4], enum rte_meter_color out
[4])
282 #define SRTCM_AWARE_CHECK_MSG "srtcm_aware_check"
283 struct rte_meter_srtcm_profile sp
;
284 struct rte_meter_srtcm sm
;
286 uint64_t hz
= rte_get_tsc_hz();
288 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
289 melog(SRTCM_AWARE_CHECK_MSG
);
290 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
291 melog(SRTCM_AWARE_CHECK_MSG
);
292 time
= rte_get_tsc_cycles() + hz
;
293 if (rte_meter_srtcm_color_aware_check(
294 &sm
, &sp
, time
, TM_TEST_SRTCM_CBS_DF
- 1, in
[0]) != out
[0])
295 melog(SRTCM_AWARE_CHECK_MSG
" %u:%u", in
[0], out
[0]);
297 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
298 melog(SRTCM_AWARE_CHECK_MSG
);
299 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
300 melog(SRTCM_AWARE_CHECK_MSG
);
301 time
= rte_get_tsc_cycles() + hz
;
302 if (rte_meter_srtcm_color_aware_check(
303 &sm
, &sp
, time
, TM_TEST_SRTCM_CBS_DF
+ 1, in
[1]) != out
[1])
304 melog(SRTCM_AWARE_CHECK_MSG
" %u:%u", in
[1], out
[1]);
306 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
307 melog(SRTCM_AWARE_CHECK_MSG
);
308 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
309 melog(SRTCM_AWARE_CHECK_MSG
);
310 time
= rte_get_tsc_cycles() + hz
;
311 if (rte_meter_srtcm_color_aware_check(
312 &sm
, &sp
, time
, TM_TEST_SRTCM_EBS_DF
- 1, in
[2]) != out
[2])
313 melog(SRTCM_AWARE_CHECK_MSG
" %u:%u", in
[2], out
[2]);
315 if (rte_meter_srtcm_profile_config(&sp
, &sparams
) != 0)
316 melog(SRTCM_AWARE_CHECK_MSG
);
317 if (rte_meter_srtcm_config(&sm
, &sp
) != 0)
318 melog(SRTCM_AWARE_CHECK_MSG
);
319 time
= rte_get_tsc_cycles() + hz
;
320 if (rte_meter_srtcm_color_aware_check(
321 &sm
, &sp
, time
, TM_TEST_SRTCM_EBS_DF
+ 1, in
[3]) != out
[3])
322 melog(SRTCM_AWARE_CHECK_MSG
" %u:%u", in
[3], out
[3]);
329 * functional test for rte_meter_srtcm_color_aware_check
332 tm_test_srtcm_color_aware_check(void)
334 enum rte_meter_color in
[4], out
[4];
337 * test 4 points that will produce green, yellow, yellow, red flag
338 * if using blind check
341 /* previouly have a green, test points should keep unchanged */
342 in
[0] = in
[1] = in
[2] = in
[3] = e_RTE_METER_GREEN
;
343 out
[0] = e_RTE_METER_GREEN
;
344 out
[1] = e_RTE_METER_YELLOW
;
345 out
[2] = e_RTE_METER_YELLOW
;
346 out
[3] = e_RTE_METER_RED
;
347 if (tm_test_srtcm_aware_check(in
, out
) != 0)
351 * previously have a yellow, green & yellow = yellow
354 in
[0] = in
[1] = in
[2] = in
[3] = e_RTE_METER_YELLOW
;
355 out
[0] = e_RTE_METER_YELLOW
;
356 out
[1] = e_RTE_METER_YELLOW
;
357 out
[2] = e_RTE_METER_YELLOW
;
358 out
[3] = e_RTE_METER_RED
;
359 if (tm_test_srtcm_aware_check(in
, out
) != 0)
363 * previously have a red, red & green = red
366 in
[0] = in
[1] = in
[2] = in
[3] = e_RTE_METER_RED
;
367 out
[0] = e_RTE_METER_RED
;
368 out
[1] = e_RTE_METER_RED
;
369 out
[2] = e_RTE_METER_RED
;
370 out
[3] = e_RTE_METER_RED
;
371 if (tm_test_srtcm_aware_check(in
, out
) != 0)
378 * @in[4] : the flags packets carries.
379 * @in[4] : the flags function expect to return.
380 * It will do blind check at the time of 1 second from beginning.
381 * At the time, it will use packets length of cbs -1, cbs + 1,
382 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
383 * aware check, expect flag out[0], out[1], out[2] and out[3]
386 tm_test_trtcm_aware_check
387 (enum rte_meter_color in
[4], enum rte_meter_color out
[4])
389 #define TRTCM_AWARE_CHECK_MSG "trtcm_aware_check"
390 struct rte_meter_trtcm_profile tp
;
391 struct rte_meter_trtcm tm
;
393 uint64_t hz
= rte_get_tsc_hz();
395 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
396 melog(TRTCM_AWARE_CHECK_MSG
);
397 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
398 melog(TRTCM_AWARE_CHECK_MSG
);
399 time
= rte_get_tsc_cycles() + hz
;
400 if (rte_meter_trtcm_color_aware_check(
401 &tm
, &tp
, time
, TM_TEST_TRTCM_CBS_DF
- 1, in
[0]) != out
[0])
402 melog(TRTCM_AWARE_CHECK_MSG
" %u:%u", in
[0], out
[0]);
404 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
405 melog(TRTCM_AWARE_CHECK_MSG
);
406 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
407 melog(TRTCM_AWARE_CHECK_MSG
);
408 time
= rte_get_tsc_cycles() + hz
;
409 if (rte_meter_trtcm_color_aware_check(
410 &tm
, &tp
, time
, TM_TEST_TRTCM_CBS_DF
+ 1, in
[1]) != out
[1])
411 melog(TRTCM_AWARE_CHECK_MSG
" %u:%u", in
[1], out
[1]);
413 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
414 melog(TRTCM_AWARE_CHECK_MSG
);
415 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
416 melog(TRTCM_AWARE_CHECK_MSG
);
417 time
= rte_get_tsc_cycles() + hz
;
418 if (rte_meter_trtcm_color_aware_check(
419 &tm
, &tp
, time
, TM_TEST_TRTCM_PBS_DF
- 1, in
[2]) != out
[2])
420 melog(TRTCM_AWARE_CHECK_MSG
" %u:%u", in
[2], out
[2]);
422 if (rte_meter_trtcm_profile_config(&tp
, &tparams
) != 0)
423 melog(TRTCM_AWARE_CHECK_MSG
);
424 if (rte_meter_trtcm_config(&tm
, &tp
) != 0)
425 melog(TRTCM_AWARE_CHECK_MSG
);
426 time
= rte_get_tsc_cycles() + hz
;
427 if (rte_meter_trtcm_color_aware_check(
428 &tm
, &tp
, time
, TM_TEST_TRTCM_PBS_DF
+ 1, in
[3]) != out
[3])
429 melog(TRTCM_AWARE_CHECK_MSG
" %u:%u", in
[3], out
[3]);
436 * functional test for rte_meter_trtcm_color_aware_check
440 tm_test_trtcm_color_aware_check(void)
442 enum rte_meter_color in
[4], out
[4];
444 * test 4 points that will produce green, yellow, yellow, red flag
445 * if using blind check
448 /* previouly have a green, test points should keep unchanged */
449 in
[0] = in
[1] = in
[2] = in
[3] = e_RTE_METER_GREEN
;
450 out
[0] = e_RTE_METER_GREEN
;
451 out
[1] = e_RTE_METER_YELLOW
;
452 out
[2] = e_RTE_METER_YELLOW
;
453 out
[3] = e_RTE_METER_RED
;
454 if (tm_test_trtcm_aware_check(in
, out
) != 0)
457 in
[0] = in
[1] = in
[2] = in
[3] = e_RTE_METER_YELLOW
;
458 out
[0] = e_RTE_METER_YELLOW
;
459 out
[1] = e_RTE_METER_YELLOW
;
460 out
[2] = e_RTE_METER_YELLOW
;
461 out
[3] = e_RTE_METER_RED
;
462 if (tm_test_trtcm_aware_check(in
, out
) != 0)
465 in
[0] = in
[1] = in
[2] = in
[3] = e_RTE_METER_RED
;
466 out
[0] = e_RTE_METER_RED
;
467 out
[1] = e_RTE_METER_RED
;
468 out
[2] = e_RTE_METER_RED
;
469 out
[3] = e_RTE_METER_RED
;
470 if (tm_test_trtcm_aware_check(in
, out
) != 0)
477 * test main entrance for library meter
482 if (tm_test_srtcm_config() != 0)
485 if (tm_test_trtcm_config() != 0)
488 if (tm_test_srtcm_color_blind_check() != 0)
491 if (tm_test_trtcm_color_blind_check() != 0)
494 if (tm_test_srtcm_color_aware_check() != 0)
497 if (tm_test_trtcm_color_aware_check() != 0)
504 REGISTER_TEST_COMMAND(meter_autotest
, test_meter
);