forked from ubisoft/Sharpmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regression_test.py
161 lines (133 loc) · 5.19 KB
/
regression_test.py
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
#!/usr/bin/env python
# Script that runs the regression tests on the output of Sharpmake. It does not
# take any argument.
#
# This script supports Python 3.
import os.path
import sys
if os.name != "nt":
import select
class Test:
def __init__(self, directory, script_name, project_root = ""):
self.directory = directory
self.assembly = directory + ".dll" # same name as the directory for now
self.script_name = script_name
self.use_mono = os.name == "posix"
if project_root == "":
self.project_root = directory
else:
self.project_root = project_root
def run_test(self, as_source):
entry_path = os.getcwd()
try:
pwd = os.path.join(entry_path, "samples")
os.chdir(pwd)
# Detects the path of the Sharpmake executable
sharpmake_path = find_target_path(self.directory, "Sharpmake.Application.exe")
write_line("Using sharpmake " + sharpmake_path)
# Builds the command line argument list.
sources = "/sources(@\"{}\")".format(os.path.join(self.directory, self.script_name))
assemblies = "/assemblies(@\"{}\")".format(find_target_path(self.directory, self.assembly))
referencedir = "/referencedir(@\"{}\")".format(os.path.join(self.directory, "reference"))
outputdir = "/outputdir(@\"{}\")".format(os.path.join(self.directory, "projects"))
remaproot = "/remaproot(@\"{}\")".format(self.project_root)
test = "/test(@\"Regression\")"
verbose = "/verbose"
args = [
sources if as_source else assemblies,
referencedir,
outputdir,
remaproot,
test,
verbose
]
if self.use_mono:
args_string = "\" \"".join([arg.replace('"','\\"') for arg in args])
cmd_line = "mono --debug {} \"{}\"".format(sharpmake_path, args_string)
else:
cmd_line = "{} \"{}\"".format(sharpmake_path, " ".join(args))
return os.system(cmd_line)
except:
raise
finally:
os.chdir(entry_path)
tests = [
Test("ConfigureOrder", "main.sharpmake.cs"),
Test("CPPCLI", "CLRTest.sharpmake.cs"),
Test("CSharpHelloWorld", "HelloWorld.sharpmake.cs"),
Test("HelloWorld", "HelloWorld.sharpmake.cs"),
Test("CSharpVsix", "CSharpVsix.sharpmake.cs"),
Test("CSharpWCF", "CSharpWCF.sharpmake.cs", "CSharpWCF\codebase"),
Test("PackageReferences", "PackageReferences.sharpmake.cs"),
Test("QTFileCustomBuild", "QTFileCustomBuild.sharpmake.cs")
]
def find_target_path(directory, target):
optim_tokens = ["debug", "release"]
for optim_token in optim_tokens:
path = os.path.abspath(os.path.join("..", "bin", optim_token, "samples", target))
if os.path.isfile(path):
return path
raise IOError("Cannot find " + target)
def write_line(str):
print(str)
sys.stdout.flush()
# Those are not cross-platform!
def red_bg():
if os.name == "nt":
os.system("color 4F")
def green_bg():
if os.name == "nt":
os.system("color 2F")
def pause(timeout=None):
if timeout is None:
input("Press any key to continue . . .")
else:
timeoutSeconds = int(timeout) if int(timeout) > 0 else 5
if os.name == "nt":
os.system("timeout /t " + str(timeoutSeconds))
else:
stop_waiting = False
for s in range(0, timeout):
if stop_waiting:
break
display = "Waiting for " + str(timeoutSeconds - s) + " seconds, press a key to continue ..."
sys.stdout.write("\r" + display)
sys.stdout.flush()
poll_frequency = 100 # ms
for ms in range(0, int(1000/poll_frequency)):
i,o,e = select.select([sys.stdin],[],[],poll_frequency/1000)
for s in i:
if s == sys.stdin:
sys.stdin.readline()
stop_waiting = True
break
if stop_waiting:
break
def launch_tests():
entry_path = os.getcwd()
try:
# Change directory to the path of this.
pwd = os.path.dirname(os.path.realpath(__file__))
os.chdir(pwd)
# Run each test. Break and exit on error.
for test in tests:
write_line("Regression test in source mode on {}...".format(test.directory))
exit_code = test.run_test(True)
if exit_code != 0:
red_bg()
write_line("Test failed.")
return exit_code
write_line("Regression test in assembly mode on {}...".format(test.directory))
exit_code = test.run_test(False)
if exit_code != 0:
red_bg()
write_line("Test failed.")
return exit_code
green_bg()
write_line("Regression tests succeeded.")
pause(5)
return 0
finally:
os.chdir(entry_path)
exit_code = launch_tests()
sys.exit(exit_code)