-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.py
296 lines (258 loc) · 9.3 KB
/
run_tests.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import argparse
import os
import time
import shutil
import subprocess
from multiprocessing import Process
testTemp = "temp"
testConfigs = "temp/test_configs"
testOutputs = "temp/test_outputs"
basePath = os.getcwd()
testTempPath = os.path.join(basePath, testTemp)
testConfigsPath = os.path.join(basePath, testConfigs)
testOutputsPath = os.path.join(basePath, testOutputs)
testsToRun = {
"test_unit",
"test_intersect",
"test_light",
"test_efficiency",
"test_feature", # For Project 4: Illuminate
# "test_fun", # For Project 4: Illuminate (optional)
# "test_legacy", # Not really relevant
# "test_refract", # For extra credit (refraction)
# "test_dof", # For extra credit (depth of field)
# "test_take_forever", # For extra credit (acceleration datastructure / parallelism)
# "test_mesh", # For extra credit (triangle mesh intersection)
# "test_area_light" # for extra credit (soft shadows and area lights)
}
testConfigParams = {
"test_unit": {
"shadows": "false",
"reflect": "false",
"refract": "false",
"texture": "false",
"parallel": "false",
"super-sample": "false",
"acceleration": "false",
"depthoffield": "false",
"texture-filter": "false",
},
"test_intersect": {
"shadows": "false",
"reflect": "false",
"refract": "false",
"texture": "false",
"parallel": "false",
"super-sample": "false",
"acceleration": "false",
"depthoffield": "false",
"texture-filter": "false",
},
"test_light": {
"shadows": "true", # false for Intersect
"reflect": "true", # false for Intersect
"refract": "false",
"texture": "true", # false for Intersect
"parallel": "false",
"super-sample": "false",
"acceleration": "false",
"depthoffield": "false",
"texture-filter": "false",
},
"test_efficiency": {
"shadows": "true", # false for Intersect
"reflect": "true", # false for Intersect
"refract": "false",
"texture": "true", # false for Intersect
"parallel": "false",
"super-sample": "false",
"acceleration": "false",
"depthoffield": "false",
"texture-filter": "false",
},
"test_feature": {
"shadows": "true",
"reflect": "true",
"refract": "false",
"texture": "true",
"parallel": "false",
"super-sample": "false",
"acceleration": "false",
"depthoffield": "false",
"texture-filter": "false",
},
"test_fun": {
"shadows": "true",
"reflect": "true",
"refract": "false",
"texture": "true",
"parallel": "true",
"super-sample": "true",
"acceleration": "true",
"depthoffield": "false",
"texture-filter": "true",
},
"test_refract": {
"shadows": "true",
"reflect": "true",
"refract": "true",
"texture": "true",
"parallel": "true",
"super-sample": "true",
"acceleration": "true",
"depthoffield": "false",
"texture-filter": "true",
},
"test_dof": {
"shadows": "true",
"reflect": "true",
"refract": "true",
"texture": "true",
"parallel": "true",
"super-sample": "false",
"acceleration": "true",
"depthoffield": "true",
"texture-filter": "true",
},
"test_take_forever": {
"shadows": "true",
"reflect": "true",
"refract": "true",
"texture": "true",
"parallel": "true",
"super-sample": "true",
"acceleration": "true",
"depthoffield": "false",
"texture-filter": "true",
},
"test_mesh": {
"shadows": "true",
"reflect": "true",
"refract": "true",
"texture": "true",
"parallel": "true",
"super-sample": "true",
"acceleration": "true",
"depthoffield": "false",
"texture-filter": "true",
},
"test_legacy": {
"shadows": "false",
"reflect": "false",
"refract": "false",
"texture": "false",
"parallel": "true",
"super-sample": "true",
"acceleration": "true",
"depthoffield": "false",
"texture-filter": "true",
},
"test_area_light": {
"shadows": "true",
"reflect": "true",
"refract": "true",
"texture": "true",
"parallel": "true",
"super-sample": "true",
"acceleration": "true",
"depthoffield": "false",
"texture-filter": "true",
},
}
def generateTestFiles(basePath, testName, filename):
if not testName in testConfigParams.keys():
raise "cannot find test: " + testName
filenameNoExt = filename.split(".")[0]
configFileName = testName + "_" + filenameNoExt
configFilePath = os.path.join(testConfigsPath, configFileName) + ".ini"
outputFilePath = os.path.join(testOutputsPath, configFileName) + ".png"
if os.path.exists(configFilePath):
os.remove(configFilePath)
params = testConfigParams[testName]
with open(configFilePath, "w") as f:
f.write("[IO]\n")
f.write("\tscene = " + os.path.join(basePath, testName, filename) + "\n")
f.write("\toutput = " + outputFilePath + "\n")
f.write("\n")
f.write("[Canvas]\n")
f.write("\twidth = 512\n")
f.write("\theight = 384\n")
f.write("\n")
f.write("[Feature]\n")
for key, value in params.items():
f.write("\t{0} = {1}\n".format(key, value))
return
def renderTests(raytracer, allTestConfigsPath):
start = time.time()
# run all tests while suppressing stdout output
for config in allTestConfigsPath:
print(raytracer + " " + config)
subprocess.run([raytracer, config], stdout=subprocess.DEVNULL)
end = time.time()
print("Take {:.6f} seconds to render all scenes".format(end - start))
return
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--timeout', default=-1,
help='The timeout for rendering in seconds. A negative value means no timeout')
args = parser.parse_args()
timeout = int(args.timeout)
# clean existing folders
if os.path.exists(testTempPath):
shutil.rmtree(testTempPath)
os.mkdir(testTempPath)
os.mkdir(testConfigsPath)
os.mkdir(testOutputsPath)
# get all test folders
allTestFolders = [file for file in os.listdir(".") if file.startswith("test_") and os.path.isdir(file)]
# generate test config files
for testFolder in allTestFolders:
if not testFolder in testsToRun:
continue
fullPath = os.path.join(basePath, testFolder)
allSceneFiles = [file for file in os.listdir(fullPath) if file.endswith(".xml")]
for filename in allSceneFiles:
generateTestFiles(basePath, testFolder, filename)
# check if the ray tracer executable exist
raytracer = os.path.join(basePath, "projects_ray")
if not os.path.exists(raytracer):
raise "Ray Tracer executable not exists"
# discover all tests to run
allTestConfigsPath = [os.path.join(testConfigsPath, file) for file in os.listdir(testConfigsPath)]
allTestConfigsPath.sort()
p = Process(target=renderTests, args=[raytracer, allTestConfigsPath])
p.start()
if timeout <= 0:
p.join()
else:
p.join(timeout)
if p.exitcode is None:
p.terminate()
print("did not finished rendering within the given time:", timeout, "seconds")
elif p.exitcode != 0:
print("process teminated with a non-zero exitcode")
else:
print("success")
# add suffix to output image
for f in os.listdir(testOutputsPath):
name, ext = f.split(".")
name += "_gen"
newF = ".".join([name, ext])
os.rename(os.path.join(testOutputsPath, f), os.path.join(testOutputsPath, newF))
# copy images from bench folder
assignmentName = "grading_illuminate"
benchImagesFolder = os.path.join(basePath, "bench", assignmentName)
allBenchImages = [f for f in os.listdir(benchImagesFolder) if f.startswith("test_")]
allBenchImages.sort()
imagesToCopy = []
for image in allBenchImages:
for testName in testsToRun:
if image.startswith(testName):
imagesToCopy.append(image)
break
for image in imagesToCopy:
src = os.path.join(benchImagesFolder, image)
name, ext = image.split(".")
name += "_ref"
dst = os.path.join(testOutputsPath, ".".join([name, ext]))
shutil.copy(src, dst)