summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-02-08 14:19:01 -0700
committerCommit Bot <commit-bot@chromium.org>2022-02-12 04:18:04 +0000
commit1a16ef361e2eaf9b113d587ba350fa1d103f800b (patch)
tree44ac0f712faf7c42cc2cdaa4740310479aa74518
parente923c737379f2970118b2c0b080bcb25191c4d25 (diff)
downloadchrome-ec-1a16ef361e2eaf9b113d587ba350fa1d103f800b.tar.gz
zmake: Add timeout to ztest test
Add a timeout for all tests run by ztest, defaulting to 2 minutes. The timeout can be customized on a test by test basis by setting test_timeout_secs in the test's BUILD.py BRANCH=None BUG=b:218493723 TEST=Set timeout to 2s, and ran zmake test on the drivers test. Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I48f56a7d67c91d482094e0dc123bdacb6ffa79df Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3449123 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/zmake/zmake/project.py1
-rw-r--r--zephyr/zmake/zmake/zmake.py19
2 files changed, 15 insertions, 5 deletions
diff --git a/zephyr/zmake/zmake/project.py b/zephyr/zmake/zmake/project.py
index a6d28a68e2..1bac91cbc4 100644
--- a/zephyr/zmake/zmake/project.py
+++ b/zephyr/zmake/zmake/project.py
@@ -98,6 +98,7 @@ class ProjectConfig:
dts_overlays: "list[str]" = dataclasses.field(default_factory=list)
kconfig_files: "list[pathlib.Path]" = dataclasses.field(default_factory=list)
project_dir: pathlib.Path = dataclasses.field(default_factory=pathlib.Path)
+ test_timeout_secs: float = dataclasses.field(default=2 * 60)
class Project:
diff --git a/zephyr/zmake/zmake/zmake.py b/zephyr/zmake/zmake/zmake.py
index 604a886815..826d26b824 100644
--- a/zephyr/zmake/zmake/zmake.py
+++ b/zephyr/zmake/zmake/zmake.py
@@ -531,7 +531,7 @@ class Zmake:
return 0
- def _run_test(self, elf_file, coverage, gcov, build_dir, lcov_file):
+ def _run_test(self, elf_file, coverage, gcov, build_dir, lcov_file, timeout=None):
"""Run a single test, with goma if enabled.
Args:
@@ -568,10 +568,18 @@ class Zmake:
proc.stderr,
job_id=job_id,
)
- if proc.wait():
- raise OSError(get_process_failure_msg(proc))
- if coverage:
- self._run_lcov(build_dir, lcov_file, initial=False, gcov=gcov)
+ try:
+ if proc.wait(timeout=timeout):
+ raise OSError(get_process_failure_msg(proc))
+ if coverage:
+ self._run_lcov(build_dir, lcov_file, initial=False, gcov=gcov)
+ except subprocess.TimeoutExpired as e:
+ proc.terminate()
+ try:
+ proc.wait(timeout=1)
+ except subprocess.TimeoutExpired:
+ proc.kill()
+ raise e
if self.goma:
_run()
@@ -604,6 +612,7 @@ class Zmake:
gcov=gcov,
build_dir=build_dir,
lcov_file=build_dir / "output" / "zephyr.info",
+ timeout=project.config.test_timeout_secs,
)
)