diff --git a/meta-selftest/recipes-test/poison/poison.bb b/meta-selftest/recipes-test/poison/poison.bb index e9eee0cdba..771113acf3 100644 --- a/meta-selftest/recipes-test/poison/poison.bb +++ b/meta-selftest/recipes-test/poison/poison.bb @@ -8,13 +8,25 @@ inherit nopackages # This test confirms that compiling code that searches /usr/include for headers # will result in compiler errors. This recipe should will fail to build and # oe-selftest has a test that verifies that. -do_compile() { - bbnote Testing preprocessor - echo "int main(int argc, char** argv) {}" | ${CPP} -I/usr/include - - bbnote Testing C compiler - echo "int main(int argc, char** argv) {}" | ${CC} -x c -I/usr/include - - bbnote Testing C++ compiler - echo "int main(int argc, char** argv) {}" | ${CC} -x c++ -I/usr/include - +python do_compile() { + import subprocess + + tests = { + "Preprocessor": "${CPP} -I/usr/include -", + "C Compiler": "${CC} -I/usr/include -x c -", + "C++ Compiler": "${CXX} -I/usr/include -x c++ -", + } + + for name, cmd in tests.items(): + cmd = d.expand(cmd) + bb.note("Test command: " + cmd) + testcode = "int main(int argc, char** argv) {}" + proc = subprocess.run(cmd, shell=True, input=testcode, capture_output=True, text=True) + + if proc.returncode != 0 and "is unsafe for cross-compilation" in proc.stderr: + bb.note(f"{name} passed: {proc.stderr}") + else: + bb.error(f"{name} is not poisoned. Exit status {proc.returncode}, output: {proc.stdout} {proc.stderr}") } EXCLUDE_FROM_WORLD = "1" diff --git a/meta/lib/oeqa/selftest/cases/buildoptions.py b/meta/lib/oeqa/selftest/cases/buildoptions.py index 09272314bb..b509bcf951 100644 --- a/meta/lib/oeqa/selftest/cases/buildoptions.py +++ b/meta/lib/oeqa/selftest/cases/buildoptions.py @@ -234,6 +234,5 @@ PREMIRRORS = "\\ class Poisoning(OESelftestTestCase): def test_poisoning(self): - res = bitbake("poison", ignore_status=True) - self.assertNotEqual(res.status, 0) - self.assertTrue("is unsafe for cross-compilation" in res.output) + # The poison recipe fails if the poisoning didn't work + bitbake("poison")