4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <rte_cycles.h>
43 #include <rte_meter.h>
45 #define mlog(format, ...) do{\
46 printf("Line %d:",__LINE__);\
47 printf(format, ##__VA_ARGS__);\
51 #define melog(format, ...) do{\
52 printf("Line %d:",__LINE__);\
53 printf(format, ##__VA_ARGS__);\
54 printf(" failed!\n");\
58 #define TM_TEST_SRTCM_CIR_DF 46000000
59 #define TM_TEST_SRTCM_CBS_DF 2048
60 #define TM_TEST_SRTCM_EBS_DF 4096
62 #define TM_TEST_TRTCM_CIR_DF 46000000
63 #define TM_TEST_TRTCM_PIR_DF 69000000
64 #define TM_TEST_TRTCM_CBS_DF 2048
65 #define TM_TEST_TRTCM_PBS_DF 4096
67 static struct rte_meter_srtcm_params sparams =
68 {.cir = TM_TEST_SRTCM_CIR_DF,
69 .cbs = TM_TEST_SRTCM_CBS_DF,
70 .ebs = TM_TEST_SRTCM_EBS_DF,};
72 static struct rte_meter_trtcm_params tparams=
73 {.cir = TM_TEST_TRTCM_CIR_DF,
74 .pir = TM_TEST_TRTCM_PIR_DF,
75 .cbs = TM_TEST_TRTCM_CBS_DF,
76 .pbs = TM_TEST_TRTCM_PBS_DF,};
79 * functional test for rte_meter_srtcm_config
82 tm_test_srtcm_config(void)
84 #define SRTCM_CFG_MSG "srtcm_config"
85 struct rte_meter_srtcm sm;
86 struct rte_meter_srtcm_params sparams1;
88 /* invalid parameter test */
89 if(rte_meter_srtcm_config(NULL, NULL) == 0)
91 if(rte_meter_srtcm_config(&sm, NULL) == 0)
93 if(rte_meter_srtcm_config(NULL, &sparams) == 0)
96 /* cbs and ebs can't both be zero */
100 if(rte_meter_srtcm_config(&sm, &sparams1) == 0)
101 melog(SRTCM_CFG_MSG);
103 /* cir should never be 0 */
106 if(rte_meter_srtcm_config(&sm, &sparams1) == 0)
107 melog(SRTCM_CFG_MSG);
109 /* one of ebs and cbs can be zero, should be successful */
112 if(rte_meter_srtcm_config(&sm, &sparams1) != 0)
113 melog(SRTCM_CFG_MSG);
117 if(rte_meter_srtcm_config(&sm, &sparams1) != 0)
118 melog(SRTCM_CFG_MSG);
120 /* usual parameter, should be successful */
121 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
122 melog(SRTCM_CFG_MSG);
129 * functional test for rte_meter_trtcm_config
132 tm_test_trtcm_config(void)
134 struct rte_meter_trtcm tm;
135 struct rte_meter_trtcm_params tparams1;
136 #define TRTCM_CFG_MSG "trtcm_config"
138 /* invalid parameter test */
139 if(rte_meter_trtcm_config(NULL, NULL) == 0)
140 melog(TRTCM_CFG_MSG);
141 if(rte_meter_trtcm_config(&tm, NULL) == 0)
142 melog(TRTCM_CFG_MSG);
143 if(rte_meter_trtcm_config(NULL, &tparams) == 0)
144 melog(TRTCM_CFG_MSG);
146 /* cir, cbs, pir and pbs never be zero */
149 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
150 melog(TRTCM_CFG_MSG);
154 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
155 melog(TRTCM_CFG_MSG);
159 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
160 melog(TRTCM_CFG_MSG);
164 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
165 melog(TRTCM_CFG_MSG);
167 /* pir should be greater or equal to cir */
169 tparams1.pir = tparams1.cir - 1;
170 if(rte_meter_trtcm_config(&tm, &tparams1) == 0)
171 melog(TRTCM_CFG_MSG" pir < cir test");
173 /* usual parameter, should be successful */
174 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
175 melog(TRTCM_CFG_MSG);
181 * functional test for rte_meter_srtcm_color_blind_check
184 tm_test_srtcm_color_blind_check(void)
186 #define SRTCM_BLIND_CHECK_MSG "srtcm_blind_check"
187 struct rte_meter_srtcm sm;
189 uint64_t hz = rte_get_tsc_hz();
192 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
193 melog(SRTCM_BLIND_CHECK_MSG);
194 time = rte_get_tsc_cycles() + hz;
195 if(rte_meter_srtcm_color_blind_check(
196 &sm, time, TM_TEST_SRTCM_CBS_DF - 1)
197 != e_RTE_METER_GREEN)
198 melog(SRTCM_BLIND_CHECK_MSG" GREEN");
201 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
202 melog(SRTCM_BLIND_CHECK_MSG);
203 time = rte_get_tsc_cycles() + hz;
204 if(rte_meter_srtcm_color_blind_check(
205 &sm, time, TM_TEST_SRTCM_CBS_DF + 1)
206 != e_RTE_METER_YELLOW)
207 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
209 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
210 melog(SRTCM_BLIND_CHECK_MSG);
211 time = rte_get_tsc_cycles() + hz;
212 if(rte_meter_srtcm_color_blind_check(
213 &sm, time, (uint32_t)sm.ebs - 1) != e_RTE_METER_YELLOW)
214 melog(SRTCM_BLIND_CHECK_MSG" YELLOW");
217 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
218 melog(SRTCM_BLIND_CHECK_MSG);
219 time = rte_get_tsc_cycles() + hz;
220 if(rte_meter_srtcm_color_blind_check(
221 &sm, time, TM_TEST_SRTCM_EBS_DF + 1)
223 melog(SRTCM_BLIND_CHECK_MSG" RED");
230 * functional test for rte_meter_trtcm_color_blind_check
233 tm_test_trtcm_color_blind_check(void)
235 #define TRTCM_BLIND_CHECK_MSG "trtcm_blind_check"
238 struct rte_meter_trtcm tm;
239 uint64_t hz = rte_get_tsc_hz();
242 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
243 melog(TRTCM_BLIND_CHECK_MSG);
244 time = rte_get_tsc_cycles() + hz;
245 if(rte_meter_trtcm_color_blind_check(
246 &tm, time, TM_TEST_TRTCM_CBS_DF - 1)
247 != e_RTE_METER_GREEN)
248 melog(TRTCM_BLIND_CHECK_MSG" GREEN");
251 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
252 melog(TRTCM_BLIND_CHECK_MSG);
253 time = rte_get_tsc_cycles() + hz;
254 if(rte_meter_trtcm_color_blind_check(
255 &tm, time, TM_TEST_TRTCM_CBS_DF + 1)
256 != e_RTE_METER_YELLOW)
257 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
259 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
260 melog(TRTCM_BLIND_CHECK_MSG);
261 time = rte_get_tsc_cycles() + hz;
262 if(rte_meter_trtcm_color_blind_check(
263 &tm, time, TM_TEST_TRTCM_PBS_DF - 1)
264 != e_RTE_METER_YELLOW)
265 melog(TRTCM_BLIND_CHECK_MSG" YELLOW");
268 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
269 melog(TRTCM_BLIND_CHECK_MSG);
270 time = rte_get_tsc_cycles() + hz;
271 if(rte_meter_trtcm_color_blind_check(
272 &tm, time, TM_TEST_TRTCM_PBS_DF + 1)
274 melog(TRTCM_BLIND_CHECK_MSG" RED");
281 * @in[4] : the flags packets carries.
282 * @in[4] : the flags function expect to return.
283 * It will do blind check at the time of 1 second from beginning.
284 * At the time, it will use packets length of cbs -1, cbs + 1,
285 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
286 * aware check, expect flag out[0], out[1], out[2] and out[3]
290 tm_test_srtcm_aware_check
291 (enum rte_meter_color in[4], enum rte_meter_color out[4])
293 #define SRTCM_AWARE_CHECK_MSG "srtcm_aware_check"
294 struct rte_meter_srtcm sm;
296 uint64_t hz = rte_get_tsc_hz();
298 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
299 melog(SRTCM_AWARE_CHECK_MSG);
300 time = rte_get_tsc_cycles() + hz;
301 if(rte_meter_srtcm_color_aware_check(
302 &sm, time, TM_TEST_SRTCM_CBS_DF - 1, in[0]) != out[0])
303 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
305 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
306 melog(SRTCM_AWARE_CHECK_MSG);
307 time = rte_get_tsc_cycles() + hz;
308 if(rte_meter_srtcm_color_aware_check(
309 &sm, time, TM_TEST_SRTCM_CBS_DF + 1, in[1]) != out[1])
310 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
312 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
313 melog(SRTCM_AWARE_CHECK_MSG);
314 time = rte_get_tsc_cycles() + hz;
315 if(rte_meter_srtcm_color_aware_check(
316 &sm, time, TM_TEST_SRTCM_EBS_DF - 1, in[2]) != out[2])
317 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
319 if(rte_meter_srtcm_config(&sm, &sparams) != 0)
320 melog(SRTCM_AWARE_CHECK_MSG);
321 time = rte_get_tsc_cycles() + hz;
322 if(rte_meter_srtcm_color_aware_check(
323 &sm, time, TM_TEST_SRTCM_EBS_DF + 1, in[3]) != out[3])
324 melog(SRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
331 * functional test for rte_meter_srtcm_color_aware_check
334 tm_test_srtcm_color_aware_check(void)
336 enum rte_meter_color in[4], out[4];
339 * test 4 points that will produce green, yellow, yellow, red flag
340 * if using blind check
343 /* previouly have a green, test points should keep unchanged */
344 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_GREEN;
345 out[0] = e_RTE_METER_GREEN;
346 out[1] = e_RTE_METER_YELLOW;
347 out[2] = e_RTE_METER_YELLOW;
348 out[3] = e_RTE_METER_RED;
349 if(tm_test_srtcm_aware_check(in, out) != 0)
353 * previously have a yellow, green & yellow = yellow
356 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_YELLOW;
357 out[0] = e_RTE_METER_YELLOW;
358 out[1] = e_RTE_METER_YELLOW;
359 out[2] = e_RTE_METER_YELLOW;
360 out[3] = e_RTE_METER_RED;
361 if(tm_test_srtcm_aware_check(in, out) != 0)
365 * previously have a red, red & green = red
368 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_RED;
369 out[0] = e_RTE_METER_RED;
370 out[1] = e_RTE_METER_RED;
371 out[2] = e_RTE_METER_RED;
372 out[3] = e_RTE_METER_RED;
373 if(tm_test_srtcm_aware_check(in, out) != 0)
380 * @in[4] : the flags packets carries.
381 * @in[4] : the flags function expect to return.
382 * It will do blind check at the time of 1 second from beginning.
383 * At the time, it will use packets length of cbs -1, cbs + 1,
384 * ebs -1 and ebs +1 with flag in[0], in[1], in[2] and in[3] to do
385 * aware check, expect flag out[0], out[1], out[2] and out[3]
388 tm_test_trtcm_aware_check
389 (enum rte_meter_color in[4], enum rte_meter_color out[4])
391 #define TRTCM_AWARE_CHECK_MSG "trtcm_aware_check"
392 struct rte_meter_trtcm tm;
394 uint64_t hz = rte_get_tsc_hz();
396 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
397 melog(TRTCM_AWARE_CHECK_MSG);
398 time = rte_get_tsc_cycles() + hz;
399 if(rte_meter_trtcm_color_aware_check(
400 &tm, time, TM_TEST_TRTCM_CBS_DF - 1, in[0]) != out[0])
401 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[0], out[0]);
403 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
404 melog(TRTCM_AWARE_CHECK_MSG);
405 time = rte_get_tsc_cycles() + hz;
406 if(rte_meter_trtcm_color_aware_check(
407 &tm, time, TM_TEST_TRTCM_CBS_DF + 1, in[1]) != out[1])
408 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[1], out[1]);
410 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
411 melog(TRTCM_AWARE_CHECK_MSG);
412 time = rte_get_tsc_cycles() + hz;
413 if(rte_meter_trtcm_color_aware_check(
414 &tm, time, TM_TEST_TRTCM_PBS_DF - 1, in[2]) != out[2])
415 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[2], out[2]);
417 if(rte_meter_trtcm_config(&tm, &tparams) != 0)
418 melog(TRTCM_AWARE_CHECK_MSG);
419 time = rte_get_tsc_cycles() + hz;
420 if(rte_meter_trtcm_color_aware_check(
421 &tm, time, TM_TEST_TRTCM_PBS_DF + 1, in[3]) != out[3])
422 melog(TRTCM_AWARE_CHECK_MSG" %u:%u", in[3], out[3]);
429 * functional test for rte_meter_trtcm_color_aware_check
433 tm_test_trtcm_color_aware_check(void)
435 enum rte_meter_color in[4], out[4];
437 * test 4 points that will produce green, yellow, yellow, red flag
438 * if using blind check
441 /* previouly have a green, test points should keep unchanged */
442 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_GREEN;
443 out[0] = e_RTE_METER_GREEN;
444 out[1] = e_RTE_METER_YELLOW;
445 out[2] = e_RTE_METER_YELLOW;
446 out[3] = e_RTE_METER_RED;
447 if(tm_test_trtcm_aware_check(in, out) != 0)
450 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_YELLOW;
451 out[0] = e_RTE_METER_YELLOW;
452 out[1] = e_RTE_METER_YELLOW;
453 out[2] = e_RTE_METER_YELLOW;
454 out[3] = e_RTE_METER_RED;
455 if(tm_test_trtcm_aware_check(in, out) != 0)
458 in[0] = in[1] = in[2] = in[3] = e_RTE_METER_RED;
459 out[0] = e_RTE_METER_RED;
460 out[1] = e_RTE_METER_RED;
461 out[2] = e_RTE_METER_RED;
462 out[3] = e_RTE_METER_RED;
463 if(tm_test_trtcm_aware_check(in, out) != 0)
470 * test main entrance for library meter
475 if(tm_test_srtcm_config() != 0 )
478 if(tm_test_trtcm_config() != 0 )
481 if(tm_test_srtcm_color_blind_check() != 0)
484 if(tm_test_trtcm_color_blind_check()!= 0)
487 if(tm_test_srtcm_color_aware_check()!= 0)
490 if(tm_test_trtcm_color_aware_check()!= 0)
497 REGISTER_TEST_COMMAND(meter_autotest, test_meter);