Class: Roby::App::AutotestConsoleReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/app/autotest_console_reporter.rb

Overview

Reporter class for the Roby autotest, that outputs on an IO object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, manager, io: STDOUT) ⇒ AutotestConsoleReporter

Returns a new instance of AutotestConsoleReporter.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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

Instance Attribute Details

#io#puts (readonly)

Returns the IO on which reporting should be done.

Returns:

  • (#puts)

    the IO on which reporting should be done



6
7
8
# File 'lib/roby/app/autotest_console_reporter.rb', line 6

def io
  @io
end

#managerAutorespawn::Manager (readonly)

Returns the autorespawn slave manager.

Returns:

  • (Autorespawn::Manager)

    the autorespawn slave manager



12
13
14
# File 'lib/roby/app/autotest_console_reporter.rb', line 12

def manager
  @manager
end

#pid_to_slaveHash<Integer,Autorespawn::Slave> (readonly)

Returns mapping from a process ID to the slave object.

Returns:

  • (Hash<Integer,Autorespawn::Slave>)

    mapping from a process ID to the slave object



20
21
22
# File 'lib/roby/app/autotest_console_reporter.rb', line 20

def pid_to_slave
  @pid_to_slave
end

#serverApp::TestServer (readonly)

Returns the test server.

Returns:



9
10
11
# File 'lib/roby/app/autotest_console_reporter.rb', line 9

def server
  @server
end

#slave_to_idHash<Autorespawn::Slave,Integer> (readonly)

Returns mapping from a slave to the unique ID associated with it.

Returns:

  • (Hash<Autorespawn::Slave,Integer>)

    mapping from a slave to the unique ID associated with it



16
17
18
# File 'lib/roby/app/autotest_console_reporter.rb', line 16

def slave_to_id
  @slave_to_id
end

Instance Method Details

#deregister_slave_pid(pid) ⇒ (Autorespawn::Slave,Integer)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deregisters a slave-to-PID mapping

Returns:

  • ((Autorespawn::Slave,Integer))

    the slave object and unique slave ID that were associated with the slave

Raises:

  • (ArgumentError)

    if there is no slave associated with the PID



82
83
84
85
86
87
88
# 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

#register_slave(slave) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register a new slave

Returns:

  • (Integer)

    the unique slave ID



34
35
36
37
38
39
# 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

#register_slave_pid(slave) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register a new slave-to-PID mapping

Parameters:

  • slave (Autorespawn::Slave)

    a slave whose #pid is valid

Returns:

  • (Integer)

    the slave’s unique slave ID

Raises:

  • (ArgumentError)

    if the slave has not been registered with #register_slave first



49
50
51
52
53
54
55
56
# 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

#slave_from_pid(pid) ⇒ (Autorespawn::Slave,Integer)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a slave from its PID

Parameters:

  • pid (Integer)

    the PID

Returns:

  • ((Autorespawn::Slave,Integer))

    the slave and its unique slave ID

Raises:

  • (ArgumentError)

    if no slave is registered for this PID



66
67
68
69
70
71
72
# 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

#slave_to_s(slave) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a slave object to the string displayed to the user



25
26
27
# 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