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

View File

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