fix the ret value by which we can stop benchmark in event
This commit is contained in:
committed by
Alexey Kopytov
parent
2cdb3adaa8
commit
b7dd7e0781
@ -26,13 +26,12 @@ bool sb_more_events(int thread_id);
|
||||
-- Main event loop. This is a Lua version of sysbench.c:thread_run()
|
||||
-- ----------------------------------------------------------------------
|
||||
function thread_run(thread_id)
|
||||
local success, ret
|
||||
|
||||
while ffi.C.sb_more_events(thread_id) do
|
||||
ffi.C.sb_event_start(thread_id)
|
||||
|
||||
local success, ret
|
||||
repeat
|
||||
local success, ret = pcall(event, thread_id)
|
||||
success, ret = pcall(event, thread_id)
|
||||
|
||||
if not success then
|
||||
if type(ret) ~= "table" or
|
||||
@ -43,7 +42,7 @@ function thread_run(thread_id)
|
||||
end
|
||||
until success
|
||||
|
||||
-- Stop the benchmark if event() returns a non-nil value
|
||||
-- Stop the benchmark if event() returns a value other than nil or false
|
||||
if ret then
|
||||
break
|
||||
end
|
||||
|
||||
@ -101,3 +101,45 @@ Error handling
|
||||
$ sysbench $SB_ARGS run
|
||||
FATAL: cannot find the event() function in *api_basic.lua (glob)
|
||||
[1]
|
||||
|
||||
########################################################################
|
||||
event() return values
|
||||
########################################################################
|
||||
|
||||
$ cat >$CRAMTMP/api_basic.lua <<EOF
|
||||
> sysbench.cmdline.options = { param = {"param", 0} }
|
||||
> function event()
|
||||
> i = (i or 0) + 1
|
||||
> local param = sysbench.opt.param
|
||||
> print(i)
|
||||
> if param == 1 then
|
||||
> return 0
|
||||
> elseif param == 2 then
|
||||
> return 1
|
||||
> elseif param == 3 then
|
||||
> return true
|
||||
> elseif param == 4 then
|
||||
> return {}
|
||||
> elseif param == 5 then
|
||||
> return false
|
||||
> elseif param == 6 then
|
||||
> return nil
|
||||
> else
|
||||
> error("Unknown param value")
|
||||
> end
|
||||
> end
|
||||
> EOF
|
||||
$ sysbench $SB_ARGS run --param=1
|
||||
1
|
||||
$ sysbench $SB_ARGS run --param=2
|
||||
1
|
||||
$ sysbench $SB_ARGS run --param=3
|
||||
1
|
||||
$ sysbench $SB_ARGS run --param=4
|
||||
1
|
||||
$ sysbench $SB_ARGS run --param=5
|
||||
1
|
||||
2
|
||||
$ sysbench $SB_ARGS run --param=6
|
||||
1
|
||||
2
|
||||
|
||||
Reference in New Issue
Block a user