1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
14 #ifdef RTE_EXEC_ENV_WINDOWS
18 printf("red not supported on Windows, skipping test\n");
25 printf("red_perf not supported on Windows, skipping test\n");
32 printf("red_all not supported on Windows, skipping test\n");
43 #ifdef __INTEL_COMPILER
44 #pragma warning(disable:2259) /* conversion may lose significant bits */
45 #pragma warning(disable:181) /* Arg incompatible with format string */
48 #define TEST_HZ_PER_KHZ 1000
49 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */
51 #define MAX_QEMPTY_TIME_MSEC 50000
52 #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */
53 #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */
54 #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */
55 #define NSEC_PER_SEC (USEC_PER_SEC * 1000) /**< Nano-seconds per second */
57 /**< structures for testing rte_red performance and function */
58 struct test_rte_red_config { /**< Test structure for RTE_RED config */
59 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
60 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
61 uint8_t *wq_log2; /**< Test wq_log2 value to use */
62 uint32_t min_th; /**< Queue minimum threshold */
63 uint32_t max_th; /**< Queue maximum threshold */
64 uint8_t *maxp_inv; /**< Inverse mark probability */
67 struct test_queue { /**< Test structure for RTE_RED Queues */
68 struct rte_red *rdata; /**< RTE_RED runtime data */
69 uint32_t num_queues; /**< Number of RTE_RED queues to test */
70 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
71 uint32_t *q; /**< Queue size */
72 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
73 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
74 uint32_t avg_tolerance; /**< Tolerance in queue average */
75 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
78 struct test_var { /**< Test variables used for testing RTE_RED */
79 uint32_t wait_usec; /**< Micro second wait interval */
80 uint32_t num_iterations; /**< Number of test iterations */
81 uint32_t num_ops; /**< Number of test operations */
82 uint64_t clk_freq; /**< CPU clock frequency */
83 uint32_t sleep_sec; /**< Seconds to sleep */
84 uint32_t *dropped; /**< Test operations dropped */
85 uint32_t *enqueued; /**< Test operations enqueued */
88 struct test_config { /**< Master test structure for RTE_RED */
89 const char *ifname; /**< Interface name */
90 const char *msg; /**< Test message for display */
91 const char *htxt; /**< Header txt display for result output */
92 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
93 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
94 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
95 uint32_t *tlevel; /**< Queue levels */
103 /**< Test structure to define tests to run */
105 struct test_config *testcfg;
106 enum test_result (*testfn)(struct test_config *);
111 uint64_t clk_min; /**< min clocks */
112 uint64_t clk_max; /**< max clocks */
113 uint64_t clk_avgc; /**< count to calc average */
114 double clk_avg; /**< cumulative sum to calc average */
118 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
119 static double inv_cycles_per_byte = 0;
120 static double pkt_time_usec = 0;
122 static void init_port_ts(uint64_t cpu_clock)
124 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
125 inv_cycles_per_byte = 1.0 / cycles_per_byte;
126 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
129 static uint64_t get_port_ts(void)
131 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
134 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
136 p->clk_min = (uint64_t)(-1LL);
143 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
145 p->clk_start = rte_rdtsc_precise();
148 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
150 uint64_t clk_start = rte_rdtsc() - p->clk_start;
153 p->clk_avg += (double) clk_start;
155 if (clk_start > p->clk_max)
156 p->clk_max = clk_start;
157 if (clk_start < p->clk_min)
158 p->clk_min = clk_start;
161 static void rdtsc_prof_print(struct rdtsc_prof *p)
164 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
169 (p->clk_avg / ((double) p->clk_avgc)));
173 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
177 * scale by 1/n and convert from fixed-point to integer
179 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
182 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
186 * scale by 1/n and convert from fixed-point to floating-point
188 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
191 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
196 * scale by n and convert from integer to fixed-point
198 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
201 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
203 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
206 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
208 return (double)dropped / ((double)enqueued + (double)dropped);
212 * calculate the drop probability
214 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
215 uint32_t maxp_inv, uint32_t avg)
217 double drop_prob = 0.0;
221 } else if (avg < max_th) {
222 drop_prob = (1.0 / (double)maxp_inv)
223 * ((double)(avg - min_th)
224 / (double)(max_th - min_th));
232 * check if drop rate matches drop probability within tolerance
234 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
236 double abs_diff = 0.0;
239 abs_diff = fabs(drop_rate - drop_prob);
240 if ((int)abs_diff == 0) {
243 *diff = (abs_diff / drop_prob) * 100.0;
244 if (*diff > tolerance) {
252 * check if average queue size is within tolerance
254 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
256 double abs_diff = 0.0;
259 abs_diff = fabs(avg - exp_avg);
260 if ((int)abs_diff == 0) {
263 *diff = (abs_diff / exp_avg) * 100.0;
264 if (*diff > tolerance) {
272 * initialize the test rte_red config
274 static enum test_result
275 test_rte_red_init(struct test_config *tcfg)
279 tcfg->tvar->clk_freq = rte_get_timer_hz();
280 init_port_ts( tcfg->tvar->clk_freq );
282 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
283 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
284 (uint16_t)tcfg->tconfig->wq_log2[i],
285 (uint16_t)tcfg->tconfig->min_th,
286 (uint16_t)tcfg->tconfig->max_th,
287 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
292 *tcfg->tqueue->q = 0;
293 *tcfg->tvar->dropped = 0;
294 *tcfg->tvar->enqueued = 0;
299 * enqueue until actual queue size reaches target level
302 increase_actual_qsize(struct rte_red_config *red_cfg,
310 for (i = 0; i < attempts; i++) {
316 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
323 * check if target actual queue size has been reached
334 * enqueue until average queue size reaches target level
337 increase_average_qsize(struct rte_red_config *red_cfg,
346 for (i = 0; i < num_ops; i++) {
350 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
353 * check if target average queue size has been reached
355 avg = rte_red_get_avg_int(red_cfg, red);
365 * setup default values for the functional test structures
367 static struct rte_red_config ft_wrconfig[1];
368 static struct rte_red ft_rtdata[1];
369 static uint8_t ft_wq_log2[] = {9};
370 static uint8_t ft_maxp_inv[] = {10};
371 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
372 static uint32_t ft_q[] ={0};
373 static uint32_t ft_dropped[] ={0};
374 static uint32_t ft_enqueued[] ={0};
376 static struct test_rte_red_config ft_tconfig = {
377 .rconfig = ft_wrconfig,
378 .num_cfg = RTE_DIM(ft_wrconfig),
379 .wq_log2 = ft_wq_log2,
382 .maxp_inv = ft_maxp_inv,
385 static struct test_queue ft_tqueue = {
387 .num_queues = RTE_DIM(ft_rtdata),
388 .qconfig = ft_qconfig,
390 .q_ramp_up = 1000000,
391 .avg_ramp_up = 1000000,
392 .avg_tolerance = 5, /* 5 percent */
393 .drop_tolerance = 50, /* 50 percent */
396 static struct test_var ft_tvar = {
401 .dropped = ft_dropped,
402 .enqueued = ft_enqueued,
403 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
407 * functional test enqueue/dequeue packets
409 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
418 for (i = 0; i < num_ops; i++) {
424 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
433 * Test F1: functional test 1
435 static uint32_t ft1_tlevels[] = {6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 144};
437 static struct test_config func_test1_config = {
438 .ifname = "functional test 1 interface",
439 .msg = "functional test 1 : use one rte_red configuration,\n"
440 " increase average queue size to various levels,\n"
441 " compare drop rate to drop probability\n\n",
451 .tconfig = &ft_tconfig,
452 .tqueue = &ft_tqueue,
454 .tlevel = ft1_tlevels,
457 static enum test_result func_test1(struct test_config *tcfg)
459 enum test_result result = PASS;
462 printf("%s", tcfg->msg);
464 if (test_rte_red_init(tcfg) != PASS) {
469 printf("%s", tcfg->htxt);
471 for (i = 0; i < RTE_DIM(ft1_tlevels); i++) {
472 const char *label = NULL;
474 double drop_rate = 0.0;
475 double drop_prob = 0.0;
479 * reset rte_red run-time data
481 rte_red_rt_data_init(tcfg->tqueue->rdata);
482 *tcfg->tvar->enqueued = 0;
483 *tcfg->tvar->dropped = 0;
485 if (increase_actual_qsize(tcfg->tconfig->rconfig,
489 tcfg->tqueue->q_ramp_up) != 0) {
494 if (increase_average_qsize(tcfg->tconfig->rconfig,
498 tcfg->tqueue->avg_ramp_up) != 0) {
503 enqueue_dequeue_func(tcfg->tconfig->rconfig,
507 tcfg->tvar->enqueued,
508 tcfg->tvar->dropped);
510 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
511 if (avg != tcfg->tlevel[i]) {
512 fprintf(stderr, "Fail: avg != level\n");
516 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
517 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
518 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
519 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
522 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
523 label = "min thresh: ";
524 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
525 label = "max thresh: ";
528 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
529 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
530 drop_prob * 100.0, drop_rate * 100.0, diff,
531 (double)tcfg->tqueue->drop_tolerance);
538 * Test F2: functional test 2
540 static uint32_t ft2_tlevel[] = {127};
541 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
542 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
543 static struct rte_red_config ft2_rconfig[10];
545 static struct test_rte_red_config ft2_tconfig = {
546 .rconfig = ft2_rconfig,
547 .num_cfg = RTE_DIM(ft2_rconfig),
548 .wq_log2 = ft2_wq_log2,
551 .maxp_inv = ft2_maxp_inv,
554 static struct test_config func_test2_config = {
555 .ifname = "functional test 2 interface",
556 .msg = "functional test 2 : use several RED configurations,\n"
557 " increase average queue size to just below maximum threshold,\n"
558 " compare drop rate to drop probability\n\n",
559 .htxt = "RED config "
568 .tconfig = &ft2_tconfig,
569 .tqueue = &ft_tqueue,
571 .tlevel = ft2_tlevel,
574 static enum test_result func_test2(struct test_config *tcfg)
576 enum test_result result = PASS;
577 double prev_drop_rate = 1.0;
580 printf("%s", tcfg->msg);
582 if (test_rte_red_init(tcfg) != PASS) {
586 rte_red_rt_data_init(tcfg->tqueue->rdata);
588 if (increase_actual_qsize(tcfg->tconfig->rconfig,
592 tcfg->tqueue->q_ramp_up) != 0) {
597 if (increase_average_qsize(tcfg->tconfig->rconfig,
601 tcfg->tqueue->avg_ramp_up) != 0) {
605 printf("%s", tcfg->htxt);
607 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
609 double drop_rate = 0.0;
610 double drop_prob = 0.0;
613 *tcfg->tvar->dropped = 0;
614 *tcfg->tvar->enqueued = 0;
616 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
620 tcfg->tvar->enqueued,
621 tcfg->tvar->dropped);
623 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
624 if (avg != *tcfg->tlevel)
627 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
628 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
629 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
630 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
633 * drop rate should decrease as maxp_inv increases
635 if (drop_rate > prev_drop_rate)
637 prev_drop_rate = drop_rate;
639 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
640 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
641 drop_prob * 100.0, drop_rate * 100.0, diff,
642 (double)tcfg->tqueue->drop_tolerance);
649 * Test F3: functional test 3
651 static uint32_t ft3_tlevel[] = {1022};
653 static struct test_rte_red_config ft3_tconfig = {
654 .rconfig = ft_wrconfig,
655 .num_cfg = RTE_DIM(ft_wrconfig),
656 .wq_log2 = ft_wq_log2,
659 .maxp_inv = ft_maxp_inv,
662 static struct test_config func_test3_config = {
663 .ifname = "functional test 3 interface",
664 .msg = "functional test 3 : use one RED configuration,\n"
665 " increase average queue size to target level,\n"
666 " dequeue all packets until queue is empty,\n"
667 " confirm that average queue size is computed correctly while queue is empty\n\n",
668 .htxt = "q avg before "
675 .tconfig = &ft3_tconfig,
676 .tqueue = &ft_tqueue,
678 .tlevel = ft3_tlevel,
681 static enum test_result func_test3(struct test_config *tcfg)
683 enum test_result result = PASS;
686 printf("%s", tcfg->msg);
688 if (test_rte_red_init(tcfg) != PASS) {
693 rte_red_rt_data_init(tcfg->tqueue->rdata);
695 if (increase_actual_qsize(tcfg->tconfig->rconfig,
699 tcfg->tqueue->q_ramp_up) != 0) {
704 if (increase_average_qsize(tcfg->tconfig->rconfig,
708 tcfg->tqueue->avg_ramp_up) != 0) {
713 printf("%s", tcfg->htxt);
715 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
716 double avg_before = 0;
717 double avg_after = 0;
721 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
726 *tcfg->tqueue->q = 0;
727 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
729 rte_delay_us(tcfg->tvar->wait_usec);
732 * enqueue one packet to recalculate average queue size
734 if (rte_red_enqueue(tcfg->tconfig->rconfig,
737 get_port_ts()) == 0) {
738 (*tcfg->tqueue->q)++;
740 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
744 exp_avg = calc_exp_avg_on_empty(avg_before,
745 (1 << *tcfg->tconfig->wq_log2),
746 tcfg->tvar->wait_usec);
747 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
748 tcfg->tqueue->rdata);
749 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
752 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
753 avg_before, avg_after, exp_avg, diff,
754 (double)tcfg->tqueue->avg_tolerance,
755 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
762 * Test F4: functional test 4
764 static uint32_t ft4_tlevel[] = {1022};
765 static uint8_t ft4_wq_log2[] = {11};
767 static struct test_rte_red_config ft4_tconfig = {
768 .rconfig = ft_wrconfig,
769 .num_cfg = RTE_DIM(ft_wrconfig),
772 .wq_log2 = ft4_wq_log2,
773 .maxp_inv = ft_maxp_inv,
776 static struct test_queue ft4_tqueue = {
778 .num_queues = RTE_DIM(ft_rtdata),
779 .qconfig = ft_qconfig,
781 .q_ramp_up = 1000000,
782 .avg_ramp_up = 1000000,
783 .avg_tolerance = 0, /* 0 percent */
784 .drop_tolerance = 50, /* 50 percent */
787 static struct test_config func_test4_config = {
788 .ifname = "functional test 4 interface",
789 .msg = "functional test 4 : use one RED configuration,\n"
790 " increase average queue size to target level,\n"
791 " dequeue all packets until queue is empty,\n"
792 " confirm that average queue size is computed correctly while\n"
793 " queue is empty for more than 50 sec,\n"
794 " (this test takes 52 sec to run)\n\n",
795 .htxt = "q avg before "
802 .tconfig = &ft4_tconfig,
803 .tqueue = &ft4_tqueue,
805 .tlevel = ft4_tlevel,
808 static enum test_result func_test4(struct test_config *tcfg)
810 enum test_result result = PASS;
811 uint64_t time_diff = 0;
813 double avg_before = 0.0;
814 double avg_after = 0.0;
815 double exp_avg = 0.0;
818 printf("%s", tcfg->msg);
820 if (test_rte_red_init(tcfg) != PASS) {
825 rte_red_rt_data_init(tcfg->tqueue->rdata);
827 if (increase_actual_qsize(tcfg->tconfig->rconfig,
831 tcfg->tqueue->q_ramp_up) != 0) {
836 if (increase_average_qsize(tcfg->tconfig->rconfig,
840 tcfg->tqueue->avg_ramp_up) != 0) {
845 printf("%s", tcfg->htxt);
847 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
852 *tcfg->tqueue->q = 0;
853 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
856 * record empty time locally
860 sleep(tcfg->tvar->sleep_sec);
863 * enqueue one packet to recalculate average queue size
865 if (rte_red_enqueue(tcfg->tconfig->rconfig,
868 get_port_ts()) != 0) {
872 (*tcfg->tqueue->q)++;
875 * calculate how long queue has been empty
877 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
879 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
881 * this could happen if sleep was interrupted for some reason
888 * confirm that average queue size is now at expected level
891 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
892 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
895 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
896 avg_before, avg_after, exp_avg,
897 diff, (double)tcfg->tqueue->avg_tolerance,
898 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
904 * Test F5: functional test 5
906 static uint32_t ft5_tlevel[] = {127};
907 static uint8_t ft5_wq_log2[] = {9, 8};
908 static uint8_t ft5_maxp_inv[] = {10, 20};
909 static struct rte_red_config ft5_config[2];
910 static struct rte_red ft5_data[4];
911 static uint32_t ft5_q[4];
912 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
913 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
915 static struct test_rte_red_config ft5_tconfig = {
916 .rconfig = ft5_config,
917 .num_cfg = RTE_DIM(ft5_config),
920 .wq_log2 = ft5_wq_log2,
921 .maxp_inv = ft5_maxp_inv,
924 static struct test_queue ft5_tqueue = {
926 .num_queues = RTE_DIM(ft5_data),
927 .qconfig = ft_qconfig,
929 .q_ramp_up = 1000000,
930 .avg_ramp_up = 1000000,
931 .avg_tolerance = 5, /* 10 percent */
932 .drop_tolerance = 50, /* 50 percent */
935 struct test_var ft5_tvar = {
937 .num_iterations = 15,
940 .dropped = ft5_dropped,
941 .enqueued = ft5_enqueued,
945 static struct test_config func_test5_config = {
946 .ifname = "functional test 5 interface",
947 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
948 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
949 " increase average queue size to just below maximum threshold,\n"
950 " compare drop rate to drop probability,\n"
951 " (this is a larger scale version of functional test 2)\n\n",
962 .tconfig = &ft5_tconfig,
963 .tqueue = &ft5_tqueue,
965 .tlevel = ft5_tlevel,
968 static enum test_result func_test5(struct test_config *tcfg)
970 enum test_result result = PASS;
973 printf("%s", tcfg->msg);
975 if (test_rte_red_init(tcfg) != PASS) {
980 printf("%s", tcfg->htxt);
982 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
983 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
984 tcfg->tqueue->q[j] = 0;
986 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
987 &tcfg->tqueue->rdata[j],
990 tcfg->tqueue->q_ramp_up) != 0) {
995 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
996 &tcfg->tqueue->rdata[j],
999 tcfg->tqueue->avg_ramp_up) != 0) {
1005 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1007 double drop_rate = 0.0;
1008 double drop_prob = 0.0;
1011 tcfg->tvar->dropped[j] = 0;
1012 tcfg->tvar->enqueued[j] = 0;
1014 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1015 &tcfg->tqueue->rdata[j],
1016 &tcfg->tqueue->q[j],
1017 tcfg->tvar->num_ops,
1018 &tcfg->tvar->enqueued[j],
1019 &tcfg->tvar->dropped[j]);
1021 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1022 &tcfg->tqueue->rdata[j]);
1023 if (avg != *tcfg->tlevel)
1026 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1027 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1028 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1030 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1033 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1034 j, tcfg->tqueue->qconfig[j], avg,
1035 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1036 drop_prob * 100.0, drop_rate * 100.0,
1037 diff, (double)tcfg->tqueue->drop_tolerance);
1044 * Test F6: functional test 6
1046 static uint32_t ft6_tlevel[] = {1022};
1047 static uint8_t ft6_wq_log2[] = {9, 8};
1048 static uint8_t ft6_maxp_inv[] = {10, 20};
1049 static struct rte_red_config ft6_config[2];
1050 static struct rte_red ft6_data[4];
1051 static uint32_t ft6_q[4];
1053 static struct test_rte_red_config ft6_tconfig = {
1054 .rconfig = ft6_config,
1055 .num_cfg = RTE_DIM(ft6_config),
1058 .wq_log2 = ft6_wq_log2,
1059 .maxp_inv = ft6_maxp_inv,
1062 static struct test_queue ft6_tqueue = {
1064 .num_queues = RTE_DIM(ft6_data),
1065 .qconfig = ft_qconfig,
1067 .q_ramp_up = 1000000,
1068 .avg_ramp_up = 1000000,
1069 .avg_tolerance = 5, /* 10 percent */
1070 .drop_tolerance = 50, /* 50 percent */
1073 static struct test_config func_test6_config = {
1074 .ifname = "functional test 6 interface",
1075 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1076 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
1077 " increase average queue size to target level,\n"
1078 " dequeue all packets until queue is empty,\n"
1079 " confirm that average queue size is computed correctly while queue is empty\n"
1080 " (this is a larger scale version of functional test 3)\n\n",
1089 .tconfig = &ft6_tconfig,
1090 .tqueue = &ft6_tqueue,
1092 .tlevel = ft6_tlevel,
1095 static enum test_result func_test6(struct test_config *tcfg)
1097 enum test_result result = PASS;
1100 printf("%s", tcfg->msg);
1101 if (test_rte_red_init(tcfg) != PASS) {
1105 printf("%s", tcfg->htxt);
1107 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1108 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1109 tcfg->tqueue->q[j] = 0;
1111 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1112 &tcfg->tqueue->rdata[j],
1113 &tcfg->tqueue->q[j],
1115 tcfg->tqueue->q_ramp_up) != 0) {
1119 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1120 &tcfg->tqueue->rdata[j],
1121 &tcfg->tqueue->q[j],
1123 tcfg->tqueue->avg_ramp_up) != 0) {
1128 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1129 double avg_before = 0;
1130 double avg_after = 0;
1134 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1135 &tcfg->tqueue->rdata[j]);
1140 tcfg->tqueue->q[j] = 0;
1141 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1142 rte_delay_us(tcfg->tvar->wait_usec);
1145 * enqueue one packet to recalculate average queue size
1147 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1148 &tcfg->tqueue->rdata[j],
1150 get_port_ts()) == 0) {
1151 tcfg->tqueue->q[j]++;
1153 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1157 exp_avg = calc_exp_avg_on_empty(avg_before,
1158 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1159 tcfg->tvar->wait_usec);
1160 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1161 &tcfg->tqueue->rdata[j]);
1162 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1165 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1166 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1167 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1168 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1175 * setup default values for the performance test structures
1177 static struct rte_red_config pt_wrconfig[1];
1178 static struct rte_red pt_rtdata[1];
1179 static uint8_t pt_wq_log2[] = {9};
1180 static uint8_t pt_maxp_inv[] = {10};
1181 static uint32_t pt_qconfig[] = {0};
1182 static uint32_t pt_q[] = {0};
1183 static uint32_t pt_dropped[] = {0};
1184 static uint32_t pt_enqueued[] = {0};
1186 static struct test_rte_red_config pt_tconfig = {
1187 .rconfig = pt_wrconfig,
1188 .num_cfg = RTE_DIM(pt_wrconfig),
1189 .wq_log2 = pt_wq_log2,
1192 .maxp_inv = pt_maxp_inv,
1195 static struct test_queue pt_tqueue = {
1197 .num_queues = RTE_DIM(pt_rtdata),
1198 .qconfig = pt_qconfig,
1200 .q_ramp_up = 1000000,
1201 .avg_ramp_up = 1000000,
1202 .avg_tolerance = 5, /* 10 percent */
1203 .drop_tolerance = 50, /* 50 percent */
1207 * enqueue/dequeue packets
1209 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1210 struct rte_red *red,
1215 struct rdtsc_prof *prof)
1219 for (i = 0; i < num_ops; i++) {
1226 rdtsc_prof_start(prof);
1227 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1228 rdtsc_prof_end(prof);
1237 * Setup test structures for tests P1, P2, P3
1238 * performance tests 1, 2 and 3
1240 static uint32_t pt1_tlevel[] = {16};
1241 static uint32_t pt2_tlevel[] = {80};
1242 static uint32_t pt3_tlevel[] = {144};
1244 static struct test_var perf1_tvar = {
1246 .num_iterations = 15,
1247 .num_ops = 50000000,
1249 .dropped = pt_dropped,
1250 .enqueued = pt_enqueued,
1254 static struct test_config perf1_test1_config = {
1255 .ifname = "performance test 1 interface",
1256 .msg = "performance test 1 : use one RED configuration,\n"
1257 " set actual and average queue sizes to level below min threshold,\n"
1258 " measure enqueue performance\n\n",
1259 .tconfig = &pt_tconfig,
1260 .tqueue = &pt_tqueue,
1261 .tvar = &perf1_tvar,
1262 .tlevel = pt1_tlevel,
1265 static struct test_config perf1_test2_config = {
1266 .ifname = "performance test 2 interface",
1267 .msg = "performance test 2 : use one RED configuration,\n"
1268 " set actual and average queue sizes to level in between min and max thresholds,\n"
1269 " measure enqueue performance\n\n",
1270 .tconfig = &pt_tconfig,
1271 .tqueue = &pt_tqueue,
1272 .tvar = &perf1_tvar,
1273 .tlevel = pt2_tlevel,
1276 static struct test_config perf1_test3_config = {
1277 .ifname = "performance test 3 interface",
1278 .msg = "performance test 3 : use one RED configuration,\n"
1279 " set actual and average queue sizes to level above max threshold,\n"
1280 " measure enqueue performance\n\n",
1281 .tconfig = &pt_tconfig,
1282 .tqueue = &pt_tqueue,
1283 .tvar = &perf1_tvar,
1284 .tlevel = pt3_tlevel,
1288 * Performance test function to measure enqueue performance.
1289 * This runs performance tests 1, 2 and 3
1291 static enum test_result perf1_test(struct test_config *tcfg)
1293 enum test_result result = PASS;
1294 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1297 printf("%s", tcfg->msg);
1299 rdtsc_prof_init(&prof, "enqueue");
1301 if (test_rte_red_init(tcfg) != PASS) {
1307 * set average queue size to target level
1309 *tcfg->tqueue->q = *tcfg->tlevel;
1312 * initialize the rte_red run time data structure
1314 rte_red_rt_data_init(tcfg->tqueue->rdata);
1317 * set the queue average
1319 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1320 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1326 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1327 tcfg->tqueue->rdata,
1329 tcfg->tvar->num_ops,
1330 tcfg->tvar->enqueued,
1331 tcfg->tvar->dropped,
1334 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1336 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1337 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1338 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1340 rdtsc_prof_print(&prof);
1346 * Setup test structures for tests P4, P5, P6
1347 * performance tests 4, 5 and 6
1349 static uint32_t pt4_tlevel[] = {16};
1350 static uint32_t pt5_tlevel[] = {80};
1351 static uint32_t pt6_tlevel[] = {144};
1353 static struct test_var perf2_tvar = {
1355 .num_iterations = 10000,
1357 .dropped = pt_dropped,
1358 .enqueued = pt_enqueued,
1362 static struct test_config perf2_test4_config = {
1363 .ifname = "performance test 4 interface",
1364 .msg = "performance test 4 : use one RED configuration,\n"
1365 " set actual and average queue sizes to level below min threshold,\n"
1366 " dequeue all packets until queue is empty,\n"
1367 " measure enqueue performance when queue is empty\n\n",
1368 .htxt = "iteration "
1375 .tconfig = &pt_tconfig,
1376 .tqueue = &pt_tqueue,
1377 .tvar = &perf2_tvar,
1378 .tlevel = pt4_tlevel,
1381 static struct test_config perf2_test5_config = {
1382 .ifname = "performance test 5 interface",
1383 .msg = "performance test 5 : use one RED configuration,\n"
1384 " set actual and average queue sizes to level in between min and max thresholds,\n"
1385 " dequeue all packets until queue is empty,\n"
1386 " measure enqueue performance when queue is empty\n\n",
1387 .htxt = "iteration "
1394 .tconfig = &pt_tconfig,
1395 .tqueue = &pt_tqueue,
1396 .tvar = &perf2_tvar,
1397 .tlevel = pt5_tlevel,
1400 static struct test_config perf2_test6_config = {
1401 .ifname = "performance test 6 interface",
1402 .msg = "performance test 6 : use one RED configuration,\n"
1403 " set actual and average queue sizes to level above max threshold,\n"
1404 " dequeue all packets until queue is empty,\n"
1405 " measure enqueue performance when queue is empty\n\n",
1406 .htxt = "iteration "
1413 .tconfig = &pt_tconfig,
1414 .tqueue = &pt_tqueue,
1415 .tvar = &perf2_tvar,
1416 .tlevel = pt6_tlevel,
1420 * Performance test function to measure enqueue performance when the
1421 * queue is empty. This runs performance tests 4, 5 and 6
1423 static enum test_result perf2_test(struct test_config *tcfg)
1425 enum test_result result = PASS;
1426 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1430 printf("%s", tcfg->msg);
1432 rdtsc_prof_init(&prof, "enqueue");
1434 if (test_rte_red_init(tcfg) != PASS) {
1439 printf("%s", tcfg->htxt);
1441 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1444 double avg_before = 0;
1448 * set average queue size to target level
1450 *tcfg->tqueue->q = *tcfg->tlevel;
1451 count = (*tcfg->tqueue->rdata).count;
1454 * initialize the rte_red run time data structure
1456 rte_red_rt_data_init(tcfg->tqueue->rdata);
1457 (*tcfg->tqueue->rdata).count = count;
1460 * set the queue average
1462 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1463 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1464 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1472 *tcfg->tqueue->q = 0;
1473 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1476 * wait for specified period of time
1478 rte_delay_us(tcfg->tvar->wait_usec);
1481 * measure performance of enqueue operation while queue is empty
1484 rdtsc_prof_start(&prof);
1485 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1486 *tcfg->tqueue->q, ts );
1487 rdtsc_prof_end(&prof);
1490 * gather enqueued/dropped statistics
1493 (*tcfg->tvar->enqueued)++;
1495 (*tcfg->tvar->dropped)++;
1498 * on first and last iteration, confirm that
1499 * average queue size was computed correctly
1501 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1502 double avg_after = 0;
1507 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1508 exp_avg = calc_exp_avg_on_empty(avg_before,
1509 (1 << *tcfg->tconfig->wq_log2),
1510 tcfg->tvar->wait_usec);
1511 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1513 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1514 i, avg_before, avg_after, exp_avg, diff,
1515 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1522 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1523 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1524 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1525 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1527 rdtsc_prof_print(&prof);
1533 * setup default values for overflow test structures
1535 static uint32_t avg_max = 0;
1536 static uint32_t avg_max_bits = 0;
1538 static struct rte_red_config ovfl_wrconfig[1];
1539 static struct rte_red ovfl_rtdata[1];
1540 static uint8_t ovfl_maxp_inv[] = {10};
1541 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1542 static uint32_t ovfl_q[] ={0};
1543 static uint32_t ovfl_dropped[] ={0};
1544 static uint32_t ovfl_enqueued[] ={0};
1545 static uint32_t ovfl_tlevel[] = {1023};
1546 static uint8_t ovfl_wq_log2[] = {12};
1548 static struct test_rte_red_config ovfl_tconfig = {
1549 .rconfig = ovfl_wrconfig,
1550 .num_cfg = RTE_DIM(ovfl_wrconfig),
1551 .wq_log2 = ovfl_wq_log2,
1554 .maxp_inv = ovfl_maxp_inv,
1557 static struct test_queue ovfl_tqueue = {
1558 .rdata = ovfl_rtdata,
1559 .num_queues = RTE_DIM(ovfl_rtdata),
1560 .qconfig = ovfl_qconfig,
1562 .q_ramp_up = 1000000,
1563 .avg_ramp_up = 1000000,
1564 .avg_tolerance = 5, /* 10 percent */
1565 .drop_tolerance = 50, /* 50 percent */
1568 static struct test_var ovfl_tvar = {
1570 .num_iterations = 1,
1573 .dropped = ovfl_dropped,
1574 .enqueued = ovfl_enqueued,
1578 static void ovfl_check_avg(uint32_t avg)
1580 if (avg > avg_max) {
1584 avg_log = log(((double)avg_max));
1585 avg_log = avg_log / log(2.0);
1586 bits = (uint32_t)ceil(avg_log);
1587 if (bits > avg_max_bits)
1588 avg_max_bits = bits;
1592 static struct test_config ovfl_test1_config = {
1593 .ifname = "queue average overflow test interface",
1594 .msg = "overflow test 1 : use one RED configuration,\n"
1595 " increase average queue size to target level,\n"
1596 " check maximum number of bits required to represent avg_s\n\n",
1597 .htxt = "avg queue size "
1607 .tconfig = &ovfl_tconfig,
1608 .tqueue = &ovfl_tqueue,
1610 .tlevel = ovfl_tlevel,
1613 static enum test_result ovfl_test1(struct test_config *tcfg)
1615 enum test_result result = PASS;
1618 double drop_rate = 0.0;
1619 double drop_prob = 0.0;
1623 printf("%s", tcfg->msg);
1625 if (test_rte_red_init(tcfg) != PASS) {
1632 * reset rte_red run-time data
1634 rte_red_rt_data_init(tcfg->tqueue->rdata);
1637 * increase actual queue size
1639 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1640 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1641 *tcfg->tqueue->q, get_port_ts());
1644 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1652 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1653 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1654 *tcfg->tqueue->q, get_port_ts());
1655 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1656 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1657 if (avg == *tcfg->tlevel) {
1659 (*tcfg->tvar->enqueued)++;
1661 (*tcfg->tvar->dropped)++;
1666 * check if target average queue size has been reached
1668 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1669 if (avg != *tcfg->tlevel) {
1675 * check drop rate against drop probability
1677 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1678 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1679 tcfg->tconfig->max_th,
1680 *tcfg->tconfig->maxp_inv,
1682 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1685 printf("%s", tcfg->htxt);
1687 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1688 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1689 avg_max, avg_max_bits,
1690 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1691 drop_prob * 100.0, drop_rate * 100.0);
1697 * define the functional and performance tests to be executed
1699 struct tests func_tests[] = {
1700 { &func_test1_config, func_test1 },
1701 { &func_test2_config, func_test2 },
1702 { &func_test3_config, func_test3 },
1703 { &func_test4_config, func_test4 },
1704 { &func_test5_config, func_test5 },
1705 { &func_test6_config, func_test6 },
1706 { &ovfl_test1_config, ovfl_test1 },
1709 struct tests func_tests_quick[] = {
1710 { &func_test1_config, func_test1 },
1711 { &func_test2_config, func_test2 },
1712 { &func_test3_config, func_test3 },
1713 /* no test 4 as it takes a lot of time */
1714 { &func_test5_config, func_test5 },
1715 { &func_test6_config, func_test6 },
1716 { &ovfl_test1_config, ovfl_test1 },
1719 struct tests perf_tests[] = {
1720 { &perf1_test1_config, perf1_test },
1721 { &perf1_test2_config, perf1_test },
1722 { &perf1_test3_config, perf1_test },
1723 { &perf2_test4_config, perf2_test },
1724 { &perf2_test5_config, perf2_test },
1725 { &perf2_test6_config, perf2_test },
1729 * function to execute the required_red tests
1731 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1733 enum test_result result = PASS;
1736 for (i = 0; i < test_count; i++) {
1737 printf("\n--------------------------------------------------------------------------------\n");
1738 result = test_type[i].testfn(test_type[i].testcfg);
1740 if (result == PASS) {
1742 printf("-------------------------------------<pass>-------------------------------------\n");
1744 printf("-------------------------------------<fail>-------------------------------------\n");
1751 * check if functions accept invalid parameters
1753 * First, all functions will be called without initialized RED
1754 * Then, all of them will be called with NULL/invalid parameters
1756 * Some functions are not tested as they are performance-critical and thus
1757 * don't do any parameter checking.
1760 test_invalid_parameters(void)
1762 struct rte_red_config config;
1764 if (rte_red_rt_data_init(NULL) == 0) {
1765 printf("rte_red_rt_data_init should have failed!\n");
1769 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1770 printf("rte_red_config_init should have failed!\n");
1774 if (rte_red_rt_data_init(NULL) == 0) {
1775 printf("rte_red_rt_data_init should have failed!\n");
1780 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1781 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1784 /* min_threshold == max_threshold */
1785 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1786 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1789 /* min_threshold > max_threshold */
1790 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1791 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1794 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1795 if (rte_red_config_init(&config,
1796 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1797 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1800 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1801 if (rte_red_config_init(&config,
1802 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1803 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1806 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1807 if (rte_red_config_init(&config,
1808 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1809 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1812 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1813 if (rte_red_config_init(&config,
1814 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1815 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1823 show_stats(const uint32_t num_tests, const uint32_t num_pass)
1825 if (num_pass == num_tests)
1826 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1828 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass,
1829 num_tests - num_pass);
1833 tell_the_result(const uint32_t num_tests, const uint32_t num_pass)
1835 return (num_pass == num_tests) ? 0 : 1;
1841 uint32_t num_tests = 0;
1842 uint32_t num_pass = 0;
1844 if (test_invalid_parameters() < 0)
1846 run_tests(func_tests_quick, RTE_DIM(func_tests_quick),
1847 &num_tests, &num_pass);
1848 show_stats(num_tests, num_pass);
1849 return tell_the_result(num_tests, num_pass);
1855 uint32_t num_tests = 0;
1856 uint32_t num_pass = 0;
1858 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1859 show_stats(num_tests, num_pass);
1860 return tell_the_result(num_tests, num_pass);
1866 uint32_t num_tests = 0;
1867 uint32_t num_pass = 0;
1869 if (test_invalid_parameters() < 0)
1872 run_tests(func_tests, RTE_DIM(func_tests), &num_tests, &num_pass);
1873 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1874 show_stats(num_tests, num_pass);
1875 return tell_the_result(num_tests, num_pass);
1878 #endif /* !RTE_EXEC_ENV_WINDOWS */
1880 REGISTER_TEST_COMMAND(red_autotest, test_red);
1881 REGISTER_TEST_COMMAND(red_perf, test_red_perf);
1882 REGISTER_TEST_COMMAND(red_all, test_red_all);