diff mbox

[v2] cunit: fix exit status so failures are caught by make check

Message ID 1416505424-583-1-git-send-email-stuart.haslam@arm.com
State New
Headers show

Commit Message

Stuart Haslam Nov. 20, 2014, 5:43 p.m. UTC
Running "make check" from the top level currently does not detect test
failures as the individual test applications report an exit status of 0
even when failures occur.

Stop using CU_get_error() as it reports framework errors rather than
test / suite failures, and the CU_cleanup_registry() clears the error
anyway. Instead exit with a failure code on framework errors, and only
exit with 0 if no tests or test suite init/cleanup functions failed.

Signed-off-by: Stuart Haslam <stuart.haslam@arm.com>
---
Change in v2: print to stderr on framework errors

 test/cunit/odp_init.c  | 38 ++++++++++++++++++++++++++------------
 test/cunit/odp_queue.c | 31 +++++++++++++++++++++----------
 2 files changed, 47 insertions(+), 22 deletions(-)

Comments

Mike Holmes Nov. 20, 2014, 7:44 p.m. UTC | #1
On 20 November 2014 12:43, Stuart Haslam <stuart.haslam@arm.com> wrote:

> Running "make check" from the top level currently does not detect test
> failures as the individual test applications report an exit status of 0
> even when failures occur.
>
> Stop using CU_get_error() as it reports framework errors rather than
> test / suite failures, and the CU_cleanup_registry() clears the error
> anyway. Instead exit with a failure code on framework errors, and only
> exit with 0 if no tests or test suite init/cleanup functions failed.
>
> Signed-off-by: Stuart Haslam <stuart.haslam@arm.com>
>

Reviewed-and-tested-by: Mike Holmes <mike.holmes@linaro.org>


> ---
> Change in v2: print to stderr on framework errors
>
>  test/cunit/odp_init.c  | 38 ++++++++++++++++++++++++++------------
>  test/cunit/odp_queue.c | 31 +++++++++++++++++++++----------
>  2 files changed, 47 insertions(+), 22 deletions(-)
>
> diff --git a/test/cunit/odp_init.c b/test/cunit/odp_init.c
> index 88e6235..07002df 100644
> --- a/test/cunit/odp_init.c
> +++ b/test/cunit/odp_init.c
> @@ -31,26 +31,40 @@ static int finalise(void)
>         return 0;
>  }
>
> -int main(void)
> +static int register_tests(void)
>  {
>         CU_pSuite ptr_suite = NULL;
> +
>         /* initialize the CUnit test registry */
>         if (CUE_SUCCESS != CU_initialize_registry())
> -               return CU_get_error();
> -       /* add a suite to the registry */
> +               return -1;
> +
> +       /* add the tests to the queue suite */
>         ptr_suite = CU_add_suite(__FILE__, init, finalise);
> -       if (NULL == ptr_suite) {
> -               CU_cleanup_registry();
> -               return CU_get_error();
> -       }
> -       /* add the tests to the suite */
> -       if (NULL == CU_ADD_TEST(ptr_suite, test_odp_init_global)) {
> -               CU_cleanup_registry();
> -               return CU_get_error();
> +       if (NULL == ptr_suite)
> +               return -1;
> +
> +       if (NULL == CU_ADD_TEST(ptr_suite, test_odp_init_global))
> +               return -1;
> +
> +       return 0;
> +}
> +
> +int main(void)
> +{
> +       int ret;
> +
> +       if (register_tests() != 0) {
> +               fprintf(stderr, "%s: framework error: %s\n",
> +                       __FILE__, CU_get_error_msg());
> +               exit(EXIT_FAILURE);
>         }
> +
>         /* Run all tests using the CUnit Basic interface */
>         CU_basic_set_mode(CU_BRM_VERBOSE);
>         CU_basic_run_tests();
> +       ret = (CU_get_number_of_failure_records() != 0);
>         CU_cleanup_registry();
> -       return CU_get_error();
> +
> +       return ret;
>  }
> diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
> index 4d233e0..46e7a2e 100644
> --- a/test/cunit/odp_queue.c
> +++ b/test/cunit/odp_queue.c
> @@ -129,29 +129,40 @@ static int finalize(void)
>         return 0;
>  }
>
> -int main(void)
> +static int register_tests(void)
>  {
>         CU_pSuite ptr_suite = NULL;
>
>         /* initialize the CUnit test registry */
>         if (CUE_SUCCESS != CU_initialize_registry())
> -               return CU_get_error();
> +               return -1;
>
>         /* add the tests to the queue suite */
>         ptr_suite = CU_add_suite(__FILE__, init, finalize);
> -       if (NULL == ptr_suite) {
> -               CU_cleanup_registry();
> -               return CU_get_error();
> -       }
> +       if (NULL == ptr_suite)
> +               return -1;
>
> -       if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
> -               CU_cleanup_registry();
> -               return CU_get_error();
> +       if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday))
> +               return -1;
> +
> +       return 0;
> +}
> +
> +int main(void)
> +{
> +       int ret;
> +
> +       if (register_tests() != 0) {
> +               fprintf(stderr, "%s: framework error: %s\n",
> +                       __FILE__, CU_get_error_msg());
> +               exit(EXIT_FAILURE);
>         }
>
>         /* Run all tests using the CUnit Basic interface */
>         CU_basic_set_mode(CU_BRM_VERBOSE);
>         CU_basic_run_tests();
> +       ret = (CU_get_number_of_failure_records() != 0);
>         CU_cleanup_registry();
> -       return CU_get_error();
> +
> +       return ret;
>  }
> --
> 2.1.1
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
diff mbox

Patch

diff --git a/test/cunit/odp_init.c b/test/cunit/odp_init.c
index 88e6235..07002df 100644
--- a/test/cunit/odp_init.c
+++ b/test/cunit/odp_init.c
@@ -31,26 +31,40 @@  static int finalise(void)
 	return 0;
 }
 
-int main(void)
+static int register_tests(void)
 {
 	CU_pSuite ptr_suite = NULL;
+
 	/* initialize the CUnit test registry */
 	if (CUE_SUCCESS != CU_initialize_registry())
-		return CU_get_error();
-	/* add a suite to the registry */
+		return -1;
+
+	/* add the tests to the queue suite */
 	ptr_suite = CU_add_suite(__FILE__, init, finalise);
-	if (NULL == ptr_suite) {
-		CU_cleanup_registry();
-		return CU_get_error();
-	}
-	/* add the tests to the suite */
-	if (NULL == CU_ADD_TEST(ptr_suite, test_odp_init_global)) {
-		CU_cleanup_registry();
-		return CU_get_error();
+	if (NULL == ptr_suite)
+		return -1;
+
+	if (NULL == CU_ADD_TEST(ptr_suite, test_odp_init_global))
+		return -1;
+
+	return 0;
+}
+
+int main(void)
+{
+	int ret;
+
+	if (register_tests() != 0) {
+		fprintf(stderr, "%s: framework error: %s\n",
+			__FILE__, CU_get_error_msg());
+		exit(EXIT_FAILURE);
 	}
+
 	/* Run all tests using the CUnit Basic interface */
 	CU_basic_set_mode(CU_BRM_VERBOSE);
 	CU_basic_run_tests();
+	ret = (CU_get_number_of_failure_records() != 0);
 	CU_cleanup_registry();
-	return CU_get_error();
+
+	return ret;
 }
diff --git a/test/cunit/odp_queue.c b/test/cunit/odp_queue.c
index 4d233e0..46e7a2e 100644
--- a/test/cunit/odp_queue.c
+++ b/test/cunit/odp_queue.c
@@ -129,29 +129,40 @@  static int finalize(void)
 	return 0;
 }
 
-int main(void)
+static int register_tests(void)
 {
 	CU_pSuite ptr_suite = NULL;
 
 	/* initialize the CUnit test registry */
 	if (CUE_SUCCESS != CU_initialize_registry())
-		return CU_get_error();
+		return -1;
 
 	/* add the tests to the queue suite */
 	ptr_suite = CU_add_suite(__FILE__, init, finalize);
-	if (NULL == ptr_suite) {
-		CU_cleanup_registry();
-		return CU_get_error();
-	}
+	if (NULL == ptr_suite)
+		return -1;
 
-	if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday)) {
-		CU_cleanup_registry();
-		return CU_get_error();
+	if (NULL == CU_ADD_TEST(ptr_suite, test_odp_queue_sunnyday))
+		return -1;
+
+	return 0;
+}
+
+int main(void)
+{
+	int ret;
+
+	if (register_tests() != 0) {
+		fprintf(stderr, "%s: framework error: %s\n",
+			__FILE__, CU_get_error_msg());
+		exit(EXIT_FAILURE);
 	}
 
 	/* Run all tests using the CUnit Basic interface */
 	CU_basic_set_mode(CU_BRM_VERBOSE);
 	CU_basic_run_tests();
+	ret = (CU_get_number_of_failure_records() != 0);
 	CU_cleanup_registry();
-	return CU_get_error();
+
+	return ret;
 }