-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun
executable file
·202 lines (151 loc) · 7.15 KB
/
run
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python3
#
# Vapor Compiler Licence
#
# Copyright © 2017-2019 Michał "Griwes" Dominiak
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation is required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
#
# TODO: make the runner print the time it took for each of the files
# TODO: make the runner be able to run things in parallel
import os
import argparse
import re
import subprocess
command_re = re.compile(r'^// (.*): (.*)$')
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
failed_tests = []
passed_count = 0
def val_or_def(value, default):
if value is not None:
return value
return default
def print_if(condition, string, **kwargs):
if condition:
print(string, **kwargs)
def parse_metadata(file_path):
steps = []
with open(file_path, encoding = 'utf-8') as f:
for line in f:
match = command_re.match(line)
if match is None:
break
if match.group(1) == 'IGNORE' and match.group(2) == 'true':
return { 'ignored': True }
steps.append({ 'name': match.group(1), 'command': match.group(2) })
if len(steps) == 0:
return { 'ignored': False, 'failed': True, 'reason': 'no steps defined!' }
return { 'ignored': False, 'steps': steps, 'failed': False }
def test_file(file_path, test_dir):
global failed_tests
global passed_count
if not os.path.exists(os.path.join(test_dir, file_path)):
if not os.path.exists(os.path.join(test_dir, file_path + '.vpr')):
print('-- Invalid test name: %s' % file_path)
return 1
file_path += '.vpr'
file_path = os.path.join(test_dir, file_path)
name = os.path.splitext(os.path.basename(file_path))[0]
test_info = parse_metadata(file_path)
if test_info['ignored']:
return 0
if pt:
print("##teamcity[testStarted name='%s' captureStandardOutput='true']" % name)
print_if(ps, '-- Testing %s ' % os.path.relpath(file_path, test_dir), end = '', flush = True)
if test_info['failed']:
failed_tests.append(file_path)
print('\n%s%s-- Failed: %s:%s' % (bcolors.FAIL, bcolors.BOLD, os.path.relpath(file_path, test_dir), bcolors.ENDC))
print('%s * %s%s' % (bcolors.FAIL, test_info['reason'], bcolors.ENDC))
if pt:
print("##teamcity[testFailed name='%s']" % name)
print("##teamcity[testFinished name='%s']" % name)
return 1
for step in test_info['steps']:
command = step['command'].format(
input = file_path,
directory = os.path.dirname(file_path),
vprc = os.path.join(args.vpr_path, 'bin', 'vprc'),
runtime = os.path.join(args.vpr_path, 'lib', 'libvprrt.a'),
llc = args.llc,
cc = args.cc
)
completed = subprocess.run(command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
print_if(ps, '%s.%s' % (bcolors.OKGREEN if completed.returncode == 0 else bcolors.FAIL, bcolors.ENDC), end = '', flush = True)
if completed.returncode != 0:
failed_tests.append(file_path)
print('\n%s%s-- Failed: %s:%s' % (bcolors.FAIL, bcolors.BOLD, os.path.relpath(file_path, test_dir), bcolors.ENDC))
print('%s * Step `%s` failed: %s%s' % (bcolors.FAIL, step['name'], command, bcolors.ENDC))
if pt:
print("##teamcity[testFailed name='%s']" % name)
print("##teamcity[testFinished name='%s']" % name)
return 1
print_if(ps, '\n%s-- Passed: %s%s' % (bcolors.OKGREEN, os.path.relpath(file_path, test_dir), bcolors.ENDC))
passed_count += 1
if pt:
print("##teamcity[testFinished name='%s']" % name)
def clear_artifacts(test_dir):
for root, dirs, files in os.walk(test_dir):
for file in files:
if os.path.splitext(file)[1] in ('.vprm', '.o', '.asm', '.ll', '.bin'):
os.unlink(os.path.join(root, file))
if __name__ == '__main__':
test_dir = os.path.dirname(__file__)
parser = argparse.ArgumentParser(description = 'Run end-to-end compiler tests for Vapor.')
parser.add_argument('--vpr-path', dest = 'vpr_path', help = 'provide the path to a Vapor build or install dir')
parser.add_argument('--llc', default = val_or_def(os.environ.get('LLC'), 'llc'), help = 'provide a custom llc path')
parser.add_argument('--cc', default = val_or_def(os.environ.get('CC'), 'cc'), help = 'provide a custom cc path')
parser.add_argument('-t', '--test', help = 'specify a single test file (otherwise runs all found)')
parser.add_argument('-e', '--error-only', default = False, action = 'store_true', dest = 'error',
help = 'only print error messages')
parser.add_argument('--teamcity', default = False, action = 'store_true', help = 'print TeamCity service messages')
args = parser.parse_args()
pt = args.teamcity
ps = not args.error
if args.test is not None:
clear_artifacts(test_dir)
exit(test_file(args.test, test_dir))
for root, dirs, files in os.walk(test_dir):
print_if(ps, '-- Running %s' % os.path.relpath(root, test_dir))
if pt:
for dir in root.split(os.path.sep):
if dir != '.':
print("##teamcity[testSuiteStarted name='%s']" % dir)
for file in files:
if os.path.splitext(file)[1] != '.vpr':
continue
clear_artifacts(test_dir)
test_file(file, root)
if pt:
for dir in root.split(os.path.sep)[::-1]:
if dir != '.':
print("##teamcity[testSuiteFinished name='%s']" % dir)
if len(failed_tests) != 0:
print('\n%s%s-- Some tests failed:' % (bcolors.FAIL, bcolors.BOLD))
for failed in failed_tests:
print(' * %s' % failed)
print(bcolors.ENDC)
print('%s%sPassed%s: %d / %d%s' % (bcolors.BOLD, bcolors.OKGREEN, bcolors.ENDC + bcolors.BOLD, passed_count, passed_count + len(failed_tests), bcolors.ENDC))
print('%s%sFailed%s: %d / %d%s' % (bcolors.BOLD, bcolors.FAIL, bcolors.ENDC + bcolors.BOLD, len(failed_tests), passed_count + len(failed_tests), bcolors.ENDC))
exit(1)
print('%s%sPassed%s: %d / %d%s' % (bcolors.BOLD, bcolors.OKGREEN, bcolors.ENDC + bcolors.BOLD, passed_count, passed_count + len(failed_tests), bcolors.ENDC))