aboutsummaryrefslogtreecommitdiffstats
path: root/xtesting/core/feature.py
diff options
context:
space:
mode:
authorVincent Danno <vincent.danno@orange.com>2021-06-07 20:53:10 +0200
committerVincent Danno <vincent.danno@orange.com>2021-06-08 14:06:41 +0200
commit5389151567d189fb65fcded344929dcc319f2db3 (patch)
treecf7311a582061125b0378b73ad0cb4016c0ef625 /xtesting/core/feature.py
parentec6921039af3b016eecc6e609f2554aea0f81e2c (diff)
MTS inherits BashFeature
Signed-off-by: Vincent Danno <vincent.danno@orange.com> Change-Id: Ifa3a5d5946c29863905490de5f875e17026744a5
Diffstat (limited to 'xtesting/core/feature.py')
-rw-r--r--xtesting/core/feature.py12
1 files changed, 10 insertions, 2 deletions
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