selftest: Add logging tests for bb.build.exec_func with shell/python code

Message ID 20220217171415.25658-1-pkj@axis.com
State New
Headers show
Series selftest: Add logging tests for bb.build.exec_func with shell/python code | expand

Commit Message

Peter Kjellerstedt Feb. 17, 2022, 5:14 p.m. UTC
The situation regarding logging is different when a function called by
bb.build.exec_func() fails compared to when the task code fails
directly.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---

The second test (with logs but without verbose) in
bblogging.BitBakeLogging.test_python_exec_func_shell_logging will
currently fail since stdout/stderr from the failing shell code is not
included in the output. This can be fixed by reverting commit fc58ad84
in bitbake, but then some of the other tests will fail as there will
be duplicated logs for them.

 .../recipes-test/logging-test/logging-test.bb | 10 +++
 meta/lib/oeqa/selftest/cases/bblogging.py     | 69 ++++++++++++++++++-
 2 files changed, 78 insertions(+), 1 deletion(-)

Patch

diff --git a/meta-selftest/recipes-test/logging-test/logging-test.bb b/meta-selftest/recipes-test/logging-test/logging-test.bb
index a6100123f9..ac3fb46f45 100644
--- a/meta-selftest/recipes-test/logging-test/logging-test.bb
+++ b/meta-selftest/recipes-test/logging-test/logging-test.bb
@@ -11,12 +11,22 @@  do_shelltest() {
 }
 addtask do_shelltest
 
+python do_pythontest_exec_func_shell() {
+    bb.build.exec_func('do_shelltest', d)
+}
+addtask do_pythontest_exec_func_shell
+
 python do_pythontest_exit () {
     print("This is python stdout")
     sys.exit(1)
 }
 addtask do_pythontest_exit
 
+python do_pythontest_exec_func_python() {
+    bb.build.exec_func('do_pythontest_exit', d)
+}
+addtask do_pythontest_exec_func_python
+
 python do_pythontest_fatal () {
     print("This is python fatal test stdout")
     bb.fatal("This is a fatal error")
diff --git a/meta/lib/oeqa/selftest/cases/bblogging.py b/meta/lib/oeqa/selftest/cases/bblogging.py
index ea6c3c8c77..6b0bbfe1c1 100644
--- a/meta/lib/oeqa/selftest/cases/bblogging.py
+++ b/meta/lib/oeqa/selftest/cases/bblogging.py
@@ -30,7 +30,7 @@  class BitBakeLogging(OESelftestTestCase):
         self.write_config('BBINCLUDELOGS = ""')
         result = bitbake("logging-test -c shelltest -f -v", ignore_status = True)
         self.assertIn("ERROR: Logfile of failure stored in:", result.output)
-        # two copies due to set +x        
+        # two copies due to set +x
         self.assertCount(result.output, "This is shell stdout", 2)
         self.assertCount(result.output, "This is shell stderr", 2)
 
@@ -42,6 +42,41 @@  class BitBakeLogging(OESelftestTestCase):
         self.assertCount(result.output, "This is shell stdout", 2)
         self.assertCount(result.output, "This is shell stderr", 2)
 
+    def test_python_exec_func_shell_logging(self):
+        # no logs, no verbose
+        self.write_config('BBINCLUDELOGS = ""')
+        result = bitbake("logging-test -c pythontest_exec_func_shell -f",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        self.assertNotIn("This is shell stdout", result.output)
+        self.assertNotIn("This is shell stderr", result.output)
+
+        # logs, no verbose
+        self.write_config('BBINCLUDELOGS = "yes"')
+        result = bitbake("logging-test -c pythontest_exec_func_shell -f",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        self.assertCount(result.output, "This is shell stdout", 1)
+        self.assertCount(result.output, "This is shell stderr", 1)
+
+        # no logs, verbose
+        self.write_config('BBINCLUDELOGS = ""')
+        result = bitbake("logging-test -c pythontest_exec_func_shell -f -v",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        # two copies due to set +x
+        self.assertCount(result.output, "This is shell stdout", 2)
+        self.assertCount(result.output, "This is shell stderr", 2)
+
+        # logs, verbose
+        self.write_config('BBINCLUDELOGS = "yes"')
+        result = bitbake("logging-test -c pythontest_exec_func_shell -f -v",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        # two copies due to set +x
+        self.assertCount(result.output, "This is shell stdout", 2)
+        self.assertCount(result.output, "This is shell stderr", 2)
+
     def test_python_exit_logging(self):
         # no logs, no verbose
         self.write_config('BBINCLUDELOGS = ""')
@@ -70,6 +105,38 @@  class BitBakeLogging(OESelftestTestCase):
         # python tasks don't log output with -v currently
         #self.assertCount(result.output, "This is python stdout", 1)
 
+    def test_python_exec_func_python_logging(self):
+        # no logs, no verbose
+        self.write_config('BBINCLUDELOGS = ""')
+        result = bitbake("logging-test -c pythontest_exec_func_python -f",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        self.assertNotIn("This is python stdout", result.output)
+
+        # logs, no verbose
+        self.write_config('BBINCLUDELOGS = "yes"')
+        result = bitbake("logging-test -c pythontest_exec_func_python -f",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        # A sys.exit() should include the output
+        self.assertCount(result.output, "This is python stdout", 1)
+
+        # no logs, verbose
+        self.write_config('BBINCLUDELOGS = ""')
+        result = bitbake("logging-test -c pythontest_exec_func_python -f -v",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        # python tasks don't log output with -v currently
+        #self.assertCount(result.output, "This is python stdout", 1)
+
+        # logs, verbose
+        self.write_config('BBINCLUDELOGS = "yes"')
+        result = bitbake("logging-test -c pythontest_exec_func_python -f -v",
+                         ignore_status = True)
+        self.assertIn("ERROR: Logfile of failure stored in:", result.output)
+        # python tasks don't log output with -v currently
+        #self.assertCount(result.output, "This is python stdout", 1)
+
     def test_python_fatal_logging(self):
         # no logs, no verbose
         self.write_config('BBINCLUDELOGS = ""')