Skip to contentSkip to conversation

tests/functional: Provide the user with hints where to find more log files

PATCH In review Thomas Huth 2 participants 2 messages Nov 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/functional: Provide the user with hints where to find more log files

Since the base.log and console.log files are not referenced from the meson test logs yet, they might be hard to find for the casual users. Thus let's print some hints in case a test case failed. For this we have to run unittest.main() with exit=False to get the results of the testing. Then we can iterate through the failed test cases to print out the information accordingly.

---
 tests/functional/qemu_test/testcase.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
tests/functional/qemu_test/testcase.py +13 -5
index aa0146265a..411978b5ef 100644
@@ -45,10 +45,10 @@ def setUp(self, bin_prefix):
         os.makedirs(self.workdir, exist_ok=True)
 
         self.logdir = self.workdir
+        self.log_filename = os.path.join(self.logdir, 'base.log')
         self.log = logging.getLogger('qemu-test')
         self.log.setLevel(logging.DEBUG)
-        self._log_fh = logging.FileHandler(os.path.join(self.logdir,
-                                                        'base.log'), mode='w')
+        self._log_fh = logging.FileHandler(self.log_filename, mode='w')
         self._log_fh.setLevel(logging.DEBUG)
         fileFormatter = logging.Formatter(
             '%(asctime)s - %(levelname)s: %(message)s')
@@ -68,7 +68,14 @@ def main():
 
         tr = pycotap.TAPTestRunner(message_log = pycotap.LogMode.LogToError,
                                    test_output_log = pycotap.LogMode.LogToError)
-        unittest.main(module = None, testRunner = tr, argv=["__dummy__", path])
+        res = unittest.main(module = None, testRunner = tr, exit = False,
+                            argv=["__dummy__", path])
+        for (test, message) in res.result.errors + res.result.failures:
+            print('More information on ' + test.id() + ' could be found here:'
+                  '\n %s' % test.log_filename, file=sys.stderr)
+            if hasattr(test, 'console_log_name'):
+                print(' %s' % test.console_log_name, file=sys.stderr)
+        sys.exit(not res.result.wasSuccessful())
 
 
 class QemuUserTest(QemuBaseTest):
@@ -101,8 +108,9 @@ def setUp(self):
 
         console_log = logging.getLogger('console')
         console_log.setLevel(logging.DEBUG)
-        self._console_log_fh = logging.FileHandler(os.path.join(self.workdir,
-                                                   'console.log'), mode='w')
+        self.console_log_name = os.path.join(self.workdir, 'console.log')
+        self._console_log_fh = logging.FileHandler(self.console_log_name,
+                                                   mode='w')
         self._console_log_fh.setLevel(logging.DEBUG)
         fileFormatter = logging.Formatter('%(asctime)s: %(message)s')
         self._console_log_fh.setFormatter(fileFormatter)
Signature · 1 line
2.47.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Thomas Huth

Since the base.log and console.log files are not referenced from the meson test logs yet, they might be hard to find for the casual users. Thus let's print some hints in case a test case failed. For this we have to run unittest.main() with exit=False to get the results of the testing. Then we can iterate through the failed test cases to print out the information accordingly.

and

not ok 1 test_aarch64_aspeed.AST2x00MachineSDK.test_aarch64_ast2700_evb_sdk_v09_02
1..1
More information on test_aarch64_aspeed.AST2x00MachineSDK.test_aarch64_ast2700_evb_sdk_v09_02 could be found here:
/home/legoater/work/qemu/qemu-aspeed.git/build/tests/functional/aarch64/test_aarch64_aspeed.AST2x00MachineSDK.test_aarch64_ast2700_evb_sdk_v09_02/base.log /home/legoater/work/qemu/qemu-aspeed.git/build/tests/functional/aarch64/test_aarch64_aspeed.AST2x00MachineSDK.test_aarch64_ast2700_evb_sdk_v09_02/console.log

Thanks,

C.

Quoted 49 lines
---
  tests/functional/qemu_test/testcase.py | 18 +++++++++++++-----
  1 file changed, 13 insertions(+), 5 deletions(-)
tests/functional/qemu_test/testcase.py +13 -5
index aa0146265a..411978b5ef 100644
@@ -45,10 +45,10 @@ def setUp(self, bin_prefix):
          os.makedirs(self.workdir, exist_ok=True)
 
          self.logdir = self.workdir
+        self.log_filename = os.path.join(self.logdir, 'base.log')
          self.log = logging.getLogger('qemu-test')
          self.log.setLevel(logging.DEBUG)
-        self._log_fh = logging.FileHandler(os.path.join(self.logdir,
-                                                        'base.log'), mode='w')
+        self._log_fh = logging.FileHandler(self.log_filename, mode='w')
          self._log_fh.setLevel(logging.DEBUG)
          fileFormatter = logging.Formatter(
              '%(asctime)s - %(levelname)s: %(message)s')
@@ -68,7 +68,14 @@ def main():
 
          tr = pycotap.TAPTestRunner(message_log = pycotap.LogMode.LogToError,
                                     test_output_log = pycotap.LogMode.LogToError)
-        unittest.main(module = None, testRunner = tr, argv=["__dummy__", path])
+        res = unittest.main(module = None, testRunner = tr, exit = False,
+                            argv=["__dummy__", path])
+        for (test, message) in res.result.errors + res.result.failures:
+            print('More information on ' + test.id() + ' could be found here:'
+                  '\n %s' % test.log_filename, file=sys.stderr)
+            if hasattr(test, 'console_log_name'):
+                print(' %s' % test.console_log_name, file=sys.stderr)
+        sys.exit(not res.result.wasSuccessful())
 
 
  class QemuUserTest(QemuBaseTest):
@@ -101,8 +108,9 @@ def setUp(self):
 
          console_log = logging.getLogger('console')
          console_log.setLevel(logging.DEBUG)
-        self._console_log_fh = logging.FileHandler(os.path.join(self.workdir,
-                                                   'console.log'), mode='w')
+        self.console_log_name = os.path.join(self.workdir, 'console.log')
+        self._console_log_fh = logging.FileHandler(self.console_log_name,
+                                                   mode='w')
          self._console_log_fh.setLevel(logging.DEBUG)
          fileFormatter = logging.Formatter('%(asctime)s: %(message)s')
          self._console_log_fh.setFormatter(fileFormatter)