Skip to content

Commit 486298e

Browse files
authored
Fix skip render in new wrapper (#94)
* Fix skip render in new wrapper * Enable linux desktop worker * Do not crash when log and PNG are here but GFZVK DONE is not in log * Add STATUS file
1 parent ffddabf commit 486298e

File tree

2 files changed

+88
-86
lines changed

2 files changed

+88
-86
lines changed

python/src/main/python/drivers/vkrun.py

+42-17
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,28 @@ def prepare_shader(shader):
5555
################################################################################
5656
# Linux
5757

58-
def run_linux(vert, frag, json):
58+
def run_linux(vert, frag, json, skip_render):
5959
assert(os.path.exists(vert))
6060
assert(os.path.exists(frag))
6161
assert(os.path.exists(json))
62+
63+
if skip_render:
64+
with open('SKIP_RENDER', 'w') as f:
65+
f.write('SKIP_RENDER')
66+
elif os.path.exists('SKIP_RENDER'):
67+
os.remove('SKIP_RENDER')
68+
6269
cmd = 'vkworker ' + vert + ' ' + frag + ' ' + json + ' > ' + LOGFILE
63-
subprocess.run(cmd, shell=True, timeout=TIMEOUT_RUN)
70+
status = 'SUCCESS'
71+
try:
72+
subprocess.run(cmd, shell=True, timeout=TIMEOUT_RUN).check_returncode()
73+
except subprocess.TimeoutExpired as err:
74+
status = 'TIMEOUT'
75+
except subprocess.CalledProcessError as err:
76+
status = 'CRASH'
77+
78+
with open('STATUS', 'w') as f:
79+
f.write(status)
6480

6581
################################################################################
6682
# Android
@@ -81,7 +97,7 @@ def adb(adbargs):
8197
else:
8298
return p
8399

84-
def run_android(vert, frag, json):
100+
def run_android(vert, frag, json, skip_render):
85101
assert(os.path.exists(vert))
86102
assert(os.path.exists(frag))
87103
assert(os.path.exists(json))
@@ -91,6 +107,11 @@ def run_android(vert, frag, json):
91107
adb('push ' + vert + ' ' + ANDROID_SDCARD + '/test.vert.spv')
92108
adb('push ' + frag + ' ' + ANDROID_SDCARD + '/test.frag.spv')
93109
adb('push ' + json + ' ' + ANDROID_SDCARD + '/test.json')
110+
111+
112+
if skip_render:
113+
adb('shell touch ' + ANDROID_SDCARD + '/SKIP_RENDER')
114+
94115
adb('logcat -c')
95116
adb('shell am start ' + ANDROID_APP + '/android.app.NativeActivity')
96117

@@ -128,16 +149,18 @@ def run_android(vert, frag, json):
128149
# Grab log
129150
adb('logcat -d > ' + LOGFILE)
130151

131-
with open(LOGFILE, 'a') as f:
132-
if done:
133-
f.write('\nGFZVK DONE\n')
134-
else:
135-
# Something went wrong, make sure to stop the app in any case
136-
adb('shell am force-stop ' + ANDROID_APP)
137-
if crash:
138-
f.write('\nGFZVK CRASH\n')
139-
else:
140-
f.write('\nGFZVK TIMEOUT\n')
152+
status = 'SUCCESS'
153+
if crash:
154+
status = 'CRASH'
155+
elif not done:
156+
status = 'TIMEOUT'
157+
158+
with open('STATUS', 'w') as f:
159+
f.write(status)
160+
161+
if status != 'SUCCESS':
162+
# Something went wrong, make sure to stop the app in any case
163+
adb('shell am force-stop ' + ANDROID_APP)
141164

142165
# Grab image if present
143166
imagepath = ANDROID_SDCARD + '/image.png'
@@ -156,9 +179,11 @@ def run_android(vert, frag, json):
156179

157180
group = parser.add_mutually_exclusive_group()
158181
group.add_argument('-a', '--android', action='store_true', help='Render on Android')
159-
group.add_argument('-s', '--serial', help='Android device serial ID. Implies --android')
182+
group.add_argument('-i', '--serial', help='Android device serial ID. Implies --android')
160183
group.add_argument('-l', '--linux', action='store_true', help='Render on Linux')
161184

185+
parser.add_argument('-s', '--skip-render', action='store_true', help='Skip render')
186+
162187
parser.add_argument('vert', help='Vertex shader: shader.vert[.asm|.spv]')
163188
parser.add_argument('frag', help='Fragment shader: shader.frag[.asm|.spv]')
164189
parser.add_argument('json', help='Uniforms values')
@@ -170,10 +195,10 @@ def run_android(vert, frag, json):
170195

171196
if args.serial:
172197
os.environ['ANDROID_SERIAL'] = args.serial
173-
run_android(vert, frag, args.json)
198+
run_android(vert, frag, args.json, args.skip_render)
174199

175200
if args.android:
176-
run_android(vert, frag, args.json)
201+
run_android(vert, frag, args.json, args.skip_render)
177202

178203
if args.linux:
179-
run_linux(vert, frag, args.json)
204+
run_linux(vert, frag, args.json, args.skip_render)

python/src/main/python/drivers/worker_vk.py

+46-69
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,6 @@ def remove(f):
6262

6363
################################################################################
6464

65-
def adb(adbargs, serial=None):
66-
67-
adbcmd = 'adb'
68-
if serial:
69-
adbcmd += ' -s {}'.format(serial)
70-
71-
adbcmd += ' ' + adbargs
72-
73-
try:
74-
p = subprocess.run(adbcmd, shell=True, timeout=TIMEOUT_ADB_CMD, stdout=subprocess.PIPE, universal_newlines=True)
75-
except subprocess.TimeoutExpired as err:
76-
print('ERROR: adb command timed out: ' + err.cmd)
77-
return 1
78-
else:
79-
return p
80-
81-
################################################################################
82-
8365
def prepareVertFile():
8466
vertFilename = 'test.vert'
8567
vertFileDefaultContent = '''#version 310 es
@@ -175,50 +157,36 @@ def doImageJob(args, imageJob):
175157
remove(png)
176158
remove(log)
177159

178-
vkrun.run_android('test.vert.spv', 'test.frag.spv', 'test.json')
179-
180-
has_log = os.path.exists(log)
181-
has_png = os.path.exists(png)
160+
if args.linux:
161+
vkrun.run_linux('test.vert.spv', 'test.frag.spv', 'test.json', skipRender)
162+
else:
163+
vkrun.run_android('test.vert.spv', 'test.frag.spv', 'test.json', skipRender)
182164

183-
if has_log:
165+
if os.path.exists(log):
184166
with open(log, 'r') as f:
185167
res.log += f.read()
186168

187-
pngcontent = ''
188-
if has_png:
169+
if os.path.exists(png):
189170
with open(png, 'rb') as f:
190-
pngcontent = f.read()
191-
192-
# Success
193-
if has_log and has_png:
194-
assert('GFZVK DONE' in res.log)
195-
res.status = tt.JobStatus.SUCCESS
196-
# may not have PNG when render_skip
197-
if has_png:
198-
res.PNG = pngcontent
199-
return res
200-
201-
# Error
202-
if has_log:
203-
204-
if 'GFZVK CRASH' in res.log:
171+
res.PNG = f.read()
172+
173+
if os.path.exists('STATUS'):
174+
with open('STATUS', 'r') as f:
175+
status = f.read().rstrip()
176+
if status == 'SUCCESS':
177+
res.status = tt.JobStatus.SUCCESS
178+
elif status == 'CRASH':
205179
res.status = tt.JobStatus.CRASH
206-
elif 'GFZVK TIMEOUT' in res.log:
180+
elif status == 'TIMEOUT':
207181
res.status = tt.JobStatus.TIMEOUT
208182
else:
183+
res.log += '\nUnknown status value: ' + status + '\n'
209184
res.status = tt.JobStatus.UNEXPECTED_ERROR
185+
else:
186+
# Not even a status file?
187+
res.log += '\nNo STATUS file\n'
188+
res.status = tt.JobStatus.UNEXPECTED_ERROR
210189

211-
if has_png:
212-
res.PNG = pngcontent
213-
214-
return res
215-
216-
# Unexpected error
217-
res.status = tt.JobStatus.UNEXPECTED_ERROR
218-
if has_png:
219-
res.PNG = pngcontent
220-
if not has_log:
221-
res.log += 'Cannot even retrieve log?\n'
222190
return res
223191

224192
################################################################################
@@ -268,11 +236,17 @@ def get_service(server, args):
268236

269237
################################################################################
270238

271-
def isDeviceOffline(serial):
272-
devices = adb('devices').stdout.splitlines()
273-
for d in devices:
274-
if serial in d and 'offline' in d:
275-
return True
239+
def isDeviceAvailable(serial):
240+
cmd = 'adb devices'
241+
devices = subprocess.run(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, timeout=2).stdout.splitlines()
242+
for line in devices:
243+
if serial in line:
244+
l = line.split()
245+
if l[1] == 'device':
246+
return True
247+
else:
248+
return False
249+
# Here the serial number was not present in `adb devices` output
276250
return False
277251

278252
################################################################################
@@ -288,6 +262,11 @@ def isDeviceOffline(serial):
288262
'--adbID',
289263
help='adb (Android Debug Bridge) ID of the device to run tests on. Run "adb devices" to list these IDs')
290264

265+
parser.add_argument(
266+
'--linux',
267+
action='store_true',
268+
help='Use Linux worker')
269+
291270
parser.add_argument(
292271
'--server',
293272
default='http://localhost:8080',
@@ -304,24 +283,22 @@ def isDeviceOffline(serial):
304283
server = args.server + '/request'
305284
print('server: ' + server)
306285

307-
# Set device ID
308-
if args.adbID:
309-
os.environ['ANDROID_SERIAL'] = args.adbID
310-
else:
311-
if 'ANDROID_SERIAL' not in os.environ:
312-
print('Please set ANDROID_SERIAL env variable, or use --adbID')
313-
exit(1)
314-
315-
# Prepare device
316-
adb('shell mkdir -p /sdcard/graphicsfuzz/')
286+
if not args.linux:
287+
# Set device ID
288+
if args.adbID:
289+
os.environ['ANDROID_SERIAL'] = args.adbID
290+
else:
291+
if 'ANDROID_SERIAL' not in os.environ:
292+
print('Please set ANDROID_SERIAL env variable, or use --adbID')
293+
exit(1)
317294

318295
service = None
319296

320297
# Main loop
321298
while True:
322299

323-
if isDeviceOffline(os.environ['ANDROID_SERIAL']):
324-
print('#### ABORT: device is offline')
300+
if not args.linux and not isDeviceAvailable(os.environ['ANDROID_SERIAL']):
301+
print('#### ABORT: device {} is not available (either offline or not connected?)'.format(os.environ['ANDROID_SERIAL']))
325302
exit(1)
326303

327304
if not(service):

0 commit comments

Comments
 (0)