[lldb/Utils] Serialize exit code in lldb-repro.py
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 5 May 2020 22:59:43 +0000 (15:59 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 5 May 2020 23:05:49 +0000 (16:05 -0700)
After 61d5b0e66394 more shell test are expected to exit with a non-zero
status code. Because the exit status is computed in the driver and not
behind the SB API layer, reproducers don't know about it and always
return 0 unless replay failed.

This discrepancy means that these tests don't work with lldb-repro.py
and skipping them for this reason would be a pity. To solve this
problem, the script now serializes the exit code during capture and
returns that during replay.

These is an assert that ensures that replay exits with a zero exit
status to prevent replay failures from being silently ignored.

lldb/utils/lldb-repro/lldb-repro.py

index fddd65e..2244e97 100755 (executable)
@@ -44,10 +44,8 @@ def main():
     # Create a new lldb invocation with capture or replay enabled.
     lldb = os.path.join(os.path.dirname(sys.argv[0]), 'lldb')
     new_args = [lldb]
-    cleanup = False
     if sys.argv[1] == "replay":
         new_args.extend(['--replay', reproducer_path])
-        cleanup = True
     elif sys.argv[1] == "capture":
         new_args.extend([
             '--capture', '--capture-path', reproducer_path,
@@ -59,8 +57,19 @@ def main():
         return 1
 
     exit_code = subprocess.call(new_args)
-    if cleanup:
+
+    # The driver always exists with a zero exit code during replay. Store the
+    # exit code and return that for tests that expect a non-zero exit code.
+    exit_code_path = os.path.join(reproducer_path, 'exit_code.txt')
+    if sys.argv[1] == "replay":
+        with open(exit_code_path, 'r') as f:
+            assert exit_code == 0
+            exit_code = int(f.read())
         shutil.rmtree(reproducer_path, True)
+    elif sys.argv[1] == "capture":
+        with open(exit_code_path, 'w') as f:
+            f.write('%d' % exit_code)
+
     return exit_code