Skip to content

Commit

Permalink
Add --argument option to the exec driver
Browse files Browse the repository at this point in the history
Allows to pass arguments to all benchmarked commands
(especially using `temci short exec`), closes #95.
  • Loading branch information
Johannes Bechberger committed Sep 24, 2019
1 parent 320f412 commit 74086d2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
19 changes: 15 additions & 4 deletions doc/temci_exec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ as ``temci exec``:
Usage: temci short exec [OPTIONS] COMMANDS
-wd, --without_description COMMAND
Benchmark the command and use itself as its description.
-d, --with_description DESCRIPTION COMMAND...
Benchmark the command and set its description attribute.
-wd, --without_description COMMAND:
Benchmark the command and use
itself as its description. Appends
'$ARGUMENT' to the command if the string
isn't present. Use the '--argument' option
to set the value that this string is
replaced with.
-d, --with_description DESCRIPTION COMMAND:
Benchmark the command
and set its description attribute.Appends
'$ARGUMENT' to the command if the string
isn't present. Use the '--argument' option
to set the value that this string is
replaced with.
(options of temci exec)
Expand Down
7 changes: 5 additions & 2 deletions temci/run/run_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ def _match_return_code(self, error_messages: _Err, cmd: str, err: str, exptected
"Not all runners support it."),
"plugin_order": ListOrTuple(Str()) // Default(["drop_fs_caches", "sync", "sleep", "preheat", "flush_cpu_caches"])
// Description("Order in which the plugins are used, plugins that do not "
"appear in this list are used before all others")
"appear in this list are used before all others"),
"argument": Str() // Default("") // Description("Argument passed to all benchmarked commands by replacing "
"$ARGUMENT with this value in the command")
}, unknown_keys=True))
class ExecRunDriver(AbstractRunDriver):
"""
Expand Down Expand Up @@ -655,7 +657,8 @@ def _exec_command(self, cmds: list, block: RunProgramBlock,
shlex.quote(center)) + post
else:
cmd = pre + " " + center + " " + post
cmd = cmd.replace("&SUDO&", "$SUDO$") .replace("&&", "&")
arg = self.misc_settings["argument"] if "argument" in self.misc_settings else ""
cmd = cmd.replace("&SUDO&", "$SUDO$").replace("&&", "&").replace("$ARGUMENT", arg)
cwd = block["cwds"][rand_index]
executed_cmd = block["cmd_prefix"] + [cmd]
if cpuset is not None and has_root_privileges():
Expand Down
16 changes: 14 additions & 2 deletions temci/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,19 @@ def cli():
"exec": CmdOptionList(CmdOption("with_description",
type_scheme=ListOrTuple(Tuple(Str(), Str()))
// Description("DESCRIPTION COMMAND: Benchmark the command and set its"
" description attribute."),
" description attribute."
"Appends '$ARGUMENT' "
"to the command if the string isn't present. "
"Use the '--argument' option to set the value "
"that this string is replaced with."),
short="d", completion_hints={"zsh": "_command"}),
CmdOption("without_description", short="wd",
type_scheme=ListOrTuple(Str()) // Description("COMMAND: Benchmark the command and use "
"itself as its description."),
"itself as its description. "
"Appends '$ARGUMENT' "
"to the command if the string isn't present. "
"Use the '--argument' option to set the value "
"that this string is replaced with."),
completion_hints={"zsh": "_command"}),
run_options["run_driver_specific"]["exec"],
run_options["common"]
Expand Down Expand Up @@ -260,6 +268,10 @@ def temci__short__exec(commands: list, with_description: list = None, without_de
"description": cmd
}
})
for run in runs:
con = run["run_config"]
if "$ARGUMENT" not in con["run_cmd"]:
con["run_cmd"][0] += " $ARGUMENT"
Settings()["run/driver"] = "exec"
benchmark_and_exit(runs)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ def test_discard_blocks_on_error():

def test_temci_short_shell():
assert "42" in run_temci_proc("short shell echo 42").out


def test_pass_arguments():
assert run_temci("short exec exit --argument 1", expect_success=False).ret_code == ErrorCode.PROGRAM_ERROR.value

0 comments on commit 74086d2

Please sign in to comment.