From 676646d647bb3745fee98ef66c051267768b3492 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 21 Jun 2022 13:57:40 -0400 Subject: [PATCH] Use monotonic clock for measuring intervals in tests. (#19659) This way we won't get spurious timeouts from clock changes. --- scripts/tests/chiptest/test_definition.py | 4 ++-- scripts/tests/run_test_suite.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/tests/chiptest/test_definition.py b/scripts/tests/chiptest/test_definition.py index e672f0787cf7a7..548ca72467c5e0 100644 --- a/scripts/tests/chiptest/test_definition.py +++ b/scripts/tests/chiptest/test_definition.py @@ -119,7 +119,7 @@ def __startServer(self, runner, command): def __waitFor(self, waitForString, server_process, outpipe): logging.debug('Waiting for %s' % waitForString) - start_time = time.time() + start_time = time.monotonic() ready, self.lastLogIndex = outpipe.CapturedLogContains( waitForString, self.lastLogIndex) while not ready: @@ -128,7 +128,7 @@ def __waitFor(self, waitForString, server_process, outpipe): (waitForString, server_process.returncode)) logging.error(died_str) raise Exception(died_str) - if time.time() - start_time > 10: + if time.monotonic() - start_time > 10: raise Exception('Timeout while waiting for %s' % waitForString) time.sleep(0.1) ready, self.lastLogIndex = outpipe.CapturedLogContains( diff --git a/scripts/tests/run_test_suite.py b/scripts/tests/run_test_suite.py index 5dc802c3b89991..5983f5061bb216 100755 --- a/scripts/tests/run_test_suite.py +++ b/scripts/tests/run_test_suite.py @@ -235,14 +235,14 @@ def cmd_run(context, iterations, all_clusters_app, lock_app, ota_provider_app, o for i in range(iterations): logging.info("Starting iteration %d" % (i+1)) for test in context.obj.tests: - test_start = time.time() + test_start = time.monotonic() try: test.Run(runner, apps_register, paths, pics_file) - test_end = time.time() + test_end = time.monotonic() logging.info('%-20s - Completed in %0.2f seconds' % (test.name, (test_end - test_start))) except Exception: - test_end = time.time() + test_end = time.monotonic() logging.exception('%s - FAILED in %0.2f seconds' % (test.name, (test_end - test_start))) apps_register.uninit()