From 5a93bb072561d974a9a4c5d482861e25356f170c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Tue, 17 Jan 2023 20:59:45 +0100 Subject: [PATCH 1/2] pylib: add run_simulator runner Fixes #106 --- pylib/run_simulator.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pylib/run_simulator.py diff --git a/pylib/run_simulator.py b/pylib/run_simulator.py new file mode 100644 index 00000000..6e510b6b --- /dev/null +++ b/pylib/run_simulator.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +# Python module to run programs natively. + +# Copyright (C) 2019 Clemson University +# Copyright (C) 2023 University of Bremen +# +# Contributor: Ola Jeppsson +# Contributor Sören Tempel +# +# This file is part of Embench. + +# SPDX-License-Identifier: GPL-3.0-or-later + +""" +Embench module to run benchmark programs. + +This version is suitable for running programs within a simulator. +""" + +__all__ = [ + 'get_target_args', + 'build_benchmark_cmd', + 'decode_results', +] + +import argparse +import re + +from run_native import decode_results +from embench_core import log + + +def get_target_args(remnant): + """Parse left over arguments""" + parser = argparse.ArgumentParser(description='Get target specific args') + parser.add_argument( + '--simulator', + type=str, + help='Simulator command to run benchmarks with' + ) + + # No target arguments + return parser.parse_args(remnant) + + +def build_benchmark_cmd(bench, args): + """Construct the command to run the benchmark. "args" is a + namespace with target specific arguments""" + simulator = args.simulator + + # Due to way the target interface currently works we need to construct + # a command that records both the return value and execution time to + # stdin/stdout. Obviously using time will not be very precise. + return ['sh', '-c', f'time -p {simulator} ./' + bench + '; echo RET=$?'] From c7a99e68c36c997ad710804e5b2b522b8d4ea19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Wed, 18 Jan 2023 22:12:18 +0100 Subject: [PATCH 2/2] run_native.py: Use multiline search in decode results Otherwise, this function does not handle multiple line output correctly. For example, if a simulator writes text to standard error for some reason. --- pylib/run_native.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylib/run_native.py b/pylib/run_native.py index c17aada1..c4a2a803 100644 --- a/pylib/run_native.py +++ b/pylib/run_native.py @@ -60,7 +60,7 @@ def decode_results(stdout_str, stderr_str): return 0.0 # Match "real s.mm?m?" - time = re.search('^real (\d+)[.](\d+)', stderr_str, re.S) + time = re.search('^real (\d+)[.](\d+)', stderr_str, re.S | re.M) if time: ms_elapsed = int(time.group(1)) * 1000 + \ int(time.group(2).ljust(3,'0')) # 0-pad