From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.elyzion.net (freeside.gandi.net [217.70.181.31]) by dpdk.org (Postfix) with ESMTP id E20BC95CD for ; Tue, 14 Jun 2016 15:03:34 +0200 (CEST) Received: from nikita (uid 1001) (envelope-from nikita@elyzion.net) id 1d1a7 by mail.elyzion.net (DragonFly Mail Agent v0.10); Tue, 14 Jun 2016 15:03:34 +0200 From: Nikita Kozlov To: dev@dpdk.org Cc: Bruce Richardson Date: Tue, 14 Jun 2016 15:03:29 +0200 Message-Id: <1465909410-4668-4-git-send-email-nikita@elyzion.net> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465909410-4668-1-git-send-email-nikita@elyzion.net> References: <1462539092-24389-1-git-send-email-bruce.richardson@intel.com> <1465909410-4668-1-git-send-email-nikita@elyzion.net> Subject: [dpdk-dev] [PATCH 3/4] test: change lpm test to use routes as resource 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, 14 Jun 2016 13:03:35 -0000 Change the lpm autotest to use the routes data from the resource data stored in the binary rather than including it directly into the C file as a C header. This speeds up compile and link time, without changing the test results. Signed-off-by: Nikita Kozlov Signed-off-by: Bruce Richardson --- app/test/test_lpm.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/app/test/test_lpm.c b/app/test/test_lpm.c index f6930fb..de54720 100644 --- a/app/test/test_lpm.c +++ b/app/test/test_lpm.c @@ -34,13 +34,26 @@ #include #include #include +#include #include +#include +#include #include "test.h" -#include "test_lpm_routes.h" +#include "resource.h" + #include "test_xmmt_ops.h" +REGISTER_LINKED_RESOURCE(test_lpm_data) + +struct route_rule { + uint32_t ip; + uint8_t depth; +}; +static struct route_rule *large_route_table; +static unsigned int num_route_entries; + #define TEST_LPM_ASSERT(cond) do { \ if (!(cond)) { \ printf("Error at line %d: \n", __LINE__); \ @@ -1217,6 +1230,62 @@ test17(void) return PASS; } +static int +load_large_route_table(void) +{ + const struct resource *r; + const char *lpm_data; + + r = resource_find("test_lpm_data"); + TEST_ASSERT_NOT_NULL(r, "No large lpm table data found"); + + /* the routing table size is going to be less than the size of the + * resource, since text extries are more verbose. Allocate this as + * the max size, and shrink the allocation later + */ + large_route_table = rte_malloc(NULL, resource_size(r), 0); + if (large_route_table == NULL) + return -1; + + /* parse the lpm table. All entries are of format: + * {IP-as-decimal-unsigned, depth} + * For example: + * {1234567U, 24}, + * We use the "U" and "}" characters as format check characters, + * after parsing each number. + */ + for (lpm_data = r->begin; lpm_data < r->end; lpm_data++) { + if (*lpm_data == '{') { + char *endptr; + + lpm_data++; + large_route_table[num_route_entries].ip = \ + strtoul(lpm_data, &endptr, 0); + if (*endptr != 'U') { + if (num_route_entries > 0) + printf("Failed parse of %.*s\n", 12, lpm_data); + continue; + } + + lpm_data = endptr + 2; /* skip U and , */ + large_route_table[num_route_entries].depth = \ + strtoul(lpm_data, &endptr, 0); + if (*endptr != '}') { + if (num_route_entries > 0) + printf("Failed parse of %.*s\n",5, lpm_data); + continue; + } + + num_route_entries++; + } + } + + large_route_table = rte_realloc(large_route_table, + sizeof(large_route_table[0]) * num_route_entries, 0); + printf("Read %u route entries\n", num_route_entries); + return 0; +} + /* * Do all unit tests. */ @@ -1227,6 +1296,8 @@ test_lpm(void) unsigned i; int status, global_status = 0; + TEST_ASSERT_SUCCESS(load_large_route_table(), "Error loading lpm table"); + for (i = 0; i < NUM_LPM_TESTS; i++) { status = tests[i](); if (status < 0) { -- 2.8.1