X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_red.c;h=348075dc396e4a154d7935722abdaf0a2de2e2f9;hb=dd0eedb1cfcf0cb7423d859177c5bc6f931eaf8a;hp=f0833494a5c1e1c1194722d3b3f4dfca978e6b67;hpb=de3cfa2c9823a7e0391d4f4a355e2d78b83eec62;p=dpdk.git diff --git a/app/test/test_red.c b/app/test/test_red.c index f0833494a5..348075dc39 100644 --- a/app/test/test_red.c +++ b/app/test/test_red.c @@ -1,35 +1,34 @@ /*- * BSD LICENSE - * - * Copyright(c) 2010-2013 Intel Corporation. All rights reserved. + * + * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions * are met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * */ #include @@ -41,12 +40,9 @@ #include #include #include -#include #include "test.h" -#ifdef RTE_LIBRTE_SCHED - #include #ifdef __INTEL_COMPILER @@ -54,7 +50,6 @@ #pragma warning(disable:181) /* Arg incompatible with format string */ #endif -#define DIM(x) (sizeof(x)/sizeof(x[0])) #define TEST_HZ_PER_KHZ 1000 #define TEST_NSEC_MARGIN 500 /**< nanosecond margin when calculating clk freq */ @@ -62,6 +57,7 @@ #define MSEC_PER_SEC 1000 /**< Milli-seconds per second */ #define USEC_PER_MSEC 1000 /**< Micro-seconds per milli-second */ #define USEC_PER_SEC 1000000 /**< Micro-seconds per second */ +#define NSEC_PER_SEC (USEC_PER_SEC * 1000) /**< Nano-seconds per second */ /**< structures for testing rte_red performance and function */ struct test_rte_red_config { /**< Test structure for RTE_RED config */ @@ -79,7 +75,7 @@ struct test_queue { /**< Test structure for RTE_RED Queues */ uint32_t *qconfig; /**< Configuration of RTE_RED queues for test */ uint32_t *q; /**< Queue size */ uint32_t q_ramp_up; /**< Num of enqueues to ramp up the queue */ - uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */ + uint32_t avg_ramp_up; /**< Average num of enqueues to ramp up the queue */ uint32_t avg_tolerance; /**< Tolerance in queue average */ double drop_tolerance; /**< Drop tolerance of packets not enqueued */ }; @@ -151,8 +147,7 @@ static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name) static inline void rdtsc_prof_start(struct rdtsc_prof *p) { - asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" ); - p->clk_start = rte_rdtsc(); + p->clk_start = rte_rdtsc_precise(); } static inline void rdtsc_prof_end(struct rdtsc_prof *p) @@ -235,7 +230,7 @@ static double calc_drop_prob(uint32_t min_th, uint32_t max_th, } else { drop_prob = 1.0; } - return (drop_prob); + return drop_prob; } /** @@ -255,7 +250,7 @@ static int check_drop_rate(double *diff, double drop_rate, double drop_prob, dou ret = 0; } } - return (ret); + return ret; } /** @@ -275,44 +270,7 @@ static int check_avg(double *diff, double avg, double exp_avg, double tolerance) ret = 0; } } - return (ret); -} - -/** - * get the clk frequency in Hz - */ -static uint64_t get_machclk_freq(void) -{ - uint64_t start = 0; - uint64_t end = 0; - uint64_t diff = 0; - uint64_t clk_freq_hz = 0; - struct timespec tv_start = {0, 0}, tv_end = {0, 0}; - struct timespec req = {0, 0}; - - req.tv_sec = 1; - req.tv_nsec = 0; - - clock_gettime(CLOCK_REALTIME, &tv_start); - start = rte_rdtsc(); - - if (nanosleep(&req, NULL) != 0) { - perror("get_machclk_freq()"); - exit(EXIT_FAILURE); - } - - clock_gettime(CLOCK_REALTIME, &tv_end); - end = rte_rdtsc(); - - diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC - + ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) / - USEC_PER_MSEC); /**< diff is in micro secs */ - - if (diff == 0) - return(0); - - clk_freq_hz = ((end - start) * USEC_PER_SEC / diff); - return (clk_freq_hz); + return ret; } /** @@ -323,7 +281,7 @@ test_rte_red_init(struct test_config *tcfg) { unsigned i = 0; - tcfg->tvar->clk_freq = get_machclk_freq(); + tcfg->tvar->clk_freq = rte_get_timer_hz(); init_port_ts( tcfg->tvar->clk_freq ); for (i = 0; i < tcfg->tconfig->num_cfg; i++) { @@ -332,14 +290,14 @@ test_rte_red_init(struct test_config *tcfg) (uint16_t)tcfg->tconfig->min_th, (uint16_t)tcfg->tconfig->max_th, (uint16_t)tcfg->tconfig->maxp_inv[i]) != 0) { - return(FAIL); + return FAIL; } } *tcfg->tqueue->q = 0; *tcfg->tvar->dropped = 0; *tcfg->tvar->enqueued = 0; - return(PASS); + return PASS; } /** @@ -370,11 +328,11 @@ increase_actual_qsize(struct rte_red_config *red_cfg, * check if target actual queue size has been reached */ if (*q != level) - return (-1); + return -1; /** * success */ - return (0); + return 0; } /** @@ -401,11 +359,11 @@ increase_average_qsize(struct rte_red_config *red_cfg, */ avg = rte_red_get_avg_int(red_cfg, red); if (avg != level) - return (-1); + return -1; /** * success */ - return (0); + return 0; } /** @@ -414,7 +372,7 @@ increase_average_qsize(struct rte_red_config *red_cfg, static struct rte_red_config ft_wrconfig[1]; static struct rte_red ft_rtdata[1]; static uint8_t ft_wq_log2[] = {9}; -static uint8_t ft_maxp_inv[] = {10}; +static uint8_t ft_maxp_inv[] = {10}; static uint32_t ft_qconfig[] = {0, 0, 1, 1}; static uint32_t ft_q[] ={0}; static uint32_t ft_dropped[] ={0}; @@ -422,7 +380,7 @@ static uint32_t ft_enqueued[] ={0}; static struct test_rte_red_config ft_tconfig = { .rconfig = ft_wrconfig, - .num_cfg = DIM(ft_wrconfig), + .num_cfg = RTE_DIM(ft_wrconfig), .wq_log2 = ft_wq_log2, .min_th = 32, .max_th = 128, @@ -431,7 +389,7 @@ static struct test_rte_red_config ft_tconfig = { static struct test_queue ft_tqueue = { .rdata = ft_rtdata, - .num_queues = DIM(ft_rtdata), + .num_queues = RTE_DIM(ft_rtdata), .qconfig = ft_qconfig, .q = ft_q, .q_ramp_up = 1000000, @@ -441,8 +399,8 @@ static struct test_queue ft_tqueue = { }; static struct test_var ft_tvar = { - .wait_usec = 250000, - .num_iterations = 20, + .wait_usec = 10000, + .num_iterations = 5, .num_ops = 10000, .clk_freq = 0, .dropped = ft_dropped, @@ -513,9 +471,9 @@ static enum test_result func_test1(struct test_config *tcfg) goto out; } - printf("%s", tcfg->htxt); + printf("%s", tcfg->htxt); - for (i = 0; i < DIM(ft1_tlevels); i++) { + for (i = 0; i < RTE_DIM(ft1_tlevels); i++) { const char *label = NULL; uint32_t avg = 0; double drop_rate = 0.0; @@ -578,7 +536,7 @@ static enum test_result func_test1(struct test_config *tcfg) (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -591,7 +549,7 @@ static struct rte_red_config ft2_rconfig[10]; static struct test_rte_red_config ft2_tconfig = { .rconfig = ft2_rconfig, - .num_cfg = DIM(ft2_rconfig), + .num_cfg = RTE_DIM(ft2_rconfig), .wq_log2 = ft2_wq_log2, .min_th = 32, .max_th = 128, @@ -689,7 +647,7 @@ static enum test_result func_test2(struct test_config *tcfg) (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -699,7 +657,7 @@ static uint32_t ft3_tlevel[] = {1022}; static struct test_rte_red_config ft3_tconfig = { .rconfig = ft_wrconfig, - .num_cfg = DIM(ft_wrconfig), + .num_cfg = RTE_DIM(ft_wrconfig), .wq_log2 = ft_wq_log2, .min_th = 32, .max_th = 1023, @@ -788,10 +746,10 @@ static enum test_result func_test3(struct test_config *tcfg) result = FAIL; } - exp_avg = calc_exp_avg_on_empty(avg_before, + exp_avg = calc_exp_avg_on_empty(avg_before, (1 << *tcfg->tconfig->wq_log2), tcfg->tvar->wait_usec); - avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, + avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata); if (!check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance)) result = FAIL; @@ -802,7 +760,7 @@ static enum test_result func_test3(struct test_config *tcfg) diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail"); } out: - return (result); + return result; } /** @@ -813,7 +771,7 @@ static uint8_t ft4_wq_log2[] = {11}; static struct test_rte_red_config ft4_tconfig = { .rconfig = ft_wrconfig, - .num_cfg = DIM(ft_wrconfig), + .num_cfg = RTE_DIM(ft_wrconfig), .min_th = 32, .max_th = 1023, .wq_log2 = ft4_wq_log2, @@ -822,7 +780,7 @@ static struct test_rte_red_config ft4_tconfig = { static struct test_queue ft4_tqueue = { .rdata = ft_rtdata, - .num_queues = DIM(ft_rtdata), + .num_queues = RTE_DIM(ft_rtdata), .qconfig = ft_qconfig, .q = ft_q, .q_ramp_up = 1000000, @@ -900,7 +858,7 @@ static enum test_result func_test4(struct test_config *tcfg) rte_red_mark_queue_empty(tcfg->tqueue->rdata, get_port_ts()); /** - * record empty time locally + * record empty time locally */ start = rte_rdtsc(); @@ -909,8 +867,8 @@ static enum test_result func_test4(struct test_config *tcfg) /** * enqueue one packet to recalculate average queue size */ - if (rte_red_enqueue(tcfg->tconfig->rconfig, - tcfg->tqueue->rdata, + if (rte_red_enqueue(tcfg->tconfig->rconfig, + tcfg->tqueue->rdata, *tcfg->tqueue->q, get_port_ts()) != 0) { result = FAIL; @@ -944,7 +902,7 @@ static enum test_result func_test4(struct test_config *tcfg) diff, (double)tcfg->tqueue->avg_tolerance, diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail"); out: - return (result); + return result; } /** @@ -961,7 +919,7 @@ static uint32_t ft5_enqueued[] = {0, 0, 0, 0}; static struct test_rte_red_config ft5_tconfig = { .rconfig = ft5_config, - .num_cfg = DIM(ft5_config), + .num_cfg = RTE_DIM(ft5_config), .min_th = 32, .max_th = 128, .wq_log2 = ft5_wq_log2, @@ -970,7 +928,7 @@ static struct test_rte_red_config ft5_tconfig = { static struct test_queue ft5_tqueue = { .rdata = ft5_data, - .num_queues = DIM(ft5_data), + .num_queues = RTE_DIM(ft5_data), .qconfig = ft_qconfig, .q = ft5_q, .q_ramp_up = 1000000, @@ -1072,7 +1030,7 @@ static enum test_result func_test5(struct test_config *tcfg) drop_rate = calc_drop_rate(tcfg->tvar->enqueued[j],tcfg->tvar->dropped[j]); drop_prob = calc_drop_prob(tcfg->tconfig->min_th, tcfg->tconfig->max_th, - tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]], + tcfg->tconfig->maxp_inv[tcfg->tqueue->qconfig[j]], *tcfg->tlevel); if (!check_drop_rate(&diff, drop_rate, drop_prob, (double)tcfg->tqueue->drop_tolerance)) result = FAIL; @@ -1084,7 +1042,7 @@ static enum test_result func_test5(struct test_config *tcfg) diff, (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -1099,7 +1057,7 @@ static uint32_t ft6_q[4]; static struct test_rte_red_config ft6_tconfig = { .rconfig = ft6_config, - .num_cfg = DIM(ft6_config), + .num_cfg = RTE_DIM(ft6_config), .min_th = 32, .max_th = 1023, .wq_log2 = ft6_wq_log2, @@ -1108,7 +1066,7 @@ static struct test_rte_red_config ft6_tconfig = { static struct test_queue ft6_tqueue = { .rdata = ft6_data, - .num_queues = DIM(ft6_data), + .num_queues = RTE_DIM(ft6_data), .qconfig = ft_qconfig, .q = ft6_q, .q_ramp_up = 1000000, @@ -1178,7 +1136,7 @@ static enum test_result func_test6(struct test_config *tcfg) double exp_avg = 0; double diff = 0.0; - avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], + avg_before = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], &tcfg->tqueue->rdata[j]); /** @@ -1191,7 +1149,7 @@ static enum test_result func_test6(struct test_config *tcfg) /** * enqueue one packet to recalculate average queue size */ - if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], + if (rte_red_enqueue(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], &tcfg->tqueue->rdata[j], tcfg->tqueue->q[j], get_port_ts()) == 0) { @@ -1201,7 +1159,7 @@ static enum test_result func_test6(struct test_config *tcfg) result = FAIL; } - exp_avg = calc_exp_avg_on_empty(avg_before, + exp_avg = calc_exp_avg_on_empty(avg_before, (1 << tcfg->tconfig->wq_log2[tcfg->tqueue->qconfig[j]]), tcfg->tvar->wait_usec); avg_after = rte_red_get_avg_float(&tcfg->tconfig->rconfig[tcfg->tqueue->qconfig[j]], @@ -1215,7 +1173,7 @@ static enum test_result func_test6(struct test_config *tcfg) diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail"); } out: - return (result); + return result; } /** @@ -1224,7 +1182,7 @@ out: static struct rte_red_config pt_wrconfig[1]; static struct rte_red pt_rtdata[1]; static uint8_t pt_wq_log2[] = {9}; -static uint8_t pt_maxp_inv[] = {10}; +static uint8_t pt_maxp_inv[] = {10}; static uint32_t pt_qconfig[] = {0}; static uint32_t pt_q[] = {0}; static uint32_t pt_dropped[] = {0}; @@ -1232,7 +1190,7 @@ static uint32_t pt_enqueued[] = {0}; static struct test_rte_red_config pt_tconfig = { .rconfig = pt_wrconfig, - .num_cfg = DIM(pt_wrconfig), + .num_cfg = RTE_DIM(pt_wrconfig), .wq_log2 = pt_wq_log2, .min_th = 32, .max_th = 128, @@ -1241,7 +1199,7 @@ static struct test_rte_red_config pt_tconfig = { static struct test_queue pt_tqueue = { .rdata = pt_rtdata, - .num_queues = DIM(pt_rtdata), + .num_queues = RTE_DIM(pt_rtdata), .qconfig = pt_qconfig, .q = pt_q, .q_ramp_up = 1000000, @@ -1281,7 +1239,7 @@ static void enqueue_dequeue_perf(struct rte_red_config *red_cfg, } /** - * Setup test structures for tests P1, P2, P3 + * Setup test structures for tests P1, P2, P3 * performance tests 1, 2 and 3 */ static uint32_t pt1_tlevel[] = {16}; @@ -1332,8 +1290,8 @@ static struct test_config perf1_test3_config = { }; /** - * Performance test function to measure enqueue performance. - * This runs performance tests 1, 2 and 3 + * Performance test function to measure enqueue performance. + * This runs performance tests 1, 2 and 3 */ static enum test_result perf1_test(struct test_config *tcfg) { @@ -1364,7 +1322,7 @@ static enum test_result perf1_test(struct test_config *tcfg) * set the queue average */ rte_red_set_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tlevel); - if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata) + if (rte_red_get_avg_int(tcfg->tconfig->rconfig, tcfg->tqueue->rdata) != *tcfg->tlevel) { result = FAIL; goto out; @@ -1386,11 +1344,11 @@ static enum test_result perf1_test(struct test_config *tcfg) rdtsc_prof_print(&prof); out: - return (result); + return result; } /** - * Setup test structures for tests P4, P5, P6 + * Setup test structures for tests P4, P5, P6 * performance tests 4, 5 and 6 */ static uint32_t pt4_tlevel[] = {16}; @@ -1464,8 +1422,8 @@ static struct test_config perf2_test6_config = { }; /** - * Performance test function to measure enqueue performance when the - * queue is empty. This runs performance tests 4, 5 and 6 + * Performance test function to measure enqueue performance when the + * queue is empty. This runs performance tests 4, 5 and 6 */ static enum test_result perf2_test(struct test_config *tcfg) { @@ -1483,7 +1441,7 @@ static enum test_result perf2_test(struct test_config *tcfg) goto out; } - printf("%s", tcfg->htxt); + printf("%s", tcfg->htxt); for (i = 0; i < tcfg->tvar->num_iterations; i++) { uint32_t count = 0; @@ -1529,7 +1487,7 @@ static enum test_result perf2_test(struct test_config *tcfg) */ ts = get_port_ts(); rdtsc_prof_start(&prof); - ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, + ret = rte_red_enqueue(tcfg->tconfig->rconfig, tcfg->tqueue->rdata, *tcfg->tqueue->q, ts ); rdtsc_prof_end(&prof); @@ -1552,7 +1510,7 @@ static enum test_result perf2_test(struct test_config *tcfg) int ok = 0; avg_after = rte_red_get_avg_float(tcfg->tconfig->rconfig, tcfg->tqueue->rdata); - exp_avg = calc_exp_avg_on_empty(avg_before, + exp_avg = calc_exp_avg_on_empty(avg_before, (1 << *tcfg->tconfig->wq_log2), tcfg->tvar->wait_usec); if (check_avg(&diff, avg_after, exp_avg, (double)tcfg->tqueue->avg_tolerance)) @@ -1573,7 +1531,7 @@ static enum test_result perf2_test(struct test_config *tcfg) rdtsc_prof_print(&prof); out: - return (result); + return result; } /** @@ -1584,7 +1542,7 @@ static uint32_t avg_max_bits = 0; static struct rte_red_config ovfl_wrconfig[1]; static struct rte_red ovfl_rtdata[1]; -static uint8_t ovfl_maxp_inv[] = {10}; +static uint8_t ovfl_maxp_inv[] = {10}; static uint32_t ovfl_qconfig[] = {0, 0, 1, 1}; static uint32_t ovfl_q[] ={0}; static uint32_t ovfl_dropped[] ={0}; @@ -1594,7 +1552,7 @@ static uint8_t ovfl_wq_log2[] = {12}; static struct test_rte_red_config ovfl_tconfig = { .rconfig = ovfl_wrconfig, - .num_cfg = DIM(ovfl_wrconfig), + .num_cfg = RTE_DIM(ovfl_wrconfig), .wq_log2 = ovfl_wq_log2, .min_th = 32, .max_th = 1023, @@ -1603,7 +1561,7 @@ static struct test_rte_red_config ovfl_tconfig = { static struct test_queue ovfl_tqueue = { .rdata = ovfl_rtdata, - .num_queues = DIM(ovfl_rtdata), + .num_queues = RTE_DIM(ovfl_rtdata), .qconfig = ovfl_qconfig, .q = ovfl_q, .q_ramp_up = 1000000, @@ -1730,30 +1688,40 @@ static enum test_result ovfl_test1(struct test_config *tcfg) result = FAIL; printf("%s", tcfg->htxt); - + printf("%-16u%-9u%-15u0x%08x %-10u%-10u%-10u%-13.2lf%-13.2lf\n", avg, *tcfg->tconfig->wq_log2, RTE_RED_SCALING, avg_max, avg_max_bits, *tcfg->tvar->enqueued, *tcfg->tvar->dropped, drop_prob * 100.0, drop_rate * 100.0); out: - return (result); + return result; } /** * define the functional and performance tests to be executed */ -struct tests func_tests[] = { +struct tests func_tests[] = { { &func_test1_config, func_test1 }, - { &func_test2_config, func_test2 }, + { &func_test2_config, func_test2 }, { &func_test3_config, func_test3 }, { &func_test4_config, func_test4 }, { &func_test5_config, func_test5 }, { &func_test6_config, func_test6 }, - { &ovfl_test1_config, ovfl_test1 }, + { &ovfl_test1_config, ovfl_test1 }, +}; + +struct tests func_tests_quick[] = { + { &func_test1_config, func_test1 }, + { &func_test2_config, func_test2 }, + { &func_test3_config, func_test3 }, + /* no test 4 as it takes a lot of time */ + { &func_test5_config, func_test5 }, + { &func_test6_config, func_test6 }, + { &ovfl_test1_config, ovfl_test1 }, }; -struct tests perf_tests[] = { +struct tests perf_tests[] = { { &perf1_test1_config, perf1_test }, { &perf1_test2_config, perf1_test }, { &perf1_test3_config, perf1_test }, @@ -1856,35 +1824,62 @@ test_invalid_parameters(void) return 0; } -int test_red(void) +static void +show_stats(const uint32_t num_tests, const uint32_t num_pass) +{ + if (num_pass == num_tests) + printf("[total: %u, pass: %u]\n", num_tests, num_pass); + else + printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, + num_tests - num_pass); +} + +static int +tell_the_result(const uint32_t num_tests, const uint32_t num_pass) +{ + return (num_pass == num_tests) ? 0 : 1; +} + +static int +test_red(void) { uint32_t num_tests = 0; uint32_t num_pass = 0; - int ret = 0; if (test_invalid_parameters() < 0) return -1; + run_tests(func_tests_quick, RTE_DIM(func_tests_quick), + &num_tests, &num_pass); + show_stats(num_tests, num_pass); + return tell_the_result(num_tests, num_pass); +} - run_tests(func_tests, DIM(func_tests), &num_tests, &num_pass); - run_tests(perf_tests, DIM(perf_tests), &num_tests, &num_pass); +static int +test_red_perf(void) +{ + uint32_t num_tests = 0; + uint32_t num_pass = 0; - if (num_pass == num_tests) { - printf("[total: %u, pass: %u]\n", num_tests, num_pass); - ret = 0; - } else { - printf("[total: %u, pass: %u, fail: %u]\n", num_tests, num_pass, num_tests - num_pass); - ret = -1; - } - return (ret); + run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass); + show_stats(num_tests, num_pass); + return tell_the_result(num_tests, num_pass); } -#else - -int -test_red(void) +static int +test_red_all(void) { - printf("The SCHED library is not included in this build\n"); - return 0; + uint32_t num_tests = 0; + uint32_t num_pass = 0; + + if (test_invalid_parameters() < 0) + return -1; + + run_tests(func_tests, RTE_DIM(func_tests), &num_tests, &num_pass); + run_tests(perf_tests, RTE_DIM(perf_tests), &num_tests, &num_pass); + show_stats(num_tests, num_pass); + return tell_the_result(num_tests, num_pass); } -#endif +REGISTER_TEST_COMMAND(red_autotest, test_red); +REGISTER_TEST_COMMAND(red_perf, test_red_perf); +REGISTER_TEST_COMMAND(red_all, test_red_all);