[API-NEXT,PATCHv2,16/23] test: drv: devio creation and destruction

Message ID 1490194110-40168-17-git-send-email-christophe.milard@linaro.org
State New
Headers show
Series
  • driver items registration and probing
Related show

Commit Message

Christophe Milard March 22, 2017, 2:48 p.m.
Testing that devios can be registered and removed in/from ODP.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 .../validation/drv/drvdriver/.gitignore            |   1 +
 .../validation/drv/drvdriver/Makefile.am           |  11 ++
 .../validation/drv/drvdriver/drvdriver_devio.c     | 209 +++++++++++++++++++++
 .../validation/drv/drvdriver/drvdriver_devio.h     |  24 +++
 .../drv/drvdriver/drvdriver_devio_main.c           |  12 ++
 test/linux-generic/Makefile.am                     |   1 +
 6 files changed, 258 insertions(+)
 create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_devio.c
 create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_devio.h
 create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c

-- 
2.7.4

Patch

diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore
index 97b4312..829c8b4 100644
--- a/test/common_plat/validation/drv/drvdriver/.gitignore
+++ b/test/common_plat/validation/drv/drvdriver/.gitignore
@@ -1,3 +1,4 @@ 
 drvdriver_enumr_class_main
 drvdriver_enumr_main
 drvdriver_device_main
+drvdriver_devio_main
diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am
index 544586c..8e695ba 100644
--- a/test/common_plat/validation/drv/drvdriver/Makefile.am
+++ b/test/common_plat/validation/drv/drvdriver/Makefile.am
@@ -36,3 +36,14 @@  drvdriver_device_main_LDADD = libtestdrvdriverdevice.la \
 				   $(LIBCUNIT_COMMON) $(LIBODP)
 
 EXTRA_DIST += drvdriver_device.h
+
+#tests for devio creation:
+noinst_LTLIBRARIES += libtestdrvdriverdevio.la
+libtestdrvdriverdevio_la_SOURCES = drvdriver_devio.c
+
+test_PROGRAMS += drvdriver_devio_main$(EXEEXT)
+dist_drvdriver_devio_main_SOURCES = drvdriver_devio_main.c
+drvdriver_devio_main_LDADD = libtestdrvdriverdevio.la \
+				   $(LIBCUNIT_COMMON) $(LIBODP)
+
+EXTRA_DIST += drvdriver_devio.h
diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_devio.c b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.c
new file mode 100644
index 0000000..cf7c7c9
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.c
@@ -0,0 +1,209 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include <odp_drv.h>
+#include <odp_api.h>
+#include <odp_cunit_common.h>
+#include "drvdriver_devio.h"
+#include <stdlib.h>
+
+static odp_instance_t odp_instance;
+
+static int devio1_removed;
+static int devio2_removed;
+static int devio3_removed;
+static int devio4_removed;
+
+static int devio1_remove(void);
+static int devio2_remove(void);
+static int devio3_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;
+}
+
+/*devio 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 devio1_register(void)
+{
+	odpdrv_devio_param_t param = {
+		.api_name = "devio_api_1",
+		.api_version = 1,
+		.enumr_api_name = "Enumerator_interface_1",
+		.enumr_api_version = 1,
+		.remove = devio1_remove,
+		.ops = NULL,
+	};
+
+	odpdrv_devio_register(&param);
+}
+
+static void ODPDRV_CONSTRUCTOR devio2_register(void)
+{
+	odpdrv_devio_param_t param = {
+		.api_name = "devio_api_2",
+		.api_version = 1,
+		.enumr_api_name = "Enumerator_interface_1",
+		.enumr_api_version = 1,
+		.probe = NULL,
+		.remove = devio2_remove,
+		.ops = NULL,
+	};
+
+	odpdrv_devio_register(&param);
+}
+
+static odpdrv_devio_t devio2_register_retry(void)
+{
+	odpdrv_devio_param_t param = {
+		.api_name = "devio_api_2",
+		.api_version = 1,
+		.enumr_api_name = "Enumerator_interface_1",
+		.enumr_api_version = 1,
+		.probe = NULL,
+		.remove = NULL,
+		.ops = NULL,
+	};
+
+	return odpdrv_devio_register(&param);
+}
+
+static void ODPDRV_CONSTRUCTOR devio3_register(void)
+{
+	odpdrv_devio_param_t param = {
+		.api_name = "devio_api_2",
+		.api_version = 1,
+		.enumr_api_name = "Enumerator_interface_2",
+		.enumr_api_version = 1,
+		.probe = NULL,
+		.remove = devio3_remove,
+		.ops = NULL,
+	};
+
+	odpdrv_devio_register(&param);
+}
+
+static void ODPDRV_CONSTRUCTOR devio4_register(void)
+{
+	odpdrv_devio_param_t param = {
+		.api_name = "devio_api_3",
+		.api_version = 1,
+		.enumr_api_name = "Enumerator_interface_3",
+		.enumr_api_version = 1,
+		.probe = NULL,
+		.remove = NULL,
+		.ops = NULL,
+	};
+
+	odpdrv_devio_register(&param);
+}
+
+/*devio remove functions, just making sure they have been run: */
+static int devio1_remove(void)
+{
+	devio1_removed = 1;
+	return 0;
+}
+
+/*devio remove functions, just making sure they have been run: */
+static int devio2_remove(void)
+{
+	devio2_removed = 1;
+	return 0;
+}
+
+/*devio remove functions, just making sure they have been run: */
+static int devio3_remove(void)
+{
+	devio3_removed = 1;
+	return 0;
+}
+
+void drvdriver_test_devio_register(void)
+{
+	CU_ASSERT(devio1_removed == 0);
+	CU_ASSERT(devio2_removed == 0);
+	CU_ASSERT(devio3_removed == 0);
+	CU_ASSERT(devio4_removed == 0);
+
+	CU_ASSERT(tests_global_init() == 0);
+
+	/* at this point (after odp init), the constructor
+	 * devios should have registered. just print them:
+	 */
+	CU_ASSERT(odpdrv_print_all() == 0);
+
+	/* re-register devio2: this should be kicked-out! */
+	CU_ASSERT(devio2_register_retry() == ODPDRV_DEVIO_INVALID);
+
+	CU_ASSERT(tests_global_term() == 0);
+
+	/* after ODP termination completion, all devios have been removed*/
+	CU_ASSERT(devio1_removed == 1);
+	CU_ASSERT(devio2_removed == 1);
+	CU_ASSERT(devio3_removed == 1);
+	CU_ASSERT(devio4_removed == 0); /* has no remove function */
+}
+
+odp_testinfo_t drvdriver_suite_devio[] = {
+	ODP_TEST_INFO(drvdriver_test_devio_register),
+	ODP_TEST_INFO_NULL,
+};
+
+odp_suiteinfo_t drvdriver_suites_devio[] = {
+	{"Devio registration", NULL, NULL, drvdriver_suite_devio},
+	ODP_SUITE_INFO_NULL,
+};
+
+int drvdriver_devio_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_devio);
+
+	if (ret == 0)
+		ret = odp_cunit_run();
+
+	return ret;
+}
diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_devio.h b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.h
new file mode 100644
index 0000000..eea9623
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/drvdriver_devio.h
@@ -0,0 +1,24 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#ifndef _ODP_TEST_DRVDRIVER_DEVIO_H_
+#define _ODP_TEST_DRVDRIVER_DEVIO_H_
+
+#include <odp_cunit_common.h>
+
+/* test functions: */
+void drvdriver_test_devio_register(void);
+
+/* test arrays: */
+extern odp_testinfo_t drvdriver_suite_devio[];
+
+/* test registry: */
+extern odp_suiteinfo_t drvdriver_suites_devio[];
+
+/* main test program: */
+int drvdriver_devio_main(int argc, char *argv[]);
+
+#endif
diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c
new file mode 100644
index 0000000..10733ad
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/drvdriver_devio_main.c
@@ -0,0 +1,12 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include "drvdriver_devio.h"
+
+int main(int argc, char *argv[])
+{
+	return drvdriver_devio_main(argc, argv);
+}
diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am
index c95449a..55db05c 100644
--- a/test/linux-generic/Makefile.am
+++ b/test/linux-generic/Makefile.am
@@ -37,6 +37,7 @@  TESTS = validation/api/pktio/pktio_run.sh \
 	$(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_devio_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) \