Expose the qtloader object globally

When testing, we need to query the state of the Qt application,
so change the scope of qtloader from inside the init function
to global scope.

Additionally, adjust the test script accordingly to query and use this
state to make good decisions on how to terminate.

Change-Id: I6264ba20843716eb87340b160680617b718f6bd9
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
David Skoland 2022-06-01 15:11:43 +02:00
parent 2c66a8a850
commit fd4f218c1e
2 changed files with 22 additions and 13 deletions

View File

@ -29,12 +29,13 @@
<canvas id="qtcanvas"></canvas>
<script type='text/javascript'>
let qtLoader = undefined;
function init() {
var spinner = document.querySelector('#qtspinner');
var canvas = document.querySelector('#qtcanvas');
var status = document.querySelector('#qtstatus')
var qtLoader = QtLoader({
qtLoader = QtLoader({
canvasElements : [canvas],
showLoader: function(loaderStatus) {
spinner.style.display = 'block';

View File

@ -27,6 +27,7 @@ class WasmTestRunner:
self.host = 'localhost'
self.webserver = None
self.webthread = None
self.exit_code = 0
paths = ['html_path', 'browser_path', 'chromedriver_path', 'tmp_dir']
@ -59,6 +60,8 @@ class WasmTestRunner:
self.shutdown_threaded_webserver()
return self.exit_code
def run_webserver(self):
webroot = self.html_path.parent.resolve()
self.server_process =\
@ -91,16 +94,16 @@ class WasmTestRunner:
driver = webdriver.Chrome(desired_capabilities=d, service=ser)
driver.get(url)
timeout = 15
test_done = False
app_state = ''
while not test_done and timeout != 0:
# HACK : we don't know for sure how long each test takes
# so just sleep a bit here until we get desired result
# The test may never produce 'Finished testing' (eg. crash),
# so we need a timeout as well
while app_state != 'Exited':
# HACK: Optimally, we would want the program to report back to us
# when it changes state and prints logs
# Unfortunately, that's rather difficult, so we resort to polling it
# at a given interval instead, which is adjustable
time.sleep(1)
timeout = timeout - 1
app_state = self.get_loader_variable(driver, 'status')
for entry in driver.get_log('browser'):
regex = re.compile(r'[^"]*"(.*)".*')
match = regex.match(entry['message'])
@ -108,8 +111,9 @@ class WasmTestRunner:
if match is not None:
console_line = match.group(1)
print(console_line)
if 'Finished testing' in console_line:
test_done = True
if self.get_loader_variable(driver, 'crashed'):
self.exit_code = 1
def run_wasm_browser(self):
if not hasattr(self, 'browser_path'):
@ -152,6 +156,10 @@ class WasmTestRunner:
self.browser_process.kill()
break
@staticmethod
def get_loader_variable(driver, varname: str):
return driver.execute_script('return qtLoader.' + varname)
def create_tmp_dir(self):
if not self.tmp_dir.exists():
self.tmp_dir.mkdir()
@ -206,8 +214,8 @@ def main():
args = vars(parser.parse_args())
test_runner = WasmTestRunner(args)
test_runner.run()
return test_runner.run()
if __name__ == '__main__':
main()
sys.exit(main())