X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_red.c;h=84c292f8d8798d55d5eb25ac2e4a51204f222757;hb=a2dfcd1ff609f5a4fd3b65774618a35c5c9f73c6;hp=262df729953a0bb5e5951801d4becc729f92b516;hpb=7822c43aba8ce07208a94124a46579fe43c0b103;p=dpdk.git diff --git a/app/test/test_red.c b/app/test/test_red.c index 262df72995..84c292f8d8 100644 --- a/app/test/test_red.c +++ b/app/test/test_red.c @@ -1,48 +1,43 @@ -/*- - * BSD LICENSE - * - * 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 - * are met: - * - * * 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 - * distribution. - * * 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 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation */ +#include "test.h" + #include #include #include #include #include #include + +#ifdef RTE_EXEC_ENV_WINDOWS +static int +test_red(void) +{ + printf("red not supported on Windows, skipping test\n"); + return TEST_SKIPPED; +} + +static int +test_red_perf(void) +{ + printf("red_perf not supported on Windows, skipping test\n"); + return TEST_SKIPPED; +} + +static int +test_red_all(void) +{ + printf("red_all not supported on Windows, skipping test\n"); + return TEST_SKIPPED; +} +#else + #include #include #include -#include "test.h" - #include #ifdef __INTEL_COMPILER @@ -57,6 +52,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 */ @@ -146,16 +142,7 @@ static void rdtsc_prof_init(struct rdtsc_prof *p, const char *name) static inline void rdtsc_prof_start(struct rdtsc_prof *p) { -#ifdef __PIC__ - asm volatile ( - "mov %%ebx, %%edi\n" - "cpuid\n" - "xchgl %%ebx, %%edi;\n" - : : : "%eax", "%edi", "%ecx", "%edx" ); -#else - asm( "cpuid" : : : "%eax", "%ebx", "%ecx", "%edx" ); -#endif - p->clk_start = rte_rdtsc(); + p->clk_start = rte_rdtsc_precise(); } static inline void rdtsc_prof_end(struct rdtsc_prof *p) @@ -238,7 +225,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; } /** @@ -258,7 +245,7 @@ static int check_drop_rate(double *diff, double drop_rate, double drop_prob, dou ret = 0; } } - return (ret); + return ret; } /** @@ -278,44 +265,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; } /** @@ -326,7 +276,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++) { @@ -335,14 +285,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; } /** @@ -373,11 +323,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; } /** @@ -404,11 +354,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; } /** @@ -444,8 +394,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, @@ -581,7 +531,7 @@ static enum test_result func_test1(struct test_config *tcfg) (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -692,7 +642,7 @@ static enum test_result func_test2(struct test_config *tcfg) (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -805,7 +755,7 @@ static enum test_result func_test3(struct test_config *tcfg) diff <= (double)tcfg->tqueue->avg_tolerance ? "pass" : "fail"); } out: - return (result); + return result; } /** @@ -947,7 +897,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; } /** @@ -1087,7 +1037,7 @@ static enum test_result func_test5(struct test_config *tcfg) diff, (double)tcfg->tqueue->drop_tolerance); } out: - return (result); + return result; } /** @@ -1123,7 +1073,7 @@ static struct test_queue ft6_tqueue = { static struct test_config func_test6_config = { .ifname = "functional test 6 interface", .msg = "functional test 6 : use several queues (each with its own run-time data),\n" - " use several RED configurations (such that each configuration is sharte_red by multiple queues),\n" + " use several RED configurations (such that each configuration is shared by multiple queues),\n" " increase average queue size to target level,\n" " dequeue all packets until queue is empty,\n" " confirm that average queue size is computed correctly while queue is empty\n" @@ -1218,7 +1168,7 @@ static enum test_result func_test6(struct test_config *tcfg) diff <= tcfg->tqueue->avg_tolerance ? "pass" : "fail"); } out: - return (result); + return result; } /** @@ -1389,7 +1339,7 @@ static enum test_result perf1_test(struct test_config *tcfg) rdtsc_prof_print(&prof); out: - return (result); + return result; } /** @@ -1576,7 +1526,7 @@ static enum test_result perf2_test(struct test_config *tcfg) rdtsc_prof_print(&prof); out: - return (result); + return result; } /** @@ -1640,10 +1590,10 @@ static void ovfl_check_avg(uint32_t avg) } static struct test_config ovfl_test1_config = { - .ifname = "queue avergage overflow test interface", + .ifname = "queue average overflow test interface", .msg = "overflow test 1 : use one RED configuration,\n" " increase average queue size to target level,\n" - " check maximum number of bits requirte_red to represent avg_s\n\n", + " check maximum number of bits required to represent avg_s\n\n", .htxt = "avg queue size " "wq_log2 " "fraction bits " @@ -1740,7 +1690,7 @@ static enum test_result ovfl_test1(struct test_config *tcfg) *tcfg->tvar->enqueued, *tcfg->tvar->dropped, drop_prob * 100.0, drop_rate * 100.0); out: - return (result); + return result; } /** @@ -1756,6 +1706,16 @@ struct tests func_tests[] = { { &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[] = { { &perf1_test1_config, perf1_test }, { &perf1_test2_config, perf1_test }, @@ -1821,12 +1781,12 @@ test_invalid_parameters(void) printf("%i: rte_red_config_init should have failed!\n", __LINE__); return -1; } - /* min_treshold == max_treshold */ + /* min_threshold == max_threshold */ if (rte_red_config_init(&config, 0, 1, 1, 0) == 0) { printf("%i: rte_red_config_init should have failed!\n", __LINE__); return -1; } - /* min_treshold > max_treshold */ + /* min_threshold > max_threshold */ if (rte_red_config_init(&config, 0, 2, 1, 0) == 0) { printf("%i: rte_red_config_init should have failed!\n", __LINE__); return -1; @@ -1859,31 +1819,64 @@ test_invalid_parameters(void) return 0; } +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); +} + +static int +test_red_perf(void) +{ + uint32_t num_tests = 0; + uint32_t num_pass = 0; - 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); +} - 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); +static int +test_red_all(void) +{ + 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); } -static struct test_command red_cmd = { - .command = "red_autotest", - .callback = test_red, -}; -REGISTER_TEST_COMMAND(red_cmd); +#endif /* !RTE_EXEC_ENV_WINDOWS */ + +REGISTER_TEST_COMMAND(red_autotest, test_red); +REGISTER_TEST_COMMAND(red_perf, test_red_perf); +REGISTER_TEST_COMMAND(red_all, test_red_all);