From 074efd9fa4bd67ac522a15be6fa8bae4af1e9d7e Mon Sep 17 00:00:00 2001 From: Alex Young Date: Thu, 31 May 2012 13:53:04 +0100 Subject: [PATCH] Add a no-op debug() define for non-debug builds and make valgrind optional in nbd_scenarios --- src/util.h | 3 +++ tests/flexnbd.rb | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/util.h b/src/util.h index 24a4994..a8e4e55 100644 --- a/src/util.h +++ b/src/util.h @@ -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, ...) \ diff --git a/tests/flexnbd.rb b/tests/flexnbd.rb index 5876f27..8ffb4b7 100644 --- a/tests/flexnbd.rb +++ b/tests/flexnbd.rb @@ -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