class Roby::App::AutotestConsoleReporter
Reporter class for the Roby
autotest, that outputs on an IO
object
Attributes
@return [#puts] the IO
on which reporting should be done
@return [Autorespawn::Manager] the autorespawn slave manager
@return [Hash<Integer,Autorespawn::Slave>] mapping from
a process ID to the slave object
@return [App::TestServer] the test server
@return [Hash<Autorespawn::Slave,Integer>] mapping from
a slave to the unique ID associated with it
Public Class Methods
# File lib/roby/app/autotest_console_reporter.rb, line 90 def initialize(server, manager, io: STDOUT) @io = io @slave_id = 0 @slave_to_id = Hash.new @pid_to_slave = Hash.new manager.on_slave_new do |slave| slave_id = register_slave(slave) io.puts "[##{slave_id}] new slave #{slave_to_s(slave)}" end manager.on_slave_start do |slave| slave_id = register_slave_pid(slave) io.puts "[##{slave_id}] slave #{slave_to_s(slave)} started (PID=#{slave.pid})" end manager.on_slave_finished do |slave| slave, slave_id = deregister_slave_pid(slave.pid) io.puts "[##{slave_id}] slave #{slave_to_s(slave)} finished (PID=#{slave.pid})" end server.on_exception do |pid, exception| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} reports exception" Roby.display_exception(io, exception) end server.on_discovery_start do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} started discovery" end server.on_discovery_finished do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} finished discovery" end server.on_test_start do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} started testing" end server.on_test_result do |pid, file, test_case_name, test_name, failures, assertions, time| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{test_case_name}##{test_name}: #{failures.size} failures and #{assertions.size} assertions (#{time})" failures.each do |e| Roby.display_exception(io, e) end end server.on_test_finished do |pid| slave, slave_id = slave_from_pid(pid) io.puts "[##{slave_id}] #{slave_to_s(slave)} finished testing" end end
Public Instance Methods
@api private
Deregisters a slave-to-PID mapping
@return [(Autorespawn::Slave,Integer)] the slave object and unique
slave ID that were associated with the slave
@raise [ArgumentError] if there is no slave associated with the
PID
# File lib/roby/app/autotest_console_reporter.rb, line 82 def deregister_slave_pid(pid) if slave = pid_to_slave.delete(pid) return slave, slave_to_id[slave] else raise ArgumentError, "no slave known for #{pid}" end end
@api private
Register a new slave
@return [Integer] the unique slave ID
# File lib/roby/app/autotest_console_reporter.rb, line 34 def register_slave(slave) if slave_to_id[slave] raise ArgumentError, "#{slave} is already registered" end slave_to_id[slave] = (@slave_id += 1) end
@api private
Register a new slave-to-PID mapping
@param [Autorespawn::Slave] slave a slave whose pid is valid @return [Integer] the slave's unique slave ID @raise [ArgumentError] if the slave has not been registered with
{#register_slave} first
# File lib/roby/app/autotest_console_reporter.rb, line 49 def register_slave_pid(slave) if slave_id = slave_to_id[slave] pid_to_slave[slave.pid] = slave return slave_id else raise ArgumentError, "#{slave} has not been registered with #register_slave" end end
@api private
Returns a slave from its PID
@param [Integer] pid the PID @return [(Autorespawn::Slave,Integer)] the slave and its unique
slave ID
@raise [ArgumentError] if no slave is registered for this PID
# File lib/roby/app/autotest_console_reporter.rb, line 66 def slave_from_pid(pid) if slave = pid_to_slave[pid] return slave, slave_to_id[slave] else raise ArgumentError, "no slave registered for PID #{pid}" end end
@api private
Converts a slave object to the string displayed to the user
# File lib/roby/app/autotest_console_reporter.rb, line 25 def slave_to_s(slave) slave.name.sort_by(&:first).map { |k, v| "#{k}: #{v}" } end