Allow benchmarks to be specified as a module name, i.e. a require() argument.
This commit is contained in:
29
src/sb_lua.c
29
src/sb_lua.c
@ -766,22 +766,35 @@ static lua_State *sb_lua_new_state(void)
|
||||
if (load_internal_scripts(L))
|
||||
return NULL;
|
||||
|
||||
if (luaL_loadfile(L, sbtest.lname))
|
||||
{
|
||||
lua_error(L);
|
||||
return NULL;
|
||||
}
|
||||
int rc;
|
||||
|
||||
if (lua_pcall(L, 0, 0, 0))
|
||||
if ((rc = luaL_loadfile(L, sbtest.lname)) != 0)
|
||||
{
|
||||
lua_error(L);
|
||||
return NULL;
|
||||
if (rc != LUA_ERRFILE)
|
||||
goto loaderr;
|
||||
|
||||
/* Try to handle the given string as a module name */
|
||||
lua_getglobal(L, "require");
|
||||
lua_pushstring(L, sbtest.lname);
|
||||
if (lua_pcall(L, 1, 0, 0))
|
||||
{
|
||||
log_text(LOG_FATAL, "Cannot find benchmark '%s': no such built-in test, "
|
||||
"file or module", sbtest.lname);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (lua_pcall(L, 0, 0, 0))
|
||||
goto loaderr;
|
||||
|
||||
/* Create new L context */
|
||||
tls_lua_ctxt.L = L;
|
||||
|
||||
return L;
|
||||
|
||||
loaderr:
|
||||
lua_error(L);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Close interpreter state */
|
||||
|
||||
@ -1468,19 +1468,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (test == NULL)
|
||||
{
|
||||
/* Is it a path? */
|
||||
if (access(sb_globals.testname, R_OK))
|
||||
{
|
||||
fprintf(stderr, "Cannot find script %s: %s\n", sb_globals.testname,
|
||||
strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if ((test = sb_load_lua(sb_globals.testname)) == NULL)
|
||||
{
|
||||
fprintf(stderr, "Script execution failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (sb_globals.cmdname == NULL)
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
$ sysbench cleanup
|
||||
sysbench * (glob)
|
||||
|
||||
Cannot find script cleanup: No such file or directory
|
||||
FATAL: Cannot find benchmark 'cleanup': no such built-in test, file or module
|
||||
[1]
|
||||
|
||||
$ cat >cmd_cleanup.lua <<EOF
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
$ sysbench help
|
||||
sysbench * (glob)
|
||||
|
||||
Cannot find script help: No such file or directory
|
||||
FATAL: Cannot find benchmark 'help': no such built-in test, file or module
|
||||
[1]
|
||||
|
||||
$ cat >cmd_help.lua <<EOF
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
$ sysbench prepare
|
||||
sysbench * (glob)
|
||||
|
||||
Cannot find script prepare: No such file or directory
|
||||
FATAL: Cannot find benchmark 'prepare': no such built-in test, file or module
|
||||
[1]
|
||||
|
||||
$ cat >cmd_prepare.lua <<EOF
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
$ sysbench run
|
||||
sysbench * (glob)
|
||||
|
||||
Cannot find script run: No such file or directory
|
||||
FATAL: Cannot find benchmark 'run': no such built-in test, file or module
|
||||
[1]
|
||||
|
||||
$ cat >cmd_run.lua <<EOF
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
$ sysbench foo bar
|
||||
sysbench * (glob)
|
||||
|
||||
Cannot find script foo: No such file or directory
|
||||
FATAL: Cannot find benchmark 'foo': no such built-in test, file or module
|
||||
[1]
|
||||
|
||||
$ sysbench foo bar baz
|
||||
@ -41,7 +41,7 @@
|
||||
> EOF
|
||||
sysbench * (glob)
|
||||
|
||||
Cannot find script run: No such file or directory
|
||||
FATAL: Cannot find benchmark 'run': no such built-in test, file or module
|
||||
[1]
|
||||
|
||||
$ cat >$CRAMTMP/cmdline.lua <<EOF
|
||||
@ -211,7 +211,6 @@ Command line options tests
|
||||
sysbench * (glob)
|
||||
|
||||
FATAL: `sysbench.cmdline.read_cmdline_options' function failed: [string "sysbench.cmdline.lua"]:*: wrong table structure in sysbench.cmdline.options (glob)
|
||||
Script execution failed (no-eol)
|
||||
[1]
|
||||
|
||||
$ sysbench fileio --invalid-option prepare
|
||||
@ -334,3 +333,20 @@ Command line options tests
|
||||
sysbench * (glob)
|
||||
|
||||
global
|
||||
|
||||
# Test benchmark specification as a module
|
||||
|
||||
$ cat > cmdline_module.lua <<EOF
|
||||
> print("cmdline_module loaded")
|
||||
> function event()
|
||||
> print("cmdline_module event")
|
||||
> end
|
||||
> EOF
|
||||
|
||||
$ LUA_PATH="$PWD/?.lua;$LUA_PATH" sysbench cmdline_module --verbosity=0
|
||||
cmdline_module loaded
|
||||
|
||||
$ LUA_PATH="$PWD/?.lua;$LUA_PATH" sysbench cmdline_module --events=1 --verbosity=0 run
|
||||
cmdline_module loaded
|
||||
cmdline_module loaded
|
||||
cmdline_module event
|
||||
|
||||
Reference in New Issue
Block a user