From patchwork Thu Mar 12 09:39:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanqin Wei X-Patchwork-Id: 1253448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48dP2R5vcxz9sQt for ; Thu, 12 Mar 2020 20:40:31 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5ABB186BB9; Thu, 12 Mar 2020 09:40:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l0FAOrxEd8dQ; Thu, 12 Mar 2020 09:40:28 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id B29A586BFF; Thu, 12 Mar 2020 09:40:28 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A6C56C1D87; Thu, 12 Mar 2020 09:40:28 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1BF1FC0177 for ; Thu, 12 Mar 2020 09:40:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 07976893A2 for ; Thu, 12 Mar 2020 09:40:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bDWWmnEiFq-j for ; Thu, 12 Mar 2020 09:40:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by hemlock.osuosl.org (Postfix) with ESMTP id 9AA16893A9 for ; Thu, 12 Mar 2020 09:40:25 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4569B1FB; Thu, 12 Mar 2020 02:40:25 -0700 (PDT) Received: from net-arm-thunderx2-03.shanghai.arm.com (net-arm-thunderx2-03.shanghai.arm.com [10.169.41.185]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 73F333F67D; Thu, 12 Mar 2020 02:40:23 -0700 (PDT) From: Yanqin Wei To: dev@openvswitch.org Date: Thu, 12 Mar 2020 17:39:53 +0800 Message-Id: <20200312093953.56756-4-Yanqin.Wei@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312093953.56756-1-Yanqin.Wei@arm.com> References: <20200312093953.56756-1-Yanqin.Wei@arm.com> Cc: nd@arm.com, Gavin.Hu@arm.com Subject: [ovs-dev] [PATCH v1 3/3] tests/test-sda-table: add check test for sda-table. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add check test for sda-table lookup, insertion and deletion. Reviewed-by: Gavin Hu Reviewed-by: Malvika Gupta Signed-off-by: Yanqin Wei --- tests/automake.mk | 3 +- tests/test-sda-table.c | 197 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 tests/test-sda-table.c diff --git a/tests/automake.mk b/tests/automake.mk index 9c7ebdce9..9581ffb8e 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -462,7 +462,8 @@ tests_ovstest_SOURCES = \ tests/test-bitmap.c \ tests/test-vconn.c \ tests/test-aa.c \ - tests/test-stopwatch.c + tests/test-stopwatch.c \ + tests/test-sda-table.c if !WIN32 tests_ovstest_SOURCES += \ diff --git a/tests/test-sda-table.c b/tests/test-sda-table.c new file mode 100644 index 000000000..6bcd4cefb --- /dev/null +++ b/tests/test-sda-table.c @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2020 Arm Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* A functional test for some of the functions and macros declared in + * sda-table.h. */ + +#include +#undef NDEBUG +#include "sda-table.h" +#include "id-pool.h" +#include +#include +#include +#include "bitmap.h" +#include "command-line.h" +#include "ovstest.h" +#include "ovs-thread.h" +#include "util.h" + +struct element { + struct sda_table_node node; +}; + +/* Tests basic sda table insertion and deletion for single node chain. */ +static void +test_sda_table_add_del_singlenode_chain(void) +{ + enum { N_ELEMS = 10000 }; + struct element elements[N_ELEMS]; + uint32_t id[N_ELEMS]; + + size_t i; + struct id_pool *pool = id_pool_create(0, UINT32_MAX - 1); + struct sda_table sda = SDA_TABLE_INITIALIZER; + const struct sda_table_node * node; + bool ret; + + for (i = 0; i < N_ELEMS; i++) { + ret = id_pool_alloc_id(pool, &id[i]); + ovs_assert(ret == true); + + ret = sda_table_insert_node(&sda, id[i], &elements[id[i]].node); + ovs_assert(ret == true); + + node = sda_table_find_node(&sda, id[i]); + ovs_assert(node == &elements[id[i]].node); + + ret = sda_table_remove_node(&sda, id[i], &elements[id[i]].node); + ovs_assert(ret == true); + + node = sda_table_find_node(&sda, id[i]); + ovs_assert(node == NULL); + + id_pool_free_id(pool, id[i]); + } + + sda_table_destroy(&sda); + id_pool_destroy(pool); +} + + +static void +test_sda_table_add_del_multinode_chain(void) +{ + enum { N_ELEMS = 10000, N_NODES = 10 }; + struct element elements[N_ELEMS][N_NODES]; + uint32_t id[N_ELEMS]; + + struct element *elm; + size_t i, j; + struct id_pool *pool = id_pool_create(0, UINT32_MAX - 1); + struct sda_table sda = SDA_TABLE_INITIALIZER; + bool ret; + + for (i = 0; i < N_ELEMS; i++) { + ret = id_pool_alloc_id(pool, &id[i]); + ovs_assert(ret == true); + + for (j = 0; j < N_NODES; j++) { + ret = sda_table_insert_node(&sda, id[i], &elements[id[i]][j].node); + ovs_assert(ret == true); + } + + SDA_TABLE_FOR_EACH_WITH_ID (elm, node, id[i], &sda) { + for (j = 0; j < N_NODES; j++) { + if (elm == &elements[id[i]][j]) { + break; + } + } + ovs_assert(elm == &elements[id[i]][j]); + } + + for (j = N_NODES / 2; j < N_NODES; j++) { + ret = sda_table_remove_node(&sda, id[i], &elements[id[i]][j].node); + ovs_assert(ret == true); + } + + SDA_TABLE_FOR_EACH_WITH_ID (elm, node, id[i], &sda) { + for (j = 0; j < N_NODES / 2; j++) { + if (elm == &elements[id[i]][j]) { + break; + } + } + ovs_assert(elm == &elements[id[i]][j]); + } + } + + for (i = N_ELEMS / 2; i < N_ELEMS; i++) { + for (j = 0; j < N_NODES; j++) { + ret = sda_table_remove_node(&sda, id[i], &elements[id[i]][j].node); + } + id_pool_free_id(pool, id[i]); + + SDA_TABLE_FOR_EACH_WITH_ID (elm, node, id[i], &sda) { + ovs_assert(elm == NULL); + } + } + + for (i = 0; i < N_ELEMS / 2; i++) { + SDA_TABLE_FOR_EACH_WITH_ID (elm, node, id[i], &sda) { + for (j = 0; j < N_NODES; j++) { + if (elm == &elements[id[i]][j]) { + break; + } + } + ovs_assert(elm == &elements[id[i]][j]); + } + } + + sda_table_destroy(&sda); + id_pool_destroy(pool); +} + +static void +test_sda_table_invalid_add_del(void) +{ + enum { N_ELEMS = 10000, N_NODES = 10 }; + struct element elements; + + struct id_pool *pool = id_pool_create(0, UINT32_MAX - 1); + struct sda_table sda = SDA_TABLE_INITIALIZER; + bool ret; + + ret = sda_table_insert_node(&sda, SDA_TABLE_BASE_SIZE * 2, &elements.node); + ovs_assert(ret == true); + + ret = sda_table_remove_node(&sda, SDA_TABLE_BASE_SIZE * 2, &elements.node); + ovs_assert(ret == true); + + ret = sda_table_remove_node(&sda, SDA_TABLE_BASE_SIZE * 2, &elements.node); + ovs_assert(ret == false); + + sda_table_destroy(&sda); + id_pool_destroy(pool); +} + + +static void +run_tests(struct ovs_cmdl_context *ctx OVS_UNUSED) +{ + test_sda_table_add_del_singlenode_chain(); + test_sda_table_add_del_multinode_chain(); + test_sda_table_invalid_add_del(); + printf("\n"); +} + +static const struct ovs_cmdl_command commands[] = { + {"check", NULL, 0, 1, run_tests, OVS_RO}, + {NULL, NULL, 0, 0, NULL, OVS_RO}, +}; + +static void +test_sda_table_main(int argc, char *argv[]) +{ + struct ovs_cmdl_context ctx = { + .argc = argc - optind, + .argv = argv + optind, + }; + + set_program_name(argv[0]); + ovs_cmdl_run_command(&ctx, commands); +} + +OVSTEST_REGISTER("test-sda-table", test_sda_table_main);