Run the nbd_scenario tests under valgrind
This commit is contained in:
@@ -4,7 +4,7 @@ require 'socket'
|
|||||||
#
|
#
|
||||||
class FlexNBD
|
class FlexNBD
|
||||||
attr_reader :bin, :ctrl, :pid, :ip, :port
|
attr_reader :bin, :ctrl, :pid, :ip, :port
|
||||||
|
|
||||||
def initialize(bin, ip, port)
|
def initialize(bin, ip, port)
|
||||||
@bin = bin
|
@bin = bin
|
||||||
raise "#{bin} not executable" unless File.executable?(bin)
|
raise "#{bin} not executable" unless File.executable?(bin)
|
||||||
@@ -12,60 +12,63 @@ class FlexNBD
|
|||||||
@ip = ip
|
@ip = ip
|
||||||
@port = port
|
@port = port
|
||||||
end
|
end
|
||||||
|
|
||||||
def serve(ip, port, file, *acl)
|
def serve(ip, port, file, *acl)
|
||||||
File.unlink(ctrl) if File.exists?(ctrl)
|
File.unlink(ctrl) if File.exists?(ctrl)
|
||||||
@pid = fork do
|
@pid = fork do
|
||||||
cmd ="#{@bin} serve "\
|
cmd ="valgrind #{@bin} serve "\
|
||||||
"--addr #{ip} "\
|
"--addr #{ip} "\
|
||||||
"--port #{port} "\
|
"--port #{port} "\
|
||||||
"--file #{file} "\
|
"--file #{file} "\
|
||||||
"--sock #{ctrl} "\
|
"--sock #{ctrl} "\
|
||||||
|
"--debug "\
|
||||||
"#{acl.join(' ')}"
|
"#{acl.join(' ')}"
|
||||||
exec(cmd)
|
exec(cmd)
|
||||||
end
|
end
|
||||||
sleep 0.1 until File.socket?(ctrl)
|
sleep 0.1 until File.socket?(ctrl)
|
||||||
end
|
end
|
||||||
|
|
||||||
def kill
|
def kill
|
||||||
Process.kill("INT", @pid)
|
Process.kill("INT", @pid)
|
||||||
Process.wait(@pid)
|
Process.wait(@pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read(offset, length)
|
def read(offset, length)
|
||||||
IO.popen("#{@bin} read "\
|
IO.popen("valgrind #{@bin} read "\
|
||||||
"--addr #{ip} "\
|
"--addr #{ip} "\
|
||||||
"--port #{port} "\
|
"--port #{port} "\
|
||||||
"--from #{offset} "\
|
"--from #{offset} "\
|
||||||
|
"--debug "\
|
||||||
"--size #{length}","r") do |fh|
|
"--size #{length}","r") do |fh|
|
||||||
return fh.read
|
return fh.read
|
||||||
end
|
end
|
||||||
raise "read failed" unless $?.success?
|
raise "read failed" unless $?.success?
|
||||||
end
|
end
|
||||||
|
|
||||||
def write(offset, data)
|
def write(offset, data)
|
||||||
IO.popen("#{@bin} write "\
|
IO.popen("valgrind #{@bin} write "\
|
||||||
"--addr #{ip} "\
|
"--addr #{ip} "\
|
||||||
"--port #{port} "\
|
"--port #{port} "\
|
||||||
"--from #{offset} "\
|
"--from #{offset} "\
|
||||||
|
"--debug "\
|
||||||
"--size #{data.length}","w") do |fh|
|
"--size #{data.length}","w") do |fh|
|
||||||
fh.write(data)
|
fh.write(data)
|
||||||
end
|
end
|
||||||
raise "write failed" unless $?.success?
|
raise "write failed" unless $?.success?
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def mirror(bandwidth=nil, action=nil)
|
def mirror(bandwidth=nil, action=nil)
|
||||||
control_command("mirror", ip, port, bandwidth, action)
|
control_command("mirror", ip, port, bandwidth, action)
|
||||||
end
|
end
|
||||||
|
|
||||||
def acl(*acl)
|
def acl(*acl)
|
||||||
control_command("acl", *acl)
|
control_command("acl", *acl)
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def control_command(*args)
|
def control_command(*args)
|
||||||
raise "Server not running" unless @pid
|
raise "Server not running" unless @pid
|
||||||
@@ -74,6 +77,6 @@ class FlexNBD
|
|||||||
u.write(args.join("\n") + "\n")
|
u.write(args.join("\n") + "\n")
|
||||||
code, message = u.readline.split(": ", 2)
|
code, message = u.readline.split(": ", 2)
|
||||||
return [code, message]
|
return [code, message]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user