ptest-cargo: fix incorrect FAIL count when multiple tests are run

When using the ptest-cargo class with multiple Rust test binaries, ptest-runner
may report FAIL: 0 even if one of the tests fails, as long as the last test passes.

This happens because the run-ptest script, as generated by the class, does not
track failures and simply returns the exit code of the last test.
To fix this, each test binary is checked individually for failure. If any test fails,
a non-zero exit code is returned.

This ensures that test failures are not silently ignored and are properly reported
by ptest-runner in multi-test scenarios.

(From OE-Core rev: 039708d2aa578da755d5b6eadd6f549121a93186)

Signed-off-by: Ines KCHELFI <ines.kchelfi@smile.fr>
Reviewed-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ines KCHELFI 2025-04-24 14:32:17 +02:00 committed by Richard Purdie
parent 40346626ec
commit 9019308b31

View File

@ -102,14 +102,15 @@ python do_install_ptest_cargo() {
with open(ptest_script, "a") as f:
if not script_exists:
f.write("#!/bin/sh\n")
f.write("rc=0\n")
else:
f.write(f"\necho \"\"\n")
f.write(f"echo \"## starting to run rust tests ##\"\n")
f.write(f"echo \"## starting to run rust tests ##\"\n")
for test_path in test_paths:
f.write(f"{test_path} {rust_test_args}\n")
f.write(f"if ! {test_path} {rust_test_args}; then rc=1; fi\n")
f.write("exit $rc\n")
if not script_exists:
os.chmod(ptest_script, 0o755)