From 5389151567d189fb65fcded344929dcc319f2db3 Mon Sep 17 00:00:00 2001 From: Vincent Danno Date: Mon, 7 Jun 2021 20:53:10 +0200 Subject: MTS inherits BashFeature Signed-off-by: Vincent Danno Change-Id: Ifa3a5d5946c29863905490de5f875e17026744a5 --- xtesting/core/feature.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'xtesting/core/feature.py') diff --git a/xtesting/core/feature.py b/xtesting/core/feature.py index f92858bd..946233d6 100644 --- a/xtesting/core/feature.py +++ b/xtesting/core/feature.py @@ -96,11 +96,13 @@ class BashFeature(Feature): Returns: 0 if cmd returns 0, - -1 otherwise. + non-zero in all other cases. """ try: cmd = kwargs["cmd"] console = kwargs["console"] if "console" in kwargs else False + # For some tests, we may need to force stop after N sec + max_duration = kwargs.get("max_duration") if not os.path.isdir(self.res_dir): os.makedirs(self.res_dir) with open(self.result_file, 'w') as f_stdout: @@ -112,7 +114,13 @@ class BashFeature(Feature): if console: sys.stdout.write(line.decode("utf-8")) f_stdout.write(line.decode("utf-8")) - process.wait() + try: + process.wait(timeout=max_duration) + except subprocess.TimeoutExpired: + process.kill() + self.__logger.info( + "Killing process after %d second(s).", max_duration) + return -2 with open(self.result_file, 'r') as f_stdin: self.__logger.debug("$ %s\n%s", cmd, f_stdin.read().rstrip()) return process.returncode -- cgit 1.2.3-korg