Module: Orocos::SelfTest

Includes:
FlexMock::ArgumentTypes, FlexMock::MockContainer, Test::Mocks, Test::RubyTasks
Included in:
Minitest::Test
Defined in:
lib/orocos/test.rb

Constant Summary collapse

TEST_MODES =

A set of “modes” that can be used to control how the tests will be performed

(ENV['OROCOS_TEST_MODES'] || "").split(',')
TEST_MODEL_LESS =

Test without models

TEST_MODES.include?('no_model')
TEST_MISSING_MODELS =

Test with models that cannot be loaded

TEST_MODES.include?('missing_model')
USE_MQUEUE =

Whether we should enable MQ support during tests

Orocos::Rake::USE_MQUEUE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Test::RubyTasks

#new_ruby_task_context

Methods included from Test::Mocks

#mock_input_port, #mock_output_port, #mock_task_context, #mock_task_context_model

Instance Attribute Details

#processesObject (readonly)

Returns the value of attribute processes


136
137
138
# File 'lib/orocos/test.rb', line 136

def processes
  @processes
end

Instance Method Details

#assert_state_equals(state, task, timeout = 1) ⇒ Object


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/orocos/test.rb', line 171

def assert_state_equals(state, task, timeout = 1)
    expected_toplevel = task.toplevel_state(state)
    toplevel = task.rtt_state
    if expected_toplevel != toplevel
        flunk("#{task} was expected to be in toplevel state #{expected_toplevel} because of #{state} but is in #{toplevel}")
    end

    Integer(timeout / 0.01).times do
        if task.state == state
            return
        end
        sleep 0.01
    end
    flunk("#{task} was expected to be in state #{state} but is in #{task.state}")
end

#data_dirObject


70
# File 'lib/orocos/test.rb', line 70

def data_dir; File.join(@test_dir, 'data') end

#get(name) ⇒ Object


142
143
144
# File 'lib/orocos/test.rb', line 142

def get(name)
    Orocos.get name
end

#ior(name) ⇒ Object

helper for generating an ior from a name


196
197
198
199
200
# File 'lib/orocos/test.rb', line 196

def ior(name)
    name_service.ior(name)
rescue Orocos::NotFound
    "IOR:010000001f00000049444c3a5254542f636f7262612f435461736b436f6e746578743a312e300000010000000000000064000000010102000d00000031302e3235302e332e31363000002bc80e000000fe8a95a65000004d25000000000000000200000000000000080000000100000000545441010000001c00000001000000010001000100000001000105090101000100000009010100"
end

#name_serviceObject


191
192
193
# File 'lib/orocos/test.rb', line 191

def name_service
    Orocos.name_service
end

#read_one_sample(reader, timeout = 1) ⇒ Object


160
161
162
163
164
165
166
167
168
169
# File 'lib/orocos/test.rb', line 160

def read_one_sample(reader, timeout = 1)
    Integer(timeout / 0.01).times do
        if value = reader.read_new
            return value
        end
        sleep 0.01

    end
    flunk("expected to receive one new sample on #{reader}, but got none (state: #{reader.port.task.rtt_state}")
end

#setupObject


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/orocos/test.rb', line 72

def setup
    @old_pkg_config_path = ENV['PKG_CONFIG_PATH'].dup
    @__warn_for_missing_default_loggers = Orocos.warn_for_missing_default_loggers?
    Orocos.warn_for_missing_default_loggers = false
    Orocos::MQueue.auto = USE_MQUEUE

    @test_dir = File.expand_path(File.join("..", "..", 'test'), File.dirname(__FILE__))

    # Since we are loading typekits over and over again, we need to
    # disable type export
    Orocos.export_types = false
    if File.directory?(work_dir)
        Orocos.default_working_directory = work_dir
        ENV['PKG_CONFIG_PATH'] += ":#{File.join(work_dir, "prefix", 'lib', 'pkgconfig')}"
        Orocos.default_pkgconfig_loader.update
    end

    if defined?(Orocos::Async)
        Orocos::Async::NameServiceBase.default_period = 0
        Orocos::Async::TaskContextBase.default_period = 0
        Orocos::Async::CORBA::Attribute.default_period = 0
        Orocos::Async::CORBA::Property.default_period = 0
        Orocos::Async::CORBA::OutputReader.default_period = 0
    end

    @processes = Array.new

    Orocos.initialize
    @__orocos_corba_timeouts = [Orocos::CORBA.call_timeout, Orocos::CORBA.connect_timeout]
    Orocos::CORBA.call_timeout = 10000
    Orocos::CORBA.connect_timeout = 10000

	    if TEST_MODEL_LESS
		flexmock(Orocos::TaskContext).new_instances(:get_from_ior).should_receive('model').and_return(nil)
		flexmock(Orocos::TaskContext).new_instances(:do_get).should_receive('model').and_return(nil)
	    elsif TEST_MISSING_MODELS
		flexmock(Orocos).should_receive(:task_model_from_name).and_raise(Orocos::NotFound)
	    end
    super
end

#spawn_and_get(component, task = component) ⇒ Object


146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/orocos/test.rb', line 146

def spawn_and_get(component, task = component)
    begin
        process = Orocos::Process.new component
        process.spawn
        process.wait_running(0.5)
    rescue Exception
        process.kill if process
        raise
    end

    processes << process
    Orocos::TaskContext.get "#{component}.#{task}"
end

#start(*spec) ⇒ Object


138
139
140
# File 'lib/orocos/test.rb', line 138

def start(*spec)
    processes.concat Orocos.run(*spec)
end

#teardownObject


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/orocos/test.rb', line 113

def teardown
    if defined? FlexMock
        flexmock_teardown
    end
    processes.each do |p|
        begin p.kill
        rescue Exception => e
            Orocos.warn "failed, in teardown, to stop process #{p}: #{e}"
        end
    end
    processes.clear
    super
    if @__orocos_corba_timeouts # can be nil if setup failed
        Orocos::CORBA.call_timeout, Orocos::CORBA.connect_timeout = *@__orocos_corba_timeouts
    end
    if @old_pkg_config_path # can be nil if setup failed
        ENV['PKG_CONFIG_PATH'] = @old_pkg_config_path
    end
    Orocos::CORBA.instance_variable_set :@loaded_typekits, []
    Orocos.clear
    Orocos.warn_for_missing_default_loggers = @__warn_for_missing_default_loggers
end

#wait_for(timeout = 5, &block) ⇒ Object


187
188
189
# File 'lib/orocos/test.rb', line 187

def wait_for(timeout = 5, &block)
    Orocos::Async.wait_for(0.005, timeout, &block)
end

#work_dirObject


69
# File 'lib/orocos/test.rb', line 69

def work_dir; File.join(@test_dir, 'working_copy') end