Add a no-op debug() define for non-debug builds and make valgrind optional in nbd_scenarios

This commit is contained in:
Alex Young
2012-05-31 13:53:04 +01:00
parent 623a398767
commit 074efd9fa4
2 changed files with 12 additions and 6 deletions

View File

@@ -15,6 +15,9 @@ void* xmalloc(size_t size);
void set_debug(int value);
#ifdef DEBUG
void debug(const char*msg, ...);
#else
/* no-op */
# define debug( msg, ...)
#endif
#define CLIENT_ERROR(msg, ...) \

View File

@@ -7,6 +7,9 @@ class FlexNBD
def initialize(bin, ip, port)
@bin = bin
@debug = `#{@bin} serve --help` =~ /--debug/ ? "--debug" : ""
@valgrind = ENV['VALGRIND'] ? "valgrind " : ""
@bin = "#{@valgrind}#{@bin}"
raise "#{bin} not executable" unless File.executable?(bin)
@ctrl = "/tmp/.flexnbd.ctrl.#{Time.now.to_i}.#{rand}"
@ip = ip
@@ -16,12 +19,12 @@ class FlexNBD
def serve(ip, port, file, *acl)
File.unlink(ctrl) if File.exists?(ctrl)
@pid = fork do
cmd ="valgrind #{@bin} serve "\
cmd ="#{@bin} serve "\
"--addr #{ip} "\
"--port #{port} "\
"--file #{file} "\
"--sock #{ctrl} "\
"--debug "\
"#{@debug} "\
"#{acl.join(' ')}"
exec(cmd)
end
@@ -34,11 +37,11 @@ class FlexNBD
end
def read(offset, length)
IO.popen("valgrind #{@bin} read "\
IO.popen("#{@bin} read "\
"--addr #{ip} "\
"--port #{port} "\
"--from #{offset} "\
"--debug "\
"#{@debug} "\
"--size #{length}","r") do |fh|
return fh.read
end
@@ -46,11 +49,11 @@ class FlexNBD
end
def write(offset, data)
IO.popen("valgrind #{@bin} write "\
IO.popen("#{@bin} write "\
"--addr #{ip} "\
"--port #{port} "\
"--from #{offset} "\
"--debug "\
"#{@debug} "\
"--size #{data.length}","w") do |fh|
fh.write(data)
end