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

Michal Sojka <[email protected]> Mon, 21 Jul 2025 00:16:16 +0200
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
Previously, the test suite returned zero exit status even if something
failed. One could lern 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 is suite initialization function, to make the
failure more understandable.

Signed-off-by: Michal Sojka <[email protected]>
---
 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..ac76bf6 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)
-- 
2.50.0