Skip to content

Commit

Permalink
Merge pull request concurrencykit#68 from grooverdan/0.5_pkg_luapkgda…
Browse files Browse the repository at this point in the history
…tadir for lua files
  • Loading branch information
akopytov authored Sep 22, 2016
2 parents ee7082c + 0fefcfb commit 5df6f74
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 20 deletions.
2 changes: 1 addition & 1 deletion sysbench/scripting/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions sysbench/scripting/script_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include "db_driver.h"

#include <stdlib.h>

#define EVENT_FUNC "event"
#define PREPARE_FUNC "prepare"
#define CLEANUP_FUNC "cleanup"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion sysbench/tests/db/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/delete.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/insert.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/oltp.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/oltp_simple.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/parallel_prepare.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/select.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/update_index.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 6 additions & 2 deletions sysbench/tests/db/update_non_index.lua
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 5df6f74

Please sign in to comment.