Skip to content

Commit

Permalink
tools: handle different python sh versions
Browse files Browse the repository at this point in the history
- ensure that 'RunningCommand' object is returned by checking
  the version of the 'sh' module.
- use '_return_cmd=True' for sh versions 2.x.

Signed-off-by: Tuna Cici <[email protected]>
  • Loading branch information
TunaCici authored and lsf37 committed Oct 7, 2024
1 parent 6a6fef6 commit f578077
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 8 additions & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ def _init_build_directory(config, initialised, directory, tute_directory, output
tute_dir = "-DTUTORIAL_DIR=" + os.path.basename(tute_directory)
args = ['-G', 'Ninja'] + config_dict[config] + [tute_dir] + \
["-C", "../projects/sel4-tutorials/settings.cmake"]
return sh.cmake(args + [tute_directory], _cwd=directory, _out=output, _err=output)
result = None
if sh.__version__.startswith("1"):
result = sh.cmake(args + [tute_directory], _cwd=directory, _out=output,
_err=output)
else:
result = sh.cmake(args + [tute_directory], _cwd=directory, _out=output,
_err=output, _return_cmd=True)
return result


def _init_tute_directory(config, tut, solution, task, directory, output=None):
Expand Down
17 changes: 14 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,28 @@ def print_pexpect_failure(failure):

def run_single_test_iteration(build_dir, solution, logfile):
# Build
result = sh.ninja(_out=logfile, _cwd=build_dir)
result = None
if sh.__version__.startswith("1"):
result = sh.ninja(_out=logfile, _cwd=build_dir)
else:
result = sh.ninja(_out=logfile, _cwd=build_dir, _return_cmd=True)
if result.exit_code != 0:
logging.error("Failed to build. Not deleting build directory %s" % build_dir)
sys.exit(1)

check = sh.Command(os.path.join(build_dir, "check"))
if solution:
result = check(_out=logfile, _cwd=build_dir)
if sh.__version__.startswith("1"):
result = check(_out=logfile, _cwd=build_dir)
else:
result = check(_out=logfile, _cwd=build_dir, _return_cmd=True)
else:
# We check the start state if not solution
result = check("--start", _out=logfile, _cwd=build_dir)
if sh.__version__.startswith("1"):
result = check("--start", _out=logfile, _cwd=build_dir)
else:
result = check("--start", _out=logfile, _cwd=build_dir,
_return_cmd=True)
for proc in psutil.process_iter():
if "qemu" in proc.name():
proc.kill()
Expand Down

0 comments on commit f578077

Please sign in to comment.