Skip to content

Commit

Permalink
Ensure that the test script does not kill itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
jblueh committed Sep 28, 2022
1 parent 1f15378 commit 36c5698
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions TestCases/TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Command:
launch : str
e.g. "mpirun -n 2", possibly empty
exec : str
e.g. "SU2_CFD", must be a suitable argument to killall to clean up what the command started
e.g. "SU2_CFD", must be suitable to identify the processes started by the command
param : str
e.g. "-t 2", possibly empty
"""
Expand All @@ -62,6 +62,10 @@ def assemble(self):
assert self.exec != ""
return " ".join([part for part in [self.launch, self.exec, self.param] if part != ""])

def killall(self):
""" Issues a shell command that kills all processes matching self.exec, except this process. """
os.system('pgrep %s | grep -vx %d | xargs kill -9' % (self.exec, os.getpid()))


def __init__(self,tag_in):

Expand Down Expand Up @@ -158,7 +162,7 @@ def run_test(self):
if running_time > self.timeout:
try:
process.kill()
os.system('killall %s' % self.command.exec) # In case of parallel execution
self.command.killall() # In case of parallel execution
except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things!
pass
timed_out = True
Expand Down Expand Up @@ -298,7 +302,7 @@ def run_filediff(self):
if running_time > self.timeout:
try:
process.kill()
os.system('killall %s' % self.command.exec) # In case of parallel execution
self.command.killall() # In case of parallel execution
except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things!
pass
timed_out = True
Expand Down Expand Up @@ -391,7 +395,7 @@ def run_opt(self):
if running_time > self.timeout:
try:
process.kill()
os.system('killall %s' % self.command.exec) # In case of parallel execution
self.command.killall() # In case of parallel execution
except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things!
pass
timed_out = True
Expand Down Expand Up @@ -523,7 +527,7 @@ def run_geo(self):
if running_time > self.timeout:
try:
process.kill()
os.system('killall %s' % self.command.exec) # In case of parallel execution
self.command.killall() # In case of parallel execution
except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things!
pass
timed_out = True
Expand Down Expand Up @@ -652,7 +656,7 @@ def run_def(self):
if running_time > self.timeout:
try:
process.kill()
os.system('killall %s' % self.command.exec) # In case of parallel execution
self.command.killall() # In case of parallel execution
except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things!
pass
timed_out = True
Expand Down

0 comments on commit 36c5698

Please sign in to comment.