Class: Syskit::Test::Spec

Inherits:
Roby::Test::Spec
  • Object
show all
Includes:
Base
Defined in:
lib/syskit/test/spec.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#assert_has_no_new_sample, #assert_has_one_new_sample, #plug_connection_management, #plug_requirement_modifications, #stub_type, #unplug_connection_management, #unplug_requirement_modifications

Class Method Details

.subject_syskit_modelObject

Returns the syskit model under test



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/syskit/test/spec.rb', line 82

def self.subject_syskit_model
    if @subject_syskit_model
        return @subject_syskit_model
    end
    parent = superclass
    if parent.respond_to?(:subject_syskit_model)
        parent.subject_syskit_model
    else
        raise ArgumentError, "no subject syskit model found"
    end
end

.use_syskit_model(model) ⇒ Object

Override the task model that should by default in tests such as #is_configurable. This is used mainly in case the task model under test is abstract



70
71
72
# File 'lib/syskit/test/spec.rb', line 70

def self.use_syskit_model(model)
    @subject_syskit_model = model
end

Instance Method Details

#planObject



132
# File 'lib/syskit/test/spec.rb', line 132

def plan; Roby.plan end

#setupObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/syskit/test/spec.rb', line 34

def setup
    NetworkGeneration::Engine.on_error = :save
    unplug_requirement_modifications
    loader = OroGen::Loaders::Base.new(Roby.app.default_loader)
    Syskit.conf.register_process_server(
        'stubs', Orocos::RubyTasks::ProcessManager.new(loader, task_context_class: Orocos::RubyTasks::StubTaskContext), "", host_id: 'syskit')
    super
    Syskit.conf.logs.disable_conf_logging
    Syskit.conf.logs.disable_port_logging
end

#subject_syskit_modelObject

Returns the syskit model under test

It is delegated to self.class.subject_syskit_model by default



77
78
79
# File 'lib/syskit/test/spec.rb', line 77

def subject_syskit_model
    self.class.subject_syskit_model
end

#syskit_stub_attached_device_model(bus_m, dev_name = 'dev') ⇒ Syskit::Component

Create a stub device task attached to a given communication bus

This is meant to be used to test the integration of specific com busses. The driver task from the communication bus is expected to exist, while the driver task for the device is stubbed as well.

The bus is called 'bus'

Parameters:

  • dev_name (String) (defaults to: 'dev')

    the name of the created device

Returns:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/syskit/test/spec.rb', line 116

def syskit_stub_attached_device_model(bus_m, dev_name = 'dev')
    robot = Syskit::Robot::RobotDefinition.new
    dev_m = Syskit::Device.new_submodel(name: "StubDevice")
    driver_m = Syskit::TaskContext.new_submodel(name: "StubDriver") do
        input_port 'bus_in', bus_m.message_type
        output_port 'bus_out', bus_m.message_type
        provides bus_m.client_srv, :as => 'can'
        driver_for dev_m, :as => 'dev'
    end
    stub_syskit_deployment_model(driver_m, 'driver_task')
    bus = robot.com_bus bus_m, :as => 'bus'
    stub_syskit_deployment_model(bus.driver_model, 'bus_task')
    robot.device(dev_m, :as => dev_name).
        attach_to(bus)
end

#syskit_stub_driver_model(dev_m, options = Hash.new) ⇒ Syskit::Component

Create a stub driver model

Parameters:

  • dev_name (String)

    the name of the created device

Returns:



98
99
100
101
102
103
104
# File 'lib/syskit/test/spec.rb', line 98

def syskit_stub_driver_model(dev_m, options = Hash.new)
    robot = Syskit::Robot::RobotDefinition.new
    device = robot.device(dev_m, options)
    task_srv = device.driver_model
    stub_syskit_deployment_model(task_srv.component_model, device.name)
    task_srv.component_model.with_arguments("#{task_srv.name}_dev" => device)
end

#teardownObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/syskit/test/spec.rb', line 45

def teardown
    if !passed? && app.public_logs?
        dataflow, hierarchy = __full_name__ + "-partial-dataflow.svg", __full_name__ + "-partial-hierarchy.svg"
        dataflow, hierarchy = [dataflow, hierarchy].map do |filename|
            filename.gsub("/", "_")
        end
        Graphviz.new(plan).to_file('dataflow', 'svg', File.join(app.log_dir, dataflow))
        Graphviz.new(plan).to_file('hierarchy', 'svg', File.join(app.log_dir, hierarchy))
    end

    super

ensure
    Syskit.conf.remove_process_server('stubs')
end

#teardown_registered_plansObject



61
62
63
64
65
# File 'lib/syskit/test/spec.rb', line 61

def teardown_registered_plans
    super
    Syskit::RequiredDataFlow.clear
    Syskit::ActualDataFlow.clear
end