[reland][lit][unit] makes sure to print stderr when no test failures are found
authorYuanfang Chen <yuanfang.chen@sony.com>
Fri, 15 Jul 2022 20:23:22 +0000 (13:23 -0700)
committerYuanfang Chen <yuanfang.chen@sony.com>
Fri, 15 Jul 2022 20:26:30 +0000 (13:26 -0700)
In some situations, like running tests with sanitizers, all test
passes but the shard could still fail due to memory issues.

Relands 65769429c0644c81d271e9d971f5b64191503

llvm/utils/lit/lit/formats/googletest.py
llvm/utils/lit/lit/main.py

index 5feefaa..ed3a19e 100644 (file)
@@ -163,6 +163,8 @@ class GoogleTest(TestFormat):
                     res.append(l)
             assert False, f'gtest did not report the result for ' + test_name
 
+        found_failed_test = False
+
         with open(test.gtest_json_file, encoding='utf-8') as f:
             jf = json.load(f)
 
@@ -179,6 +181,7 @@ class GoogleTest(TestFormat):
                     header = f"Script:\n--\n%s --gtest_filter=%s\n--\n" % (
                         ' '.join(cmd), testname)
                     if 'failures' in testinfo:
+                        found_failed_test = True
                         output += header
                         test_out = get_test_stdout(testname)
                         if test_out:
@@ -189,6 +192,12 @@ class GoogleTest(TestFormat):
                     elif result != 'COMPLETED':
                         output += header
                         output += 'unresolved test result\n'
+
+        # In some situations, like running tests with sanitizers, all test passes but
+        # the shard could still fail due to memory issues.
+        if not found_failed_test:
+            output += f"\n{out}\n--\nexit: {exitCode}\n--\n"
+
         return lit.Test.FAIL, output
 
     def prepareCmd(self, cmd):
@@ -217,7 +226,11 @@ class GoogleTest(TestFormat):
         discovered_tests = remove_gtest(discovered_tests)
         gtests = [t for t in selected_tests if t.gtest_json_file]
         selected_tests = remove_gtest(selected_tests)
+        has_failure = False
         for test in gtests:
+            if test.isFailure():
+                has_failure = True
+
             # In case gtest has bugs such that no JSON file was emitted.
             if not os.path.exists(test.gtest_json_file):
                 selected_tests.append(test)
@@ -269,4 +282,4 @@ class GoogleTest(TestFormat):
                         discovered_tests.append(subtest)
             os.remove(test.gtest_json_file)
 
-        return selected_tests, discovered_tests
+        return selected_tests, discovered_tests, has_failure
index 27bcef1..67d9efa 100755 (executable)
@@ -108,7 +108,7 @@ def main(builtin_params={}):
 
     record_test_times(selected_tests, lit_config)
 
-    selected_tests, discovered_tests = GoogleTest.post_process_shard_results(
+    selected_tests, discovered_tests, has_failure = GoogleTest.post_process_shard_results(
         selected_tests, discovered_tests)
 
     if opts.time_tests:
@@ -127,7 +127,7 @@ def main(builtin_params={}):
     if lit_config.numWarnings:
         sys.stderr.write('\n%d warning(s) in tests\n' % lit_config.numWarnings)
 
-    has_failure = any(t.isFailure() for t in discovered_tests)
+    has_failure = has_failure or any(t.isFailure() for t in discovered_tests)
     if has_failure:
         if opts.ignoreFail:
             sys.stderr.write("\nExiting with status 0 instead of 1 because "