The original stdbuf use only checked if /usr/bin/stdbuf exists in the
host's system but failed to verify compatibility between stdbuf and the
target test binary.

The issue occurs when:
- Host system has glibc-based stdbuf from coreutils
- Selftest binaries are compiled with a non-glibc toolchain (cross
  compilation)

The fix adds a runtime compatibility test against the target test binary
before enabling stdbuf, enabling cross-compiled selftests to run
successfully.

Signed-off-by: Aqib Faruqui <aqi...@amazon.com>
---
 tools/testing/selftests/kselftest/runner.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kselftest/runner.sh 
b/tools/testing/selftests/kselftest/runner.sh
index 2c3c58e65..8d4e33bd5 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -107,7 +107,7 @@ run_one()
                echo "# Warning: file $TEST is missing!"
                echo "not ok $test_num $TEST_HDR_MSG"
        else
-               if [ -x /usr/bin/stdbuf ]; then
+               if [ -x /usr/bin/stdbuf ] && [ -x "$TEST" ] && /usr/bin/stdbuf 
--output=L ldd "$TEST" >/dev/null 2>&1; then
                        stdbuf="/usr/bin/stdbuf --output=L "
                fi
                eval kselftest_cmd_args="\$${kselftest_cmd_args_ref:-}"
-- 
2.47.3


Reply via email to