On 2015-10-14 10:28, Stuart Haslam wrote: > Add an odp_cunit_update() function to allow some attributes of previously > registered tests to be modified, such as whether it's active or not. > > Previously, registering and running tests was done in a single step; > > odp_cunit_run(testsuites); > > But this is now split; > > odp_cunit_register(testsuites); > odp_cunit_update(testsuites_updates); > odp_cunit_run(); > > The odp_cunit_update() is optional and none of the currently defined > tests use it, so there's no functional change in this patch. > > Signed-off-by: Stuart Haslam <[email protected]>
Reviewed-by: Christophe Milard <[email protected]> > --- > test/validation/buffer/buffer.c | 7 +- > test/validation/classification/classification.c | 7 +- > test/validation/common/odp_cunit_common.c | 139 > +++++++++++++++++++++--- > test/validation/common/odp_cunit_common.h | 10 +- > test/validation/cpumask/cpumask.c | 7 +- > test/validation/crypto/crypto.c | 10 +- > test/validation/errno/errno.c | 7 +- > test/validation/init/init.c | 29 ++++- > test/validation/packet/packet.c | 7 +- > test/validation/pktio/pktio.c | 7 +- > test/validation/pool/pool.c | 7 +- > test/validation/queue/queue.c | 7 +- > test/validation/random/random.c | 7 +- > test/validation/scheduler/scheduler.c | 7 +- > test/validation/shmem/shmem.c | 7 +- > test/validation/synchronizers/synchronizers.c | 10 +- > test/validation/system/system.c | 7 +- > test/validation/thread/thread.c | 7 +- > test/validation/time/time.c | 7 +- > test/validation/timer/timer.c | 7 +- > 20 files changed, 267 insertions(+), 36 deletions(-) > > diff --git a/test/validation/buffer/buffer.c b/test/validation/buffer/buffer.c > index 4600e59..257e95c 100644 > --- a/test/validation/buffer/buffer.c > +++ b/test/validation/buffer/buffer.c > @@ -153,5 +153,10 @@ odp_suiteinfo_t buffer_suites[] = { > > int buffer_main(void) > { > - return odp_cunit_run(buffer_suites); > + int ret = odp_cunit_register(buffer_suites); > + > + if (ret == 0) > + odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/classification/classification.c > b/test/validation/classification/classification.c > index b868c61..fe9a827 100644 > --- a/test/validation/classification/classification.c > +++ b/test/validation/classification/classification.c > @@ -23,5 +23,10 @@ odp_suiteinfo_t classification_suites[] = { > > int classification_main(void) > { > - return odp_cunit_run(classification_suites); > + int ret = odp_cunit_register(classification_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/common/odp_cunit_common.c > b/test/validation/common/odp_cunit_common.c > index 95cbbc0..aade1c3 100644 > --- a/test/validation/common/odp_cunit_common.c > +++ b/test/validation/common/odp_cunit_common.c > @@ -103,6 +103,18 @@ static odp_suiteinfo_t *cunit_get_suite_info(const char > *suite_name) > return NULL; > } > > +static odp_testinfo_t *cunit_get_test_info(odp_suiteinfo_t *sinfo, > + const char *test_name) > +{ > + odp_testinfo_t *tinfo; > + > + for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) > + if (strcmp(tinfo->testinfo.pName, test_name) == 0) > + return tinfo; > + > + return NULL; > +} > + > /* A wrapper for the suite's init function. This is done to allow for a > * potential runtime check to determine whether each test in the suite > * is active (enabled by using ODP_TEST_INFO_CONDITIONAL()). If present, > @@ -186,27 +198,90 @@ static int cunit_register_suites(odp_suiteinfo_t > testsuites[]) > return 0; > } > > +static int cunit_update_test(CU_pSuite suite, > + odp_suiteinfo_t *sinfo, > + odp_testinfo_t *updated_tinfo) > +{ > + CU_pTest test = NULL; > + CU_ErrorCode err; > + odp_testinfo_t *tinfo; > + const char *test_name = updated_tinfo->testinfo.pName; > + > + tinfo = cunit_get_test_info(sinfo, test_name); > + if (tinfo) > + test = CU_get_test(suite, test_name); > + > + if (!tinfo || !test) { > + fprintf(stderr, "%s: unable to find existing test named %s\n", > + __func__, test_name); > + return -1; > + } > + > + err = CU_set_test_func(test, updated_tinfo->testinfo.pTestFunc); > + if (err != CUE_SUCCESS) { > + fprintf(stderr, "%s: failed to update test func for %s\n", > + __func__, test_name); > + return -1; > + } > + > + tinfo->check_active = updated_tinfo->check_active; > + > + return 0; > +} > + > +static int cunit_update_suite(odp_suiteinfo_t *updated_sinfo) > +{ > + CU_pSuite suite = NULL; > + CU_ErrorCode err; > + odp_suiteinfo_t *sinfo; > + odp_testinfo_t *tinfo; > + > + /* find previously registered suite with matching name */ > + sinfo = cunit_get_suite_info(updated_sinfo->pName); > + > + if (sinfo) { > + /* lookup the associated CUnit suite */ > + suite = CU_get_suite_by_name(updated_sinfo->pName, > + CU_get_registry()); > + } > + > + if (!sinfo || !suite) { > + fprintf(stderr, "%s: unable to find existing suite named %s\n", > + __func__, updated_sinfo->pName); > + return -1; > + } > + > + sinfo->pInitFunc = updated_sinfo->pInitFunc; > + sinfo->pCleanupFunc = updated_sinfo->pCleanupFunc; > + > + err = CU_set_suite_cleanupfunc(suite, updated_sinfo->pCleanupFunc); > + if (err != CUE_SUCCESS) { > + fprintf(stderr, "%s: failed to update cleanup func for %s\n", > + __func__, updated_sinfo->pName); > + return -1; > + } > + > + for (tinfo = updated_sinfo->pTests; tinfo->testinfo.pName; tinfo++) { > + int ret; > + > + ret = cunit_update_test(suite, sinfo, tinfo); > + if (ret != 0) > + return ret; > + } > + > + return 0; > +} > + > /* > - * Register test suites to be run via odp_cunit_run() > + * Run tests previously registered via odp_cunit_register() > */ > -int odp_cunit_run(odp_suiteinfo_t testsuites[]) > +int odp_cunit_run(void) > { > int ret; > > printf("\tODP API version: %s\n", odp_version_api_str()); > printf("\tODP implementation version: %s\n", odp_version_impl_str()); > > - /* call test executable init hook, if any */ > - if (global_init_term.global_init_ptr && > - ((*global_init_term.global_init_ptr)() != 0)) > - return -1; > - > - CU_set_error_action(CUEA_ABORT); > - > - CU_initialize_registry(); > - global_testsuites = testsuites; > - cunit_register_suites(testsuites); > - CU_set_fail_on_inactive(CU_FALSE); > CU_basic_set_mode(CU_BRM_VERBOSE); > CU_basic_run_tests(); > > @@ -221,3 +296,41 @@ int odp_cunit_run(odp_suiteinfo_t testsuites[]) > > return (ret) ? -1 : 0; > } > + > +/* > + * Update suites/tests previously registered via odp_cunit_register(). > + * > + * Note that this is intended for modifying the properties of already > + * registered suites/tests. New suites/tests can only be registered via > + * odp_cunit_register(). > + */ > +int odp_cunit_update(odp_suiteinfo_t testsuites[]) > +{ > + int ret = 0; > + odp_suiteinfo_t *sinfo; > + > + for (sinfo = testsuites; sinfo->pName && ret == 0; sinfo++) > + ret = cunit_update_suite(sinfo); > + > + return ret; > +} > + > +/* > + * Register test suites to be run via odp_cunit_run() > + */ > +int odp_cunit_register(odp_suiteinfo_t testsuites[]) > +{ > + /* call test executable init hook, if any */ > + if (global_init_term.global_init_ptr && > + ((*global_init_term.global_init_ptr)() != 0)) > + return -1; > + > + CU_set_error_action(CUEA_ABORT); > + > + CU_initialize_registry(); > + global_testsuites = testsuites; > + cunit_register_suites(testsuites); > + CU_set_fail_on_inactive(CU_FALSE); > + > + return 0; > +} > diff --git a/test/validation/common/odp_cunit_common.h > b/test/validation/common/odp_cunit_common.h > index 3421eea..c689054 100644 > --- a/test/validation/common/odp_cunit_common.h > +++ b/test/validation/common/odp_cunit_common.h > @@ -68,12 +68,16 @@ typedef struct { > int numthrds; /**< no of pthreads to create */ > } pthrd_arg; > > +/* register suites to be run via odp_cunit_run() */ > +int odp_cunit_register(odp_suiteinfo_t testsuites[]); > +/* update tests previously registered via odp_cunit_register() */ > +int odp_cunit_update(odp_suiteinfo_t testsuites[]); > /* the function, called by module main(), to run the testsuites: */ > -int odp_cunit_run(odp_suiteinfo_t testsuites[]); > +int odp_cunit_run(void); > > /** create thread fro start_routine function */ > -extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); > -extern int odp_cunit_thread_exit(pthrd_arg *); > +int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); > +int odp_cunit_thread_exit(pthrd_arg *); > > /** > * Global tests initialization/termination. > diff --git a/test/validation/cpumask/cpumask.c > b/test/validation/cpumask/cpumask.c > index 37dee6a..bf5421e 100644 > --- a/test/validation/cpumask/cpumask.c > +++ b/test/validation/cpumask/cpumask.c > @@ -101,5 +101,10 @@ odp_suiteinfo_t cpumask_suites[] = { > > int cpumask_main(void) > { > - return odp_cunit_run(cpumask_suites); > + int ret = odp_cunit_register(cpumask_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/crypto/crypto.c b/test/validation/crypto/crypto.c > index b2f9d96..9229cab 100644 > --- a/test/validation/crypto/crypto.c > +++ b/test/validation/crypto/crypto.c > @@ -94,7 +94,15 @@ int crypto_term(void) > > int crypto_main(void) > { > + int ret; > + > odp_cunit_register_global_init(crypto_init); > odp_cunit_register_global_term(crypto_term); > - return odp_cunit_run(crypto_suites); > + > + ret = odp_cunit_register(crypto_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/errno/errno.c b/test/validation/errno/errno.c > index 6196164..d0e2128 100644 > --- a/test/validation/errno/errno.c > +++ b/test/validation/errno/errno.c > @@ -31,5 +31,10 @@ odp_suiteinfo_t errno_suites[] = { > > int errno_main(void) > { > - return odp_cunit_run(errno_suites); > + int ret = odp_cunit_register(errno_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/init/init.c b/test/validation/init/init.c > index d5ec333..a8a5640 100644 > --- a/test/validation/init/init.c > +++ b/test/validation/init/init.c > @@ -53,12 +53,19 @@ static void odp_init_abort(void) > > int init_main_abort(void) > { > + int ret; > + > /* prevent default ODP init: */ > odp_cunit_register_global_init(NULL); > odp_cunit_register_global_term(NULL); > > /* run the tests: */ > - return odp_cunit_run(init_suites_abort); > + ret = odp_cunit_register(init_suites_abort); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > > /* test ODP global init, with alternate log function */ > @@ -109,12 +116,20 @@ static int odp_init_log(odp_log_level_e level > __attribute__((unused)), > > int init_main_log(void) > { > + int ret; > + > /* prevent default ODP init: */ > odp_cunit_register_global_init(NULL); > odp_cunit_register_global_term(NULL); > > + /* register the tests: */ > + ret = odp_cunit_register(init_suites_log); > + > /* run the tests: */ > - return odp_cunit_run(init_suites_log); > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > > /* test normal ODP global init */ > @@ -141,10 +156,18 @@ odp_suiteinfo_t init_suites_ok[] = { > > int init_main_ok(void) > { > + int ret; > + > /* prevent default ODP init: */ > odp_cunit_register_global_init(NULL); > odp_cunit_register_global_term(NULL); > > + /* register the tests: */ > + ret = odp_cunit_register(init_suites_ok); > + > /* run the tests: */ > - return odp_cunit_run(init_suites_ok); > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/packet/packet.c b/test/validation/packet/packet.c > index 8a4f0a6..d9a543f 100644 > --- a/test/validation/packet/packet.c > +++ b/test/validation/packet/packet.c > @@ -805,5 +805,10 @@ odp_suiteinfo_t packet_suites[] = { > > int packet_main(void) > { > - return odp_cunit_run(packet_suites); > + int ret = odp_cunit_register(packet_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c > index bfcaace..118fe89 100644 > --- a/test/validation/pktio/pktio.c > +++ b/test/validation/pktio/pktio.c > @@ -908,5 +908,10 @@ odp_suiteinfo_t pktio_suites[] = { > > int pktio_main(void) > { > - return odp_cunit_run(pktio_suites); > + int ret = odp_cunit_register(pktio_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/pool/pool.c b/test/validation/pool/pool.c > index 3de2714..bca210a 100644 > --- a/test/validation/pool/pool.c > +++ b/test/validation/pool/pool.c > @@ -116,5 +116,10 @@ odp_suiteinfo_t pool_suites[] = { > > int pool_main(void) > { > - return odp_cunit_run(pool_suites); > + int ret = odp_cunit_register(pool_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/queue/queue.c b/test/validation/queue/queue.c > index 7d6de54..98da2ec 100644 > --- a/test/validation/queue/queue.c > +++ b/test/validation/queue/queue.c > @@ -137,5 +137,10 @@ odp_suiteinfo_t queue_suites[] = { > > int queue_main(void) > { > - return odp_cunit_run(queue_suites); > + int ret = odp_cunit_register(queue_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/random/random.c b/test/validation/random/random.c > index a9a5a01..8ed5944 100644 > --- a/test/validation/random/random.c > +++ b/test/validation/random/random.c > @@ -29,5 +29,10 @@ odp_suiteinfo_t random_suites[] = { > > int random_main(void) > { > - return odp_cunit_run(random_suites); > + int ret = odp_cunit_register(random_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/scheduler/scheduler.c > b/test/validation/scheduler/scheduler.c > index b8c92a0..5cddade 100644 > --- a/test/validation/scheduler/scheduler.c > +++ b/test/validation/scheduler/scheduler.c > @@ -1147,5 +1147,10 @@ odp_suiteinfo_t scheduler_suites[] = { > > int scheduler_main(void) > { > - return odp_cunit_run(scheduler_suites); > + int ret = odp_cunit_register(scheduler_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/shmem/shmem.c b/test/validation/shmem/shmem.c > index 41ec725..5524b5c 100644 > --- a/test/validation/shmem/shmem.c > +++ b/test/validation/shmem/shmem.c > @@ -88,5 +88,10 @@ odp_suiteinfo_t shmem_suites[] = { > > int shmem_main(void) > { > - return odp_cunit_run(shmem_suites); > + int ret = odp_cunit_register(shmem_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/synchronizers/synchronizers.c > b/test/validation/synchronizers/synchronizers.c > index 49b7dad..7d8f6b0 100644 > --- a/test/validation/synchronizers/synchronizers.c > +++ b/test/validation/synchronizers/synchronizers.c > @@ -1214,6 +1214,14 @@ odp_suiteinfo_t synchronizers_suites[] = { > > int synchronizers_main(void) > { > + int ret; > + > odp_cunit_register_global_init(synchronizers_init); > - return odp_cunit_run(synchronizers_suites); > + > + ret = odp_cunit_register(synchronizers_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/system/system.c b/test/validation/system/system.c > index cf0ab0a..7dc2cc0 100644 > --- a/test/validation/system/system.c > +++ b/test/validation/system/system.c > @@ -101,5 +101,10 @@ odp_suiteinfo_t system_suites[] = { > > int system_main(void) > { > - return odp_cunit_run(system_suites); > + int ret = odp_cunit_register(system_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/thread/thread.c b/test/validation/thread/thread.c > index b86ebd3..9ba8322 100644 > --- a/test/validation/thread/thread.c > +++ b/test/validation/thread/thread.c > @@ -125,5 +125,10 @@ odp_suiteinfo_t thread_suites[] = { > > int thread_main(void) > { > - return odp_cunit_run(thread_suites); > + int ret = odp_cunit_register(thread_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/time/time.c b/test/validation/time/time.c > index f2c196c..41db0e9 100644 > --- a/test/validation/time/time.c > +++ b/test/validation/time/time.c > @@ -75,5 +75,10 @@ odp_suiteinfo_t time_suites[] = { > > int time_main(void) > { > - return odp_cunit_run(time_suites); > + int ret = odp_cunit_register(time_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > diff --git a/test/validation/timer/timer.c b/test/validation/timer/timer.c > index 02398f7..645dc58 100644 > --- a/test/validation/timer/timer.c > +++ b/test/validation/timer/timer.c > @@ -544,5 +544,10 @@ odp_suiteinfo_t timer_suites[] = { > > int timer_main(void) > { > - return odp_cunit_run(timer_suites); > + int ret = odp_cunit_register(timer_suites); > + > + if (ret == 0) > + ret = odp_cunit_run(); > + > + return ret; > } > -- > 2.1.1 > _______________________________________________ lng-odp mailing list [email protected] https://lists.linaro.org/mailman/listinfo/lng-odp
