null+****@clear*****
null+****@clear*****
2012年 7月 8日 (日) 17:32:42 JST
Kouhei Sutou 2012-07-08 17:32:42 +0900 (Sun, 08 Jul 2012) New Revision: 9f8541d2b7a91fa41be78a93c796bfe39081499a https://github.com/groonga/grntest/commit/9f8541d2b7a91fa41be78a93c796bfe39081499a Log: Add --gdb option to run groonga on gdb Modified files: lib/groonga/tester.rb Modified: lib/groonga/tester.rb (+83 -22) =================================================================== --- lib/groonga/tester.rb 2012-06-14 13:06:03 +0900 (609fa54) +++ lib/groonga/tester.rb 2012-07-08 17:32:42 +0900 (77e2d08) @@ -95,6 +95,12 @@ module Groonga diff_option_is_specified = true end + parser.on("--gdb[=COMMAND]", + "Run groonga on gdb and use COMMAND as gdb", + "(#{tester.default_gdb})") do |command| + tester.gdb = command || tester.default_gdb + end + parser.on("--[no-]keep-database", "Keep used database for debug after test is finished", "(#{tester.keep_database?})") do |boolean| @@ -113,6 +119,7 @@ module Groonga attr_accessor :groonga, :groonga_httpd, :groonga_suggest_create_dataset, :protocol attr_accessor :base_directory, :diff, :diff_options + attr_accessor :gdb, :default_gdb attr_writer :keep_database def initialize @groonga = "groonga" @@ -121,6 +128,7 @@ module Groonga @protocol = :gqtp @base_directory = "." detect_suitable_diff + initialize_debuggers end def run(*targets) @@ -191,6 +199,11 @@ module Groonga end end + def initialize_debuggers + @gdb = nil + @default_gdb = "gdb" + end + def command_exist?(name) ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| absolute_path = File.join(path, name) @@ -289,39 +302,87 @@ module Groonga end def run_groonga_gqtp(context) + pid = nil + begin + open_pipe do |input_read, input_write, output_read, output_write| + groonga_input = input_write + groonga_output = output_read + + input_fd = input_read.to_i + output_fd = output_write.to_i + command_line = groonga_command_line + command_line += [ + "--input-fd", input_fd.to_s, + "--output-fd", output_fd.to_s, + "-n", context.db_path, + ] + env = {} + options = { + input_fd => input_fd, + output_fd => output_fd + } + pid = Process.spawn(env, *command_line, options) + executor = GQTPExecutor.new(groonga_input, groonga_output, context) + executor.ensure_groonga_ready + yield(executor) + end + ensure + Process.waitpid(pid) if pid + end + end + + def open_pipe read = 0 write = 1 - input_pipe = IO.pipe - output_pipe = IO.pipe - input_fd = input_pipe[read].to_i - output_fd = output_pipe[write].to_i - command_line = [ - @tester.groonga, - "--input-fd", input_fd.to_s, - "--output-fd", output_fd.to_s, - "-n", context.db_path, - ] - env = {} - options = { - input_fd => input_fd, - output_fd => output_fd - } - pid = Process.spawn(env, *command_line, options) begin - groonga_input = input_pipe[write] - groonga_output = output_pipe[read] - executor = GQTPExecutor.new(groonga_input, groonga_output, context) - executor.ensure_groonga_ready - yield(executor) + input_pipe = IO.pipe + output_pipe = IO.pipe + yield(input_pipe[read], input_pipe[write], + output_pipe[read], output_pipe[write]) ensure + input_pipe ||= [] + output_pipe ||= [] (input_pipe + output_pipe).each do |io| io.close unless io.closed? end - Process.waitpid(pid) end end + def groonga_command_line + command_line = [] + groonga =****@teste***** + if****@teste***** + if libtool_wrapper?(groonga) + command_line << find_libtool(groonga) + command_line << "--mode=execute" + end + command_line << @tester.gdb + command_line << "--args" + end + command_line << groonga + command_line + end + + def libtool_wrapper?(command) + return false unless File.exist?(command) + File.open(command, "r") do |command_file| + first_line = command_file.gets + first_line.start_with?("#!") + end + end + + def find_libtool(command) + command_path = Pathname.new(command) + directory = command_path.dirname + until directory.root? + libtool = directory + "libtool" + return libtool.to_s if libtool.executable? + directory = directory.parent + end + "libtool" + end + def run_groonga_http(context) host = "127.0.0.1" port = 50041 -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... Download