From 9fdec9dccff28505abd0a86cda77597ed5a20ca6 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Wed, 1 Feb 2017 19:31:53 +0300 Subject: [PATCH] Rename sysbench.option_defs to sysbench.cmdline.options. --- src/lua/internal/sysbench.cmdline.lua | 23 +++++++++++++---------- src/lua/oltp_common.lua | 2 +- src/lua/select_random_points.lua | 2 +- src/lua/select_random_ranges.lua | 4 ++-- src/sb_lua.c | 22 +++++++++++----------- tests/t/cmdline.t | 6 +++--- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/lua/internal/sysbench.cmdline.lua b/src/lua/internal/sysbench.cmdline.lua index d35f302..ac2244d 100644 --- a/src/lua/internal/sysbench.cmdline.lua +++ b/src/lua/internal/sysbench.cmdline.lua @@ -73,28 +73,30 @@ local arg_types = { } -- Parse command line options definitions, if present in the script as a --- 'sysbench.option_defs' table. If no such table exists, or if there a parsing --- error, return false. Return true on success. -function sysbench.cmdline.read_option_defs() - if sysbench.option_defs == nil then +-- 'sysbench.cmdline.options' table. If no such table exists, or if there a +-- parsing error, return false. Return true on success. After parsing the +-- command line arguments, option values are available as the sysbench.opt +-- table. +function sysbench.cmdline.read_cmdline_options() + if sysbench.cmdline.options == nil then return true end - local t = type(sysbench.option_defs) - assert(t == "table", "wrong type for sysbench.option_defs: " .. t) + local t = type(sysbench.cmdline.options) + assert(t == "table", "wrong type for sysbench.cmdline.options: " .. t) local i = 0 - for name, def in pairs(sysbench.option_defs) do + for name, def in pairs(sysbench.cmdline.options) do i = i+1 end local args = ffi.new('sb_arg_t[?]', i) i = 0 - for name, def in pairs(sysbench.option_defs) do + for name, def in pairs(sysbench.cmdline.options) do -- name assert(type(name) == "string" and type(def) == "table", - "wrong table structure in sysbench.option_defs") + "wrong table structure in sysbench.cmdline.options") args[i].name = name -- description @@ -171,7 +173,8 @@ void sb_print_test_options(void); ]] -- ---------------------------------------------------------------------- --- Print descriptions of command line options, if defined by option_defs +-- Print descriptions of command line options, if defined by +-- sysbench.cmdline.options -- ---------------------------------------------------------------------- function sysbench.cmdline.print_test_options() ffi.C.sb_print_test_options() diff --git a/src/lua/oltp_common.lua b/src/lua/oltp_common.lua index 9ecae8a..197525f 100644 --- a/src/lua/oltp_common.lua +++ b/src/lua/oltp_common.lua @@ -30,7 +30,7 @@ if sysbench.cmdline.command == nil then end -- Command line options -sysbench.option_defs = { +sysbench.cmdline.options = { table_size = {"Number of rows per table", 10000}, range_size = diff --git a/src/lua/select_random_points.lua b/src/lua/select_random_points.lua index 9f960f3..a16ce69 100755 --- a/src/lua/select_random_points.lua +++ b/src/lua/select_random_points.lua @@ -9,7 +9,7 @@ require("oltp_common") -- Add random_points to the list of standard OLTP options -sysbench.option_defs.random_points = +sysbench.cmdline.options.random_points = {"Number of random points in the IN() clause in generated SELECTs", 10} -- Override standard prepare/cleanup OLTP functions, as this benchmark does not diff --git a/src/lua/select_random_ranges.lua b/src/lua/select_random_ranges.lua index ac59aca..6c12add 100755 --- a/src/lua/select_random_ranges.lua +++ b/src/lua/select_random_ranges.lua @@ -9,9 +9,9 @@ require("oltp_common") -- Add --number-of-ranges and --delta to the list of standard OLTP options -sysbench.option_defs.number_of_ranges = +sysbench.cmdline.options.number_of_ranges = {"Number of random BETWEEN ranges per SELECT", 10} -sysbench.option_defs.delta = +sysbench.cmdline.options.delta = {"Size of BETWEEN ranges", 5} -- Override standard prepare/cleanup OLTP functions, as this benchmark does not diff --git a/src/sb_lua.c b/src/sb_lua.c index 5e1eddd..f35af30 100644 --- a/src/sb_lua.c +++ b/src/sb_lua.c @@ -177,7 +177,7 @@ static int sb_lua_db_free_results(lua_State *); static unsigned int sb_lua_table_size(lua_State *, int); -static int read_option_defs(lua_State *L); +static int read_cmdline_options(lua_State *L); static bool sb_lua_hook_defined(lua_State *, const char *); static bool sb_lua_hook_push(lua_State *, const char *); static void sb_lua_report_intermediate(sb_stat_t *); @@ -301,9 +301,9 @@ static int do_export_options(lua_State *L, bool global) } /* - Export options to the 'sysbench.opt' table. If the script does not declare - supported options with sysbench.option_defs also export to the global - namespace for compatibility with the legacy API. + Export option values to the 'sysbench.opt' table. If the script does not + declare supported options with sysbench.cmdline.options also export to the + global namespace for compatibility with the legacy API. */ static int export_options(lua_State *L) @@ -338,7 +338,7 @@ sb_test_t *sb_load_lua(const char *testname) if (gstate == NULL) goto error; - if (read_option_defs(gstate)) + if (read_cmdline_options(gstate)) goto error; /* Test commands */ @@ -640,20 +640,20 @@ int sb_lua_set_test_args(sb_arg_t *args, size_t len) /* Parse command line options definitions, if present in the script as a - 'sysbench.option_defs' table. If there was a parsing error, return 1. Return 0 - on success. + sysbench.cmdline.options table. If there was a parsing error, return 1. Return + 0 on success. */ -static int read_option_defs(lua_State *L) +static int read_cmdline_options(lua_State *L) { lua_getglobal(L, "sysbench"); lua_getfield(L, -1, "cmdline"); - lua_getfield(L, -1, "read_option_defs"); + lua_getfield(L, -1, "read_cmdline_options"); if (!lua_isfunction(L, -1)) { log_text(LOG_WARNING, - "Cannot find the sysbench.cmdline.read_option_defs() function"); + "Cannot find sysbench.cmdline.read_cmdline_options()"); lua_pop(L, 3); return 1; @@ -661,7 +661,7 @@ static int read_option_defs(lua_State *L) if (lua_pcall(L, 0, 1, 0) != 0) { - call_error(L, "sysbench.cmdline.read_option_defs"); + call_error(L, "sysbench.cmdline.read_cmdline_options"); lua_pop(L, 2); return 1; } diff --git a/tests/t/cmdline.t b/tests/t/cmdline.t index 8e173fd..4be5fe3 100644 --- a/tests/t/cmdline.t +++ b/tests/t/cmdline.t @@ -92,7 +92,7 @@ Command line options tests ######################################################################## $ cat >cmdline.lua < sysbench.option_defs = { + > sysbench.cmdline.options = { > str_opt1 = {"str_opt1 description"}, > str_opt2 = {"str_opt2 description", "opt2"}, > str_opt3 = {"str_opt3 description", "opt3", sysbench.cmdline.ARG_STRING}, @@ -200,7 +200,7 @@ Command line options tests [1] $ cat >cmdline.lua < sysbench.option_defs = { + > sysbench.cmdline.options = { > {}, > } > @@ -210,7 +210,7 @@ Command line options tests $ sysbench cmdline.lua help sysbench * (glob) - FATAL: `sysbench.cmdline.read_option_defs' function failed: [string "sysbench.cmdline.lua"]:*: wrong table structure in sysbench.option_defs (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]