From 2a3ca019cbb3a29d9c70c847dee4385c88c3032c Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Wed, 1 Feb 2017 10:56:05 +0300 Subject: [PATCH] if the test name on the command line is "-", read Lua script from the standard input. --- README.md | 5 +++-- src/sysbench.c | 4 +++- tests/t/cmdline.t | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5b36984..df355f5 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,9 @@ The general command line syntax for sysbench is: `memory`, `cpu`, etc.), or a name of one of the bundled Lua scripts (e.g. `oltp_read_only`), or a *path* to a custom Lua script. If no test name is specified on the command line (and thus, there is no - *command* too, as in that case it would be parsed as a *testname*), - then sysbench expects a Lua script to execute on its standard input. + *command* too, as in that case it would be parsed as a *testname*), or + the test name is a dash ("`-`"), then sysbench expects a Lua script to + execute on its standard input. - *command* is an optional argument that will be passed by sysbench to the built-in test or script specified with *testname*. *command* diff --git a/src/sysbench.c b/src/sysbench.c index 35cd9aa..c4b680a 100644 --- a/src/sysbench.c +++ b/src/sysbench.c @@ -1430,7 +1430,7 @@ int main(int argc, char *argv[]) print_header(); - if (sb_globals.testname != NULL) + if (sb_globals.testname != NULL && strcmp(sb_globals.testname, "-")) { /* Is it a built-in test name? */ test = find_test(sb_globals.testname); @@ -1468,6 +1468,8 @@ int main(int argc, char *argv[]) } else { + sb_globals.testname = NULL; + if (SB_ISATTY()) log_text(LOG_NOTICE, "Reading the script from the standard input:\n"); diff --git a/tests/t/cmdline.t b/tests/t/cmdline.t index 8f83112..5e675ab 100644 --- a/tests/t/cmdline.t +++ b/tests/t/cmdline.t @@ -85,7 +85,7 @@ Threads fairness: events (avg/stddev): 1.0000/0.00 - execution time (avg/stddev): 0.0000/0.00 + execution time (avg/stddev): *.*/0.00 (glob) ######################################################################## Command line options tests @@ -317,3 +317,20 @@ Command line options tests argv[3] = cmdline.lua argv[4] = prepare sysbench.cmdline.command = prepare + + $ sysbench - < print("hello") + > EOF + sysbench * (glob) + + hello + + $ sysbench - prepare < function prepare() + > print("prepare") + > end + > print("global") + > EOF + sysbench * (glob) + + global