From 78bd5b3819e45697a4d5104cb0513bbf4cddee39 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 22 Sep 2016 09:14:31 +1000 Subject: [PATCH 1/3] {common,bulkinsert}.lua missing from Makefile Also change the defination so that these get installed to the pkgdatadir which will help packagers. Signed-off-by: Daniel Black --- sysbench/tests/db/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysbench/tests/db/Makefile.am b/sysbench/tests/db/Makefile.am index e7647ac..3d6a7e4 100644 --- a/sysbench/tests/db/Makefile.am +++ b/sysbench/tests/db/Makefile.am @@ -15,7 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -EXTRA_DIST = delete.lua insert.lua oltp.lua \ +dist_pkgdata_DATA = common.lua delete.lua insert.lua bulk_insert.lua \ + oltp.lua \ oltp_simple.lua \ parallel_prepare.lua \ select_random_points.lua \ From 16ba86827fca12e27e2bf535e13d82e7ff36d636 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 22 Sep 2016 09:15:55 +1000 Subject: [PATCH 2/3] Load script from pkgdatadir if not local If the --test=XXX{.lua} script isn't local, load it from the pkgdatadir where some inbuilt scripts are installed. Autoappend the .lua extension if this wasn't done alrady. Here we set the LUA_PATH so that further lua 'require' directives also pull the source from the pkgdatadir. Signed-off-by: Daniel Black --- sysbench/scripting/Makefile.am | 2 +- sysbench/scripting/script_lua.c | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/sysbench/scripting/Makefile.am b/sysbench/scripting/Makefile.am index d8f1868..331e2d8 100644 --- a/sysbench/scripting/Makefile.am +++ b/sysbench/scripting/Makefile.am @@ -18,7 +18,7 @@ if USE_LUA SUBDIRS = lua . lua_sources = script_lua.c script_lua.h -AM_CPPFLAGS += -I$(srcdir)/lua/src +AM_CPPFLAGS += -I$(srcdir)/lua/src -DDATA_PATH=\"$(pkgdatadir)\" endif noinst_LIBRARIES = libsbscript.a diff --git a/sysbench/scripting/script_lua.c b/sysbench/scripting/script_lua.c index f14c33e..108dd3b 100644 --- a/sysbench/scripting/script_lua.c +++ b/sysbench/scripting/script_lua.c @@ -29,6 +29,8 @@ #include "db_driver.h" +#include + #define EVENT_FUNC "event" #define PREPARE_FUNC "prepare" #define CLEANUP_FUNC "cleanup" @@ -169,6 +171,8 @@ int script_load_lua(const char *testname, sb_test_t *test) { unsigned int i; + setenv("LUA_PATH", DATA_PATH LUA_DIRSEP "?.lua", 0); + /* Initialize global interpreter state */ gstate = sb_lua_new_state(testname, -1); if (gstate == NULL) @@ -488,8 +492,27 @@ lua_State *sb_lua_new_state(const char *scriptname, int thread_id) luaL_newmetatable(state, "sysbench.stmt"); luaL_newmetatable(state, "sysbench.rs"); - - if (luaL_loadfile(state, scriptname) || lua_pcall(state, 0, 0, 0)) + + if (luaL_loadfile(state, scriptname)) + { + /* first location failed - look in DATA_PATH */ + char p[PATH_MAX + 1]; + strncpy(p, DATA_PATH LUA_DIRSEP, sizeof(p)); + strncat(p, scriptname, sizeof(p)); + if (!strrchr(scriptname, '.')) + { + /* add .lua extension if there isn't one */ + strncat(p, ".lua", sizeof(p)); + } + + if (luaL_loadfile(state, p)) + { + lua_error(state); + return NULL; + } + } + + if (lua_pcall(state, 0, 0, 0)) { lua_error(state); return NULL; From 0fefcfbc9bb4b96bb6a5186692fb9f020d7b3b9f Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 22 Sep 2016 09:19:05 +1000 Subject: [PATCH 3/3] Change lua scripts to 'require common' if a testdir wasn't passed This completes what is needed to cause these scripts to pull in common from the LUA_PATH. Signed-off-by: Daniel Black --- sysbench/tests/db/delete.lua | 8 ++++++-- sysbench/tests/db/insert.lua | 8 ++++++-- sysbench/tests/db/oltp.lua | 8 ++++++-- sysbench/tests/db/oltp_simple.lua | 8 ++++++-- sysbench/tests/db/parallel_prepare.lua | 8 ++++++-- sysbench/tests/db/select.lua | 8 ++++++-- sysbench/tests/db/update_index.lua | 8 ++++++-- sysbench/tests/db/update_non_index.lua | 8 ++++++-- 8 files changed, 48 insertions(+), 16 deletions(-) diff --git a/sysbench/tests/db/delete.lua b/sysbench/tests/db/delete.lua index b4e4dc7..85c9c94 100644 --- a/sysbench/tests/db/delete.lua +++ b/sysbench/tests/db/delete.lua @@ -1,6 +1,10 @@ -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars() diff --git a/sysbench/tests/db/insert.lua b/sysbench/tests/db/insert.lua index d206609..60e9567 100644 --- a/sysbench/tests/db/insert.lua +++ b/sysbench/tests/db/insert.lua @@ -1,6 +1,10 @@ -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars() diff --git a/sysbench/tests/db/oltp.lua b/sysbench/tests/db/oltp.lua index 4b7de99..0cdbe08 100644 --- a/sysbench/tests/db/oltp.lua +++ b/sysbench/tests/db/oltp.lua @@ -1,6 +1,10 @@ -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars() diff --git a/sysbench/tests/db/oltp_simple.lua b/sysbench/tests/db/oltp_simple.lua index 13da9b1..c55cc57 100644 --- a/sysbench/tests/db/oltp_simple.lua +++ b/sysbench/tests/db/oltp_simple.lua @@ -1,6 +1,10 @@ -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars() diff --git a/sysbench/tests/db/parallel_prepare.lua b/sysbench/tests/db/parallel_prepare.lua index f956eb7..d001310 100644 --- a/sysbench/tests/db/parallel_prepare.lua +++ b/sysbench/tests/db/parallel_prepare.lua @@ -1,8 +1,12 @@ -- for proper initialization use --max-requests = N, where N is --num-threads -- -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars() diff --git a/sysbench/tests/db/select.lua b/sysbench/tests/db/select.lua index a43f7b7..b2a75f6 100644 --- a/sysbench/tests/db/select.lua +++ b/sysbench/tests/db/select.lua @@ -1,6 +1,10 @@ -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars() diff --git a/sysbench/tests/db/update_index.lua b/sysbench/tests/db/update_index.lua index e74027f..077240c 100644 --- a/sysbench/tests/db/update_index.lua +++ b/sysbench/tests/db/update_index.lua @@ -1,6 +1,10 @@ -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars() diff --git a/sysbench/tests/db/update_non_index.lua b/sysbench/tests/db/update_non_index.lua index bb17dad..1a6a502 100644 --- a/sysbench/tests/db/update_non_index.lua +++ b/sysbench/tests/db/update_non_index.lua @@ -1,6 +1,10 @@ -pathtest = string.match(test, "(.*/)") or "" +pathtest = string.match(test, "(.*/)") -dofile(pathtest .. "common.lua") +if pathtest then + dofile(pathtest .. "common.lua") +else + require("common") +end function thread_init(thread_id) set_vars()