[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / utils / rsp_bisect_test / test.py
blob1cf0df589023d5d1d4a73373b56266fe2f03d069
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, '--test', test_script, '--rsp', rsp, '--other-rel-path',
25 '../Other'
27 res = subprocess.run(args, capture_output=True, encoding='UTF-8')
28 if len(sys.argv) > 1 and sys.argv[1] == '-v':
29 print('Ran {} with return code {}'.format(args, res.returncode))
30 print('Stdout:')
31 print(res.stdout)
32 print('Stderr:')
33 print(res.stderr)
34 if res.returncode != (0 if success else 1):
35 print(res.stdout)
36 print(res.stderr)
37 raise AssertionError('unexpected bisection return code for ' + str(args))
38 return res.stdout
41 # Test that an empty rsp file fails.
42 with open(rsp, 'w') as f:
43 pass
45 run_bisect(False, test1)
47 # Test that an rsp file without any paths fails.
48 with open(rsp, 'w') as f:
49 f.write('hello\nfoo\n')
51 run_bisect(False, test1)
53 # Test that an rsp file with one path succeeds.
54 with open(rsp, 'w') as f:
55 f.write('./foo\n')
57 output = run_bisect(True, test1)
58 assert './foo' in output
60 # Test that an rsp file with one path and one extra arg succeeds.
61 with open(rsp, 'w') as f:
62 f.write('hello\n./foo\n')
64 output = run_bisect(True, test1)
65 assert './foo' in output
67 # Test that an rsp file with three paths and one extra arg succeeds.
68 with open(rsp, 'w') as f:
69 f.write('hello\n./foo\n./bar\n./baz\n')
71 output = run_bisect(True, test1)
72 assert './foo' in output
74 with open(rsp, 'w') as f:
75 f.write('hello\n./bar\n./foo\n./baz\n')
77 output = run_bisect(True, test1)
78 assert './foo' in output
80 with open(rsp, 'w') as f:
81 f.write('hello\n./bar\n./baz\n./foo\n')
83 output = run_bisect(True, test1)
84 assert './foo' in output
86 output = run_bisect(True, test2)
87 assert './foo' in output
89 with open(rsp + '.0', 'r') as f:
90 contents = f.read()
91 assert ' ../Other/./foo' in contents
93 with open(rsp + '.1', 'r') as f:
94 contents = f.read()
95 assert ' ./foo' in contents
97 os.remove(rsp)
98 os.remove(rsp + '.0')
99 os.remove(rsp + '.1')
101 print('Success!')