diff options
author | David Skoland <david.skoland@qt.io> | 2022-06-01 15:11:43 +0200 |
---|---|---|
committer | David Skoland <david.skoland@qt.io> | 2022-06-03 05:30:46 +0200 |
commit | fd4f218c1eb4cdbc96c1ef2086e3390fe26fa63f (patch) | |
tree | 345d2aee0306f542b4d571c7362510ab23b2e59a /util | |
parent | 2c66a8a850ca1a25e6b00f6c42d423328621ede7 (diff) | |
download | qtbase-fd4f218c1eb4cdbc96c1ef2086e3390fe26fa63f.tar.gz |
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>
Diffstat (limited to 'util')
-rwxr-xr-x | util/wasm/wasmtestrunner/qt-wasmtestrunner.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/util/wasm/wasmtestrunner/qt-wasmtestrunner.py b/util/wasm/wasmtestrunner/qt-wasmtestrunner.py index 9b5cfaeb28..d67acf8550 100755 --- a/util/wasm/wasmtestrunner/qt-wasmtestrunner.py +++ b/util/wasm/wasmtestrunner/qt-wasmtestrunner.py @@ -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()) |