Module: Orocos::SelfTest
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_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
#helpers_dir, #new_external_ruby_task_context, #new_ruby_task_context, #register_allocated_ruby_tasks
#mock_input_port, #mock_output_port, #mock_task_context, #mock_task_context_model
Instance Attribute Details
#processes ⇒ Object
Returns the value of attribute processes
135
136
137
|
# File 'lib/orocos/test.rb', line 135
def processes
@processes
end
|
Instance Method Details
#assert_async_polls_until(period: 0.01, timeout: 5) ⇒ Object
Polls the async event loop until a condition is met
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/orocos/test.rb', line 216
def assert_async_polls_until(period: 0.01, timeout: 5)
start = Time.now
while true
Orocos::Async.step
if result = yield
return result
end
if Time.now - start > timeout
flunk("timed out while waiting for condition")
end
sleep period
end
end
|
#assert_state_equals(state, task, timeout = 1) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/orocos/test.rb', line 176
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_dir ⇒ Object
64
|
# File 'lib/orocos/test.rb', line 64
def data_dir; File.join(@test_dir, 'data') end
|
#get(name) ⇒ Object
147
148
149
|
# File 'lib/orocos/test.rb', line 147
def get(name)
Orocos.get name
end
|
#ior(name) ⇒ Object
helper for generating an ior from a name
201
202
203
204
205
|
# File 'lib/orocos/test.rb', line 201
def ior(name)
name_service.ior(name)
rescue Orocos::NotFound
"IOR:010000001f00000049444c3a5254542f636f7262612f435461736b436f6e746578743a312e300000010000000000000064000000010102000d00000031302e3235302e332e31363000002bc80e000000fe8a95a65000004d25000000000000000200000000000000080000000100000000545441010000001c00000001000000010001000100000001000105090101000100000009010100"
end
|
#make_tmpdir ⇒ Object
137
138
139
140
141
|
# File 'lib/orocos/test.rb', line 137
def make_tmpdir
dir = Dir.mktmpdir
@__tmpdirs << dir
dir
end
|
#name_service ⇒ Object
196
197
198
|
# File 'lib/orocos/test.rb', line 196
def name_service
Orocos.name_service
end
|
#read_one_sample(reader, timeout = 1) ⇒ Object
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/orocos/test.rb', line 165
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
|
#spawn_and_get(component, task = component) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/orocos/test.rb', line 151
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
143
144
145
|
# File 'lib/orocos/test.rb', line 143
def start(*spec)
processes.concat Orocos.run(*spec)
end
|
#teardown ⇒ Object
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
|
# File 'lib/orocos/test.rb', line 108
def teardown
if defined? FlexMock
flexmock_teardown
end
@__tmpdirs.each do |dir|
FileUtils.rm_rf dir
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 Orocos::CORBA.call_timeout, Orocos::CORBA.connect_timeout = *@__orocos_corba_timeouts
end
if @old_pkg_config_path ENV['PKG_CONFIG_PATH'] = @old_pkg_config_path
end
Orocos::CORBA.instance_variable_set :@loaded_typekits, []
Orocos.warn_for_missing_default_loggers = @__warn_for_missing_default_loggers
ensure
Orocos.clear
end
|
#wait_for(timeout = 5, &block) ⇒ Object
192
193
194
|
# File 'lib/orocos/test.rb', line 192
def wait_for(timeout = 5, &block)
Orocos::Async.wait_for(0.005, timeout, &block)
end
|
#work_dir ⇒ Object
63
|
# File 'lib/orocos/test.rb', line 63
def work_dir; File.join(@test_dir, 'working_copy') end
|