diff mbox series

[API-NEXT,03/21] test: drv: enumerator_class registration tests

Message ID 1487768164-43184-4-git-send-email-christophe.milard@linaro.org
State Superseded
Headers show
Series driver items registration and probing | expand

Commit Message

Christophe Milard Feb. 22, 2017, 12:55 p.m. UTC
Testing that enumerators classes can register properly.
Saddly restricted to statically linked enumerators classes, as testing with
modules in autotools seems to be an issue so far.

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

---
 test/common_plat/m4/configure.m4                   |   1 +
 test/common_plat/validation/drv/Makefile.am        |   1 +
 .../validation/drv/drvdriver/.gitignore            |   1 +
 .../validation/drv/drvdriver/Makefile.am           |  16 ++
 .../drv/drvdriver/drvdriver_enumr_class.c          | 174 +++++++++++++++++++++
 .../drv/drvdriver/drvdriver_enumr_class.h          |  24 +++
 .../drv/drvdriver/drvdriver_enumr_class_main.c     |  12 ++
 test/linux-generic/Makefile.am                     |   1 +
 8 files changed, 230 insertions(+)
 create mode 100644 test/common_plat/validation/drv/drvdriver/.gitignore
 create mode 100644 test/common_plat/validation/drv/drvdriver/Makefile.am
 create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c
 create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h
 create mode 100644 test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c

-- 
2.7.4

Comments

Bill Fischofer Feb. 22, 2017, 9:13 p.m. UTC | #1
On Wed, Feb 22, 2017 at 6:55 AM, Christophe Milard <
christophe.milard@linaro.org> wrote:

> Testing that enumerators classes can register properly.

> Saddly restricted to statically linked enumerators classes, as testing with

> modules in autotools seems to be an issue so far.

>

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

> ---

>  test/common_plat/m4/configure.m4                   |   1 +

>  test/common_plat/validation/drv/Makefile.am        |   1 +

>  .../validation/drv/drvdriver/.gitignore            |   1 +

>  .../validation/drv/drvdriver/Makefile.am           |  16 ++

>  .../drv/drvdriver/drvdriver_enumr_class.c          | 174

> +++++++++++++++++++++

>  .../drv/drvdriver/drvdriver_enumr_class.h          |  24 +++

>  .../drv/drvdriver/drvdriver_enumr_class_main.c     |  12 ++

>  test/linux-generic/Makefile.am                     |   1 +

>  8 files changed, 230 insertions(+)

>  create mode 100644 test/common_plat/validation/drv/drvdriver/.gitignore

>  create mode 100644 test/common_plat/validation/drv/drvdriver/Makefile.am

>  create mode 100644 test/common_plat/validation/

> drv/drvdriver/drvdriver_enumr_class.c

>  create mode 100644 test/common_plat/validation/

> drv/drvdriver/drvdriver_enumr_class.h

>  create mode 100644 test/common_plat/validation/

> drv/drvdriver/drvdriver_enumr_class_main.c

>

> diff --git a/test/common_plat/m4/configure.m4 b/test/common_plat/m4/

> configure.m4

> index 13a13bd..400750c 100644

> --- a/test/common_plat/m4/configure.m4

> +++ b/test/common_plat/m4/configure.m4

> @@ -34,4 +34,5 @@ AC_CONFIG_FILES([test/common_plat/Makefile

>                  test/common_plat/validation/api/traffic_mngr/Makefile

>                  test/common_plat/validation/drv/Makefile

>                  test/common_plat/validation/drv/drvatomic/Makefile

> +                test/common_plat/validation/drv/drvdriver/Makefile

>                  test/common_plat/validation/drv/drvshmem/Makefile])

> diff --git a/test/common_plat/validation/drv/Makefile.am

> b/test/common_plat/validation/drv/Makefile.am

> index bcdb92e..7329a89 100644

> --- a/test/common_plat/validation/drv/Makefile.am

> +++ b/test/common_plat/validation/drv/Makefile.am

> @@ -1,4 +1,5 @@

>  ODPDRV_MODULES = drvatomic \

> +                drvdriver \

>                  drvshmem

>

>  SUBDIRS = $(ODPDRV_MODULES)

> diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore

> b/test/common_plat/validation/drv/drvdriver/.gitignore

> new file mode 100644

> index 0000000..9268315

> --- /dev/null

> +++ b/test/common_plat/validation/drv/drvdriver/.gitignore

> @@ -0,0 +1 @@

> +drvdriver_enumr_class_main

> diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am

> b/test/common_plat/validation/drv/drvdriver/Makefile.am

> new file mode 100644

> index 0000000..9e941ee

> --- /dev/null

> +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am

> @@ -0,0 +1,16 @@

> +include ../Makefile.inc

> +

> +# because most of driver activity occurs at init time, and due to the

> +# fact that many sequential ODP runs are not allowed from the same

> process,

> +# we need different binaries for each things being tested (as API init)

>


I'm not sure I understand this comment. While this may be a good idea from
a test modularity standpoint, the intent of ODP is that after
odp_term_global() is called it's perfectly fine to call odp_init_global()
again to start up another ODP instance. What we haven't (yet) worked out is
the full ramifications of supporting multiple ODP instances on the same
platform simultaneously, something we need to do as part of the Cloud
profile for NFV.


> +

> +#tests for enumerator class registration:

> +noinst_LTLIBRARIES = libtestdrvdriverenumrclass.la

> +libtestdrvdriverenumrclass_la_SOURCES = drvdriver_enumr_class.c

> +

> +test_PROGRAMS = drvdriver_enumr_class_main$(EXEEXT)

> +dist_drvdriver_enumr_class_main_SOURCES = drvdriver_enumr_class_main.c

> +drvdriver_enumr_class_main_LDADD = libtestdrvdriverenumrclass.la \

> +                                  $(LIBCUNIT_COMMON) $(LIBODP)

> +

> +EXTRA_DIST = drvdriver_enumr_class.h

> diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c

> b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c

> new file mode 100644

> index 0000000..62b99ea

> --- /dev/null

> +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c

> @@ -0,0 +1,174 @@

> +/* 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_enumr_class.h"

> +#include <stdlib.h>

> +

> +static odp_instance_t odp_instance;

> +

> +static int enumr_class1_probed;

> +static int enumr_class2_probed;

> +

> +/* forward declaration */

> +static int enumr_class1_probe(void);

> +static int enumr_class2_probe(void);

> +

> +static int enumr_class1_remove(void);

> +static int enumr_class2_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 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 __attribute__ ((constructor)) enumr_class1_register(void)

>


We've been using ODP_xxx macros to wrapper various __attribute__
designations (e.g, ODP_UNUSED). Should we have an ODP_CONSTRUCTOR (or
ODPDRV_CONSTRUCTOR) macro here to do the same?


> +{

> +       odpdrv_enumr_class_param_t param = {

> +               .name = "Enumerator_class1",

> +               .probe = enumr_class1_probe,

> +               .remove = enumr_class1_remove

> +       };

> +

> +       odpdrv_enumr_class_register(&param);

> +}

> +

> +static void __attribute__ ((constructor)) enumr_class2_register(void)

> +{

> +       odpdrv_enumr_class_param_t param = {

> +               .name = "Enumerator_class2",

> +               .probe = enumr_class2_probe,

> +               .remove = enumr_class2_remove

> +       };

> +

> +       odpdrv_enumr_class_register(&param);

> +}

> +

> +static odpdrv_enumr_class_t enumr_class2_register_retry(void)

> +{

> +       odpdrv_enumr_class_param_t param = {

> +               .name = "Enumerator_class2",

> +               .probe = enumr_class2_probe,

> +               .remove = enumr_class2_remove

> +       };

> +

> +       return odpdrv_enumr_class_register(&param);

> +}

> +

> +/*enumerator class probe functions, just making sure they have been ran:

> */

>


Grammar: have been run


> +static int enumr_class1_probe(void)

> +{

> +       enumr_class1_probed = 1;

> +       return 0;

> +}

> +

> +static int enumr_class2_probe(void)

> +{

> +       enumr_class2_probed = 1;

> +       return 0;

> +}

> +

> +/*enumerator class remove functions, just making sure they have been ran:

> */

>


have been run


> +static int enumr_class1_remove(void)

> +{

> +       enumr_class1_probed = -1;

> +       return 0;

> +}

> +

> +static int enumr_class2_remove(void)

> +{

> +       enumr_class2_probed = -1;

> +       return 0;

> +}

> +

> +void drvdriver_test_enumr_class_register(void)

> +{

> +       CU_ASSERT(enumr_class1_probed == 0);

> +       CU_ASSERT(enumr_class2_probed == 0);

> +

> +       CU_ASSERT(tests_global_init() == 0);

> +

> +       /* at this point (after odp init), the (__constructor__)

> +        * enumerator classes should have registered and been probed:

> +        */

> +       CU_ASSERT(odpdrv_print_all() == 0);

> +

> +       CU_ASSERT(enumr_class1_probed == 1);

> +       CU_ASSERT(enumr_class2_probed == 1);

> +       CU_ASSERT(odpdrv_print_all() == 0);

> +

> +       /* re-register enumr_class2: this should be kicked-out! */

> +       CU_ASSERT(enumr_class2_register_retry() ==

> ODPDRV_ENUMR_CLASS_INVALID);

> +

> +       CU_ASSERT(tests_global_term() == 0);

> +

> +       /* after ODP terminaison completion, all enumerators should be

> removed*/

> +       CU_ASSERT(enumr_class1_probed == -1);

> +       CU_ASSERT(enumr_class2_probed == -1);

> +}

> +

> +odp_testinfo_t drvdriver_suite_enumr_class[] = {

> +       ODP_TEST_INFO(drvdriver_test_enumr_class_register),

> +       ODP_TEST_INFO_NULL,

> +};

> +

> +odp_suiteinfo_t drvdriver_suites_enumr_class[] = {

> +       {"Enumerator registration", NULL, NULL,

> drvdriver_suite_enumr_class},

> +       ODP_SUITE_INFO_NULL,

> +};

> +

> +int drvdriver_enumr_class_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_enumr_class);

> +

> +       if (ret == 0)

> +               ret = odp_cunit_run();

> +

> +       return ret;

> +}

> diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h

> b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h

> new file mode 100644

> index 0000000..a4f6cdc

> --- /dev/null

> +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h

> @@ -0,0 +1,24 @@

> +/* Copyright (c) 2017, Linaro Limited

> + * All rights reserved.

> + *

> + * SPDX-License-Identifier:     BSD-3-Clause

> + */

> +

> +#ifndef _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_

> +#define _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_

> +

> +#include <odp_cunit_common.h>

> +

> +/* test functions: */

> +void drvdriver_test_enumr_class_register(void);

> +

> +/* test arrays: */

> +extern odp_testinfo_t drvdriver_suite_enumr_class[];

> +

> +/* test registry: */

> +extern odp_suiteinfo_t drvdriver_suites_enumr_class[];

> +

> +/* main test program: */

> +int drvdriver_enumr_class_main(int argc, char *argv[]);

> +

> +#endif

> diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c

> b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c

> new file mode 100644

> index 0000000..45a4c1a

> --- /dev/null

> +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_

> class_main.c

> @@ -0,0 +1,12 @@

> +/* Copyright (c) 2017, Linaro Limited

> + * All rights reserved.

> + *

> + * SPDX-License-Identifier:     BSD-3-Clause

> + */

> +

> +#include "drvdriver_enumr_class.h"

> +

> +int main(int argc, char *argv[])

> +{

> +       return drvdriver_enumr_class_main(argc, argv);

> +}

> diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.

> am

> index 26d39cc..16a5cb6 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_enumr_

> class_main$(EXEEXT)\

>         $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \

>         ring/ring_main$(EXEEXT)

>

> --

> 2.7.4

>

>
Christophe Milard Feb. 27, 2017, 10:25 a.m. UTC | #2
On 22 February 2017 at 22:13, Bill Fischofer <bill.fischofer@linaro.org> wrote:
>

>

> On Wed, Feb 22, 2017 at 6:55 AM, Christophe Milard

> <christophe.milard@linaro.org> wrote:

>>

>> Testing that enumerators classes can register properly.

>> Saddly restricted to statically linked enumerators classes, as testing

>> with

>> modules in autotools seems to be an issue so far.

>>

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

>> ---

>>  test/common_plat/m4/configure.m4                   |   1 +

>>  test/common_plat/validation/drv/Makefile.am        |   1 +

>>  .../validation/drv/drvdriver/.gitignore            |   1 +

>>  .../validation/drv/drvdriver/Makefile.am           |  16 ++

>>  .../drv/drvdriver/drvdriver_enumr_class.c          | 174

>> +++++++++++++++++++++

>>  .../drv/drvdriver/drvdriver_enumr_class.h          |  24 +++

>>  .../drv/drvdriver/drvdriver_enumr_class_main.c     |  12 ++

>>  test/linux-generic/Makefile.am                     |   1 +

>>  8 files changed, 230 insertions(+)

>>  create mode 100644 test/common_plat/validation/drv/drvdriver/.gitignore

>>  create mode 100644 test/common_plat/validation/drv/drvdriver/Makefile.am

>>  create mode 100644

>> test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c

>>  create mode 100644

>> test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h

>>  create mode 100644

>> test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c

>>

>> diff --git a/test/common_plat/m4/configure.m4

>> b/test/common_plat/m4/configure.m4

>> index 13a13bd..400750c 100644

>> --- a/test/common_plat/m4/configure.m4

>> +++ b/test/common_plat/m4/configure.m4

>> @@ -34,4 +34,5 @@ AC_CONFIG_FILES([test/common_plat/Makefile

>>                  test/common_plat/validation/api/traffic_mngr/Makefile

>>                  test/common_plat/validation/drv/Makefile

>>                  test/common_plat/validation/drv/drvatomic/Makefile

>> +                test/common_plat/validation/drv/drvdriver/Makefile

>>                  test/common_plat/validation/drv/drvshmem/Makefile])

>> diff --git a/test/common_plat/validation/drv/Makefile.am

>> b/test/common_plat/validation/drv/Makefile.am

>> index bcdb92e..7329a89 100644

>> --- a/test/common_plat/validation/drv/Makefile.am

>> +++ b/test/common_plat/validation/drv/Makefile.am

>> @@ -1,4 +1,5 @@

>>  ODPDRV_MODULES = drvatomic \

>> +                drvdriver \

>>                  drvshmem

>>

>>  SUBDIRS = $(ODPDRV_MODULES)

>> diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore

>> b/test/common_plat/validation/drv/drvdriver/.gitignore

>> new file mode 100644

>> index 0000000..9268315

>> --- /dev/null

>> +++ b/test/common_plat/validation/drv/drvdriver/.gitignore

>> @@ -0,0 +1 @@

>> +drvdriver_enumr_class_main

>> diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am

>> b/test/common_plat/validation/drv/drvdriver/Makefile.am

>> new file mode 100644

>> index 0000000..9e941ee

>> --- /dev/null

>> +++ b/test/common_plat/validation/drv/drvdriver/Makefile.am

>> @@ -0,0 +1,16 @@

>> +include ../Makefile.inc

>> +

>> +# because most of driver activity occurs at init time, and due to the

>> +# fact that many sequential ODP runs are not allowed from the same

>> process,

>> +# we need different binaries for each things being tested (as API init)

>

>

> I'm not sure I understand this comment. While this may be a good idea from a

> test modularity standpoint, the intent of ODP is that after

> odp_term_global() is called it's perfectly fine to call odp_init_global()

> again to start up another ODP instance. What we haven't (yet) worked out is

> the full ramifications of supporting multiple ODP instances on the same

> platform simultaneously, something we need to do as part of the Cloud

> profile for NFV.

>


I did call odp_init_global() after odp_term_global() when I worked on
the init test suite a while ago: most ODP implementation failed on
that. We eventually agreed that once a given process has call
odp_term_global() is is not allowed to "restart a new odp instance",
i.e. to call odp_init_global() again.
This is why the init test are 3 different binaries rather than one
simgle test suite.

>>

>> +

>> +#tests for enumerator class registration:

>> +noinst_LTLIBRARIES = libtestdrvdriverenumrclass.la

>> +libtestdrvdriverenumrclass_la_SOURCES = drvdriver_enumr_class.c

>> +

>> +test_PROGRAMS = drvdriver_enumr_class_main$(EXEEXT)

>> +dist_drvdriver_enumr_class_main_SOURCES = drvdriver_enumr_class_main.c

>> +drvdriver_enumr_class_main_LDADD = libtestdrvdriverenumrclass.la \

>> +                                  $(LIBCUNIT_COMMON) $(LIBODP)

>> +

>> +EXTRA_DIST = drvdriver_enumr_class.h

>> diff --git

>> a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c

>> b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c

>> new file mode 100644

>> index 0000000..62b99ea

>> --- /dev/null

>> +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c

>> @@ -0,0 +1,174 @@

>> +/* 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_enumr_class.h"

>> +#include <stdlib.h>

>> +

>> +static odp_instance_t odp_instance;

>> +

>> +static int enumr_class1_probed;

>> +static int enumr_class2_probed;

>> +

>> +/* forward declaration */

>> +static int enumr_class1_probe(void);

>> +static int enumr_class2_probe(void);

>> +

>> +static int enumr_class1_remove(void);

>> +static int enumr_class2_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 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 __attribute__ ((constructor)) enumr_class1_register(void)

>

>

> We've been using ODP_xxx macros to wrapper various __attribute__

> designations (e.g, ODP_UNUSED). Should we have an ODP_CONSTRUCTOR (or

> ODPDRV_CONSTRUCTOR) macro here to do the same?


makes sense: => V2

>

>>

>> +{

>> +       odpdrv_enumr_class_param_t param = {

>> +               .name = "Enumerator_class1",

>> +               .probe = enumr_class1_probe,

>> +               .remove = enumr_class1_remove

>> +       };

>> +

>> +       odpdrv_enumr_class_register(&param);

>> +}

>> +

>> +static void __attribute__ ((constructor)) enumr_class2_register(void)

>> +{

>> +       odpdrv_enumr_class_param_t param = {

>> +               .name = "Enumerator_class2",

>> +               .probe = enumr_class2_probe,

>> +               .remove = enumr_class2_remove

>> +       };

>> +

>> +       odpdrv_enumr_class_register(&param);

>> +}

>> +

>> +static odpdrv_enumr_class_t enumr_class2_register_retry(void)

>> +{

>> +       odpdrv_enumr_class_param_t param = {

>> +               .name = "Enumerator_class2",

>> +               .probe = enumr_class2_probe,

>> +               .remove = enumr_class2_remove

>> +       };

>> +

>> +       return odpdrv_enumr_class_register(&param);

>> +}

>> +

>> +/*enumerator class probe functions, just making sure they have been ran:

>> */

>

>

> Grammar: have been run


Lucky I am no longer at school: that would have given me a bad mark!
=>V2

>

>>

>> +static int enumr_class1_probe(void)

>> +{

>> +       enumr_class1_probed = 1;

>> +       return 0;

>> +}

>> +

>> +static int enumr_class2_probe(void)

>> +{

>> +       enumr_class2_probed = 1;

>> +       return 0;

>> +}

>> +

>> +/*enumerator class remove functions, just making sure they have been ran:

>> */

>

>

> have been run


=>V2

>

>>

>> +static int enumr_class1_remove(void)

>> +{

>> +       enumr_class1_probed = -1;

>> +       return 0;

>> +}

>> +

>> +static int enumr_class2_remove(void)

>> +{

>> +       enumr_class2_probed = -1;

>> +       return 0;

>> +}

>> +

>> +void drvdriver_test_enumr_class_register(void)

>> +{

>> +       CU_ASSERT(enumr_class1_probed == 0);

>> +       CU_ASSERT(enumr_class2_probed == 0);

>> +

>> +       CU_ASSERT(tests_global_init() == 0);

>> +

>> +       /* at this point (after odp init), the (__constructor__)

>> +        * enumerator classes should have registered and been probed:

>> +        */

>> +       CU_ASSERT(odpdrv_print_all() == 0);

>> +

>> +       CU_ASSERT(enumr_class1_probed == 1);

>> +       CU_ASSERT(enumr_class2_probed == 1);

>> +       CU_ASSERT(odpdrv_print_all() == 0);

>> +

>> +       /* re-register enumr_class2: this should be kicked-out! */

>> +       CU_ASSERT(enumr_class2_register_retry() ==

>> ODPDRV_ENUMR_CLASS_INVALID);

>> +

>> +       CU_ASSERT(tests_global_term() == 0);

>> +

>> +       /* after ODP terminaison completion, all enumerators should be

>> removed*/

>> +       CU_ASSERT(enumr_class1_probed == -1);

>> +       CU_ASSERT(enumr_class2_probed == -1);

>> +}

>> +

>> +odp_testinfo_t drvdriver_suite_enumr_class[] = {

>> +       ODP_TEST_INFO(drvdriver_test_enumr_class_register),

>> +       ODP_TEST_INFO_NULL,

>> +};

>> +

>> +odp_suiteinfo_t drvdriver_suites_enumr_class[] = {

>> +       {"Enumerator registration", NULL, NULL,

>> drvdriver_suite_enumr_class},

>> +       ODP_SUITE_INFO_NULL,

>> +};

>> +

>> +int drvdriver_enumr_class_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_enumr_class);

>> +

>> +       if (ret == 0)

>> +               ret = odp_cunit_run();

>> +

>> +       return ret;

>> +}

>> diff --git

>> a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h

>> b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h

>> new file mode 100644

>> index 0000000..a4f6cdc

>> --- /dev/null

>> +++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h

>> @@ -0,0 +1,24 @@

>> +/* Copyright (c) 2017, Linaro Limited

>> + * All rights reserved.

>> + *

>> + * SPDX-License-Identifier:     BSD-3-Clause

>> + */

>> +

>> +#ifndef _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_

>> +#define _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_

>> +

>> +#include <odp_cunit_common.h>

>> +

>> +/* test functions: */

>> +void drvdriver_test_enumr_class_register(void);

>> +

>> +/* test arrays: */

>> +extern odp_testinfo_t drvdriver_suite_enumr_class[];

>> +

>> +/* test registry: */

>> +extern odp_suiteinfo_t drvdriver_suites_enumr_class[];

>> +

>> +/* main test program: */

>> +int drvdriver_enumr_class_main(int argc, char *argv[]);

>> +

>> +#endif

>> diff --git

>> a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c

>> b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c

>> new file mode 100644

>> index 0000000..45a4c1a

>> --- /dev/null

>> +++

>> b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c

>> @@ -0,0 +1,12 @@

>> +/* Copyright (c) 2017, Linaro Limited

>> + * All rights reserved.

>> + *

>> + * SPDX-License-Identifier:     BSD-3-Clause

>> + */

>> +

>> +#include "drvdriver_enumr_class.h"

>> +

>> +int main(int argc, char *argv[])

>> +{

>> +       return drvdriver_enumr_class_main(argc, argv);

>> +}

>> diff --git a/test/linux-generic/Makefile.am

>> b/test/linux-generic/Makefile.am

>> index 26d39cc..16a5cb6 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_enumr_class_main$(EXEEXT)\

>>         $(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \

>>         ring/ring_main$(EXEEXT)

>>

>> --

>> 2.7.4

>>

>
diff mbox series

Patch

diff --git a/test/common_plat/m4/configure.m4 b/test/common_plat/m4/configure.m4
index 13a13bd..400750c 100644
--- a/test/common_plat/m4/configure.m4
+++ b/test/common_plat/m4/configure.m4
@@ -34,4 +34,5 @@  AC_CONFIG_FILES([test/common_plat/Makefile
 		 test/common_plat/validation/api/traffic_mngr/Makefile
 		 test/common_plat/validation/drv/Makefile
 		 test/common_plat/validation/drv/drvatomic/Makefile
+		 test/common_plat/validation/drv/drvdriver/Makefile
 		 test/common_plat/validation/drv/drvshmem/Makefile])
diff --git a/test/common_plat/validation/drv/Makefile.am b/test/common_plat/validation/drv/Makefile.am
index bcdb92e..7329a89 100644
--- a/test/common_plat/validation/drv/Makefile.am
+++ b/test/common_plat/validation/drv/Makefile.am
@@ -1,4 +1,5 @@ 
 ODPDRV_MODULES = drvatomic \
+		 drvdriver \
 		 drvshmem
 
 SUBDIRS = $(ODPDRV_MODULES)
diff --git a/test/common_plat/validation/drv/drvdriver/.gitignore b/test/common_plat/validation/drv/drvdriver/.gitignore
new file mode 100644
index 0000000..9268315
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/.gitignore
@@ -0,0 +1 @@ 
+drvdriver_enumr_class_main
diff --git a/test/common_plat/validation/drv/drvdriver/Makefile.am b/test/common_plat/validation/drv/drvdriver/Makefile.am
new file mode 100644
index 0000000..9e941ee
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/Makefile.am
@@ -0,0 +1,16 @@ 
+include ../Makefile.inc
+
+# because most of driver activity occurs at init time, and due to the
+# fact that many sequential ODP runs are not allowed from the same process,
+# we need different binaries for each things being tested (as API init)
+
+#tests for enumerator class registration:
+noinst_LTLIBRARIES = libtestdrvdriverenumrclass.la
+libtestdrvdriverenumrclass_la_SOURCES = drvdriver_enumr_class.c
+
+test_PROGRAMS = drvdriver_enumr_class_main$(EXEEXT)
+dist_drvdriver_enumr_class_main_SOURCES = drvdriver_enumr_class_main.c
+drvdriver_enumr_class_main_LDADD = libtestdrvdriverenumrclass.la \
+				   $(LIBCUNIT_COMMON) $(LIBODP)
+
+EXTRA_DIST = drvdriver_enumr_class.h
diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c
new file mode 100644
index 0000000..62b99ea
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.c
@@ -0,0 +1,174 @@ 
+/* 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_enumr_class.h"
+#include <stdlib.h>
+
+static odp_instance_t odp_instance;
+
+static int enumr_class1_probed;
+static int enumr_class2_probed;
+
+/* forward declaration */
+static int enumr_class1_probe(void);
+static int enumr_class2_probe(void);
+
+static int enumr_class1_remove(void);
+static int enumr_class2_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 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 __attribute__ ((constructor)) enumr_class1_register(void)
+{
+	odpdrv_enumr_class_param_t param = {
+		.name = "Enumerator_class1",
+		.probe = enumr_class1_probe,
+		.remove = enumr_class1_remove
+	};
+
+	odpdrv_enumr_class_register(&param);
+}
+
+static void __attribute__ ((constructor)) enumr_class2_register(void)
+{
+	odpdrv_enumr_class_param_t param = {
+		.name = "Enumerator_class2",
+		.probe = enumr_class2_probe,
+		.remove = enumr_class2_remove
+	};
+
+	odpdrv_enumr_class_register(&param);
+}
+
+static odpdrv_enumr_class_t enumr_class2_register_retry(void)
+{
+	odpdrv_enumr_class_param_t param = {
+		.name = "Enumerator_class2",
+		.probe = enumr_class2_probe,
+		.remove = enumr_class2_remove
+	};
+
+	return odpdrv_enumr_class_register(&param);
+}
+
+/*enumerator class probe functions, just making sure they have been ran: */
+static int enumr_class1_probe(void)
+{
+	enumr_class1_probed = 1;
+	return 0;
+}
+
+static int enumr_class2_probe(void)
+{
+	enumr_class2_probed = 1;
+	return 0;
+}
+
+/*enumerator class remove functions, just making sure they have been ran: */
+static int enumr_class1_remove(void)
+{
+	enumr_class1_probed = -1;
+	return 0;
+}
+
+static int enumr_class2_remove(void)
+{
+	enumr_class2_probed = -1;
+	return 0;
+}
+
+void drvdriver_test_enumr_class_register(void)
+{
+	CU_ASSERT(enumr_class1_probed == 0);
+	CU_ASSERT(enumr_class2_probed == 0);
+
+	CU_ASSERT(tests_global_init() == 0);
+
+	/* at this point (after odp init), the (__constructor__)
+	 * enumerator classes should have registered and been probed:
+	 */
+	CU_ASSERT(odpdrv_print_all() == 0);
+
+	CU_ASSERT(enumr_class1_probed == 1);
+	CU_ASSERT(enumr_class2_probed == 1);
+	CU_ASSERT(odpdrv_print_all() == 0);
+
+	/* re-register enumr_class2: this should be kicked-out! */
+	CU_ASSERT(enumr_class2_register_retry() == ODPDRV_ENUMR_CLASS_INVALID);
+
+	CU_ASSERT(tests_global_term() == 0);
+
+	/* after ODP terminaison completion, all enumerators should be removed*/
+	CU_ASSERT(enumr_class1_probed == -1);
+	CU_ASSERT(enumr_class2_probed == -1);
+}
+
+odp_testinfo_t drvdriver_suite_enumr_class[] = {
+	ODP_TEST_INFO(drvdriver_test_enumr_class_register),
+	ODP_TEST_INFO_NULL,
+};
+
+odp_suiteinfo_t drvdriver_suites_enumr_class[] = {
+	{"Enumerator registration", NULL, NULL, drvdriver_suite_enumr_class},
+	ODP_SUITE_INFO_NULL,
+};
+
+int drvdriver_enumr_class_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_enumr_class);
+
+	if (ret == 0)
+		ret = odp_cunit_run();
+
+	return ret;
+}
diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h
new file mode 100644
index 0000000..a4f6cdc
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class.h
@@ -0,0 +1,24 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#ifndef _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_
+#define _ODP_TEST_DRVDRIVER_ENUMR_CLASS_H_
+
+#include <odp_cunit_common.h>
+
+/* test functions: */
+void drvdriver_test_enumr_class_register(void);
+
+/* test arrays: */
+extern odp_testinfo_t drvdriver_suite_enumr_class[];
+
+/* test registry: */
+extern odp_suiteinfo_t drvdriver_suites_enumr_class[];
+
+/* main test program: */
+int drvdriver_enumr_class_main(int argc, char *argv[]);
+
+#endif
diff --git a/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c
new file mode 100644
index 0000000..45a4c1a
--- /dev/null
+++ b/test/common_plat/validation/drv/drvdriver/drvdriver_enumr_class_main.c
@@ -0,0 +1,12 @@ 
+/* Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+#include "drvdriver_enumr_class.h"
+
+int main(int argc, char *argv[])
+{
+	return drvdriver_enumr_class_main(argc, argv);
+}
diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am
index 26d39cc..16a5cb6 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_enumr_class_main$(EXEEXT)\
 	$(ALL_DRV_VALIDATION_DIR)/drvshmem/drvshmem_main$(EXEEXT) \
 	ring/ring_main$(EXEEXT)