Re: [PATCH v2 1/2] libtracefs: utest: Return non-zero exit code when something fails

Steven Rostedt <[email protected]> Fri, 1 Aug 2025 21:47:47 -0400
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
This is a "v2" of just 1/2. I don't see a 2/2 of this version.

-- Steve



On Mon, 28 Jul 2025 16:34:33 +0200
Michal Sojka <[email protected]> wrote:

> Previously, the test suite returned zero exit status even if something
> failed. One could learn about the failure from the output, such as:
> 
>     WARNING - Suite initialization failed for 'tracefs library'.
>     Run Summary:    Type  Total    Ran Passed Failed Inactive
>                   suites      1      0    n/a      1        0
>                    tests     37      0      0      0        0
> 
> However, when the test suite is run via meson, i.e. with:
> 
>     meson setup build && meson test -C build
> 
> Meson always reports success, because it primarily looks at process
> exit code.
> 
> To not make meson mask failures, this commit sets the exit code to one
> if some suite (we have just one) or test fails. Additionally, it
> prints error messages in the suite initialization function, to make
> the failure more understandable.
> 
> Signed-off-by: Michal Sojka <[email protected]>
> 
> ---
> Changes in v2:
> - Fixed typos in the commit message.
> - Use tabs instead of spaces for indentation.
> ---
>  utest/trace-utest.c   | 8 +++++++-
>  utest/tracefs-utest.c | 8 ++++++--
>  2 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/utest/trace-utest.c b/utest/trace-utest.c
> index 39485a1..b40a217 100644
> --- a/utest/trace-utest.c
> +++ b/utest/trace-utest.c
> @@ -79,6 +79,12 @@ int main(int argc, char **argv)
>  
>  	CU_basic_set_mode(verbose);
>  	CU_basic_run_tests();
> +
> +	int err = CU_get_error() != CUE_SUCCESS ||
> +		CU_get_number_of_suites_failed() > 0 ||
> +		CU_get_number_of_failures() > 0;
> +
>  	CU_cleanup_registry();
> -	return 0;
> +
> +	return err ? 1 : 0;
>  }
> diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
> index cc7e689..4a412b2 100644
> --- a/utest/tracefs-utest.c
> +++ b/utest/tracefs-utest.c
> @@ -3849,11 +3849,15 @@ static int test_suite_destroy(void)
>  static int test_suite_init(void)
>  {
>  	test_tep = tracefs_local_events(NULL);
> -	if (test_tep == NULL)
> +	if (test_tep == NULL) {
> +		perror("tracefs_local_events");
>  		return 1;
> +	}
>  	test_instance = tracefs_instance_create(TEST_INSTANCE_NAME);
> -	if (!test_instance)
> +	if (!test_instance) {
> +		perror("tracefs_instance_create");
>  		return 1;
> +	}
>  
>  	mapping_is_supported = tracefs_mapped_is_supported();
>  	if (mapping_is_supported)