File: test.py

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,634,820 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (101 lines) | stat: -rwxr-xr-x 2,634 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
#===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===----------------------------------------------------------------------===##

import os
import subprocess
import sys
import tempfile

cur_dir = os.path.dirname(os.path.realpath(__file__))
bisect_script = os.path.join(cur_dir, "..", "rsp_bisect.py")
test1 = os.path.join(cur_dir, "test_script.py")
test2 = os.path.join(cur_dir, "test_script_inv.py")
rsp = os.path.join(cur_dir, "rsp")


def run_bisect(success, test_script):
  args = [
      bisect_script, '--test', test_script, '--rsp', rsp, '--other-rel-path',
      '../Other'
  ]
  res = subprocess.run(args, capture_output=True, encoding='UTF-8')
  if len(sys.argv) > 1 and sys.argv[1] == '-v':
    print('Ran {} with return code {}'.format(args, res.returncode))
    print('Stdout:')
    print(res.stdout)
    print('Stderr:')
    print(res.stderr)
  if res.returncode != (0 if success else 1):
    print(res.stdout)
    print(res.stderr)
    raise AssertionError('unexpected bisection return code for ' + str(args))
  return res.stdout


# Test that an empty rsp file fails.
with open(rsp, 'w') as f:
  pass

run_bisect(False, test1)

# Test that an rsp file without any paths fails.
with open(rsp, 'w') as f:
  f.write('hello\nfoo\n')

run_bisect(False, test1)

# Test that an rsp file with one path succeeds.
with open(rsp, 'w') as f:
  f.write('./foo\n')

output = run_bisect(True, test1)
assert './foo' in output

# Test that an rsp file with one path and one extra arg succeeds.
with open(rsp, 'w') as f:
  f.write('hello\n./foo\n')

output = run_bisect(True, test1)
assert './foo' in output

# Test that an rsp file with three paths and one extra arg succeeds.
with open(rsp, 'w') as f:
  f.write('hello\n./foo\n./bar\n./baz\n')

output = run_bisect(True, test1)
assert './foo' in output

with open(rsp, 'w') as f:
  f.write('hello\n./bar\n./foo\n./baz\n')

output = run_bisect(True, test1)
assert './foo' in output

with open(rsp, 'w') as f:
  f.write('hello\n./bar\n./baz\n./foo\n')

output = run_bisect(True, test1)
assert './foo' in output

output = run_bisect(True, test2)
assert './foo' in output

with open(rsp + '.0', 'r') as f:
  contents = f.read()
  assert ' ../Other/./foo' in contents

with open(rsp + '.1', 'r') as f:
  contents = f.read()
  assert ' ./foo' in contents

os.remove(rsp)
os.remove(rsp + '.0')
os.remove(rsp + '.1')

print('Success!')