From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id A946E68CA for ; Tue, 28 Jan 2014 17:06:08 +0100 (CET) Received: by mail-wg0-f42.google.com with SMTP id l18so6298022wgh.3 for ; Tue, 28 Jan 2014 08:07:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AuIw/rykq15+U7pflqJBERqx1zqXmrqpRZ4SiFokUfQ=; b=SFIHO3esUmMv6PI1keftZbWLtaROCX96L+xrxtJs8FK9X5JpAgYHta+T3cRXOj5Czr pdW34NK6SkaqdqpxaQe/QSvSBv31hHiHGHpbOgcaqymmelC1H3u08IX81IZVCwewX/Ak jVrq4K4YZEzkaGwYSIPHS/prc/t5MIpqN05LaWFknEYzEzKr0b2kTm8Hrk6E0bzLW4OZ x+4HpilwpqqaDl5G8Jo6LxpjicVEWzegzsQOM+y9JRI7xx+fsZZvIKqJ7RYUuXA0lQGG XpsAnjqEyiXrUxLH7RBXdlqWTgMywV+hrasYSWl47vOxp7Onfei3oWp1VJBP25jvqRXp UzwQ== X-Gm-Message-State: ALoCoQlnKJILSGuQwosSj8gTdc8WtjwfFr68bfSsw3exHfd1pWSeYR4ePtAL28XDbBtwVp0tQ4Yc X-Received: by 10.194.176.163 with SMTP id cj3mr1644349wjc.8.1390925246802; Tue, 28 Jan 2014 08:07:26 -0800 (PST) Received: from glumotte.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id d6sm36407821wic.9.2014.01.28.08.07.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2014 08:07:25 -0800 (PST) From: Olivier Matz To: dev@dpdk.org Date: Tue, 28 Jan 2014 17:06:44 +0100 Message-Id: <1390925204-10800-12-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1390925204-10800-1-git-send-email-olivier.matz@6wind.com> References: <1390925204-10800-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH 11/11] kvargs: add test case in app/test 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: Tue, 28 Jan 2014 16:06:09 -0000 Add a file app/test/test_kvargs.c that checks the rte_kvargs API. The test passes: RTE>>kvargs == test valid case == == test invalid case == PMD: Error parsing device, invalid key Test OK I also tested that rte_eth_pcap runs with the following arguments: ./app/testpmd -c 0x15 -n 3 --proc-type=primary --huge-dir=/mnt/huge \ --use-device="eth_pcap0;iface=ixgbe0" \ -- -i --port-topology=chained ./app/testpmd -c 0x15 -n 3 --proc-type=primary --huge-dir=/mnt/huge \ --use-device="eth_pcap0;rx_iface=ixgbe0;rx_iface=ixgbe1;tx_iface=ixgbe0" \ -- -i --port-topology=chained Signed-off-by: Olivier Matz --- app/test/Makefile | 1 + app/test/commands.c | 8 ++ app/test/test.h | 1 + app/test/test_kvargs.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 app/test/test_kvargs.c diff --git a/app/test/Makefile b/app/test/Makefile index bb2e907..b022705 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -96,6 +96,7 @@ SRCS-$(CONFIG_RTE_APP_TEST) += test_timer_perf.c ifeq ($(CONFIG_RTE_APP_TEST),y) SRCS-$(CONFIG_RTE_LIBRTE_ACL) += test_acl.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) += test_pmd_ring.c +SRCS-$(CONFIG_RTE_LIBRTE_KVARGS) += test_kvargs.c endif CFLAGS += -O3 diff --git a/app/test/commands.c b/app/test/commands.c index 83f737f..9f42d36 100644 --- a/app/test/commands.c +++ b/app/test/commands.c @@ -2,6 +2,7 @@ * BSD LICENSE * * Copyright(c) 2010-2013 Intel Corporation. All rights reserved. + * Copyright(c) 2014 6WIND S.A. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -191,6 +192,10 @@ static void cmd_autotest_parsed(void *parsed_result, if (all || !strcmp(res->autotest, "acl_autotest")) ret |= test_acl(); #endif /* RTE_LIBRTE_ACL */ +#ifdef RTE_LIBRTE_KVARGS + if (all || !strcmp(res->autotest, "kvargs_autotest")) + ret |= test_kvargs(); +#endif /* RTE_LIBRTE_KVARGS */ if (ret == 0) printf("Test OK\n"); @@ -231,6 +236,9 @@ cmdline_parse_token_string_t cmd_autotest_autotest = #ifdef RTE_LIBRTE_PMD_RING "ring_pmd_autotest#" #endif +#ifdef RTE_LIBRTE_KVARGS + "kvargs_autotest#" +#endif "common_autotest#all_autotests"); cmdline_parse_inst_t cmd_autotest = { diff --git a/app/test/test.h b/app/test/test.h index bb349b2..bb77594 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -91,6 +91,7 @@ int test_kni(void); int test_power(void); int test_common(void); int test_pmd_ring(void); +int test_kvargs(void); int test_pci_run; diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c new file mode 100644 index 0000000..371d36d --- /dev/null +++ b/app/test/test_kvargs.c @@ -0,0 +1,235 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2014 6WIND S.A. + * 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. + */ + +#include +#include +#include + +#include +#include + +#include "test.h" + +/* incrementd in handler, to check it is properly called once per + * key/value association */ +static unsigned count; + +/* this handler increment the "count" variable at each call and check + * that the key is "check" and the value is "value%d" */ +static int check_handler(const char *key, const char *value, + __rte_unused void *opaque) +{ + char buf[16]; + + /* we check that the value is "check" */ + if (strcmp(key, "check")) + return -1; + + /* we check that the value is "value$(count)" */ + snprintf(buf, sizeof(buf), "value%d", count); + if (strncmp(buf, value, sizeof(buf))) + return -1; + + count ++; + return 0; +} + +/* test a valid case */ +static int test_valid_kvargs(void) +{ + struct rte_kvargs *kvlist; + const char *args; + const char *valid_keys_list[] = { "foo", "check", NULL }; + const char **valid_keys; + + /* empty args is valid */ + args = ""; + valid_keys = NULL; + kvlist = rte_kvargs_parse(args, valid_keys); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error"); + rte_kvargs_free(kvlist); + goto fail; + } + rte_kvargs_free(kvlist); + + /* first test without valid_keys */ + args = "foo=1234;check=value0;check=value1"; + valid_keys = NULL; + kvlist = rte_kvargs_parse(args, valid_keys); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error"); + rte_kvargs_free(kvlist); + goto fail; + } + /* call check_handler() for all entries with key="check" */ + count = 0; + if (rte_kvargs_process(kvlist, "check", check_handler, NULL) < 0) { + printf("rte_kvargs_process() error\n"); + rte_kvargs_free(kvlist); + goto fail; + } + if (count != 2) { + printf("invalid count value %d after rte_kvargs_process(check)\n", + count); + rte_kvargs_free(kvlist); + goto fail; + } + count = 0; + /* call check_handler() for all entries with key="unexistant_key" */ + if (rte_kvargs_process(kvlist, "unexistant_key", check_handler, NULL) < 0) { + printf("rte_kvargs_process() error\n"); + rte_kvargs_free(kvlist); + goto fail; + } + if (count != 0) { + printf("invalid count value %d after rte_kvargs_process(unexistant_key)\n", + count); + rte_kvargs_free(kvlist); + goto fail; + } + /* count all entries with key="foo" */ + count = rte_kvargs_count(kvlist, "foo"); + if (count != 1) { + printf("invalid count value %d after rte_kvargs_count(foo)\n", + count); + rte_kvargs_free(kvlist); + goto fail; + } + /* count all entries */ + count = rte_kvargs_count(kvlist, NULL); + if (count != 3) { + printf("invalid count value %d after rte_kvargs_count(NULL)\n", + count); + rte_kvargs_free(kvlist); + goto fail; + } + /* count all entries with key="unexistant_key" */ + count = rte_kvargs_count(kvlist, "unexistant_key"); + if (count != 0) { + printf("invalid count value %d after rte_kvargs_count(unexistant_key)\n", + count); + rte_kvargs_free(kvlist); + goto fail; + } + rte_kvargs_free(kvlist); + + /* second test using valid_keys */ + args = "foo=droids;check=value0;check=value1;check=wrong_value"; + valid_keys = valid_keys_list; + kvlist = rte_kvargs_parse(args, valid_keys); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error"); + rte_kvargs_free(kvlist); + goto fail; + } + /* call check_handler() on all entries with key="check", it + * should fail as the value is not recognized by the handler */ + if (rte_kvargs_process(kvlist, "check", check_handler, NULL) == 0) { + printf("rte_kvargs_process() is success bu should not\n"); + rte_kvargs_free(kvlist); + goto fail; + } + count = rte_kvargs_count(kvlist, "check"); + if (count != 3) { + printf("invalid count value %d after rte_kvargs_count(check)\n", + count); + rte_kvargs_free(kvlist); + goto fail; + } + rte_kvargs_free(kvlist); + + return 0; + + fail: + printf("while processing <%s>", args); + if (valid_keys != NULL && *valid_keys != NULL) { + printf(" using valid_keys=<%s", *valid_keys); + while (*(++valid_keys) != NULL) + printf(",%s", *valid_keys); + printf(">"); + } + printf("\n"); + return -1; +} + +/* test several error cases */ +static int test_invalid_kvargs(void) +{ + struct rte_kvargs *kvlist; + /* list of argument that should fail */ + const char *args_list[] = { + "wrong-key=x", /* key not in valid_keys_list */ + "foo=1;foo=", /* empty value */ + "foo=1;;foo=2", /* empty key/value */ + "foo=1;foo", /* no value */ + "foo=1;=2", /* no key */ + ";=", /* also test with a smiley */ + NULL }; + const char **args; + const char *valid_keys_list[] = { "foo", "check", NULL }; + const char **valid_keys = valid_keys_list; + + for (args = args_list; *args != NULL; args++) { + + kvlist = rte_kvargs_parse(*args, valid_keys); + if (kvlist != NULL) { + printf("rte_kvargs_parse() returned 0 (but should not)\n"); + rte_kvargs_free(kvlist); + goto fail; + } + return 0; + } + + fail: + printf("while processing <%s>", *args); + if (valid_keys != NULL && *valid_keys != NULL) { + printf(" using valid_keys=<%s", *valid_keys); + while (*(++valid_keys) != NULL) + printf(",%s", *valid_keys); + printf(">"); + } + printf("\n"); + return -1; +} + +int test_kvargs(void) +{ + printf("== test valid case ==\n"); + if (test_valid_kvargs() < 0) + return -1; + printf("== test invalid case ==\n"); + if (test_invalid_kvargs() < 0) + return -1; + return 0; +} -- 1.8.4.rc3