-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run.lua
62 lines (56 loc) · 2.01 KB
/
test_run.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local function abort(name)
return function(inspector)
print('test_run failed: unknown method ' .. name)
os.exit(-1)
end
end
local function get_cfg(inspector, cfg_name)
if cfg_name == 'engine' then
return 'memtx'
else
print('test_run:get_cfg failed: unknown option ' .. cfg_name)
os.exit(-1)
end
end
local function cmd(inspector, command)
if command == 'restart server default' then
local has_xdotool = os.execute('xdotool --version > /dev/null 2>&1') == 0
local fio = require('fio')
local ffi = require('ffi')
ffi.cdef('int open(const char *name, int flags, int mode);')
ffi.cdef('int close(int fd);')
ffi.cdef('ssize_t read(int fd, void *buf, size_t count);')
local buf = ffi.new('char[16384]')
local file = ffi.C.open("/proc/self/status", 0, 0)
local text_size = ffi.C.read(file, buf, 16384)
ffi.C.close(file)
local text = ffi.string(buf, text_size)
local tracer_pid = string.match(text, "TracerPid:[ \t]*([0-9]+)[^0-9]")
local is_gdb = tracer_pid and tracer_pid ~= '' and tracer_pid ~= '0'
local bin = arg[-1]
local args = "'" .. arg[0] .. "' '" .. arg[1] .. "' " .. tostring(reprun_current_line_no)
local cmd = ''
if is_gdb then
--cmd = "gdb '" .. bin .. "' -ex 'run " .. args .. "'"
cmd = "run " .. args
else
cmd = bin .. ' ' .. args
end
if has_xdotool then
local ex = "xdotool type --args 1 \"" .. cmd .. "\" key KP_Enter"
os.execute(ex)
else
print('xdotool was not found! run the following by your own:')
print(cmd)
end
os.exit(0)
else
print('test_run:cmd failed: unknown command ' .. command)
os.exit(-1)
end
end
local function new()
local res = {get_cfg = get_cfg, cmd = cmd}
return setmetatable(res, {__index=function(t,name) return abort(name) end})
end
return {new = new}