Message ID | 1447928549-6030-1-git-send-email-stuart.haslam@linaro.org |
---|---|
State | Accepted |
Commit | 605ed61bc0ecb885ff616e7ba4881d1a80cd9b3c |
Headers | show |
On 19.11.15 12:22, Stuart Haslam wrote: > This makes it a bit easier to get a new system set up for running the > unit tests. There has always been a dependency on using a version of > CUnit >= 2.1-3, using an older version would result in an error: > > error: initialization discards ‘const’ qualifier from pointer target type [-Werror] > > caused by CUnit's CU_TestInfo structure taking a char * for the test > name rather than a const char *, and we always pass string literals as > names. Version 2.1-3 of CUnit changed this but that's still not packaged > with most distributions so we end up needing to build it from source > most of the time. We now don't use the CU_TestInfo structure directly in > any of our tests so a couple of small changes in the common code make > the issue go away. > > Tested with CUnit versions 2.1-2.dfsg-1 (packaged with Ubuntu 14.04) and > 2.1-3 (which most people will still be using). > > Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org> > --- Reviewed-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> > There is a FAQ on the website explaining the compiler error, which > could (eventually) be removed after this change. > > DEPENDENCIES | 2 +- > test/validation/common/odp_cunit_common.c | 22 +++++++++++----------- > test/validation/common/odp_cunit_common.h | 11 ++++++----- > 3 files changed, 18 insertions(+), 17 deletions(-) > > diff --git a/DEPENDENCIES b/DEPENDENCIES > index 341fe69..fec65d2 100644 > --- a/DEPENDENCIES > +++ b/DEPENDENCIES > @@ -162,7 +162,7 @@ Prerequisites for building the OpenDataPlane (ODP) API > > 4.1 Native Cunit install > > - # Debian/Ubuntu check it is 2.1-3 > + # Debian/Ubuntu > $ apt-get install libcunit1-dev > > 4.2 Built from src > diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c > index a98042d..bc786ec 100644 > --- a/test/validation/common/odp_cunit_common.c > +++ b/test/validation/common/odp_cunit_common.c > @@ -108,8 +108,8 @@ static odp_testinfo_t *cunit_get_test_info(odp_suiteinfo_t *sinfo, > { > odp_testinfo_t *tinfo; > > - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) > - if (strcmp(tinfo->testinfo.pName, test_name) == 0) > + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) > + if (strcmp(tinfo->pName, test_name) == 0) > return tinfo; > > return NULL; > @@ -144,7 +144,7 @@ static int _cunit_suite_init(void) > } > > /* run any configured conditional checks and mark inactive tests */ > - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) { > + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) { > CU_pTest ptest; > CU_ErrorCode err; > > @@ -152,7 +152,7 @@ static int _cunit_suite_init(void) > continue; > > /* test is inactive, mark it as such */ > - ptest = CU_get_test_by_name(tinfo->testinfo.pName, cur_suite); > + ptest = CU_get_test_by_name(tinfo->pName, cur_suite); > if (ptest) > err = CU_set_test_active(ptest, CU_FALSE); > else > @@ -160,7 +160,7 @@ static int _cunit_suite_init(void) > > if (err != CUE_SUCCESS) { > fprintf(stderr, "%s: failed to set test %s inactive\n", > - __func__, tinfo->testinfo.pName); > + __func__, tinfo->pName); > return -1; > } > } > @@ -187,9 +187,9 @@ static int cunit_register_suites(odp_suiteinfo_t testsuites[]) > if (!suite) > return CU_get_error(); > > - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) { > - test = CU_add_test(suite, tinfo->testinfo.pName, > - tinfo->testinfo.pTestFunc); > + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) { > + test = CU_add_test(suite, tinfo->pName, > + tinfo->pTestFunc); > if (!test) > return CU_get_error(); > } > @@ -205,7 +205,7 @@ static int cunit_update_test(CU_pSuite suite, > CU_pTest test = NULL; > CU_ErrorCode err; > odp_testinfo_t *tinfo; > - const char *test_name = updated_tinfo->testinfo.pName; > + const char *test_name = updated_tinfo->pName; > > tinfo = cunit_get_test_info(sinfo, test_name); > if (tinfo) > @@ -217,7 +217,7 @@ static int cunit_update_test(CU_pSuite suite, > return -1; > } > > - err = CU_set_test_func(test, updated_tinfo->testinfo.pTestFunc); > + err = CU_set_test_func(test, updated_tinfo->pTestFunc); > if (err != CUE_SUCCESS) { > fprintf(stderr, "%s: failed to update test func for %s\n", > __func__, test_name); > @@ -261,7 +261,7 @@ static int cunit_update_suite(odp_suiteinfo_t *updated_sinfo) > return -1; > } > > - for (tinfo = updated_sinfo->pTests; tinfo->testinfo.pName; tinfo++) { > + for (tinfo = updated_sinfo->pTests; tinfo->pName; tinfo++) { > int ret; > > ret = cunit_update_test(suite, sinfo, tinfo); > diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h > index c689054..8dbbb9f 100644 > --- a/test/validation/common/odp_cunit_common.h > +++ b/test/validation/common/odp_cunit_common.h > @@ -22,7 +22,8 @@ > typedef int (*cunit_test_check_active)(void); > > typedef struct { > - CU_TestInfo testinfo; > + const char *pName; > + CU_TestFunc pTestFunc; > cunit_test_check_active check_active; > } odp_testinfo_t; > > @@ -38,21 +39,21 @@ static inline void odp_cunit_test_missing(void) { } > > /* An active test case, with the test name matching the test function name */ > #define ODP_TEST_INFO(test_func) \ > - {{#test_func, test_func}, NULL} > + {#test_func, test_func, NULL} > > /* A test case that is unconditionally inactive. Its name will be registered > * with CUnit but it won't be executed and will be reported as inactive in > * the result summary. */ > #define ODP_TEST_INFO_INACTIVE(test_func) \ > - {{#test_func, odp_cunit_test_missing}, odp_cunit_test_inactive} > + {#test_func, odp_cunit_test_missing, odp_cunit_test_inactive} > > /* A test case that may be marked as inactive at runtime based on the > * return value of the cond_func function. A return value of 0 means > * inactive, anything else is active. */ > #define ODP_TEST_INFO_CONDITIONAL(test_func, cond_func) \ > - {{#test_func, test_func}, cond_func} > + {#test_func, test_func, cond_func} > > -#define ODP_TEST_INFO_NULL {CU_TEST_INFO_NULL, NULL} > +#define ODP_TEST_INFO_NULL {NULL, NULL, NULL} > #define ODP_SUITE_INFO_NULL {NULL, NULL, NULL, NULL} > > typedef struct { >
Merged, Maxim. On 11/19/2015 14:16, Ivan Khoronzhuk wrote: > > > On 19.11.15 12:22, Stuart Haslam wrote: >> This makes it a bit easier to get a new system set up for running the >> unit tests. There has always been a dependency on using a version of >> CUnit >= 2.1-3, using an older version would result in an error: >> >> error: initialization discards ‘const’ qualifier from pointer target >> type [-Werror] >> >> caused by CUnit's CU_TestInfo structure taking a char * for the test >> name rather than a const char *, and we always pass string literals as >> names. Version 2.1-3 of CUnit changed this but that's still not packaged >> with most distributions so we end up needing to build it from source >> most of the time. We now don't use the CU_TestInfo structure directly in >> any of our tests so a couple of small changes in the common code make >> the issue go away. >> >> Tested with CUnit versions 2.1-2.dfsg-1 (packaged with Ubuntu 14.04) and >> 2.1-3 (which most people will still be using). >> >> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org> >> --- > > Reviewed-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> > >> There is a FAQ on the website explaining the compiler error, which >> could (eventually) be removed after this change. >> >> DEPENDENCIES | 2 +- >> test/validation/common/odp_cunit_common.c | 22 +++++++++++----------- >> test/validation/common/odp_cunit_common.h | 11 ++++++----- >> 3 files changed, 18 insertions(+), 17 deletions(-) >> >> diff --git a/DEPENDENCIES b/DEPENDENCIES >> index 341fe69..fec65d2 100644 >> --- a/DEPENDENCIES >> +++ b/DEPENDENCIES >> @@ -162,7 +162,7 @@ Prerequisites for building the OpenDataPlane >> (ODP) API >> >> 4.1 Native Cunit install >> >> - # Debian/Ubuntu check it is 2.1-3 >> + # Debian/Ubuntu >> $ apt-get install libcunit1-dev >> >> 4.2 Built from src >> diff --git a/test/validation/common/odp_cunit_common.c >> b/test/validation/common/odp_cunit_common.c >> index a98042d..bc786ec 100644 >> --- a/test/validation/common/odp_cunit_common.c >> +++ b/test/validation/common/odp_cunit_common.c >> @@ -108,8 +108,8 @@ static odp_testinfo_t >> *cunit_get_test_info(odp_suiteinfo_t *sinfo, >> { >> odp_testinfo_t *tinfo; >> >> - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) >> - if (strcmp(tinfo->testinfo.pName, test_name) == 0) >> + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) >> + if (strcmp(tinfo->pName, test_name) == 0) >> return tinfo; >> >> return NULL; >> @@ -144,7 +144,7 @@ static int _cunit_suite_init(void) >> } >> >> /* run any configured conditional checks and mark inactive >> tests */ >> - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) { >> + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) { >> CU_pTest ptest; >> CU_ErrorCode err; >> >> @@ -152,7 +152,7 @@ static int _cunit_suite_init(void) >> continue; >> >> /* test is inactive, mark it as such */ >> - ptest = CU_get_test_by_name(tinfo->testinfo.pName, cur_suite); >> + ptest = CU_get_test_by_name(tinfo->pName, cur_suite); >> if (ptest) >> err = CU_set_test_active(ptest, CU_FALSE); >> else >> @@ -160,7 +160,7 @@ static int _cunit_suite_init(void) >> >> if (err != CUE_SUCCESS) { >> fprintf(stderr, "%s: failed to set test %s inactive\n", >> - __func__, tinfo->testinfo.pName); >> + __func__, tinfo->pName); >> return -1; >> } >> } >> @@ -187,9 +187,9 @@ static int cunit_register_suites(odp_suiteinfo_t >> testsuites[]) >> if (!suite) >> return CU_get_error(); >> >> - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) { >> - test = CU_add_test(suite, tinfo->testinfo.pName, >> - tinfo->testinfo.pTestFunc); >> + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) { >> + test = CU_add_test(suite, tinfo->pName, >> + tinfo->pTestFunc); >> if (!test) >> return CU_get_error(); >> } >> @@ -205,7 +205,7 @@ static int cunit_update_test(CU_pSuite suite, >> CU_pTest test = NULL; >> CU_ErrorCode err; >> odp_testinfo_t *tinfo; >> - const char *test_name = updated_tinfo->testinfo.pName; >> + const char *test_name = updated_tinfo->pName; >> >> tinfo = cunit_get_test_info(sinfo, test_name); >> if (tinfo) >> @@ -217,7 +217,7 @@ static int cunit_update_test(CU_pSuite suite, >> return -1; >> } >> >> - err = CU_set_test_func(test, updated_tinfo->testinfo.pTestFunc); >> + err = CU_set_test_func(test, updated_tinfo->pTestFunc); >> if (err != CUE_SUCCESS) { >> fprintf(stderr, "%s: failed to update test func for %s\n", >> __func__, test_name); >> @@ -261,7 +261,7 @@ static int cunit_update_suite(odp_suiteinfo_t >> *updated_sinfo) >> return -1; >> } >> >> - for (tinfo = updated_sinfo->pTests; tinfo->testinfo.pName; >> tinfo++) { >> + for (tinfo = updated_sinfo->pTests; tinfo->pName; tinfo++) { >> int ret; >> >> ret = cunit_update_test(suite, sinfo, tinfo); >> diff --git a/test/validation/common/odp_cunit_common.h >> b/test/validation/common/odp_cunit_common.h >> index c689054..8dbbb9f 100644 >> --- a/test/validation/common/odp_cunit_common.h >> +++ b/test/validation/common/odp_cunit_common.h >> @@ -22,7 +22,8 @@ >> typedef int (*cunit_test_check_active)(void); >> >> typedef struct { >> - CU_TestInfo testinfo; >> + const char *pName; >> + CU_TestFunc pTestFunc; >> cunit_test_check_active check_active; >> } odp_testinfo_t; >> >> @@ -38,21 +39,21 @@ static inline void odp_cunit_test_missing(void) { } >> >> /* An active test case, with the test name matching the test >> function name */ >> #define ODP_TEST_INFO(test_func) \ >> - {{#test_func, test_func}, NULL} >> + {#test_func, test_func, NULL} >> >> /* A test case that is unconditionally inactive. Its name will be >> registered >> * with CUnit but it won't be executed and will be reported as >> inactive in >> * the result summary. */ >> #define ODP_TEST_INFO_INACTIVE(test_func) \ >> - {{#test_func, odp_cunit_test_missing}, odp_cunit_test_inactive} >> + {#test_func, odp_cunit_test_missing, odp_cunit_test_inactive} >> >> /* A test case that may be marked as inactive at runtime based on the >> * return value of the cond_func function. A return value of 0 means >> * inactive, anything else is active. */ >> #define ODP_TEST_INFO_CONDITIONAL(test_func, cond_func) \ >> - {{#test_func, test_func}, cond_func} >> + {#test_func, test_func, cond_func} >> >> -#define ODP_TEST_INFO_NULL {CU_TEST_INFO_NULL, NULL} >> +#define ODP_TEST_INFO_NULL {NULL, NULL, NULL} >> #define ODP_SUITE_INFO_NULL {NULL, NULL, NULL, NULL} >> >> typedef struct { >> >
diff --git a/DEPENDENCIES b/DEPENDENCIES index 341fe69..fec65d2 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -162,7 +162,7 @@ Prerequisites for building the OpenDataPlane (ODP) API 4.1 Native Cunit install - # Debian/Ubuntu check it is 2.1-3 + # Debian/Ubuntu $ apt-get install libcunit1-dev 4.2 Built from src diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c index a98042d..bc786ec 100644 --- a/test/validation/common/odp_cunit_common.c +++ b/test/validation/common/odp_cunit_common.c @@ -108,8 +108,8 @@ static odp_testinfo_t *cunit_get_test_info(odp_suiteinfo_t *sinfo, { odp_testinfo_t *tinfo; - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) - if (strcmp(tinfo->testinfo.pName, test_name) == 0) + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) + if (strcmp(tinfo->pName, test_name) == 0) return tinfo; return NULL; @@ -144,7 +144,7 @@ static int _cunit_suite_init(void) } /* run any configured conditional checks and mark inactive tests */ - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) { + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) { CU_pTest ptest; CU_ErrorCode err; @@ -152,7 +152,7 @@ static int _cunit_suite_init(void) continue; /* test is inactive, mark it as such */ - ptest = CU_get_test_by_name(tinfo->testinfo.pName, cur_suite); + ptest = CU_get_test_by_name(tinfo->pName, cur_suite); if (ptest) err = CU_set_test_active(ptest, CU_FALSE); else @@ -160,7 +160,7 @@ static int _cunit_suite_init(void) if (err != CUE_SUCCESS) { fprintf(stderr, "%s: failed to set test %s inactive\n", - __func__, tinfo->testinfo.pName); + __func__, tinfo->pName); return -1; } } @@ -187,9 +187,9 @@ static int cunit_register_suites(odp_suiteinfo_t testsuites[]) if (!suite) return CU_get_error(); - for (tinfo = sinfo->pTests; tinfo->testinfo.pName; tinfo++) { - test = CU_add_test(suite, tinfo->testinfo.pName, - tinfo->testinfo.pTestFunc); + for (tinfo = sinfo->pTests; tinfo->pName; tinfo++) { + test = CU_add_test(suite, tinfo->pName, + tinfo->pTestFunc); if (!test) return CU_get_error(); } @@ -205,7 +205,7 @@ static int cunit_update_test(CU_pSuite suite, CU_pTest test = NULL; CU_ErrorCode err; odp_testinfo_t *tinfo; - const char *test_name = updated_tinfo->testinfo.pName; + const char *test_name = updated_tinfo->pName; tinfo = cunit_get_test_info(sinfo, test_name); if (tinfo) @@ -217,7 +217,7 @@ static int cunit_update_test(CU_pSuite suite, return -1; } - err = CU_set_test_func(test, updated_tinfo->testinfo.pTestFunc); + err = CU_set_test_func(test, updated_tinfo->pTestFunc); if (err != CUE_SUCCESS) { fprintf(stderr, "%s: failed to update test func for %s\n", __func__, test_name); @@ -261,7 +261,7 @@ static int cunit_update_suite(odp_suiteinfo_t *updated_sinfo) return -1; } - for (tinfo = updated_sinfo->pTests; tinfo->testinfo.pName; tinfo++) { + for (tinfo = updated_sinfo->pTests; tinfo->pName; tinfo++) { int ret; ret = cunit_update_test(suite, sinfo, tinfo); diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h index c689054..8dbbb9f 100644 --- a/test/validation/common/odp_cunit_common.h +++ b/test/validation/common/odp_cunit_common.h @@ -22,7 +22,8 @@ typedef int (*cunit_test_check_active)(void); typedef struct { - CU_TestInfo testinfo; + const char *pName; + CU_TestFunc pTestFunc; cunit_test_check_active check_active; } odp_testinfo_t; @@ -38,21 +39,21 @@ static inline void odp_cunit_test_missing(void) { } /* An active test case, with the test name matching the test function name */ #define ODP_TEST_INFO(test_func) \ - {{#test_func, test_func}, NULL} + {#test_func, test_func, NULL} /* A test case that is unconditionally inactive. Its name will be registered * with CUnit but it won't be executed and will be reported as inactive in * the result summary. */ #define ODP_TEST_INFO_INACTIVE(test_func) \ - {{#test_func, odp_cunit_test_missing}, odp_cunit_test_inactive} + {#test_func, odp_cunit_test_missing, odp_cunit_test_inactive} /* A test case that may be marked as inactive at runtime based on the * return value of the cond_func function. A return value of 0 means * inactive, anything else is active. */ #define ODP_TEST_INFO_CONDITIONAL(test_func, cond_func) \ - {{#test_func, test_func}, cond_func} + {#test_func, test_func, cond_func} -#define ODP_TEST_INFO_NULL {CU_TEST_INFO_NULL, NULL} +#define ODP_TEST_INFO_NULL {NULL, NULL, NULL} #define ODP_SUITE_INFO_NULL {NULL, NULL, NULL, NULL} typedef struct {
This makes it a bit easier to get a new system set up for running the unit tests. There has always been a dependency on using a version of CUnit >= 2.1-3, using an older version would result in an error: error: initialization discards ‘const’ qualifier from pointer target type [-Werror] caused by CUnit's CU_TestInfo structure taking a char * for the test name rather than a const char *, and we always pass string literals as names. Version 2.1-3 of CUnit changed this but that's still not packaged with most distributions so we end up needing to build it from source most of the time. We now don't use the CU_TestInfo structure directly in any of our tests so a couple of small changes in the common code make the issue go away. Tested with CUnit versions 2.1-2.dfsg-1 (packaged with Ubuntu 14.04) and 2.1-3 (which most people will still be using). Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org> --- There is a FAQ on the website explaining the compiler error, which could (eventually) be removed after this change. DEPENDENCIES | 2 +- test/validation/common/odp_cunit_common.c | 22 +++++++++++----------- test/validation/common/odp_cunit_common.h | 11 ++++++----- 3 files changed, 18 insertions(+), 17 deletions(-)