From patchwork Wed Mar 22 14:48:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 95737 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp228756obz; Wed, 22 Mar 2017 07:01:16 -0700 (PDT) X-Received: by 10.55.60.137 with SMTP id j131mr32087813qka.19.1490191276757; Wed, 22 Mar 2017 07:01:16 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u63si487526qkf.173.2017.03.22.07.01.16; Wed, 22 Mar 2017 07:01:16 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 573B462D5D; Wed, 22 Mar 2017 14:01:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED,URI_NOVOWEL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 566C2608DE; Wed, 22 Mar 2017 13:51:01 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C3A8D6094C; Wed, 22 Mar 2017 13:50:55 +0000 (UTC) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by lists.linaro.org (Postfix) with ESMTPS id E9BBB642CB for ; Wed, 22 Mar 2017 13:49:28 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id v203so8915479wmg.0 for ; Wed, 22 Mar 2017 06:49:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7+6db+8yd1186qqQEIT+e7bLEfk8u2CqxA2HM6rq4Aw=; b=mxBrlB1+pcP4tTGn8gTet4nX+QC49k68B2rdml+0TzVVL1EYKhVyuX3r8pmSIX0Sig i3ML8wijZ6OwX/5EI62rSoewLkeEyCdWfTv0V1FQGMlJH6DJ0Dvucsu0sENPD+02jdLn w63kP2UuVCI7rhjF1+fQwBnXrEef2fEy4W85b9O9dGGtF5/WFP7mHkDyxkNkkb1H2vL0 +yLVJ/FRbosNEwdMX803Fh2bs7LJmTPc3r9xtrhP+wbWQGQgCB6bctr3tTj38sCKZyjY U/mS3Abc+W5aYqlfh6ZLoslIxUvXrprki1QAv9pYdFT+lYKYz0RXd94olGQc/hkstRe8 RIsA== X-Gm-Message-State: AFeK/H1hPq/8AR94RT/XRNJjVRZ5ln82Sv2t+EZU0zN6NCQxGRXro+tICsKvtR2CIddfEGlPlSI= X-Received: by 10.25.99.27 with SMTP id x27mr11343363lfb.104.1490190567684; Wed, 22 Mar 2017 06:49:27 -0700 (PDT) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id l23sm522305lfk.27.2017.03.22.06.49.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Mar 2017 06:49:27 -0700 (PDT) From: Christophe Milard To: yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Wed, 22 Mar 2017 15:48:20 +0100 Message-Id: <1490194110-40168-14-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> References: <1490194110-40168-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv2 13/23] test: drv: device creation and destruction X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Testing that devices can be created and removed from ODP. Signed-off-by: Christophe Milard --- .../validation/drv/drvdriver/.gitignore | 1 + .../validation/drv/drvdriver/Makefile.am | 11 ++ .../validation/drv/drvdriver/drvdriver_device.c | 218 +++++++++++++++++++++ .../validation/drv/drvdriver/drvdriver_device.h | 24 +++ .../drv/drvdriver/drvdriver_device_main.c | 12 ++ test/linux-generic/Makefile.am | 1 + 6 files changed, 267 insertions(+) create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_device.c create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_device.h create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c -- 2.7.4 diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore index a842448..97b4312 100644 --- a/test/common_plat/validation/drv/drvdriver/.gitignore +++ b/test/common_plat/validation/drv/drvdriver/.gitignore @@ -1,2 +1,3 @@ drvdriver_enumr_class_main drvdriver_enumr_main +drvdriver_device_main diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am index 3476c50..544586c 100644 --- a/test/common_plat/validation/drv/drvdriver/Makefile.am +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am @@ -25,3 +25,14 @@ drvdriver_enumr_main_LDADD = libtestdrvdriverenumr.la \ $(LIBCUNIT_COMMON) $(LIBODP) EXTRA_DIST += drvdriver_enumr.h + +#tests for device creation: +noinst_LTLIBRARIES += libtestdrvdriverdevice.la +libtestdrvdriverdevice_la_SOURCES = drvdriver_device.c + +test_PROGRAMS += drvdriver_device_main$(EXEEXT) +dist_drvdriver_device_main_SOURCES = drvdriver_device_main.c +drvdriver_device_main_LDADD = libtestdrvdriverdevice.la \ + $(LIBCUNIT_COMMON) $(LIBODP) + +EXTRA_DIST += drvdriver_device.h diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_device.c b/test/common_plat/validation/drv/drvdriver/drvdriver_device.c new file mode 100644 index 0000000..d010026 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_device.c @@ -0,0 +1,218 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include "drvdriver_device.h" +#include + +static odp_instance_t odp_instance; +static odpdrv_enumr_class_t enumr_class1; +static odpdrv_enumr_t enumr1; + +typedef struct dev_enumr_data_t { /* enumerator data for registered devices */ + odpdrv_shm_t shm_handle; + int device_number; +} dev_enumr_data_t; + +#define NB_DEVICES 5 + +/* forward declaration */ +static int enumr1_probe(void); +static int enumr1_remove(void); +static int enumr_class1_probe(void); +static int enumr_class1_remove(void); + +/* because many things to be checked are performed during ODP initialisation, + * the initialisation functions have to be a part of the test + */ +static int tests_global_init(void) +{ + if (0 != odp_init_global(&odp_instance, NULL, NULL)) { + fprintf(stderr, "error: odp_init_global() failed.\n"); + return -1; + } + if (0 != odp_init_local(odp_instance, ODP_THREAD_CONTROL)) { + fprintf(stderr, "error: odp_init_local() failed.\n"); + return -1; + } + + return 0; +} + +static int tests_global_term(void) +{ + if (0 != odp_term_local()) { + fprintf(stderr, "error: odp_term_local() failed.\n"); + return -1; + } + + if (0 != odp_term_global(odp_instance)) { + fprintf(stderr, "error: odp_term_global() failed.\n"); + return -1; + } + + return 0; +} + +/*enumerator register functions */ +static odpdrv_enumr_t enumr1_register(void) +{ + odpdrv_enumr_param_t param = { + .enumr_class = enumr_class1, + .api_name = "Enumerator_interface_1", + .api_version = 1, + .probe = enumr1_probe, + .remove = enumr1_remove, + .register_notifier = NULL + }; + + enumr1 = odpdrv_enumr_register(¶m); + return enumr1; +} + +/*enumerator probe functions, just making sure they have been run: */ +static int enumr1_probe(void) +{ + int dev; + odpdrv_shm_t shm; + dev_enumr_data_t *dev_data; + + odpdrv_device_param_t param = { + .enumerator = enumr1, + .address = "00:00:0X", + .enum_dev = NULL + }; + + /* create 5 devices: */ + for (dev = 0; dev < NB_DEVICES; dev++) { + shm = odpdrv_shm_reserve(NULL, sizeof(dev_enumr_data_t), + 0, ODPDRV_SHM_SINGLE_VA); + CU_ASSERT(ODPDRV_SHM_INVALID != shm); + dev_data = odpdrv_shm_addr(shm); + CU_ASSERT_PTR_NOT_NULL(dev_data); + + dev_data->shm_handle = shm; + dev_data->device_number = dev; + + param.address[7] = '0' + dev; /* change X in the address */ + param.enum_dev = dev_data; + + CU_ASSERT(odpdrv_device_create(¶m) != + ODPDRV_DEVICE_INVALID); + } + + CU_ASSERT(odpdrv_print_all() == 0); + + return 0; +} + +/* enumerator device removal callback function: */ +static void enumr5_device_destroy_terminate(void *priv_data) +{ + dev_enumr_data_t *dev_data; + int dev_nb; + odpdrv_shm_t shm; + + dev_data = (dev_enumr_data_t *)priv_data; + dev_nb = dev_data->device_number; + printf("removing device number: %d\n", dev_nb); + CU_ASSERT(dev_nb < NB_DEVICES); + CU_ASSERT(dev_nb >= 0); + shm = dev_data->shm_handle; + CU_ASSERT(!odpdrv_shm_free_by_handle(shm)); +} + +/*enumerator remove functions, to remove the enumerated devices: */ +static int enumr1_remove(void) +{ + odpdrv_device_t *my_devices; + odpdrv_device_t *dev; + int count = 0; + + /* destroy all devices created by enumerator 5: */ + my_devices = odpdrv_device_query(enumr1, NULL); + + for (dev = my_devices; *dev != ODPDRV_DEVICE_INVALID; dev++) { + odpdrv_device_destroy(*dev, enumr5_device_destroy_terminate, 0); + count++; + } + + CU_ASSERT(count == NB_DEVICES); + + free(my_devices); + return 0; +} + +/*enumerator class register functions, all "statically linked" + *(i.e. directely run at start), due to the fact that platorm independent + * shared lib loading in autotools is a mess */ +static void ODPDRV_CONSTRUCTOR enumr_class1_register(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "Enumerator_class1", + .probe = enumr_class1_probe, + .remove = enumr_class1_remove + }; + + enumr_class1 = odpdrv_enumr_class_register(¶m); +} + +/*enumerator class probe functions, registering enumerators: */ +static int enumr_class1_probe(void) +{ + CU_ASSERT(enumr1_register() != ODPDRV_ENUMR_INVALID); + return 0; +} + +/*enumerator class remove functions, just making sure they have been run: */ +static int enumr_class1_remove(void) +{ + return 0; +} + +void drvdriver_test_device_register(void) +{ + CU_ASSERT(tests_global_init() == 0); + + /* at this point (after odp init), the 5 devices should be there: + */ + CU_ASSERT(odpdrv_print_all() == 0); + + CU_ASSERT(tests_global_term() == 0); +} + +odp_testinfo_t drvdriver_suite_device[] = { + ODP_TEST_INFO(drvdriver_test_device_register), + ODP_TEST_INFO_NULL, +}; + +odp_suiteinfo_t drvdriver_suites_device[] = { + {"Enumerator registration", NULL, NULL, drvdriver_suite_device}, + ODP_SUITE_INFO_NULL, +}; + +int drvdriver_device_main(int argc, char *argv[]) +{ + int ret; + + /* parse common options: */ + if (odp_cunit_parse_options(argc, argv)) + return -1; + + /* prevent default ODP init: */ + odp_cunit_register_global_init(NULL); + odp_cunit_register_global_term(NULL); + + /* register the tests: */ + ret = odp_cunit_register(drvdriver_suites_device); + + if (ret == 0) + ret = odp_cunit_run(); + + return ret; +} diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_device.h b/test/common_plat/validation/drv/drvdriver/drvdriver_device.h new file mode 100644 index 0000000..afc04c5 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_device.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_DRVDRIVER_DEVICE_H_ +#define _ODP_TEST_DRVDRIVER_DEVICE_H_ + +#include + +/* test functions: */ +void drvdriver_test_device_register(void); + +/* test arrays: */ +extern odp_testinfo_t drvdriver_suite_device[]; + +/* test registry: */ +extern odp_suiteinfo_t drvdriver_suites_device[]; + +/* main test program: */ +int drvdriver_device_main(int argc, char *argv[]); + +#endif diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c new file mode 100644 index 0000000..27de9c5 --- /dev/null +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_device_main.c @@ -0,0 +1,12 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "drvdriver_device.h" + +int main(int argc, char *argv[]) +{ + return drvdriver_device_main(argc, argv); +} diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index a0606f3..c95449a 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -36,6 +36,7 @@ TESTS = validation/api/pktio/pktio_run.sh \ $(ALL_API_VALIDATION_DIR)/shmem/shmem_main$(EXEEXT) \ $(ALL_API_VALIDATION_DIR)/system/system_main$(EXEEXT) \ $(ALL_DRV_VALIDATION_DIR)/drvatomic/drvatomic_main$(EXEEXT) \ + $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_device_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_class_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvdriver/drvdriver_enumr_main$(EXEEXT)\ $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \