Skip to contentSkip to conversation

selftests/bpf: Better error messages for ima_setup.sh failures

PATCH In review KP Singh 2 participants 2 messages Mar 22, 2021 – Mar 26, 2021

Subsystems (3)
lore
Share & tools
lore

KP Singh

author
#0 lore raw

PATCH 1/1 selftests/bpf: Better error messages for ima_setup.sh failures

The current implementation uses the CHECK_FAIL macro which does not provide useful error messages when the script fails. Use the CHECK macro instead and provide more descriptive messages to aid debugging.

---
 tools/testing/selftests/bpf/prog_tests/test_ima.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_ima.c +4 -2
index b54bc0c351b7..0252f61d611a 100644
@@ -68,7 +68,8 @@ void test_test_ima(void)
 		goto close_prog;
 
 	snprintf(cmd, sizeof(cmd), "./ima_setup.sh setup %s", measured_dir);
-	if (CHECK_FAIL(system(cmd)))
+	err = system(cmd);
+	if (CHECK(err, "failed to run command", "%s, errno = %d\n", cmd, errno))
 		goto close_clean;
 
 	err = run_measured_process(measured_dir, &skel->bss->monitored_pid);
@@ -81,7 +82,8 @@ void test_test_ima(void)
 
 close_clean:
 	snprintf(cmd, sizeof(cmd), "./ima_setup.sh cleanup %s", measured_dir);
-	CHECK_FAIL(system(cmd));
+	err = system(cmd);
+	CHECK(err, "failed to run command", "%s, errno = %d\n", cmd, errno);
 close_prog:
 	ima__destroy(skel);
 }
Signature · 1 line
2.31.0.rc2.261.g7f71774620-goog
#1 lore raw
Quoted 7 lines · KP Singh

The current implementation uses the CHECK_FAIL macro which does not provide useful error messages when the script fails. Use the CHECK macro instead and provide more descriptive messages to aid debugging.

---

This was applied to bpf-next, but commit bot doesn't seem very attentive at the moment :) Thanks for improvements!

Quoted 30 lines
 tools/testing/selftests/bpf/prog_tests/test_ima.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_ima.c +4 -3
index b54bc0c351b7..0252f61d611a 100644
@@ -68,7 +68,8 @@ void test_test_ima(void)
                goto close_prog;
 
        snprintf(cmd, sizeof(cmd), "./ima_setup.sh setup %s", measured_dir);
-       if (CHECK_FAIL(system(cmd)))
+       err = system(cmd);
+       if (CHECK(err, "failed to run command", "%s, errno = %d\n", cmd, errno))
                goto close_clean;
 
        err = run_measured_process(measured_dir, &skel->bss->monitored_pid);
@@ -81,7 +82,8 @@ void test_test_ima(void)
 
 close_clean:
        snprintf(cmd, sizeof(cmd), "./ima_setup.sh cleanup %s", measured_dir);
-       CHECK_FAIL(system(cmd));
+       err = system(cmd);
+       CHECK(err, "failed to run command", "%s, errno = %d\n", cmd, errno);
 close_prog:
        ima__destroy(skel);
 }
--

2.31.0.rc2.261.g7f71774620-goog