forked from ubisoft/Sharpmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctional_test.py
174 lines (133 loc) · 5.13 KB
/
functional_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
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python
# Script that runs the functional tests on the Sharpmake. It does not take any argument.
#
# This script supports Python 3.
import os.path
import sys
if os.name != "nt":
import select
class FunctionalTest:
def __init__(self, directory, script_name, project_root = ""):
self.directory = directory
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):
entry_path = os.getcwd()
try:
pwd = os.path.join(entry_path, "Sharpmake.FunctionalTests")
os.chdir(pwd)
# Detects the path of the Sharpmake executable
sharpmake_path = find_target_path(os.path.join(entry_path, "bin", "release"), "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))
verbose = "/verbose"
args = [
sources,
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))
generation_exit_code = os.system(cmd_line)
if generation_exit_code != 0:
return generation_exit_code
os.chdir(entry_path)
return self.build(pwd)
except:
raise
finally:
os.chdir(entry_path)
def build(self, projectDir):
print("implement build method")
return -1
class FastBuildFunctionalTest(FunctionalTest):
def build(self, projectDir):
entry_path = os.getcwd()
fastBuildPath = os.path.join(entry_path, "tools", "FastBuild", "FBuild.exe");
if not os.path.isfile(fastBuildPath):
return -1
os.chdir(os.path.join(projectDir, self.directory, "projects"))
return os.system(fastBuildPath + " All-Configs -vs -summary -verbose -config " + self.directory + ".bff")
class MSBuildFunctionalTest(FunctionalTest):
def build(self, projectDir):
entry_path = os.getcwd()
os.chdir(os.path.join(projectDir, self.directory, "projects"))
return os.system("msbuild " + self.directory + ".sln")
class CustomBuildFunctionalTest(FunctionalTest):
def build(self, projectDir):
entry_path = os.getcwd()
os.environ["tools"] = os.path.join(entry_path, "tools")
os.chdir(os.path.join(projectDir, self.directory))
return os.system("build.bat");
funcTests = [
FastBuildFunctionalTest("FastBuildFunctionalTest", "FastBuildFunctionalTest.sharpmake.cs")
]
def find_target_path(directory, target):
path = os.path.abspath(os.path.join(directory, 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_functional_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 funcTests:
write_line("Functional test on {}...".format(test.directory))
exit_code = test.run_test()
if exit_code != 0:
red_bg()
write_line("Test failed.")
return exit_code
green_bg()
write_line("Functional tests succeeded.")
pause(5)
return 0
finally:
os.chdir(entry_path)
exit_code = launch_functional_tests()
sys.exit(exit_code)