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.
48 #ifdef __INTEL_COMPILER
49 #pragma warning(disable:2259) /* conversion may lose significant bits */
50 #pragma warning(disable:181) /* Arg incompatible with format string */
53 #define TEST_HZ_PER_KHZ 1000
54 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */
56 #define MAX_QEMPTY_TIME_MSEC 50000
57 #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */
58 #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */
59 #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */
60 #define NSEC_PER_SEC (USEC_PER_SEC * 1000) /**< Nano-seconds per second */
62 /**< structures for testing rte_red performance and function */
63 struct test_rte_red_config { /**< Test structure for RTE_RED config */
64 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
65 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
66 uint8_t *wq_log2; /**< Test wq_log2 value to use */
67 uint32_t min_th; /**< Queue minimum threshold */
68 uint32_t max_th; /**< Queue maximum threshold */
69 uint8_t *maxp_inv; /**< Inverse mark probability */
72 struct test_queue { /**< Test structure for RTE_RED Queues */
73 struct rte_red *rdata; /**< RTE_RED runtime data */
74 uint32_t num_queues; /**< Number of RTE_RED queues to test */
75 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
76 uint32_t *q; /**< Queue size */
77 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
78 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
79 uint32_t avg_tolerance; /**< Tolerance in queue average */
80 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
83 struct test_var { /**< Test variables used for testing RTE_RED */
84 uint32_t wait_usec; /**< Micro second wait interval */
85 uint32_t num_iterations; /**< Number of test iterations */
86 uint32_t num_ops; /**< Number of test operations */
87 uint64_t clk_freq; /**< CPU clock frequency */
88 uint32_t sleep_sec; /**< Seconds to sleep */
89 uint32_t *dropped; /**< Test operations dropped */
90 uint32_t *enqueued; /**< Test operations enqueued */
93 struct test_config { /**< Master test structure for RTE_RED */
94 const char *ifname; /**< Interface name */
95 const char *msg; /**< Test message for display */
96 const char *htxt; /**< Header txt display for result output */
97 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
98 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
99 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
100 uint32_t *tlevel; /**< Queue levels */
108 /**< Test structure to define tests to run */
110 struct test_config *testcfg;
111 enum test_result (*testfn)(struct test_config *);
116 uint64_t clk_min; /**< min clocks */
117 uint64_t clk_max; /**< max clocks */
118 uint64_t clk_avgc; /**< count to calc average */
119 double clk_avg; /**< cumulative sum to calc average */
123 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
124 static double inv_cycles_per_byte = 0;
125 static double pkt_time_usec = 0;
127 static void init_port_ts(uint64_t cpu_clock)
129 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
130 inv_cycles_per_byte = 1.0 / cycles_per_byte;
131 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
134 static uint64_t get_port_ts(void)
136 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
139 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
141 p->clk_min = (uint64_t)(-1LL);
148 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
150 p->clk_start = rte_rdtsc_precise();
153 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
155 uint64_t clk_start = rte_rdtsc() - p->clk_start;
158 p->clk_avg += (double) clk_start;
160 if (clk_start > p->clk_max)
161 p->clk_max = clk_start;
162 if (clk_start < p->clk_min)
163 p->clk_min = clk_start;
166 static void rdtsc_prof_print(struct rdtsc_prof *p)
169 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
174 (p->clk_avg / ((double) p->clk_avgc)));
178 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
182 * scale by 1/n and convert from fixed-point to integer
184 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
187 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
191 * scale by 1/n and convert from fixed-point to floating-point
193 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
196 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
201 * scale by n and convert from integer to fixed-point
203 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
206 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
208 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
211 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
213 return (double)dropped / ((double)enqueued + (double)dropped);
217 * calculate the drop probability
219 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
220 uint32_t maxp_inv, uint32_t avg)
222 double drop_prob = 0.0;
226 } else if (avg < max_th) {
227 drop_prob = (1.0 / (double)maxp_inv)
228 * ((double)(avg - min_th)
229 / (double)(max_th - min_th));
237 * check if drop rate matches drop probability within tolerance
239 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
241 double abs_diff = 0.0;
244 abs_diff = fabs(drop_rate - drop_prob);
245 if ((int)abs_diff == 0) {
248 *diff = (abs_diff / drop_prob) * 100.0;
249 if (*diff > tolerance) {
257 * check if average queue size is within tolerance
259 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
261 double abs_diff = 0.0;
264 abs_diff = fabs(avg - exp_avg);
265 if ((int)abs_diff == 0) {
268 *diff = (abs_diff / exp_avg) * 100.0;
269 if (*diff > tolerance) {
277 * get the clk frequency in Hz
279 static uint64_t get_machclk_freq(void)
284 static uint64_t clk_freq_hz;
285 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
286 struct timespec req = {0, 0};
288 if (clk_freq_hz != 0)
292 req.tv_nsec = NSEC_PER_SEC / 4;
294 clock_gettime(CLOCK_REALTIME, &tv_start);
297 if (nanosleep(&req, NULL) != 0) {
298 perror("get_machclk_freq()");
302 clock_gettime(CLOCK_REALTIME, &tv_end);
305 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
306 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
307 USEC_PER_MSEC); /**< diff is in micro secs */
312 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
317 * initialize the test rte_red config
319 static enum test_result
320 test_rte_red_init(struct test_config *tcfg)
324 tcfg->tvar->clk_freq = get_machclk_freq();
325 init_port_ts( tcfg->tvar->clk_freq );
327 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
328 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
329 (uint16_t)tcfg->tconfig->wq_log2[i],
330 (uint16_t)tcfg->tconfig->min_th,
331 (uint16_t)tcfg->tconfig->max_th,
332 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
337 *tcfg->tqueue->q = 0;
338 *tcfg->tvar->dropped = 0;
339 *tcfg->tvar->enqueued = 0;
344 * enqueue until actual queue size reaches target level
347 increase_actual_qsize(struct rte_red_config *red_cfg,
355 for (i = 0; i < attempts; i++) {
361 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
368 * check if target actual queue size has been reached
379 * enqueue until average queue size reaches target level
382 increase_average_qsize(struct rte_red_config *red_cfg,
391 for (i = 0; i < num_ops; i++) {
395 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
398 * check if target average queue size has been reached
400 avg = rte_red_get_avg_int(red_cfg, red);
410 * setup default values for the functional test structures
412 static struct rte_red_config ft_wrconfig[1];
413 static struct rte_red ft_rtdata[1];
414 static uint8_t ft_wq_log2[] = {9};
415 static uint8_t ft_maxp_inv[] = {10};
416 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
417 static uint32_t ft_q[] ={0};
418 static uint32_t ft_dropped[] ={0};
419 static uint32_t ft_enqueued[] ={0};
421 static struct test_rte_red_config ft_tconfig = {
422 .rconfig = ft_wrconfig,
423 .num_cfg = RTE_DIM(ft_wrconfig),
424 .wq_log2 = ft_wq_log2,
427 .maxp_inv = ft_maxp_inv,
430 static struct test_queue ft_tqueue = {
432 .num_queues = RTE_DIM(ft_rtdata),
433 .qconfig = ft_qconfig,
435 .q_ramp_up = 1000000,
436 .avg_ramp_up = 1000000,
437 .avg_tolerance = 5, /* 5 percent */
438 .drop_tolerance = 50, /* 50 percent */
441 static struct test_var ft_tvar = {
446 .dropped = ft_dropped,
447 .enqueued = ft_enqueued,
448 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
452 * functional test enqueue/dequeue packets
454 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
463 for (i = 0; i < num_ops; i++) {
469 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
478 * Test F1: functional test 1
480 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};
482 static struct test_config func_test1_config = {
483 .ifname = "functional test 1 interface",
484 .msg = "functional test 1 : use one rte_red configuration,\n"
485 " increase average queue size to various levels,\n"
486 " compare drop rate to drop probability\n\n",
496 .tconfig = &ft_tconfig,
497 .tqueue = &ft_tqueue,
499 .tlevel = ft1_tlevels,
502 static enum test_result func_test1(struct test_config *tcfg)
504 enum test_result result = PASS;
507 printf("%s", tcfg->msg);
509 if (test_rte_red_init(tcfg) != PASS) {
514 printf("%s", tcfg->htxt);
516 for (i = 0; i < RTE_DIM(ft1_tlevels); i++) {
517 const char *label = NULL;
519 double drop_rate = 0.0;
520 double drop_prob = 0.0;
524 * reset rte_red run-time data
526 rte_red_rt_data_init(tcfg->tqueue->rdata);
527 *tcfg->tvar->enqueued = 0;
528 *tcfg->tvar->dropped = 0;
530 if (increase_actual_qsize(tcfg->tconfig->rconfig,
534 tcfg->tqueue->q_ramp_up) != 0) {
539 if (increase_average_qsize(tcfg->tconfig->rconfig,
543 tcfg->tqueue->avg_ramp_up) != 0) {
548 enqueue_dequeue_func(tcfg->tconfig->rconfig,
552 tcfg->tvar->enqueued,
553 tcfg->tvar->dropped);
555 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
556 if (avg != tcfg->tlevel[i]) {
557 fprintf(stderr, "Fail: avg != level\n");
561 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
562 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
563 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
564 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
567 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
568 label = "min thresh: ";
569 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
570 label = "max thresh: ";
573 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
574 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
575 drop_prob * 100.0, drop_rate * 100.0, diff,
576 (double)tcfg->tqueue->drop_tolerance);
583 * Test F2: functional test 2
585 static uint32_t ft2_tlevel[] = {127};
586 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
587 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
588 static struct rte_red_config ft2_rconfig[10];
590 static struct test_rte_red_config ft2_tconfig = {
591 .rconfig = ft2_rconfig,
592 .num_cfg = RTE_DIM(ft2_rconfig),
593 .wq_log2 = ft2_wq_log2,
596 .maxp_inv = ft2_maxp_inv,
599 static struct test_config func_test2_config = {
600 .ifname = "functional test 2 interface",
601 .msg = "functional test 2 : use several RED configurations,\n"
602 " increase average queue size to just below maximum threshold,\n"
603 " compare drop rate to drop probability\n\n",
604 .htxt = "RED config "
613 .tconfig = &ft2_tconfig,
614 .tqueue = &ft_tqueue,
616 .tlevel = ft2_tlevel,
619 static enum test_result func_test2(struct test_config *tcfg)
621 enum test_result result = PASS;
622 double prev_drop_rate = 1.0;
625 printf("%s", tcfg->msg);
627 if (test_rte_red_init(tcfg) != PASS) {
631 rte_red_rt_data_init(tcfg->tqueue->rdata);
633 if (increase_actual_qsize(tcfg->tconfig->rconfig,
637 tcfg->tqueue->q_ramp_up) != 0) {
642 if (increase_average_qsize(tcfg->tconfig->rconfig,
646 tcfg->tqueue->avg_ramp_up) != 0) {
650 printf("%s", tcfg->htxt);
652 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
654 double drop_rate = 0.0;
655 double drop_prob = 0.0;
658 *tcfg->tvar->dropped = 0;
659 *tcfg->tvar->enqueued = 0;
661 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
665 tcfg->tvar->enqueued,
666 tcfg->tvar->dropped);
668 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
669 if (avg != *tcfg->tlevel)
672 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
673 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
674 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
675 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
678 * drop rate should decrease as maxp_inv increases
680 if (drop_rate > prev_drop_rate)
682 prev_drop_rate = drop_rate;
684 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
685 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
686 drop_prob * 100.0, drop_rate * 100.0, diff,
687 (double)tcfg->tqueue->drop_tolerance);
694 * Test F3: functional test 3
696 static uint32_t ft3_tlevel[] = {1022};
698 static struct test_rte_red_config ft3_tconfig = {
699 .rconfig = ft_wrconfig,
700 .num_cfg = RTE_DIM(ft_wrconfig),
701 .wq_log2 = ft_wq_log2,
704 .maxp_inv = ft_maxp_inv,
707 static struct test_config func_test3_config = {
708 .ifname = "functional test 3 interface",
709 .msg = "functional test 3 : use one RED configuration,\n"
710 " increase average queue size to target level,\n"
711 " dequeue all packets until queue is empty,\n"
712 " confirm that average queue size is computed correctly while queue is empty\n\n",
713 .htxt = "q avg before "
720 .tconfig = &ft3_tconfig,
721 .tqueue = &ft_tqueue,
723 .tlevel = ft3_tlevel,
726 static enum test_result func_test3(struct test_config *tcfg)
728 enum test_result result = PASS;
731 printf("%s", tcfg->msg);
733 if (test_rte_red_init(tcfg) != PASS) {
738 rte_red_rt_data_init(tcfg->tqueue->rdata);
740 if (increase_actual_qsize(tcfg->tconfig->rconfig,
744 tcfg->tqueue->q_ramp_up) != 0) {
749 if (increase_average_qsize(tcfg->tconfig->rconfig,
753 tcfg->tqueue->avg_ramp_up) != 0) {
758 printf("%s", tcfg->htxt);
760 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
761 double avg_before = 0;
762 double avg_after = 0;
766 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
771 *tcfg->tqueue->q = 0;
772 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
774 rte_delay_us(tcfg->tvar->wait_usec);
777 * enqueue one packet to recalculate average queue size
779 if (rte_red_enqueue(tcfg->tconfig->rconfig,
782 get_port_ts()) == 0) {
783 (*tcfg->tqueue->q)++;
785 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
789 exp_avg = calc_exp_avg_on_empty(avg_before,
790 (1 << *tcfg->tconfig->wq_log2),
791 tcfg->tvar->wait_usec);
792 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
793 tcfg->tqueue->rdata);
794 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
797 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
798 avg_before, avg_after, exp_avg, diff,
799 (double)tcfg->tqueue->avg_tolerance,
800 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
807 * Test F4: functional test 4
809 static uint32_t ft4_tlevel[] = {1022};
810 static uint8_t ft4_wq_log2[] = {11};
812 static struct test_rte_red_config ft4_tconfig = {
813 .rconfig = ft_wrconfig,
814 .num_cfg = RTE_DIM(ft_wrconfig),
817 .wq_log2 = ft4_wq_log2,
818 .maxp_inv = ft_maxp_inv,
821 static struct test_queue ft4_tqueue = {
823 .num_queues = RTE_DIM(ft_rtdata),
824 .qconfig = ft_qconfig,
826 .q_ramp_up = 1000000,
827 .avg_ramp_up = 1000000,
828 .avg_tolerance = 0, /* 0 percent */
829 .drop_tolerance = 50, /* 50 percent */
832 static struct test_config func_test4_config = {
833 .ifname = "functional test 4 interface",
834 .msg = "functional test 4 : use one RED configuration,\n"
835 " increase average queue size to target level,\n"
836 " dequeue all packets until queue is empty,\n"
837 " confirm that average queue size is computed correctly while\n"
838 " queue is empty for more than 50 sec,\n"
839 " (this test takes 52 sec to run)\n\n",
840 .htxt = "q avg before "
847 .tconfig = &ft4_tconfig,
848 .tqueue = &ft4_tqueue,
850 .tlevel = ft4_tlevel,
853 static enum test_result func_test4(struct test_config *tcfg)
855 enum test_result result = PASS;
856 uint64_t time_diff = 0;
858 double avg_before = 0.0;
859 double avg_after = 0.0;
860 double exp_avg = 0.0;
863 printf("%s", tcfg->msg);
865 if (test_rte_red_init(tcfg) != PASS) {
870 rte_red_rt_data_init(tcfg->tqueue->rdata);
872 if (increase_actual_qsize(tcfg->tconfig->rconfig,
876 tcfg->tqueue->q_ramp_up) != 0) {
881 if (increase_average_qsize(tcfg->tconfig->rconfig,
885 tcfg->tqueue->avg_ramp_up) != 0) {
890 printf("%s", tcfg->htxt);
892 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
897 *tcfg->tqueue->q = 0;
898 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
901 * record empty time locally
905 sleep(tcfg->tvar->sleep_sec);
908 * enqueue one packet to recalculate average queue size
910 if (rte_red_enqueue(tcfg->tconfig->rconfig,
913 get_port_ts()) != 0) {
917 (*tcfg->tqueue->q)++;
920 * calculate how long queue has been empty
922 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
924 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
926 * this could happen if sleep was interrupted for some reason
933 * confirm that average queue size is now at expected level
936 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
937 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
940 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
941 avg_before, avg_after, exp_avg,
942 diff, (double)tcfg->tqueue->avg_tolerance,
943 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
949 * Test F5: functional test 5
951 static uint32_t ft5_tlevel[] = {127};
952 static uint8_t ft5_wq_log2[] = {9, 8};
953 static uint8_t ft5_maxp_inv[] = {10, 20};
954 static struct rte_red_config ft5_config[2];
955 static struct rte_red ft5_data[4];
956 static uint32_t ft5_q[4];
957 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
958 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
960 static struct test_rte_red_config ft5_tconfig = {
961 .rconfig = ft5_config,
962 .num_cfg = RTE_DIM(ft5_config),
965 .wq_log2 = ft5_wq_log2,
966 .maxp_inv = ft5_maxp_inv,
969 static struct test_queue ft5_tqueue = {
971 .num_queues = RTE_DIM(ft5_data),
972 .qconfig = ft_qconfig,
974 .q_ramp_up = 1000000,
975 .avg_ramp_up = 1000000,
976 .avg_tolerance = 5, /* 10 percent */
977 .drop_tolerance = 50, /* 50 percent */
980 struct test_var ft5_tvar = {
982 .num_iterations = 15,
985 .dropped = ft5_dropped,
986 .enqueued = ft5_enqueued,
990 static struct test_config func_test5_config = {
991 .ifname = "functional test 5 interface",
992 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
993 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
994 " increase average queue size to just below maximum threshold,\n"
995 " compare drop rate to drop probability,\n"
996 " (this is a larger scale version of functional test 2)\n\n",
1007 .tconfig = &ft5_tconfig,
1008 .tqueue = &ft5_tqueue,
1010 .tlevel = ft5_tlevel,
1013 static enum test_result func_test5(struct test_config *tcfg)
1015 enum test_result result = PASS;
1018 printf("%s", tcfg->msg);
1020 if (test_rte_red_init(tcfg) != PASS) {
1025 printf("%s", tcfg->htxt);
1027 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1028 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1029 tcfg->tqueue->q[j] = 0;
1031 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1032 &tcfg->tqueue->rdata[j],
1033 &tcfg->tqueue->q[j],
1035 tcfg->tqueue->q_ramp_up) != 0) {
1040 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1041 &tcfg->tqueue->rdata[j],
1042 &tcfg->tqueue->q[j],
1044 tcfg->tqueue->avg_ramp_up) != 0) {
1050 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1052 double drop_rate = 0.0;
1053 double drop_prob = 0.0;
1056 tcfg->tvar->dropped[j] = 0;
1057 tcfg->tvar->enqueued[j] = 0;
1059 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1060 &tcfg->tqueue->rdata[j],
1061 &tcfg->tqueue->q[j],
1062 tcfg->tvar->num_ops,
1063 &tcfg->tvar->enqueued[j],
1064 &tcfg->tvar->dropped[j]);
1066 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1067 &tcfg->tqueue->rdata[j]);
1068 if (avg != *tcfg->tlevel)
1071 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1072 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1073 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1075 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1078 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1079 j, tcfg->tqueue->qconfig[j], avg,
1080 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1081 drop_prob * 100.0, drop_rate * 100.0,
1082 diff, (double)tcfg->tqueue->drop_tolerance);
1089 * Test F6: functional test 6
1091 static uint32_t ft6_tlevel[] = {1022};
1092 static uint8_t ft6_wq_log2[] = {9, 8};
1093 static uint8_t ft6_maxp_inv[] = {10, 20};
1094 static struct rte_red_config ft6_config[2];
1095 static struct rte_red ft6_data[4];
1096 static uint32_t ft6_q[4];
1098 static struct test_rte_red_config ft6_tconfig = {
1099 .rconfig = ft6_config,
1100 .num_cfg = RTE_DIM(ft6_config),
1103 .wq_log2 = ft6_wq_log2,
1104 .maxp_inv = ft6_maxp_inv,
1107 static struct test_queue ft6_tqueue = {
1109 .num_queues = RTE_DIM(ft6_data),
1110 .qconfig = ft_qconfig,
1112 .q_ramp_up = 1000000,
1113 .avg_ramp_up = 1000000,
1114 .avg_tolerance = 5, /* 10 percent */
1115 .drop_tolerance = 50, /* 50 percent */
1118 static struct test_config func_test6_config = {
1119 .ifname = "functional test 6 interface",
1120 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1121 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1122 " increase average queue size to target level,\n"
1123 " dequeue all packets until queue is empty,\n"
1124 " confirm that average queue size is computed correctly while queue is empty\n"
1125 " (this is a larger scale version of functional test 3)\n\n",
1134 .tconfig = &ft6_tconfig,
1135 .tqueue = &ft6_tqueue,
1137 .tlevel = ft6_tlevel,
1140 static enum test_result func_test6(struct test_config *tcfg)
1142 enum test_result result = PASS;
1145 printf("%s", tcfg->msg);
1146 if (test_rte_red_init(tcfg) != PASS) {
1150 printf("%s", tcfg->htxt);
1152 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1153 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1154 tcfg->tqueue->q[j] = 0;
1156 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1157 &tcfg->tqueue->rdata[j],
1158 &tcfg->tqueue->q[j],
1160 tcfg->tqueue->q_ramp_up) != 0) {
1164 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1165 &tcfg->tqueue->rdata[j],
1166 &tcfg->tqueue->q[j],
1168 tcfg->tqueue->avg_ramp_up) != 0) {
1173 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1174 double avg_before = 0;
1175 double avg_after = 0;
1179 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1180 &tcfg->tqueue->rdata[j]);
1185 tcfg->tqueue->q[j] = 0;
1186 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1187 rte_delay_us(tcfg->tvar->wait_usec);
1190 * enqueue one packet to recalculate average queue size
1192 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1193 &tcfg->tqueue->rdata[j],
1195 get_port_ts()) == 0) {
1196 tcfg->tqueue->q[j]++;
1198 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1202 exp_avg = calc_exp_avg_on_empty(avg_before,
1203 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1204 tcfg->tvar->wait_usec);
1205 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1206 &tcfg->tqueue->rdata[j]);
1207 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1210 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1211 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1212 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1213 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1220 * setup default values for the performance test structures
1222 static struct rte_red_config pt_wrconfig[1];
1223 static struct rte_red pt_rtdata[1];
1224 static uint8_t pt_wq_log2[] = {9};
1225 static uint8_t pt_maxp_inv[] = {10};
1226 static uint32_t pt_qconfig[] = {0};
1227 static uint32_t pt_q[] = {0};
1228 static uint32_t pt_dropped[] = {0};
1229 static uint32_t pt_enqueued[] = {0};
1231 static struct test_rte_red_config pt_tconfig = {
1232 .rconfig = pt_wrconfig,
1233 .num_cfg = RTE_DIM(pt_wrconfig),
1234 .wq_log2 = pt_wq_log2,
1237 .maxp_inv = pt_maxp_inv,
1240 static struct test_queue pt_tqueue = {
1242 .num_queues = RTE_DIM(pt_rtdata),
1243 .qconfig = pt_qconfig,
1245 .q_ramp_up = 1000000,
1246 .avg_ramp_up = 1000000,
1247 .avg_tolerance = 5, /* 10 percent */
1248 .drop_tolerance = 50, /* 50 percent */
1252 * enqueue/dequeue packets
1254 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1255 struct rte_red *red,
1260 struct rdtsc_prof *prof)
1264 for (i = 0; i < num_ops; i++) {
1271 rdtsc_prof_start(prof);
1272 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1273 rdtsc_prof_end(prof);
1282 * Setup test structures for tests P1, P2, P3
1283 * performance tests 1, 2 and 3
1285 static uint32_t pt1_tlevel[] = {16};
1286 static uint32_t pt2_tlevel[] = {80};
1287 static uint32_t pt3_tlevel[] = {144};
1289 static struct test_var perf1_tvar = {
1291 .num_iterations = 15,
1292 .num_ops = 50000000,
1294 .dropped = pt_dropped,
1295 .enqueued = pt_enqueued,
1299 static struct test_config perf1_test1_config = {
1300 .ifname = "performance test 1 interface",
1301 .msg = "performance test 1 : use one RED configuration,\n"
1302 " set actual and average queue sizes to level below min threshold,\n"
1303 " measure enqueue performance\n\n",
1304 .tconfig = &pt_tconfig,
1305 .tqueue = &pt_tqueue,
1306 .tvar = &perf1_tvar,
1307 .tlevel = pt1_tlevel,
1310 static struct test_config perf1_test2_config = {
1311 .ifname = "performance test 2 interface",
1312 .msg = "performance test 2 : use one RED configuration,\n"
1313 " set actual and average queue sizes to level in between min and max thresholds,\n"
1314 " measure enqueue performance\n\n",
1315 .tconfig = &pt_tconfig,
1316 .tqueue = &pt_tqueue,
1317 .tvar = &perf1_tvar,
1318 .tlevel = pt2_tlevel,
1321 static struct test_config perf1_test3_config = {
1322 .ifname = "performance test 3 interface",
1323 .msg = "performance test 3 : use one RED configuration,\n"
1324 " set actual and average queue sizes to level above max threshold,\n"
1325 " measure enqueue performance\n\n",
1326 .tconfig = &pt_tconfig,
1327 .tqueue = &pt_tqueue,
1328 .tvar = &perf1_tvar,
1329 .tlevel = pt3_tlevel,
1333 * Performance test function to measure enqueue performance.
1334 * This runs performance tests 1, 2 and 3
1336 static enum test_result perf1_test(struct test_config *tcfg)
1338 enum test_result result = PASS;
1339 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1342 printf("%s", tcfg->msg);
1344 rdtsc_prof_init(&prof, "enqueue");
1346 if (test_rte_red_init(tcfg) != PASS) {
1352 * set average queue size to target level
1354 *tcfg->tqueue->q = *tcfg->tlevel;
1357 * initialize the rte_red run time data structure
1359 rte_red_rt_data_init(tcfg->tqueue->rdata);
1362 * set the queue average
1364 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1365 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1371 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1372 tcfg->tqueue->rdata,
1374 tcfg->tvar->num_ops,
1375 tcfg->tvar->enqueued,
1376 tcfg->tvar->dropped,
1379 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1381 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1382 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1383 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1385 rdtsc_prof_print(&prof);
1391 * Setup test structures for tests P4, P5, P6
1392 * performance tests 4, 5 and 6
1394 static uint32_t pt4_tlevel[] = {16};
1395 static uint32_t pt5_tlevel[] = {80};
1396 static uint32_t pt6_tlevel[] = {144};
1398 static struct test_var perf2_tvar = {
1400 .num_iterations = 10000,
1402 .dropped = pt_dropped,
1403 .enqueued = pt_enqueued,
1407 static struct test_config perf2_test4_config = {
1408 .ifname = "performance test 4 interface",
1409 .msg = "performance test 4 : use one RED configuration,\n"
1410 " set actual and average queue sizes to level below min threshold,\n"
1411 " dequeue all packets until queue is empty,\n"
1412 " measure enqueue performance when queue is empty\n\n",
1413 .htxt = "iteration "
1420 .tconfig = &pt_tconfig,
1421 .tqueue = &pt_tqueue,
1422 .tvar = &perf2_tvar,
1423 .tlevel = pt4_tlevel,
1426 static struct test_config perf2_test5_config = {
1427 .ifname = "performance test 5 interface",
1428 .msg = "performance test 5 : use one RED configuration,\n"
1429 " set actual and average queue sizes to level in between min and max thresholds,\n"
1430 " dequeue all packets until queue is empty,\n"
1431 " measure enqueue performance when queue is empty\n\n",
1432 .htxt = "iteration "
1439 .tconfig = &pt_tconfig,
1440 .tqueue = &pt_tqueue,
1441 .tvar = &perf2_tvar,
1442 .tlevel = pt5_tlevel,
1445 static struct test_config perf2_test6_config = {
1446 .ifname = "performance test 6 interface",
1447 .msg = "performance test 6 : use one RED configuration,\n"
1448 " set actual and average queue sizes to level above max threshold,\n"
1449 " dequeue all packets until queue is empty,\n"
1450 " measure enqueue performance when queue is empty\n\n",
1451 .htxt = "iteration "
1458 .tconfig = &pt_tconfig,
1459 .tqueue = &pt_tqueue,
1460 .tvar = &perf2_tvar,
1461 .tlevel = pt6_tlevel,
1465 * Performance test function to measure enqueue performance when the
1466 * queue is empty. This runs performance tests 4, 5 and 6
1468 static enum test_result perf2_test(struct test_config *tcfg)
1470 enum test_result result = PASS;
1471 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1475 printf("%s", tcfg->msg);
1477 rdtsc_prof_init(&prof, "enqueue");
1479 if (test_rte_red_init(tcfg) != PASS) {
1484 printf("%s", tcfg->htxt);
1486 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1489 double avg_before = 0;
1493 * set average queue size to target level
1495 *tcfg->tqueue->q = *tcfg->tlevel;
1496 count = (*tcfg->tqueue->rdata).count;
1499 * initialize the rte_red run time data structure
1501 rte_red_rt_data_init(tcfg->tqueue->rdata);
1502 (*tcfg->tqueue->rdata).count = count;
1505 * set the queue average
1507 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1508 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1509 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1517 *tcfg->tqueue->q = 0;
1518 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1521 * wait for specified period of time
1523 rte_delay_us(tcfg->tvar->wait_usec);
1526 * measure performance of enqueue operation while queue is empty
1529 rdtsc_prof_start(&prof);
1530 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1531 *tcfg->tqueue->q, ts );
1532 rdtsc_prof_end(&prof);
1535 * gather enqueued/dropped statistics
1538 (*tcfg->tvar->enqueued)++;
1540 (*tcfg->tvar->dropped)++;
1543 * on first and last iteration, confirm that
1544 * average queue size was computed correctly
1546 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1547 double avg_after = 0;
1552 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1553 exp_avg = calc_exp_avg_on_empty(avg_before,
1554 (1 << *tcfg->tconfig->wq_log2),
1555 tcfg->tvar->wait_usec);
1556 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1558 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1559 i, avg_before, avg_after, exp_avg, diff,
1560 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1567 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1568 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1569 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1570 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1572 rdtsc_prof_print(&prof);
1578 * setup default values for overflow test structures
1580 static uint32_t avg_max = 0;
1581 static uint32_t avg_max_bits = 0;
1583 static struct rte_red_config ovfl_wrconfig[1];
1584 static struct rte_red ovfl_rtdata[1];
1585 static uint8_t ovfl_maxp_inv[] = {10};
1586 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1587 static uint32_t ovfl_q[] ={0};
1588 static uint32_t ovfl_dropped[] ={0};
1589 static uint32_t ovfl_enqueued[] ={0};
1590 static uint32_t ovfl_tlevel[] = {1023};
1591 static uint8_t ovfl_wq_log2[] = {12};
1593 static struct test_rte_red_config ovfl_tconfig = {
1594 .rconfig = ovfl_wrconfig,
1595 .num_cfg = RTE_DIM(ovfl_wrconfig),
1596 .wq_log2 = ovfl_wq_log2,
1599 .maxp_inv = ovfl_maxp_inv,
1602 static struct test_queue ovfl_tqueue = {
1603 .rdata = ovfl_rtdata,
1604 .num_queues = RTE_DIM(ovfl_rtdata),
1605 .qconfig = ovfl_qconfig,
1607 .q_ramp_up = 1000000,
1608 .avg_ramp_up = 1000000,
1609 .avg_tolerance = 5, /* 10 percent */
1610 .drop_tolerance = 50, /* 50 percent */
1613 static struct test_var ovfl_tvar = {
1615 .num_iterations = 1,
1618 .dropped = ovfl_dropped,
1619 .enqueued = ovfl_enqueued,
1623 static void ovfl_check_avg(uint32_t avg)
1625 if (avg > avg_max) {
1629 avg_log = log(((double)avg_max));
1630 avg_log = avg_log / log(2.0);
1631 bits = (uint32_t)ceil(avg_log);
1632 if (bits > avg_max_bits)
1633 avg_max_bits = bits;
1637 static struct test_config ovfl_test1_config = {
1638 .ifname = "queue avergage overflow test interface",
1639 .msg = "overflow test 1 : use one RED configuration,\n"
1640 " increase average queue size to target level,\n"
1641 " check maximum number of bits requirte_red to represent avg_s\n\n",
1642 .htxt = "avg queue size "
1652 .tconfig = &ovfl_tconfig,
1653 .tqueue = &ovfl_tqueue,
1655 .tlevel = ovfl_tlevel,
1658 static enum test_result ovfl_test1(struct test_config *tcfg)
1660 enum test_result result = PASS;
1663 double drop_rate = 0.0;
1664 double drop_prob = 0.0;
1668 printf("%s", tcfg->msg);
1670 if (test_rte_red_init(tcfg) != PASS) {
1677 * reset rte_red run-time data
1679 rte_red_rt_data_init(tcfg->tqueue->rdata);
1682 * increase actual queue size
1684 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1685 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1686 *tcfg->tqueue->q, get_port_ts());
1689 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1697 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1698 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1699 *tcfg->tqueue->q, get_port_ts());
1700 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1701 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1702 if (avg == *tcfg->tlevel) {
1704 (*tcfg->tvar->enqueued)++;
1706 (*tcfg->tvar->dropped)++;
1711 * check if target average queue size has been reached
1713 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1714 if (avg != *tcfg->tlevel) {
1720 * check drop rate against drop probability
1722 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1723 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1724 tcfg->tconfig->max_th,
1725 *tcfg->tconfig->maxp_inv,
1727 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1730 printf("%s", tcfg->htxt);
1732 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1733 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1734 avg_max, avg_max_bits,
1735 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1736 drop_prob * 100.0, drop_rate * 100.0);
1742 * define the functional and performance tests to be executed
1744 struct tests func_tests[] = {
1745 { &func_test1_config, func_test1 },
1746 { &func_test2_config, func_test2 },
1747 { &func_test3_config, func_test3 },
1748 { &func_test4_config, func_test4 },
1749 { &func_test5_config, func_test5 },
1750 { &func_test6_config, func_test6 },
1751 { &ovfl_test1_config, ovfl_test1 },
1754 struct tests func_tests_quick[] = {
1755 { &func_test1_config, func_test1 },
1756 { &func_test2_config, func_test2 },
1757 { &func_test3_config, func_test3 },
1758 /* no test 4 as it takes a lot of time */
1759 { &func_test5_config, func_test5 },
1760 { &func_test6_config, func_test6 },
1761 { &ovfl_test1_config, ovfl_test1 },
1764 struct tests perf_tests[] = {
1765 { &perf1_test1_config, perf1_test },
1766 { &perf1_test2_config, perf1_test },
1767 { &perf1_test3_config, perf1_test },
1768 { &perf2_test4_config, perf2_test },
1769 { &perf2_test5_config, perf2_test },
1770 { &perf2_test6_config, perf2_test },
1774 * function to execute the required_red tests
1776 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1778 enum test_result result = PASS;
1781 for (i = 0; i < test_count; i++) {
1782 printf("\n--------------------------------------------------------------------------------\n");
1783 result = test_type[i].testfn(test_type[i].testcfg);
1785 if (result == PASS) {
1787 printf("-------------------------------------<pass>-------------------------------------\n");
1789 printf("-------------------------------------<fail>-------------------------------------\n");
1796 * check if functions accept invalid parameters
1798 * First, all functions will be called without initialized RED
1799 * Then, all of them will be called with NULL/invalid parameters
1801 * Some functions are not tested as they are performance-critical and thus
1802 * don't do any parameter checking.
1805 test_invalid_parameters(void)
1807 struct rte_red_config config;
1809 if (rte_red_rt_data_init(NULL) == 0) {
1810 printf("rte_red_rt_data_init should have failed!\n");
1814 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1815 printf("rte_red_config_init should have failed!\n");
1819 if (rte_red_rt_data_init(NULL) == 0) {
1820 printf("rte_red_rt_data_init should have failed!\n");
1825 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1826 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1829 /* min_treshold == max_treshold */
1830 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1831 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1834 /* min_treshold > max_treshold */
1835 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1836 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1839 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1840 if (rte_red_config_init(&config,
1841 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1842 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1845 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1846 if (rte_red_config_init(&config,
1847 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1848 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1851 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1852 if (rte_red_config_init(&config,
1853 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1854 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1857 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1858 if (rte_red_config_init(&config,
1859 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1860 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1868 show_stats(const uint32_t num_tests, const uint32_t num_pass)
1870 if (num_pass == num_tests)
1871 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1873 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass,
1874 num_tests - num_pass);
1878 tell_the_result(const uint32_t num_tests, const uint32_t num_pass)
1880 return (num_pass == num_tests) ? 0 : 1;
1886 uint32_t num_tests = 0;
1887 uint32_t num_pass = 0;
1889 if (test_invalid_parameters() < 0)
1891 run_tests(func_tests_quick, RTE_DIM(func_tests_quick),
1892 &num_tests, &num_pass);
1893 show_stats(num_tests, num_pass);
1894 return tell_the_result(num_tests, num_pass);
1900 uint32_t num_tests = 0;
1901 uint32_t num_pass = 0;
1903 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1904 show_stats(num_tests, num_pass);
1905 return tell_the_result(num_tests, num_pass);
1911 uint32_t num_tests = 0;
1912 uint32_t num_pass = 0;
1914 if (test_invalid_parameters() < 0)
1917 run_tests(func_tests, RTE_DIM(func_tests), &num_tests, &num_pass);
1918 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1919 show_stats(num_tests, num_pass);
1920 return tell_the_result(num_tests, num_pass);
1923 static struct test_command red_cmd = {
1924 .command = "red_autotest",
1925 .callback = test_red,
1927 REGISTER_TEST_COMMAND(red_cmd);
1929 static struct test_command red_cmd_perf = {
1930 .command = "red_perf",
1931 .callback = test_red_perf,
1933 REGISTER_TEST_COMMAND(red_cmd_perf);
1935 static struct test_command red_cmd_all = {
1936 .command = "red_all",
1937 .callback = test_red_all,
1939 REGISTER_TEST_COMMAND(red_cmd_all);