[RISCV] Regenerate autogen test to remove spurious diff
[llvm-project.git] / llvm / utils / rsp_bisect_test / test.py
blob2433d8653e3166b0e2fb7ef3414b30074372a224
1 #!/usr/bin/env python3
2 # ===----------------------------------------------------------------------===##
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 # ===----------------------------------------------------------------------===##
10 import os
11 import subprocess
12 import sys
13 import tempfile
15 cur_dir = os.path.dirname(os.path.realpath(__file__))
16 bisect_script = os.path.join(cur_dir, "..", "rsp_bisect.py")
17 test1 = os.path.join(cur_dir, "test_script.py")
18 test2 = os.path.join(cur_dir, "test_script_inv.py")
19 rsp = os.path.join(cur_dir, "rsp")
22 def run_bisect(success, test_script):
23 args = [
24 bisect_script,
25 "--test",
26 test_script,
27 "--rsp",
28 rsp,
29 "--other-rel-path",
30 "../Other",
32 res = subprocess.run(args, capture_output=True, encoding="UTF-8")
33 if len(sys.argv) > 1 and sys.argv[1] == "-v":
34 print("Ran {} with return code {}".format(args, res.returncode))
35 print("Stdout:")
36 print(res.stdout)
37 print("Stderr:")
38 print(res.stderr)
39 if res.returncode != (0 if success else 1):
40 print(res.stdout)
41 print(res.stderr)
42 raise AssertionError("unexpected bisection return code for " + str(args))
43 return res.stdout
46 # Test that an empty rsp file fails.
47 with open(rsp, "w") as f:
48 pass
50 run_bisect(False, test1)
52 # Test that an rsp file without any paths fails.
53 with open(rsp, "w") as f:
54 f.write("hello\nfoo\n")
56 run_bisect(False, test1)
58 # Test that an rsp file with one path succeeds.
59 with open(rsp, "w") as f:
60 f.write("./foo\n")
62 output = run_bisect(True, test1)
63 assert "./foo" in output
65 # Test that an rsp file with one path and one extra arg succeeds.
66 with open(rsp, "w") as f:
67 f.write("hello\n./foo\n")
69 output = run_bisect(True, test1)
70 assert "./foo" in output
72 # Test that an rsp file with three paths and one extra arg succeeds.
73 with open(rsp, "w") as f:
74 f.write("hello\n./foo\n./bar\n./baz\n")
76 output = run_bisect(True, test1)
77 assert "./foo" in output
79 with open(rsp, "w") as f:
80 f.write("hello\n./bar\n./foo\n./baz\n")
82 output = run_bisect(True, test1)
83 assert "./foo" in output
85 with open(rsp, "w") as f:
86 f.write("hello\n./bar\n./baz\n./foo\n")
88 output = run_bisect(True, test1)
89 assert "./foo" in output
91 output = run_bisect(True, test2)
92 assert "./foo" in output
94 with open(rsp + ".0", "r") as f:
95 contents = f.read()
96 assert " ../Other/./foo" in contents
98 with open(rsp + ".1", "r") as f:
99 contents = f.read()
100 assert " ./foo" in contents
102 os.remove(rsp)
103 os.remove(rsp + ".0")
104 os.remove(rsp + ".1")
106 print("Success!")