From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by dpdk.org (Postfix) with ESMTP id 74F27B372 for ; Mon, 18 Aug 2014 11:23:06 +0200 (CEST) Received: by mail-wi0-f172.google.com with SMTP id n3so3382533wiv.17 for ; Mon, 18 Aug 2014 02:26:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JYZIpIypb7162QeeHIH77AeiOhK18B8xxA8c/Uzk758=; b=NKxsRzEfApG7Qx9Vex1iq63inas5fuj1tDp0UVizb3i1TrnxdKjBhB2wPbUQ9vz8Jk 4o+ii4hhhaFWbarETamus11QN5jvC3RXrXLJXlZlUKkCmvhAAjBIcPjlwUn/0wvMQM+l rITfUxONzl5o+INyQlllw9wDxnkHR6FcGwSU3p/SS4iE07f9NSjzIyz/MN2mJYrGX3fU /huYOwApZDtD3ZeMqbIucRagW4NDJl74xf1v/JjjuTvA3FfhoK9QlM9Umscb5Ti+JS5h jffUCZGE8DvNoJl2NCalWEianrF3SV5ZP7yB2cJJW0IVj+YhB0UXwiYDeFa+YdLPBWsa VyGw== X-Gm-Message-State: ALoCoQkVv8gTmJaXvyr0sA4z+9hxM4yqpkjFkR84px/yFu9ZFhRfDRCPRktZA39g3MMXSN2IfmcE X-Received: by 10.194.118.201 with SMTP id ko9mr39265220wjb.26.1408353988732; Mon, 18 Aug 2014 02:26:28 -0700 (PDT) Received: from alcyon.dev.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id za9sm25087627wjc.29.2014.08.18.02.26.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Aug 2014 02:26:28 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Mon, 18 Aug 2014 11:26:10 +0200 Message-Id: <1408353973-16663-5-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1408353973-16663-1-git-send-email-david.marchand@6wind.com> References: <1408353973-16663-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH 4/7] app/test: introduce dynamic commands list X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Aug 2014 09:23:07 -0000 This patch adds a way to dynamically add a test without modifying commands.c. Move all current tests in a builtin_commands[] list, next patch will convert them to this new system. Signed-off-by: David Marchand --- app/test/commands.c | 118 ++++++++++++++++++++++++++++++++++----------------- app/test/test.c | 3 ++ app/test/test.h | 21 +++++++++ 3 files changed, 103 insertions(+), 39 deletions(-) diff --git a/app/test/commands.c b/app/test/commands.c index 4a0cc05..a1ffd43 100644 --- a/app/test/commands.c +++ b/app/test/commands.c @@ -78,6 +78,15 @@ /****************/ +static struct test_commands_list commands_list = + TAILQ_HEAD_INITIALIZER(commands_list); + +void +add_test_command(struct test_command *t) +{ + TAILQ_INSERT_TAIL(&commands_list, t, next); +} + struct cmd_autotest_result { cmdline_fixed_string_t autotest; }; @@ -86,9 +95,15 @@ static void cmd_autotest_parsed(void *parsed_result, __attribute__((unused)) struct cmdline *cl, __attribute__((unused)) void *data) { + struct test_command *t; struct cmd_autotest_result *res = parsed_result; int ret = 0; + TAILQ_FOREACH(t, &commands_list, next) { + if (!strcmp(res->autotest, t->command)) + ret = t->callback(); + } + if (!strcmp(res->autotest, "version_autotest")) ret = test_version(); if (!strcmp(res->autotest, "eal_fs_autotest")) @@ -214,45 +229,7 @@ static void cmd_autotest_parsed(void *parsed_result, cmdline_parse_token_string_t cmd_autotest_autotest = TOKEN_STRING_INITIALIZER(struct cmd_autotest_result, autotest, - "pci_autotest#memory_autotest#" - "per_lcore_autotest#spinlock_autotest#" - "rwlock_autotest#atomic_autotest#" - "byteorder_autotest#prefetch_autotest#" - "cycles_autotest#logs_autotest#" - "memzone_autotest#ring_autotest#" - "mempool_autotest#mbuf_autotest#" - "timer_autotest#malloc_autotest#" - "memcpy_autotest#hash_autotest#" - "lpm_autotest#debug_autotest#" - "lpm6_autotest#" - "errno_autotest#tailq_autotest#" - "string_autotest#multiprocess_autotest#" - "cpuflags_autotest#eal_flags_autotest#" - "alarm_autotest#interrupt_autotest#" - "version_autotest#eal_fs_autotest#" - "cmdline_autotest#func_reentrancy_autotest#" -#ifdef RTE_LIBRTE_PMD_BOND - "link_bonding_autotest#" -#endif - "mempool_perf_autotest#hash_perf_autotest#" - "memcpy_perf_autotest#ring_perf_autotest#" - "red_autotest#meter_autotest#sched_autotest#" - "memcpy_perf_autotest#kni_autotest#" - "ivshmem_autotest#" - "devargs_autotest#table_autotest#" -#ifdef RTE_LIBRTE_ACL - "acl_autotest#" -#endif - "power_autotest#" - "timer_perf_autotest#" -#ifdef RTE_LIBRTE_PMD_RING - "ring_pmd_autotest#" -#endif -#ifdef RTE_LIBRTE_KVARGS - "kvargs_autotest#" -#endif - "common_autotest#" - "distributor_autotest#distributor_perf_autotest"); + ""); cmdline_parse_inst_t cmd_autotest = { .f = cmd_autotest_parsed, /* function to call */ @@ -460,3 +437,66 @@ cmdline_parse_ctx_t main_ctx[] = { NULL, }; +int commands_init(void) +{ + struct test_command *t; + char builtin_commands[] = + "pci_autotest#memory_autotest#" + "per_lcore_autotest#spinlock_autotest#" + "rwlock_autotest#atomic_autotest#" + "byteorder_autotest#prefetch_autotest#" + "cycles_autotest#logs_autotest#" + "memzone_autotest#ring_autotest#" + "mempool_autotest#mbuf_autotest#" + "timer_autotest#malloc_autotest#" + "memcpy_autotest#hash_autotest#" + "lpm_autotest#debug_autotest#" + "lpm6_autotest#" + "errno_autotest#tailq_autotest#" + "string_autotest#multiprocess_autotest#" + "cpuflags_autotest#eal_flags_autotest#" + "alarm_autotest#interrupt_autotest#" + "version_autotest#eal_fs_autotest#" + "cmdline_autotest#func_reentrancy_autotest#" +#ifdef RTE_LIBRTE_PMD_BOND + "link_bonding_autotest#" +#endif + "mempool_perf_autotest#hash_perf_autotest#" + "memcpy_perf_autotest#ring_perf_autotest#" + "red_autotest#meter_autotest#sched_autotest#" + "memcpy_perf_autotest#kni_autotest#" + "ivshmem_autotest#" + "devargs_autotest#table_autotest#" +#ifdef RTE_LIBRTE_ACL + "acl_autotest#" +#endif + "power_autotest#" + "timer_perf_autotest#" +#ifdef RTE_LIBRTE_PMD_RING + "ring_pmd_autotest#" +#endif +#ifdef RTE_LIBRTE_KVARGS + "kvargs_autotest#" +#endif + "common_autotest#" + "distributor_autotest#distributor_perf_autotest"; + char *commands, *ptr; + int commands_len = strlen(builtin_commands) + 1; + + TAILQ_FOREACH(t, &commands_list, next) { + commands_len += strlen(t->command) + 1; + } + + commands = malloc(commands_len); + if (!commands) + return -1; + + ptr = commands; + TAILQ_FOREACH(t, &commands_list, next) { + ptr += sprintf(ptr, "%s#", t->command); + } + ptr += sprintf(ptr, "%s", builtin_commands); + + cmd_autotest_autotest.string_data.str = commands; + return 0; +} diff --git a/app/test/test.c b/app/test/test.c index 589a168..a33b2b5 100644 --- a/app/test/test.c +++ b/app/test/test.c @@ -126,6 +126,9 @@ main(int argc, char **argv) rte_timer_subsystem_init(); #endif + if (commands_init() < 0) + return -1; + argv += ret; prgname = argv[0]; diff --git a/app/test/test.h b/app/test/test.h index 181c38e..bba0ec5 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -34,6 +34,8 @@ #ifndef _TEST_H_ #define _TEST_H_ +#include + #define TEST_ASSERT(cond, msg, ...) do { \ if (!(cond)) { \ printf("TestCase %s() line %d failed: " \ @@ -125,6 +127,8 @@ int unit_test_suite_runner(struct unit_test_suite *suite); extern const char *prgname; +int commands_init(void); + int main(int argc, char **argv); int test_pci(void); @@ -183,4 +187,21 @@ int test_link_bonding(void); int test_pci_run; +typedef int (test_callback)(void); +TAILQ_HEAD(test_commands_list, test_command); +struct test_command { + TAILQ_ENTRY(test_command) next; + const char *command; + test_callback *callback; +}; + +void add_test_command(struct test_command *t); + +#define REGISTER_TEST_COMMAND(t) \ +static void testfn_##t(void);\ +void __attribute__((constructor, used)) testfn_##t(void)\ +{\ + add_test_command(&t);\ +} + #endif -- 1.7.10.4