Skip to content

Commit 277288c

Browse files
committed
Address general issues and no longer wait 45 for starting the profile
1 parent 264802c commit 277288c

4 files changed

Lines changed: 101 additions & 94 deletions

File tree

runner/main.py

Lines changed: 88 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ def submit_image(result: TestResult, hardware: str, timestamp: str, file: str,
4747
Submits a new candidate image to the provided URL. This function logs a method
4848
indicating whether the image submission succeeded
4949
"""
50+
f = open(file, "rb")
5051
res = requests.post(
5152
url,
53+
timeout=30,
5254
data = {
5355
"group": result.group,
5456
"name": result.name,
@@ -59,7 +61,7 @@ def submit_image(result: TestResult, hardware: str, timestamp: str, file: str,
5961
"commitHash": result.commit
6062
},
6163
files = {
62-
"file": open(file, "rb"),
64+
"file": f,
6365
"log": result.error
6466
}
6567
)
@@ -68,6 +70,7 @@ def submit_image(result: TestResult, hardware: str, timestamp: str, file: str,
6870
print(res.text)
6971
else:
7072
print("Image submitted successfully")
73+
f.close()
7174

7275

7376

@@ -132,80 +135,88 @@ def setup_argparse():
132135
return args
133136

134137

138+
if __name__ == "__main__":
139+
global_start = time.perf_counter()
140+
if os.path.exists("config.json"):
141+
submit_images = True
142+
with open("config.json") as f:
143+
config = json.load(f)
144+
url = config["url"]
145+
submit_url = f"{url}/api/submit-test"
146+
hardware = config["hardware"]
147+
runner_id = config["id"]
148+
else:
149+
print("No 'config.json' provided. Test results will be stored locally instead")
150+
submit_images = False
151+
152+
153+
args = setup_argparse()
135154

136-
global_start = time.perf_counter()
137-
if os.path.exists("config.json"):
138-
submit_images = True
139-
with open("config.json") as f:
140-
config = json.load(f)
141-
url = config["url"]
142-
submit_url = f"{url}/api/submit-test"
143-
hardware = config["hardware"]
144-
runner_id = config["id"]
145-
else:
146-
print("No 'config.json' provided. Test results will be stored locally instead")
147-
submit_images = False
148-
149-
150-
args = setup_argparse()
151-
152-
# Find the executable location and its name
153-
if os.name == "nt":
154-
# Windows
155-
executable = f"{args.dir}/bin/RelWithDebInfo/OpenSpace.exe"
156-
else:
157-
# Linux/Mac
158-
executable = f"{args.dir}/bin/OpenSpace"
159-
160-
if not os.path.exists(executable):
161-
raise Exception(f"Could not find executable '{executable}'")
162-
163-
164-
if args.overwrite_path != None:
165-
write_configuration_overwrite(args.dir, args.overwrite_path)
166-
167-
168-
169-
# Running the tests
170-
if args.test is None:
171-
print("Running all tests in OpenSpace folder")
172-
files = glob.glob(f"{args.dir}/{test_base_dir}/**/*.ostest", recursive=True)
173-
for file in files:
174-
# Normalize the path endings to always do forward slashes
175-
file = file.replace(os.sep, "/")
176-
timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
177-
if args.dry_run:
178-
print(f"Test: '{file}' run against executable '{executable}'")
179-
continue
180-
181-
result = run_single_test(file, executable)
182-
for file in result.files:
183-
if submit_images:
184-
submit_image(result, hardware, timestamp, file, runner_id, submit_url)
185-
else:
186-
store_image(result, file)
187-
time.sleep(5.0)
188-
else:
189-
tests = args.test.split(",")
190-
print(f"Running tests: {tests}")
191-
for test in tests:
192-
path = f"{args.dir}/{test_base_dir}/{test}.ostest"
193-
if not os.path.isfile(path):
194-
raise Exception(f"Could not find test '{path}'")
195-
196-
timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
197-
198-
if args.dry_run:
199-
print(f"Test: '{path}' run against executable '{executable}'")
200-
continue
201-
202-
result = run_single_test(path, executable)
203-
for file in result.files:
204-
if submit_images:
205-
submit_image(result, hardware, timestamp, file, runner_id, submit_url)
206-
else:
207-
store_image(result, file)
208-
time.sleep(5.0)
209-
210-
global_end = time.perf_counter()
211-
print(f"Total time for all tests: {global_end - global_start}")
155+
# Find the executable location and its name
156+
if os.name == "nt":
157+
# Windows
158+
executable = f"{args.dir}/bin/RelWithDebInfo/OpenSpace.exe"
159+
else:
160+
# Linux
161+
executable = f"{args.dir}/bin/OpenSpace"
162+
163+
if not os.path.exists(executable):
164+
raise Exception(f"Could not find executable '{executable}'")
165+
166+
167+
if args.overwrite_path != None:
168+
write_configuration_overwrite(args.dir, args.overwrite_path)
169+
170+
171+
172+
# Running the tests
173+
if args.test is None:
174+
print("Running all tests in OpenSpace folder")
175+
files = glob.glob(f"{args.dir}/{test_base_dir}/**/*.ostest", recursive=True)
176+
for file in files:
177+
# Normalize the path endings to always do forward slashes
178+
file = file.replace(os.sep, "/")
179+
timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
180+
if args.dry_run:
181+
print(f"Test: '{file}' run against executable '{executable}'")
182+
continue
183+
184+
try:
185+
result = run_single_test(file, executable)
186+
except Exception as e:
187+
print(f"Test '{file}' failed with error: {e}")
188+
continue
189+
for img in result.files:
190+
if submit_images:
191+
submit_image(result, hardware, timestamp, img, runner_id, submit_url)
192+
else:
193+
store_image(result, img)
194+
time.sleep(5.0)
195+
else:
196+
tests = args.test.split(",")
197+
print(f"Running tests: {tests}")
198+
for test in tests:
199+
path = f"{args.dir}/{test_base_dir}/{test}.ostest"
200+
if not os.path.isfile(path):
201+
raise Exception(f"Could not find test '{path}'")
202+
203+
timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
204+
205+
if args.dry_run:
206+
print(f"Test: '{path}' run against executable '{executable}'")
207+
continue
208+
209+
try:
210+
result = run_single_test(path, executable)
211+
except Exception as e:
212+
print(f"Test '{path}' failed with error: {e}")
213+
continue
214+
for file in result.files:
215+
if submit_images:
216+
submit_image(result, hardware, timestamp, file, runner_id, submit_url)
217+
else:
218+
store_image(result, file)
219+
time.sleep(5.0)
220+
221+
global_end = time.perf_counter()
222+
print(f"Total time for all tests: {global_end - global_start}")

runner/testsuite/instruction.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
2323
##########################################################################################
2424

25-
import time
25+
import asyncio
2626

2727

2828

@@ -57,7 +57,7 @@ def __init__(self, obj):
5757

5858
if not obj["type"] in Allowed_Types:
5959
type = obj["type"]
60-
raise Exception(f"Invalid type '{type}")
60+
raise Exception(f"Invalid type '{type}'")
6161

6262
self.type = obj["type"]
6363

@@ -142,7 +142,7 @@ async def run(self, openspace):
142142
print(" Take Screenshot")
143143
# We'll wait an extra 5 seconds before taking a screenshot just to be sure that
144144
# everything is finished
145-
time.sleep(5)
145+
await asyncio.sleep(5)
146146

147147
# Take the screenshot
148148
await openspace.takeScreenshot()
@@ -152,7 +152,7 @@ async def run(self, openspace):
152152
# screenshot. The writing should be on the order of 100 ms + about 35 ms for two
153153
# frames get us to 135 ms. Lets be on the safe side with a 35x margin and go for
154154
# a wait of 5 seconds
155-
time.sleep(5)
155+
await asyncio.sleep(5)
156156

157157
case "script":
158158
print(f" Script: {self.value}")
@@ -164,7 +164,7 @@ async def run(self, openspace):
164164

165165
case "wait":
166166
print(f" Wait: {self.value}")
167-
time.sleep(int(self.value))
167+
await asyncio.sleep(int(self.value))
168168

169169
case _:
170-
raise Exception(f"Unrecognized instruction type '{type}'")
170+
raise Exception(f"Unrecognized instruction type '{self.type}'")

runner/testsuite/openspace.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def write_configuration_overwrite(base_path, data_path):
5151
# Remove the version checking URL as it would otherwise count as a "user"
5252
f.write("VersionCheckUrl = [[]]\n")
5353

54-
# Checking the OpenGL state will cause OpenGL errors to appear in the log
54+
# Setting this to true will cause OpenGL errors to appear in the log
5555
f.write("CheckOpenGLState = true\n")
5656

5757
# We can reduce the amount of time that we have to wait for OpenSpace to shut down
@@ -91,7 +91,7 @@ async def internal_run(openspace, test):
9191
This function assumes that the `openspace` library object is already authenticated and
9292
connected to the OpenSpace instance and is ready to take commands.
9393
"""
94-
print(f" Starting test")
94+
print(" Starting test")
9595
await setup_test_run(openspace)
9696
await test.run(openspace)
9797
print(" Finished test")
@@ -138,11 +138,6 @@ def run_single_test(test_path, executable) -> TestResult:
138138
stderr=subprocess.PIPE
139139
)
140140

141-
# Add a sleeping time instead of repeatedly trying to reconnect. Starting up OpenSpace
142-
# in general takes longer than this, so we don't actually lose any time
143-
time.sleep(45)
144-
145-
146141
async def mainLoop():
147142
"""
148143
The main loop of an async event loop that is needed for the OpenSpace Python API to

runner/testsuite/test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
2323
##########################################################################################
2424

25+
import asyncio
2526
import json
2627
import os
2728
import time
@@ -41,7 +42,7 @@ class TestResult:
4142
"""
4243
group: str
4344
name: str
44-
files = list[str]
45+
files: list[str]
4546
timing: float
4647
commit: str
4748
error: str
@@ -55,13 +56,13 @@ class Test:
5556
"""
5657
def __init__(self, path: str):
5758
assert(os.path.isfile(path))
58-
self.test_path = path
59+
self.test_path = path.replace(os.sep, "/")
5960

6061
with open(path) as f:
6162
content = json.load(f)
6263

6364
if content["profile"] is None:
64-
raise f"Missing 'profile' in test {path}'"
65+
raise Exception(f"Missing 'profile' in test {path}'")
6566
self.profile = content["profile"]
6667

6768
if content["commands"] is None:
@@ -103,4 +104,4 @@ async def run(self, openspace):
103104
"""
104105
for instruction in self.instructions:
105106
await instruction.run(openspace)
106-
time.sleep(1.0)
107+
await asyncio.sleep(1.0)

0 commit comments

Comments
 (0)