Rename sysbench.option_defs to sysbench.cmdline.options.

This commit is contained in:
Alexey Kopytov
2017-02-01 19:31:53 +03:00
parent b5b1878740
commit 9fdec9dccf
6 changed files with 31 additions and 28 deletions

View File

@ -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()

View File

@ -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 =

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -92,7 +92,7 @@ Command line options tests
########################################################################
$ cat >cmdline.lua <<EOF
> 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 <<EOF
> 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]