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 */
61 /**< structures for testing rte_red performance and function */
62 struct test_rte_red_config { /**< Test structure for RTE_RED config */
63 struct rte_red_config *rconfig; /**< RTE_RED configuration parameters */
64 uint8_t num_cfg; /**< Number of RTE_RED configs to test */
65 uint8_t *wq_log2; /**< Test wq_log2 value to use */
66 uint32_t min_th; /**< Queue minimum threshold */
67 uint32_t max_th; /**< Queue maximum threshold */
68 uint8_t *maxp_inv; /**< Inverse mark probability */
71 struct test_queue { /**< Test structure for RTE_RED Queues */
72 struct rte_red *rdata; /**< RTE_RED runtime data */
73 uint32_t num_queues; /**< Number of RTE_RED queues to test */
74 uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */
75 uint32_t *q; /**< Queue size */
76 uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */
77 uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */
78 uint32_t avg_tolerance; /**< Tolerance in queue average */
79 double drop_tolerance; /**< Drop tolerance of packets not enqueued */
82 struct test_var { /**< Test variables used for testing RTE_RED */
83 uint32_t wait_usec; /**< Micro second wait interval */
84 uint32_t num_iterations; /**< Number of test iterations */
85 uint32_t num_ops; /**< Number of test operations */
86 uint64_t clk_freq; /**< CPU clock frequency */
87 uint32_t sleep_sec; /**< Seconds to sleep */
88 uint32_t *dropped; /**< Test operations dropped */
89 uint32_t *enqueued; /**< Test operations enqueued */
92 struct test_config { /**< Master test structure for RTE_RED */
93 const char *ifname; /**< Interface name */
94 const char *msg; /**< Test message for display */
95 const char *htxt; /**< Header txt display for result output */
96 struct test_rte_red_config *tconfig; /**< Test structure for RTE_RED config */
97 struct test_queue *tqueue; /**< Test structure for RTE_RED Queues */
98 struct test_var *tvar; /**< Test variables used for testing RTE_RED */
99 uint32_t *tlevel; /**< Queue levels */
107 /**< Test structure to define tests to run */
109 struct test_config *testcfg;
110 enum test_result (*testfn)(struct test_config *);
115 uint64_t clk_min; /**< min clocks */
116 uint64_t clk_max; /**< max clocks */
117 uint64_t clk_avgc; /**< count to calc average */
118 double clk_avg; /**< cumulative sum to calc average */
122 static const uint64_t port_speed_bytes = (10ULL*1000ULL*1000ULL*1000ULL)/8ULL;
123 static double inv_cycles_per_byte = 0;
124 static double pkt_time_usec = 0;
126 static void init_port_ts(uint64_t cpu_clock)
128 double cycles_per_byte = (double)(cpu_clock) / (double)(port_speed_bytes);
129 inv_cycles_per_byte = 1.0 / cycles_per_byte;
130 pkt_time_usec = 1000000.0 / ((double)port_speed_bytes / (double)RTE_RED_S);
133 static uint64_t get_port_ts(void)
135 return (uint64_t)((double)rte_rdtsc() * inv_cycles_per_byte);
138 static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name)
140 p->clk_min = (uint64_t)(-1LL);
147 static inline void rdtsc_prof_start(struct rdtsc_prof *p)
149 p->clk_start = rte_rdtsc_precise();
152 static inline void rdtsc_prof_end(struct rdtsc_prof *p)
154 uint64_t clk_start = rte_rdtsc() - p->clk_start;
157 p->clk_avg += (double) clk_start;
159 if (clk_start > p->clk_max)
160 p->clk_max = clk_start;
161 if (clk_start < p->clk_min)
162 p->clk_min = clk_start;
165 static void rdtsc_prof_print(struct rdtsc_prof *p)
168 printf("RDTSC stats for %s: n=%" PRIu64 ", min=%" PRIu64 ", max=%" PRIu64 ", avg=%.1f\n",
173 (p->clk_avg / ((double) p->clk_avgc)));
177 static uint32_t rte_red_get_avg_int(const struct rte_red_config *red_cfg,
181 * scale by 1/n and convert from fixed-point to integer
183 return red->avg >> (RTE_RED_SCALING + red_cfg->wq_log2);
186 static double rte_red_get_avg_float(const struct rte_red_config *red_cfg,
190 * scale by 1/n and convert from fixed-point to floating-point
192 return ldexp((double)red->avg, -(RTE_RED_SCALING + red_cfg->wq_log2));
195 static void rte_red_set_avg_int(const struct rte_red_config *red_cfg,
200 * scale by n and convert from integer to fixed-point
202 red->avg = avg << (RTE_RED_SCALING + red_cfg->wq_log2);
205 static double calc_exp_avg_on_empty(double avg, uint32_t n, uint32_t time_diff)
207 return avg * pow((1.0 - 1.0 / (double)n), (double)time_diff / pkt_time_usec);
210 static double calc_drop_rate(uint32_t enqueued, uint32_t dropped)
212 return (double)dropped / ((double)enqueued + (double)dropped);
216 * calculate the drop probability
218 static double calc_drop_prob(uint32_t min_th, uint32_t max_th,
219 uint32_t maxp_inv, uint32_t avg)
221 double drop_prob = 0.0;
225 } else if (avg < max_th) {
226 drop_prob = (1.0 / (double)maxp_inv)
227 * ((double)(avg - min_th)
228 / (double)(max_th - min_th));
236 * check if drop rate matches drop probability within tolerance
238 static int check_drop_rate(double *diff, double drop_rate, double drop_prob, double tolerance)
240 double abs_diff = 0.0;
243 abs_diff = fabs(drop_rate - drop_prob);
244 if ((int)abs_diff == 0) {
247 *diff = (abs_diff / drop_prob) * 100.0;
248 if (*diff > tolerance) {
256 * check if average queue size is within tolerance
258 static int check_avg(double *diff, double avg, double exp_avg, double tolerance)
260 double abs_diff = 0.0;
263 abs_diff = fabs(avg - exp_avg);
264 if ((int)abs_diff == 0) {
267 *diff = (abs_diff / exp_avg) * 100.0;
268 if (*diff > tolerance) {
276 * get the clk frequency in Hz
278 static uint64_t get_machclk_freq(void)
283 uint64_t clk_freq_hz = 0;
284 struct timespec tv_start = {0, 0}, tv_end = {0, 0};
285 struct timespec req = {0, 0};
290 clock_gettime(CLOCK_REALTIME, &tv_start);
293 if (nanosleep(&req, NULL) != 0) {
294 perror("get_machclk_freq()");
298 clock_gettime(CLOCK_REALTIME, &tv_end);
301 diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
302 + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
303 USEC_PER_MSEC); /**< diff is in micro secs */
308 clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
313 * initialize the test rte_red config
315 static enum test_result
316 test_rte_red_init(struct test_config *tcfg)
320 tcfg->tvar->clk_freq = get_machclk_freq();
321 init_port_ts( tcfg->tvar->clk_freq );
323 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
324 if (rte_red_config_init(&tcfg->tconfig->rconfig[i],
325 (uint16_t)tcfg->tconfig->wq_log2[i],
326 (uint16_t)tcfg->tconfig->min_th,
327 (uint16_t)tcfg->tconfig->max_th,
328 (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) {
333 *tcfg->tqueue->q = 0;
334 *tcfg->tvar->dropped = 0;
335 *tcfg->tvar->enqueued = 0;
340 * enqueue until actual queue size reaches target level
343 increase_actual_qsize(struct rte_red_config *red_cfg,
351 for (i = 0; i < attempts; i++) {
357 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts() );
364 * check if target actual queue size has been reached
375 * enqueue until average queue size reaches target level
378 increase_average_qsize(struct rte_red_config *red_cfg,
387 for (i = 0; i < num_ops; i++) {
391 rte_red_enqueue(red_cfg, red, *q, get_port_ts());
394 * check if target average queue size has been reached
396 avg = rte_red_get_avg_int(red_cfg, red);
406 * setup default values for the functional test structures
408 static struct rte_red_config ft_wrconfig[1];
409 static struct rte_red ft_rtdata[1];
410 static uint8_t ft_wq_log2[] = {9};
411 static uint8_t ft_maxp_inv[] = {10};
412 static uint32_t ft_qconfig[] = {0, 0, 1, 1};
413 static uint32_t ft_q[] ={0};
414 static uint32_t ft_dropped[] ={0};
415 static uint32_t ft_enqueued[] ={0};
417 static struct test_rte_red_config ft_tconfig = {
418 .rconfig = ft_wrconfig,
419 .num_cfg = RTE_DIM(ft_wrconfig),
420 .wq_log2 = ft_wq_log2,
423 .maxp_inv = ft_maxp_inv,
426 static struct test_queue ft_tqueue = {
428 .num_queues = RTE_DIM(ft_rtdata),
429 .qconfig = ft_qconfig,
431 .q_ramp_up = 1000000,
432 .avg_ramp_up = 1000000,
433 .avg_tolerance = 5, /* 5 percent */
434 .drop_tolerance = 50, /* 50 percent */
437 static struct test_var ft_tvar = {
439 .num_iterations = 20,
442 .dropped = ft_dropped,
443 .enqueued = ft_enqueued,
444 .sleep_sec = (MAX_QEMPTY_TIME_MSEC / MSEC_PER_SEC) + 2,
448 * functional test enqueue/dequeue packets
450 static void enqueue_dequeue_func(struct rte_red_config *red_cfg,
459 for (i = 0; i < num_ops; i++) {
465 ret = rte_red_enqueue(red_cfg, red, *q, get_port_ts());
474 * Test F1: functional test 1
476 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};
478 static struct test_config func_test1_config = {
479 .ifname = "functional test 1 interface",
480 .msg = "functional test 1 : use one rte_red configuration,\n"
481 " increase average queue size to various levels,\n"
482 " compare drop rate to drop probability\n\n",
492 .tconfig = &ft_tconfig,
493 .tqueue = &ft_tqueue,
495 .tlevel = ft1_tlevels,
498 static enum test_result func_test1(struct test_config *tcfg)
500 enum test_result result = PASS;
503 printf("%s", tcfg->msg);
505 if (test_rte_red_init(tcfg) != PASS) {
510 printf("%s", tcfg->htxt);
512 for (i = 0; i < RTE_DIM(ft1_tlevels); i++) {
513 const char *label = NULL;
515 double drop_rate = 0.0;
516 double drop_prob = 0.0;
520 * reset rte_red run-time data
522 rte_red_rt_data_init(tcfg->tqueue->rdata);
523 *tcfg->tvar->enqueued = 0;
524 *tcfg->tvar->dropped = 0;
526 if (increase_actual_qsize(tcfg->tconfig->rconfig,
530 tcfg->tqueue->q_ramp_up) != 0) {
535 if (increase_average_qsize(tcfg->tconfig->rconfig,
539 tcfg->tqueue->avg_ramp_up) != 0) {
544 enqueue_dequeue_func(tcfg->tconfig->rconfig,
548 tcfg->tvar->enqueued,
549 tcfg->tvar->dropped);
551 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
552 if (avg != tcfg->tlevel[i]) {
553 fprintf(stderr, "Fail: avg != level\n");
557 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
558 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
559 *tcfg->tconfig->maxp_inv, tcfg->tlevel[i]);
560 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
563 if (tcfg->tlevel[i] == tcfg->tconfig->min_th)
564 label = "min thresh: ";
565 else if (tcfg->tlevel[i] == tcfg->tconfig->max_th)
566 label = "max thresh: ";
569 printf("%s%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
570 label, avg, *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
571 drop_prob * 100.0, drop_rate * 100.0, diff,
572 (double)tcfg->tqueue->drop_tolerance);
579 * Test F2: functional test 2
581 static uint32_t ft2_tlevel[] = {127};
582 static uint8_t ft2_wq_log2[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
583 static uint8_t ft2_maxp_inv[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
584 static struct rte_red_config ft2_rconfig[10];
586 static struct test_rte_red_config ft2_tconfig = {
587 .rconfig = ft2_rconfig,
588 .num_cfg = RTE_DIM(ft2_rconfig),
589 .wq_log2 = ft2_wq_log2,
592 .maxp_inv = ft2_maxp_inv,
595 static struct test_config func_test2_config = {
596 .ifname = "functional test 2 interface",
597 .msg = "functional test 2 : use several RED configurations,\n"
598 " increase average queue size to just below maximum threshold,\n"
599 " compare drop rate to drop probability\n\n",
600 .htxt = "RED config "
609 .tconfig = &ft2_tconfig,
610 .tqueue = &ft_tqueue,
612 .tlevel = ft2_tlevel,
615 static enum test_result func_test2(struct test_config *tcfg)
617 enum test_result result = PASS;
618 double prev_drop_rate = 1.0;
621 printf("%s", tcfg->msg);
623 if (test_rte_red_init(tcfg) != PASS) {
627 rte_red_rt_data_init(tcfg->tqueue->rdata);
629 if (increase_actual_qsize(tcfg->tconfig->rconfig,
633 tcfg->tqueue->q_ramp_up) != 0) {
638 if (increase_average_qsize(tcfg->tconfig->rconfig,
642 tcfg->tqueue->avg_ramp_up) != 0) {
646 printf("%s", tcfg->htxt);
648 for (i = 0; i < tcfg->tconfig->num_cfg; i++) {
650 double drop_rate = 0.0;
651 double drop_prob = 0.0;
654 *tcfg->tvar->dropped = 0;
655 *tcfg->tvar->enqueued = 0;
657 enqueue_dequeue_func(&tcfg->tconfig->rconfig[i],
661 tcfg->tvar->enqueued,
662 tcfg->tvar->dropped);
664 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[i], tcfg->tqueue->rdata);
665 if (avg != *tcfg->tlevel)
668 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
669 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
670 tcfg->tconfig->maxp_inv[i], *tcfg->tlevel);
671 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
674 * drop rate should decrease as maxp_inv increases
676 if (drop_rate > prev_drop_rate)
678 prev_drop_rate = drop_rate;
680 printf("%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
681 i, avg, tcfg->tconfig->min_th, tcfg->tconfig->max_th,
682 drop_prob * 100.0, drop_rate * 100.0, diff,
683 (double)tcfg->tqueue->drop_tolerance);
690 * Test F3: functional test 3
692 static uint32_t ft3_tlevel[] = {1022};
694 static struct test_rte_red_config ft3_tconfig = {
695 .rconfig = ft_wrconfig,
696 .num_cfg = RTE_DIM(ft_wrconfig),
697 .wq_log2 = ft_wq_log2,
700 .maxp_inv = ft_maxp_inv,
703 static struct test_config func_test3_config = {
704 .ifname = "functional test 3 interface",
705 .msg = "functional test 3 : use one RED configuration,\n"
706 " increase average queue size to target level,\n"
707 " dequeue all packets until queue is empty,\n"
708 " confirm that average queue size is computed correctly while queue is empty\n\n",
709 .htxt = "q avg before "
716 .tconfig = &ft3_tconfig,
717 .tqueue = &ft_tqueue,
719 .tlevel = ft3_tlevel,
722 static enum test_result func_test3(struct test_config *tcfg)
724 enum test_result result = PASS;
727 printf("%s", tcfg->msg);
729 if (test_rte_red_init(tcfg) != PASS) {
734 rte_red_rt_data_init(tcfg->tqueue->rdata);
736 if (increase_actual_qsize(tcfg->tconfig->rconfig,
740 tcfg->tqueue->q_ramp_up) != 0) {
745 if (increase_average_qsize(tcfg->tconfig->rconfig,
749 tcfg->tqueue->avg_ramp_up) != 0) {
754 printf("%s", tcfg->htxt);
756 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
757 double avg_before = 0;
758 double avg_after = 0;
762 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
767 *tcfg->tqueue->q = 0;
768 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
770 rte_delay_us(tcfg->tvar->wait_usec);
773 * enqueue one packet to recalculate average queue size
775 if (rte_red_enqueue(tcfg->tconfig->rconfig,
778 get_port_ts()) == 0) {
779 (*tcfg->tqueue->q)++;
781 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
785 exp_avg = calc_exp_avg_on_empty(avg_before,
786 (1 << *tcfg->tconfig->wq_log2),
787 tcfg->tvar->wait_usec);
788 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig,
789 tcfg->tqueue->rdata);
790 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
793 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
794 avg_before, avg_after, exp_avg, diff,
795 (double)tcfg->tqueue->avg_tolerance,
796 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
803 * Test F4: functional test 4
805 static uint32_t ft4_tlevel[] = {1022};
806 static uint8_t ft4_wq_log2[] = {11};
808 static struct test_rte_red_config ft4_tconfig = {
809 .rconfig = ft_wrconfig,
810 .num_cfg = RTE_DIM(ft_wrconfig),
813 .wq_log2 = ft4_wq_log2,
814 .maxp_inv = ft_maxp_inv,
817 static struct test_queue ft4_tqueue = {
819 .num_queues = RTE_DIM(ft_rtdata),
820 .qconfig = ft_qconfig,
822 .q_ramp_up = 1000000,
823 .avg_ramp_up = 1000000,
824 .avg_tolerance = 0, /* 0 percent */
825 .drop_tolerance = 50, /* 50 percent */
828 static struct test_config func_test4_config = {
829 .ifname = "functional test 4 interface",
830 .msg = "functional test 4 : use one RED configuration,\n"
831 " increase average queue size to target level,\n"
832 " dequeue all packets until queue is empty,\n"
833 " confirm that average queue size is computed correctly while\n"
834 " queue is empty for more than 50 sec,\n"
835 " (this test takes 52 sec to run)\n\n",
836 .htxt = "q avg before "
843 .tconfig = &ft4_tconfig,
844 .tqueue = &ft4_tqueue,
846 .tlevel = ft4_tlevel,
849 static enum test_result func_test4(struct test_config *tcfg)
851 enum test_result result = PASS;
852 uint64_t time_diff = 0;
854 double avg_before = 0.0;
855 double avg_after = 0.0;
856 double exp_avg = 0.0;
859 printf("%s", tcfg->msg);
861 if (test_rte_red_init(tcfg) != PASS) {
866 rte_red_rt_data_init(tcfg->tqueue->rdata);
868 if (increase_actual_qsize(tcfg->tconfig->rconfig,
872 tcfg->tqueue->q_ramp_up) != 0) {
877 if (increase_average_qsize(tcfg->tconfig->rconfig,
881 tcfg->tqueue->avg_ramp_up) != 0) {
886 printf("%s", tcfg->htxt);
888 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
893 *tcfg->tqueue->q = 0;
894 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
897 * record empty time locally
901 sleep(tcfg->tvar->sleep_sec);
904 * enqueue one packet to recalculate average queue size
906 if (rte_red_enqueue(tcfg->tconfig->rconfig,
909 get_port_ts()) != 0) {
913 (*tcfg->tqueue->q)++;
916 * calculate how long queue has been empty
918 time_diff = ((rte_rdtsc() - start) / tcfg->tvar->clk_freq)
920 if (time_diff < MAX_QEMPTY_TIME_MSEC) {
922 * this could happen if sleep was interrupted for some reason
929 * confirm that average queue size is now at expected level
932 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
933 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
936 printf("%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
937 avg_before, avg_after, exp_avg,
938 diff, (double)tcfg->tqueue->avg_tolerance,
939 diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail");
945 * Test F5: functional test 5
947 static uint32_t ft5_tlevel[] = {127};
948 static uint8_t ft5_wq_log2[] = {9, 8};
949 static uint8_t ft5_maxp_inv[] = {10, 20};
950 static struct rte_red_config ft5_config[2];
951 static struct rte_red ft5_data[4];
952 static uint32_t ft5_q[4];
953 static uint32_t ft5_dropped[] = {0, 0, 0, 0};
954 static uint32_t ft5_enqueued[] = {0, 0, 0, 0};
956 static struct test_rte_red_config ft5_tconfig = {
957 .rconfig = ft5_config,
958 .num_cfg = RTE_DIM(ft5_config),
961 .wq_log2 = ft5_wq_log2,
962 .maxp_inv = ft5_maxp_inv,
965 static struct test_queue ft5_tqueue = {
967 .num_queues = RTE_DIM(ft5_data),
968 .qconfig = ft_qconfig,
970 .q_ramp_up = 1000000,
971 .avg_ramp_up = 1000000,
972 .avg_tolerance = 5, /* 10 percent */
973 .drop_tolerance = 50, /* 50 percent */
976 struct test_var ft5_tvar = {
978 .num_iterations = 15,
981 .dropped = ft5_dropped,
982 .enqueued = ft5_enqueued,
986 static struct test_config func_test5_config = {
987 .ifname = "functional test 5 interface",
988 .msg = "functional test 5 : use several queues (each with its own run-time data),\n"
989 " use several RED configurations (such that each configuration is shared by multiple queues),\n"
990 " increase average queue size to just below maximum threshold,\n"
991 " compare drop rate to drop probability,\n"
992 " (this is a larger scale version of functional test 2)\n\n",
1003 .tconfig = &ft5_tconfig,
1004 .tqueue = &ft5_tqueue,
1006 .tlevel = ft5_tlevel,
1009 static enum test_result func_test5(struct test_config *tcfg)
1011 enum test_result result = PASS;
1014 printf("%s", tcfg->msg);
1016 if (test_rte_red_init(tcfg) != PASS) {
1021 printf("%s", tcfg->htxt);
1023 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1024 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1025 tcfg->tqueue->q[j] = 0;
1027 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1028 &tcfg->tqueue->rdata[j],
1029 &tcfg->tqueue->q[j],
1031 tcfg->tqueue->q_ramp_up) != 0) {
1036 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1037 &tcfg->tqueue->rdata[j],
1038 &tcfg->tqueue->q[j],
1040 tcfg->tqueue->avg_ramp_up) != 0) {
1046 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1048 double drop_rate = 0.0;
1049 double drop_prob = 0.0;
1052 tcfg->tvar->dropped[j] = 0;
1053 tcfg->tvar->enqueued[j] = 0;
1055 enqueue_dequeue_func(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1056 &tcfg->tqueue->rdata[j],
1057 &tcfg->tqueue->q[j],
1058 tcfg->tvar->num_ops,
1059 &tcfg->tvar->enqueued[j],
1060 &tcfg->tvar->dropped[j]);
1062 avg = rte_red_get_avg_int(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1063 &tcfg->tqueue->rdata[j]);
1064 if (avg != *tcfg->tlevel)
1067 drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]);
1068 drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1069 tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]],
1071 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1074 printf("%-15u%-15u%-15u%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf\n",
1075 j, tcfg->tqueue->qconfig[j], avg,
1076 tcfg->tconfig->min_th, tcfg->tconfig->max_th,
1077 drop_prob * 100.0, drop_rate * 100.0,
1078 diff, (double)tcfg->tqueue->drop_tolerance);
1085 * Test F6: functional test 6
1087 static uint32_t ft6_tlevel[] = {1022};
1088 static uint8_t ft6_wq_log2[] = {9, 8};
1089 static uint8_t ft6_maxp_inv[] = {10, 20};
1090 static struct rte_red_config ft6_config[2];
1091 static struct rte_red ft6_data[4];
1092 static uint32_t ft6_q[4];
1094 static struct test_rte_red_config ft6_tconfig = {
1095 .rconfig = ft6_config,
1096 .num_cfg = RTE_DIM(ft6_config),
1099 .wq_log2 = ft6_wq_log2,
1100 .maxp_inv = ft6_maxp_inv,
1103 static struct test_queue ft6_tqueue = {
1105 .num_queues = RTE_DIM(ft6_data),
1106 .qconfig = ft_qconfig,
1108 .q_ramp_up = 1000000,
1109 .avg_ramp_up = 1000000,
1110 .avg_tolerance = 5, /* 10 percent */
1111 .drop_tolerance = 50, /* 50 percent */
1114 static struct test_config func_test6_config = {
1115 .ifname = "functional test 6 interface",
1116 .msg = "functional test 6 : use several queues (each with its own run-time data),\n"
1117 " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n"
1118 " increase average queue size to target level,\n"
1119 " dequeue all packets until queue is empty,\n"
1120 " confirm that average queue size is computed correctly while queue is empty\n"
1121 " (this is a larger scale version of functional test 3)\n\n",
1130 .tconfig = &ft6_tconfig,
1131 .tqueue = &ft6_tqueue,
1133 .tlevel = ft6_tlevel,
1136 static enum test_result func_test6(struct test_config *tcfg)
1138 enum test_result result = PASS;
1141 printf("%s", tcfg->msg);
1142 if (test_rte_red_init(tcfg) != PASS) {
1146 printf("%s", tcfg->htxt);
1148 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1149 rte_red_rt_data_init(&tcfg->tqueue->rdata[j]);
1150 tcfg->tqueue->q[j] = 0;
1152 if (increase_actual_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1153 &tcfg->tqueue->rdata[j],
1154 &tcfg->tqueue->q[j],
1156 tcfg->tqueue->q_ramp_up) != 0) {
1160 if (increase_average_qsize(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1161 &tcfg->tqueue->rdata[j],
1162 &tcfg->tqueue->q[j],
1164 tcfg->tqueue->avg_ramp_up) != 0) {
1169 for (j = 0; j < tcfg->tqueue->num_queues; j++) {
1170 double avg_before = 0;
1171 double avg_after = 0;
1175 avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1176 &tcfg->tqueue->rdata[j]);
1181 tcfg->tqueue->q[j] = 0;
1182 rte_red_mark_queue_empty(&tcfg->tqueue->rdata[j], get_port_ts());
1183 rte_delay_us(tcfg->tvar->wait_usec);
1186 * enqueue one packet to recalculate average queue size
1188 if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1189 &tcfg->tqueue->rdata[j],
1191 get_port_ts()) == 0) {
1192 tcfg->tqueue->q[j]++;
1194 printf("%s:%d: packet enqueued on empty queue was dropped\n", __func__, __LINE__);
1198 exp_avg = calc_exp_avg_on_empty(avg_before,
1199 (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]),
1200 tcfg->tvar->wait_usec);
1201 avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]],
1202 &tcfg->tqueue->rdata[j]);
1203 if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1206 printf("%-15u%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1207 j, tcfg->tqueue->qconfig[j], avg_before, avg_after,
1208 exp_avg, diff, (double)tcfg->tqueue->avg_tolerance,
1209 diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail");
1216 * setup default values for the performance test structures
1218 static struct rte_red_config pt_wrconfig[1];
1219 static struct rte_red pt_rtdata[1];
1220 static uint8_t pt_wq_log2[] = {9};
1221 static uint8_t pt_maxp_inv[] = {10};
1222 static uint32_t pt_qconfig[] = {0};
1223 static uint32_t pt_q[] = {0};
1224 static uint32_t pt_dropped[] = {0};
1225 static uint32_t pt_enqueued[] = {0};
1227 static struct test_rte_red_config pt_tconfig = {
1228 .rconfig = pt_wrconfig,
1229 .num_cfg = RTE_DIM(pt_wrconfig),
1230 .wq_log2 = pt_wq_log2,
1233 .maxp_inv = pt_maxp_inv,
1236 static struct test_queue pt_tqueue = {
1238 .num_queues = RTE_DIM(pt_rtdata),
1239 .qconfig = pt_qconfig,
1241 .q_ramp_up = 1000000,
1242 .avg_ramp_up = 1000000,
1243 .avg_tolerance = 5, /* 10 percent */
1244 .drop_tolerance = 50, /* 50 percent */
1248 * enqueue/dequeue packets
1250 static void enqueue_dequeue_perf(struct rte_red_config *red_cfg,
1251 struct rte_red *red,
1256 struct rdtsc_prof *prof)
1260 for (i = 0; i < num_ops; i++) {
1267 rdtsc_prof_start(prof);
1268 ret = rte_red_enqueue(red_cfg, red, *q, ts );
1269 rdtsc_prof_end(prof);
1278 * Setup test structures for tests P1, P2, P3
1279 * performance tests 1, 2 and 3
1281 static uint32_t pt1_tlevel[] = {16};
1282 static uint32_t pt2_tlevel[] = {80};
1283 static uint32_t pt3_tlevel[] = {144};
1285 static struct test_var perf1_tvar = {
1287 .num_iterations = 15,
1288 .num_ops = 50000000,
1290 .dropped = pt_dropped,
1291 .enqueued = pt_enqueued,
1295 static struct test_config perf1_test1_config = {
1296 .ifname = "performance test 1 interface",
1297 .msg = "performance test 1 : use one RED configuration,\n"
1298 " set actual and average queue sizes to level below min threshold,\n"
1299 " measure enqueue performance\n\n",
1300 .tconfig = &pt_tconfig,
1301 .tqueue = &pt_tqueue,
1302 .tvar = &perf1_tvar,
1303 .tlevel = pt1_tlevel,
1306 static struct test_config perf1_test2_config = {
1307 .ifname = "performance test 2 interface",
1308 .msg = "performance test 2 : use one RED configuration,\n"
1309 " set actual and average queue sizes to level in between min and max thresholds,\n"
1310 " measure enqueue performance\n\n",
1311 .tconfig = &pt_tconfig,
1312 .tqueue = &pt_tqueue,
1313 .tvar = &perf1_tvar,
1314 .tlevel = pt2_tlevel,
1317 static struct test_config perf1_test3_config = {
1318 .ifname = "performance test 3 interface",
1319 .msg = "performance test 3 : use one RED configuration,\n"
1320 " set actual and average queue sizes to level above max threshold,\n"
1321 " measure enqueue performance\n\n",
1322 .tconfig = &pt_tconfig,
1323 .tqueue = &pt_tqueue,
1324 .tvar = &perf1_tvar,
1325 .tlevel = pt3_tlevel,
1329 * Performance test function to measure enqueue performance.
1330 * This runs performance tests 1, 2 and 3
1332 static enum test_result perf1_test(struct test_config *tcfg)
1334 enum test_result result = PASS;
1335 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1338 printf("%s", tcfg->msg);
1340 rdtsc_prof_init(&prof, "enqueue");
1342 if (test_rte_red_init(tcfg) != PASS) {
1348 * set average queue size to target level
1350 *tcfg->tqueue->q = *tcfg->tlevel;
1353 * initialize the rte_red run time data structure
1355 rte_red_rt_data_init(tcfg->tqueue->rdata);
1358 * set the queue average
1360 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1361 if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata)
1367 enqueue_dequeue_perf(tcfg->tconfig->rconfig,
1368 tcfg->tqueue->rdata,
1370 tcfg->tvar->num_ops,
1371 tcfg->tvar->enqueued,
1372 tcfg->tvar->dropped,
1375 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1377 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1378 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1379 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1381 rdtsc_prof_print(&prof);
1387 * Setup test structures for tests P4, P5, P6
1388 * performance tests 4, 5 and 6
1390 static uint32_t pt4_tlevel[] = {16};
1391 static uint32_t pt5_tlevel[] = {80};
1392 static uint32_t pt6_tlevel[] = {144};
1394 static struct test_var perf2_tvar = {
1396 .num_iterations = 10000,
1398 .dropped = pt_dropped,
1399 .enqueued = pt_enqueued,
1403 static struct test_config perf2_test4_config = {
1404 .ifname = "performance test 4 interface",
1405 .msg = "performance test 4 : use one RED configuration,\n"
1406 " set actual and average queue sizes to level below min threshold,\n"
1407 " dequeue all packets until queue is empty,\n"
1408 " measure enqueue performance when queue is empty\n\n",
1409 .htxt = "iteration "
1416 .tconfig = &pt_tconfig,
1417 .tqueue = &pt_tqueue,
1418 .tvar = &perf2_tvar,
1419 .tlevel = pt4_tlevel,
1422 static struct test_config perf2_test5_config = {
1423 .ifname = "performance test 5 interface",
1424 .msg = "performance test 5 : use one RED configuration,\n"
1425 " set actual and average queue sizes to level in between min and max thresholds,\n"
1426 " dequeue all packets until queue is empty,\n"
1427 " measure enqueue performance when queue is empty\n\n",
1428 .htxt = "iteration "
1435 .tconfig = &pt_tconfig,
1436 .tqueue = &pt_tqueue,
1437 .tvar = &perf2_tvar,
1438 .tlevel = pt5_tlevel,
1441 static struct test_config perf2_test6_config = {
1442 .ifname = "performance test 6 interface",
1443 .msg = "performance test 6 : use one RED configuration,\n"
1444 " set actual and average queue sizes to level above max threshold,\n"
1445 " dequeue all packets until queue is empty,\n"
1446 " measure enqueue performance when queue is empty\n\n",
1447 .htxt = "iteration "
1454 .tconfig = &pt_tconfig,
1455 .tqueue = &pt_tqueue,
1456 .tvar = &perf2_tvar,
1457 .tlevel = pt6_tlevel,
1461 * Performance test function to measure enqueue performance when the
1462 * queue is empty. This runs performance tests 4, 5 and 6
1464 static enum test_result perf2_test(struct test_config *tcfg)
1466 enum test_result result = PASS;
1467 struct rdtsc_prof prof = {0, 0, 0, 0, 0.0, NULL};
1471 printf("%s", tcfg->msg);
1473 rdtsc_prof_init(&prof, "enqueue");
1475 if (test_rte_red_init(tcfg) != PASS) {
1480 printf("%s", tcfg->htxt);
1482 for (i = 0; i < tcfg->tvar->num_iterations; i++) {
1485 double avg_before = 0;
1489 * set average queue size to target level
1491 *tcfg->tqueue->q = *tcfg->tlevel;
1492 count = (*tcfg->tqueue->rdata).count;
1495 * initialize the rte_red run time data structure
1497 rte_red_rt_data_init(tcfg->tqueue->rdata);
1498 (*tcfg->tqueue->rdata).count = count;
1501 * set the queue average
1503 rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel);
1504 avg_before = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1505 if ((avg_before < *tcfg->tlevel) || (avg_before > *tcfg->tlevel)) {
1513 *tcfg->tqueue->q = 0;
1514 rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts());
1517 * wait for specified period of time
1519 rte_delay_us(tcfg->tvar->wait_usec);
1522 * measure performance of enqueue operation while queue is empty
1525 rdtsc_prof_start(&prof);
1526 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1527 *tcfg->tqueue->q, ts );
1528 rdtsc_prof_end(&prof);
1531 * gather enqueued/dropped statistics
1534 (*tcfg->tvar->enqueued)++;
1536 (*tcfg->tvar->dropped)++;
1539 * on first and last iteration, confirm that
1540 * average queue size was computed correctly
1542 if ((i == 0) || (i == tcfg->tvar->num_iterations - 1)) {
1543 double avg_after = 0;
1548 avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1549 exp_avg = calc_exp_avg_on_empty(avg_before,
1550 (1 << *tcfg->tconfig->wq_log2),
1551 tcfg->tvar->wait_usec);
1552 if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance))
1554 printf("%-15u%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15.4lf%-15s\n",
1555 i, avg_before, avg_after, exp_avg, diff,
1556 (double)tcfg->tqueue->avg_tolerance, ok ? "pass" : "fail");
1563 total = *tcfg->tvar->enqueued + *tcfg->tvar->dropped;
1564 printf("\ntotal: %u, enqueued: %u (%.2lf%%), dropped: %u (%.2lf%%)\n", total,
1565 *tcfg->tvar->enqueued, ((double)(*tcfg->tvar->enqueued) / (double)total) * 100.0,
1566 *tcfg->tvar->dropped, ((double)(*tcfg->tvar->dropped) / (double)total) * 100.0);
1568 rdtsc_prof_print(&prof);
1574 * setup default values for overflow test structures
1576 static uint32_t avg_max = 0;
1577 static uint32_t avg_max_bits = 0;
1579 static struct rte_red_config ovfl_wrconfig[1];
1580 static struct rte_red ovfl_rtdata[1];
1581 static uint8_t ovfl_maxp_inv[] = {10};
1582 static uint32_t ovfl_qconfig[] = {0, 0, 1, 1};
1583 static uint32_t ovfl_q[] ={0};
1584 static uint32_t ovfl_dropped[] ={0};
1585 static uint32_t ovfl_enqueued[] ={0};
1586 static uint32_t ovfl_tlevel[] = {1023};
1587 static uint8_t ovfl_wq_log2[] = {12};
1589 static struct test_rte_red_config ovfl_tconfig = {
1590 .rconfig = ovfl_wrconfig,
1591 .num_cfg = RTE_DIM(ovfl_wrconfig),
1592 .wq_log2 = ovfl_wq_log2,
1595 .maxp_inv = ovfl_maxp_inv,
1598 static struct test_queue ovfl_tqueue = {
1599 .rdata = ovfl_rtdata,
1600 .num_queues = RTE_DIM(ovfl_rtdata),
1601 .qconfig = ovfl_qconfig,
1603 .q_ramp_up = 1000000,
1604 .avg_ramp_up = 1000000,
1605 .avg_tolerance = 5, /* 10 percent */
1606 .drop_tolerance = 50, /* 50 percent */
1609 static struct test_var ovfl_tvar = {
1611 .num_iterations = 1,
1614 .dropped = ovfl_dropped,
1615 .enqueued = ovfl_enqueued,
1619 static void ovfl_check_avg(uint32_t avg)
1621 if (avg > avg_max) {
1625 avg_log = log(((double)avg_max));
1626 avg_log = avg_log / log(2.0);
1627 bits = (uint32_t)ceil(avg_log);
1628 if (bits > avg_max_bits)
1629 avg_max_bits = bits;
1633 static struct test_config ovfl_test1_config = {
1634 .ifname = "queue avergage overflow test interface",
1635 .msg = "overflow test 1 : use one RED configuration,\n"
1636 " increase average queue size to target level,\n"
1637 " check maximum number of bits requirte_red to represent avg_s\n\n",
1638 .htxt = "avg queue size "
1648 .tconfig = &ovfl_tconfig,
1649 .tqueue = &ovfl_tqueue,
1651 .tlevel = ovfl_tlevel,
1654 static enum test_result ovfl_test1(struct test_config *tcfg)
1656 enum test_result result = PASS;
1659 double drop_rate = 0.0;
1660 double drop_prob = 0.0;
1664 printf("%s", tcfg->msg);
1666 if (test_rte_red_init(tcfg) != PASS) {
1673 * reset rte_red run-time data
1675 rte_red_rt_data_init(tcfg->tqueue->rdata);
1678 * increase actual queue size
1680 for (i = 0; i < tcfg->tqueue->q_ramp_up; i++) {
1681 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1682 *tcfg->tqueue->q, get_port_ts());
1685 if (++(*tcfg->tqueue->q) >= *tcfg->tlevel)
1693 for (i = 0; i < tcfg->tqueue->avg_ramp_up; i++) {
1694 ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata,
1695 *tcfg->tqueue->q, get_port_ts());
1696 ovfl_check_avg((*tcfg->tqueue->rdata).avg);
1697 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1698 if (avg == *tcfg->tlevel) {
1700 (*tcfg->tvar->enqueued)++;
1702 (*tcfg->tvar->dropped)++;
1707 * check if target average queue size has been reached
1709 avg = rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata);
1710 if (avg != *tcfg->tlevel) {
1716 * check drop rate against drop probability
1718 drop_rate = calc_drop_rate(*tcfg->tvar->enqueued, *tcfg->tvar->dropped);
1719 drop_prob = calc_drop_prob(tcfg->tconfig->min_th,
1720 tcfg->tconfig->max_th,
1721 *tcfg->tconfig->maxp_inv,
1723 if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance))
1726 printf("%s", tcfg->htxt);
1728 printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n",
1729 avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING,
1730 avg_max, avg_max_bits,
1731 *tcfg->tvar->enqueued, *tcfg->tvar->dropped,
1732 drop_prob * 100.0, drop_rate * 100.0);
1738 * define the functional and performance tests to be executed
1740 struct tests func_tests[] = {
1741 { &func_test1_config, func_test1 },
1742 { &func_test2_config, func_test2 },
1743 { &func_test3_config, func_test3 },
1744 { &func_test4_config, func_test4 },
1745 { &func_test5_config, func_test5 },
1746 { &func_test6_config, func_test6 },
1747 { &ovfl_test1_config, ovfl_test1 },
1750 struct tests perf_tests[] = {
1751 { &perf1_test1_config, perf1_test },
1752 { &perf1_test2_config, perf1_test },
1753 { &perf1_test3_config, perf1_test },
1754 { &perf2_test4_config, perf2_test },
1755 { &perf2_test5_config, perf2_test },
1756 { &perf2_test6_config, perf2_test },
1760 * function to execute the required_red tests
1762 static void run_tests(struct tests *test_type, uint32_t test_count, uint32_t *num_tests, uint32_t *num_pass)
1764 enum test_result result = PASS;
1767 for (i = 0; i < test_count; i++) {
1768 printf("\n--------------------------------------------------------------------------------\n");
1769 result = test_type[i].testfn(test_type[i].testcfg);
1771 if (result == PASS) {
1773 printf("-------------------------------------<pass>-------------------------------------\n");
1775 printf("-------------------------------------<fail>-------------------------------------\n");
1782 * check if functions accept invalid parameters
1784 * First, all functions will be called without initialized RED
1785 * Then, all of them will be called with NULL/invalid parameters
1787 * Some functions are not tested as they are performance-critical and thus
1788 * don't do any parameter checking.
1791 test_invalid_parameters(void)
1793 struct rte_red_config config;
1795 if (rte_red_rt_data_init(NULL) == 0) {
1796 printf("rte_red_rt_data_init should have failed!\n");
1800 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1801 printf("rte_red_config_init should have failed!\n");
1805 if (rte_red_rt_data_init(NULL) == 0) {
1806 printf("rte_red_rt_data_init should have failed!\n");
1811 if (rte_red_config_init(NULL, 0, 0, 0, 0) == 0) {
1812 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1815 /* min_treshold == max_treshold */
1816 if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) {
1817 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1820 /* min_treshold > max_treshold */
1821 if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) {
1822 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1825 /* wq_log2 > RTE_RED_WQ_LOG2_MAX */
1826 if (rte_red_config_init(&config,
1827 RTE_RED_WQ_LOG2_MAX + 1, 1, 2, 0) == 0) {
1828 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1831 /* wq_log2 < RTE_RED_WQ_LOG2_MIN */
1832 if (rte_red_config_init(&config,
1833 RTE_RED_WQ_LOG2_MIN - 1, 1, 2, 0) == 0) {
1834 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1837 /* maxp_inv > RTE_RED_MAXP_INV_MAX */
1838 if (rte_red_config_init(&config,
1839 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MAX + 1) == 0) {
1840 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1843 /* maxp_inv < RTE_RED_MAXP_INV_MIN */
1844 if (rte_red_config_init(&config,
1845 RTE_RED_WQ_LOG2_MIN, 1, 2, RTE_RED_MAXP_INV_MIN - 1) == 0) {
1846 printf("%i: rte_red_config_init should have failed!\n", __LINE__);
1856 uint32_t num_tests = 0;
1857 uint32_t num_pass = 0;
1860 if (test_invalid_parameters() < 0)
1863 run_tests(func_tests, RTE_DIM(func_tests), &num_tests, &num_pass);
1864 run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass);
1866 if (num_pass == num_tests) {
1867 printf("[total: %u, pass: %u]\n", num_tests, num_pass);
1870 printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass);
1876 static struct test_command red_cmd = {
1877 .command = "red_autotest",
1878 .callback = test_red,
1880 REGISTER_TEST_COMMAND(red_cmd);