testability-driver 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/native_extensions.c +53 -25
- data/lib/matti.rb +0 -5
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +4 -4
- data/lib/tdriver/base/behaviour/factory.rb +120 -7
- data/lib/tdriver/base/errors.rb +1 -1
- data/lib/tdriver/base/state_object.rb +3 -2
- data/lib/tdriver/base/sut/controller.rb +2 -2
- data/lib/tdriver/base/sut/factory.rb +207 -201
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +3 -6
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +1 -1
- data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +14 -14
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +5 -5
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +14 -14
- data/lib/tdriver/base/sut/generic/behaviours/verification.rb +3 -18
- data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +6 -6
- data/lib/tdriver/base/sut/generic/plugin.rb +4 -9
- data/lib/tdriver/base/sut/sut.rb +2 -6
- data/lib/tdriver/base/test_object/abstract.rb +1 -1
- data/lib/tdriver/base/test_object/adapter.rb +5 -5
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +7 -6
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +18 -18
- data/lib/tdriver/base/test_object/factory.rb +147 -96
- data/lib/tdriver/base/test_object/verification.rb +6 -9
- data/lib/tdriver/base/test_object/xml/adapter.rb +5 -5
- data/lib/tdriver/matti.rb +1 -1
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +17 -8
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +7 -7
- data/lib/tdriver/report/report_api.rb +172 -79
- data/lib/tdriver/report/report_crash_file_capture.rb +4 -7
- data/lib/tdriver/report/report_creator.rb +16 -20
- data/lib/tdriver/report/report_file_capture.rb +3 -3
- data/lib/tdriver/report/report_javascript.rb +3 -3
- data/lib/tdriver/report/report_test_case_run.rb +20 -10
- data/lib/tdriver/report/report_test_run.rb +11 -10
- data/lib/tdriver/report/report_writer.rb +13 -11
- data/lib/tdriver/tdriver.rb +6 -6
- data/lib/tdriver/util/common/array.rb +2 -2
- data/lib/tdriver/util/common/file.rb +9 -11
- data/lib/tdriver/util/common/gem.rb +1 -1
- data/lib/tdriver/util/common/kernel.rb +4 -4
- data/lib/tdriver/util/common/retryable.rb +2 -2
- data/lib/tdriver/util/common/string.rb +2 -3
- data/lib/tdriver/util/hooking/hooking.rb +2 -2
- data/lib/tdriver/util/localisation/localisation.rb +12 -12
- data/lib/tdriver/util/logger/logger.rb +7 -25
- data/lib/tdriver/util/operator_data/operator_data.rb +5 -5
- data/lib/tdriver/util/parameter/parameter.rb +2 -2
- data/lib/tdriver/util/plugin/abstract.rb +4 -3
- data/lib/tdriver/util/plugin/service.rb +31 -4
- data/lib/tdriver/util/recorder/recorder.rb +4 -4
- data/lib/tdriver/util/user_data/user_data.rb +5 -5
- data/lib/tdriver/util/video/camera_windows.rb +1 -1
- data/lib/tdriver/util/xml/builder.rb +3 -1
- data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +1 -1
- data/lib/tdriver/util/xml/xml.rb +5 -5
- data/lib/tdriver/verify/verify.rb +26 -26
- data/lib/tdriver/version.rb +1 -1
- data/xml/behaviours/generic.xml +1 -2
- metadata +2 -3
- data/lib/tdriver/verify/verify.rb_org +0 -630
data/ext/native_extensions.c
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
#include "ruby.h"
|
23
23
|
|
24
24
|
static const CCITT_16[ 256 ] = {
|
25
|
+
|
25
26
|
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
26
27
|
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
27
28
|
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
@@ -54,6 +55,7 @@ static const CCITT_16[ 256 ] = {
|
|
54
55
|
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
55
56
|
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
56
57
|
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
|
58
|
+
|
57
59
|
};
|
58
60
|
|
59
61
|
|
@@ -96,7 +98,21 @@ static VALUE crc16_ibm( VALUE self, VALUE string ) {
|
|
96
98
|
*/
|
97
99
|
|
98
100
|
static VALUE crc16( int argc, VALUE* argv, VALUE self ) {
|
99
|
-
|
101
|
+
|
102
|
+
/*
|
103
|
+
|
104
|
+
# CRC-16-CCITT
|
105
|
+
def crc16( buf, crc = 0 )
|
106
|
+
|
107
|
+
# calculate the checksum
|
108
|
+
buf.each_byte{ | x | crc = ( ( crc << 8 ) ^ @CCITT_16[ ( crc >> 8 ) ^ x ] ) & 0xffff }
|
109
|
+
|
110
|
+
# result
|
111
|
+
crc
|
112
|
+
|
113
|
+
end # crc16
|
114
|
+
|
115
|
+
*/
|
100
116
|
|
101
117
|
// variables for arguments
|
102
118
|
VALUE string, initial_crc;
|
@@ -104,29 +120,26 @@ static VALUE crc16( int argc, VALUE* argv, VALUE self ) {
|
|
104
120
|
// retrieve arguments
|
105
121
|
rb_scan_args(argc, argv, "11", &string, &initial_crc);
|
106
122
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
123
|
+
// verify argument type
|
124
|
+
Check_Type( string, T_STRING );
|
125
|
+
|
126
|
+
// initialize crc
|
127
|
+
unsigned int crc = 0;
|
112
128
|
|
113
|
-
|
129
|
+
if (!NIL_P(initial_crc)){
|
114
130
|
|
115
131
|
// verify initial crc value
|
116
132
|
Check_Type( initial_crc, T_FIXNUM );
|
117
133
|
|
118
|
-
crc =
|
134
|
+
crc = FIX2INT( initial_crc );
|
119
135
|
|
120
136
|
}
|
121
|
-
|
122
|
-
// verify argument type
|
123
|
-
Check_Type( string, T_STRING );
|
124
137
|
|
125
|
-
const char* data = RSTRING_PTR( string );
|
138
|
+
const unsigned char* data = RSTRING_PTR( string );
|
126
139
|
|
127
|
-
int len = RSTRING_LEN( string );
|
140
|
+
unsigned int len = RSTRING_LEN( string );
|
128
141
|
|
129
|
-
|
142
|
+
unsigned char c = 0;
|
130
143
|
|
131
144
|
while( len-- ){
|
132
145
|
|
@@ -142,7 +155,26 @@ static VALUE crc16( int argc, VALUE* argv, VALUE self ) {
|
|
142
155
|
}
|
143
156
|
|
144
157
|
static VALUE crc16_ibm( int argc, VALUE* argv, VALUE self ) {
|
145
|
-
|
158
|
+
|
159
|
+
/*
|
160
|
+
|
161
|
+
# IBM-CRC-16: fallback when native extensions are not supported (e.g. jruby)
|
162
|
+
def crc16_ibm( buf, crc = 0xffff )
|
163
|
+
|
164
|
+
buf.each_byte do | c |
|
165
|
+
|
166
|
+
crc = ( ( crc >> 4 ) & 0x0fff ) ^ @IBM_16[ ( ( crc ^ c ) & 15 ) ]
|
167
|
+
|
168
|
+
crc = ( ( crc >> 4 ) & 0x0fff ) ^ @IBM_16[ ( ( crc ^ ( c >> 4 ) ) & 15 ) ]
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
# result
|
173
|
+
~crc & 0xffff
|
174
|
+
|
175
|
+
end # crc16_ibm
|
176
|
+
|
177
|
+
*/
|
146
178
|
|
147
179
|
// variables for arguments
|
148
180
|
VALUE string, initial_crc;
|
@@ -150,29 +182,25 @@ static VALUE crc16_ibm( int argc, VALUE* argv, VALUE self ) {
|
|
150
182
|
// retrieve arguments
|
151
183
|
rb_scan_args(argc, argv, "11", &string, &initial_crc);
|
152
184
|
|
153
|
-
int crc
|
154
|
-
|
155
|
-
if (NIL_P(initial_crc)){
|
185
|
+
unsigned int crc = 0xffff;
|
156
186
|
|
157
|
-
|
158
|
-
|
159
|
-
} else {
|
187
|
+
if (!NIL_P(initial_crc)){
|
160
188
|
|
161
189
|
// verify initial crc value
|
162
190
|
Check_Type( initial_crc, T_FIXNUM );
|
163
191
|
|
164
|
-
crc =
|
192
|
+
crc = FIX2INT( initial_crc );
|
165
193
|
|
166
194
|
}
|
167
195
|
|
168
196
|
// verify argument type
|
169
197
|
Check_Type( string, T_STRING );
|
170
198
|
|
171
|
-
const char* data = RSTRING_PTR( string );
|
199
|
+
const unsigned char* data = RSTRING_PTR( string );
|
172
200
|
|
173
|
-
int len = RSTRING_LEN( string );
|
201
|
+
unsigned int len = RSTRING_LEN( string );
|
174
202
|
|
175
|
-
|
203
|
+
unsigned char c = 0;
|
176
204
|
|
177
205
|
while( len-- ){
|
178
206
|
|
data/lib/matti.rb
CHANGED
@@ -17,11 +17,6 @@
|
|
17
17
|
##
|
18
18
|
############################################################################
|
19
19
|
|
20
|
-
=begin
|
21
|
-
file, line = ( caller.first || "%s:%s" % [ __FILE__, __LINE__ ] ).split(":")
|
22
|
-
$stderr.puts "%s:%s warning: require 'matti' deprecated, use require 'tdriver' instead also 'MATTI' is deprecated, use 'TDriver' instead " % [ file, line]
|
23
|
-
=end
|
24
|
-
|
25
20
|
$stderr.puts "%s:%s warning: require 'matti' deprecated, use require 'tdriver' instead. Please note that class 'MATTI' is also deprecated, use 'TDriver' instead " % ( caller.first || "%s:%s" % [ __FILE__, __LINE__ ] ).split(":")[ 0..1 ]
|
26
21
|
|
27
22
|
# load matti resources and framework
|
@@ -73,7 +73,7 @@ module MobyBehaviour
|
|
73
73
|
|
74
74
|
else
|
75
75
|
|
76
|
-
TDriver::BehaviourFactory.collect_behaviours( :index => @object_behaviours ).collect{ | behaviour | behaviour[ :name ] }.uniq.compact
|
76
|
+
TDriver::BehaviourFactory.collect_behaviours( :index => @object_behaviours ).collect{ | behaviour | behaviour[ :name ] }.uniq.compact
|
77
77
|
|
78
78
|
end
|
79
79
|
|
@@ -101,7 +101,7 @@ module MobyBehaviour
|
|
101
101
|
|
102
102
|
)
|
103
103
|
|
104
|
-
}.uniq.compact
|
104
|
+
}.uniq.compact
|
105
105
|
|
106
106
|
end
|
107
107
|
|
@@ -145,10 +145,10 @@ module MobyBehaviour
|
|
145
145
|
#
|
146
146
|
# == exceptions
|
147
147
|
# TypeError
|
148
|
-
# description: Wrong argument type
|
148
|
+
# description: Wrong argument type <class> for method name (expected Symbol or String)
|
149
149
|
#
|
150
150
|
# ArgumentError
|
151
|
-
# description: Test object type of
|
151
|
+
# description: Test object type of <type> does not have method <name>
|
152
152
|
#
|
153
153
|
def describe_method( method_name, print = true, return_result = false )
|
154
154
|
|
@@ -48,6 +48,44 @@ module TDriver
|
|
48
48
|
|
49
49
|
end
|
50
50
|
|
51
|
+
def remove_behaviours( object )
|
52
|
+
|
53
|
+
object.check_type [ MobyBase::TestObject, MobyBase::SUT ], 'wrong argument type $1 for target object (expected $2)'
|
54
|
+
|
55
|
+
# add behaviour information to test object
|
56
|
+
behaviour_index = object.instance_variable_get( :@object_behaviours )
|
57
|
+
|
58
|
+
collect_behaviours( :index => behaviour_index ).collect{ | behaviour |
|
59
|
+
|
60
|
+
_module = behaviour[ :module ]
|
61
|
+
|
62
|
+
instance_methods = [
|
63
|
+
_module.instance_methods( false ),
|
64
|
+
_module.private_instance_methods( false ),
|
65
|
+
_module.protected_instance_methods( false )
|
66
|
+
].inject([]){ | result, methods |
|
67
|
+
|
68
|
+
result.concat( methods )
|
69
|
+
|
70
|
+
}
|
71
|
+
|
72
|
+
# remove behaviour instance methods from target object
|
73
|
+
instance_methods.each do | method_name |
|
74
|
+
|
75
|
+
object.instance_eval( "undef :#{ method_name.to_s }") # if respond_to?(:#{ method_name.to_s })" )
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
behaviour_index.delete( behaviour[ :index ] )
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
behaviour_index = object.instance_variable_set( :@object_behaviours, behaviour_index )
|
84
|
+
|
85
|
+
object
|
86
|
+
|
87
|
+
end
|
88
|
+
|
51
89
|
# TODO: document me
|
52
90
|
def apply_behaviour( rule )
|
53
91
|
|
@@ -132,12 +170,63 @@ module TDriver
|
|
132
170
|
rule.default = [ '*' ]
|
133
171
|
|
134
172
|
# store as local variable for less AST lookups
|
135
|
-
_index = rule.fetch( :index
|
173
|
+
_index = rule.fetch( :index, [] )
|
136
174
|
_object_type = rule[ :object_type ]
|
137
175
|
_input_type = rule[ :input_type ]
|
138
176
|
_env = rule[ :env ]
|
139
177
|
_version = rule[ :version ]
|
140
178
|
|
179
|
+
_name = rule[ :name ]
|
180
|
+
_any = [ '*' ]
|
181
|
+
|
182
|
+
# collect behaviours
|
183
|
+
enabled_plugins.inject([]){ | result, plugin |
|
184
|
+
|
185
|
+
@behaviours_per_plugin.fetch( plugin, [] ).each do | behaviour |
|
186
|
+
|
187
|
+
# match other rules if no exact index given
|
188
|
+
if _index.empty?
|
189
|
+
|
190
|
+
case _name
|
191
|
+
|
192
|
+
when behaviour[ :name ]
|
193
|
+
|
194
|
+
# exact match with name
|
195
|
+
result << behaviour
|
196
|
+
|
197
|
+
when _any
|
198
|
+
|
199
|
+
# compare rules and behaviour attributes
|
200
|
+
if !( _object_type & behaviour[ :object_type ] ).empty? &&
|
201
|
+
!( _input_type & behaviour[ :input_type ] ).empty? &&
|
202
|
+
!( _env & behaviour[ :env ] ).empty? &&
|
203
|
+
!( _version & behaviour[ :version ] ).empty?
|
204
|
+
|
205
|
+
result << behaviour
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
else
|
210
|
+
|
211
|
+
false
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
else
|
216
|
+
|
217
|
+
# index given
|
218
|
+
result << behaviour if Array( _index ).include?( behaviour[ :index ] )
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
result
|
225
|
+
|
226
|
+
}
|
227
|
+
|
228
|
+
=begin
|
229
|
+
|
141
230
|
@behaviours.select do | behaviour |
|
142
231
|
|
143
232
|
# skip if required plugin is not registered or enabled; compare requires array and enabled_plugins array
|
@@ -146,14 +235,14 @@ module TDriver
|
|
146
235
|
# match other rules if no exact index given
|
147
236
|
if _index.empty?
|
148
237
|
|
149
|
-
case
|
238
|
+
case _name
|
150
239
|
|
151
240
|
when behaviour[ :name ]
|
152
241
|
|
153
242
|
# exact match with name
|
154
243
|
true
|
155
244
|
|
156
|
-
when
|
245
|
+
when _any
|
157
246
|
|
158
247
|
# compare rules and behaviour attributes
|
159
248
|
!( _object_type & behaviour[ :object_type ] ).empty? &&
|
@@ -175,6 +264,7 @@ module TDriver
|
|
175
264
|
end
|
176
265
|
|
177
266
|
end # behaviours.select
|
267
|
+
=end
|
178
268
|
|
179
269
|
end
|
180
270
|
|
@@ -243,11 +333,30 @@ module TDriver
|
|
243
333
|
# behaviours container
|
244
334
|
@behaviours = []
|
245
335
|
|
336
|
+
@behaviours_per_plugin = {}
|
337
|
+
|
246
338
|
# behaviour cache; re-collecting behaviours is not required for similar target objects
|
247
339
|
@behaviours_cache = {}
|
248
340
|
|
249
341
|
end
|
250
342
|
|
343
|
+
# TODO: document me
|
344
|
+
def store( behaviour_data )
|
345
|
+
|
346
|
+
behaviour_data[ :requires ].each{ | plugin |
|
347
|
+
|
348
|
+
# retrieve array of plugin specific behaviours
|
349
|
+
behaviours_array = @behaviours_per_plugin[ plugin ] || []
|
350
|
+
|
351
|
+
# apply empty array unless already exist
|
352
|
+
@behaviours_per_plugin[ plugin ] = behaviours_array if behaviours_array.empty?
|
353
|
+
|
354
|
+
behaviours_array << behaviour_data
|
355
|
+
|
356
|
+
}
|
357
|
+
|
358
|
+
end
|
359
|
+
|
251
360
|
# load and parse behaviours files
|
252
361
|
def load_behaviours( path )
|
253
362
|
|
@@ -295,7 +404,7 @@ module TDriver
|
|
295
404
|
module_name.not_empty "behaviour #{ attributes[ "name" ].inspect } does not have module name defined or is empty", RuntimeError
|
296
405
|
|
297
406
|
# store behaviour
|
298
|
-
|
407
|
+
behaviour_data = {
|
299
408
|
|
300
409
|
:index => @behaviours.count,
|
301
410
|
|
@@ -325,6 +434,10 @@ module TDriver
|
|
325
434
|
|
326
435
|
}
|
327
436
|
|
437
|
+
store behaviour_data
|
438
|
+
|
439
|
+
@behaviours << behaviour_data
|
440
|
+
|
328
441
|
end # behaviour.each
|
329
442
|
|
330
443
|
end # behaviours.each
|
@@ -334,8 +447,8 @@ module TDriver
|
|
334
447
|
raise
|
335
448
|
|
336
449
|
rescue MobyUtil::XML::ParseError
|
337
|
-
|
338
|
-
raise MobyUtil::XML::ParseError, "Error while parsing behaviours file #{
|
450
|
+
|
451
|
+
raise MobyUtil::XML::ParseError, "Error while parsing behaviours file #{ filename } due to #{ $!.message }"
|
339
452
|
|
340
453
|
rescue
|
341
454
|
|
@@ -346,7 +459,7 @@ module TDriver
|
|
346
459
|
} # Dir.glob
|
347
460
|
|
348
461
|
end # behaviours
|
349
|
-
|
462
|
+
|
350
463
|
end # self
|
351
464
|
|
352
465
|
# initialize behaviour factory
|
data/lib/tdriver/base/errors.rb
CHANGED
@@ -114,7 +114,8 @@ module MobyBase
|
|
114
114
|
|
115
115
|
else
|
116
116
|
|
117
|
-
|
117
|
+
# Load the new xml only, so old is not supported
|
118
|
+
@test_object_adapter = TDriver::OptimizedXML::TestObjectAdapter
|
118
119
|
|
119
120
|
end
|
120
121
|
|
@@ -176,7 +177,7 @@ module MobyBase
|
|
176
177
|
end
|
177
178
|
|
178
179
|
# raise exception
|
179
|
-
|
180
|
+
raise MobyBase::TestObjectNotFoundError.new(
|
180
181
|
"The state object (#{ object_attributes.join(", ") }) has no child object with type or behaviour method with name #{ method_id.to_s.inspect }#{ search_attributes_string }"
|
181
182
|
)
|
182
183
|
|
@@ -28,7 +28,7 @@ module MobyBase
|
|
28
28
|
# sut_adapter:: MobyController::SutAdapter descendant, e.g. MobyController::QT::SutAdapter
|
29
29
|
# == raises
|
30
30
|
# TypeError:: Wrong argument type $1 for SUT controller (expected $2)
|
31
|
-
# NameError:: No SUT controller found for
|
31
|
+
# NameError:: No SUT controller found for <type> (<class>)
|
32
32
|
def initialize( sut_controllers, sut_adapter )
|
33
33
|
|
34
34
|
sut_controllers.check_type String, 'Wrong argument type $1 for SUT controller (expected $2)'
|
@@ -123,7 +123,7 @@ module MobyBase
|
|
123
123
|
|
124
124
|
retries += 1
|
125
125
|
|
126
|
-
if
|
126
|
+
if TDriver::SUTFactory.connected_suts.include?( @sut_adapter.sut_id.to_sym )
|
127
127
|
|
128
128
|
@sut_adapter.disconnect
|
129
129
|
|
@@ -17,317 +17,323 @@
|
|
17
17
|
##
|
18
18
|
############################################################################
|
19
19
|
|
20
|
-
module
|
20
|
+
module TDriver
|
21
21
|
|
22
|
-
# Class to create SUT objects
|
23
|
-
# Hides actual SUT object from the clients -> clients should be able to use the instantiated SUT object as if it was any SUT
|
24
22
|
class SUTFactory
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
# Initialize the singleton
|
29
|
-
def initialize()
|
30
|
-
|
31
|
-
reset
|
32
|
-
|
33
|
-
end
|
24
|
+
# private methods and variables
|
25
|
+
class << self
|
34
26
|
|
35
|
-
|
36
|
-
def reset
|
27
|
+
private
|
37
28
|
|
38
|
-
|
29
|
+
# TODO: document me
|
30
|
+
def initialize_class
|
39
31
|
|
40
|
-
|
32
|
+
reset
|
41
33
|
|
42
|
-
|
34
|
+
end
|
43
35
|
|
44
|
-
|
36
|
+
def mapped_sut?( sut_id )
|
45
37
|
|
46
|
-
|
38
|
+
$parameters[ :mappings, {} ].has_key?( sut_id.to_sym )
|
47
39
|
|
40
|
+
end
|
48
41
|
|
49
|
-
|
42
|
+
def get_mapped_sut( sut_id )
|
50
43
|
|
51
|
-
|
44
|
+
$parameters[ :mappings ][ sut_id.to_sym ].to_sym
|
52
45
|
|
53
|
-
|
46
|
+
end
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
# sut_type:: sut_type - sut type, supportes all types defined by SUTFactory constants
|
58
|
-
# id:: id - unique identifier for identifying particular SUT from each other. Is propagated to proper initializers.
|
59
|
-
# === returns
|
60
|
-
# return:: SUT object
|
61
|
-
# raise::
|
62
|
-
# ArgumentError:: SUT ID '%s' not found from tdriver_parameters.xml
|
63
|
-
def make( sut_attributes )
|
48
|
+
# gets sut from sut-factorys list - if not connected tries to reconnect first
|
49
|
+
def get_sut_from_list( id )
|
64
50
|
|
65
|
-
|
51
|
+
unless @_sut_list[ id ][ :is_connected ]
|
66
52
|
|
67
|
-
|
53
|
+
@_sut_list[ id ][ :sut ].connect( id )
|
54
|
+
@_sut_list[ id ][ :is_connected ] = true
|
68
55
|
|
69
|
-
|
70
|
-
return get_sut_from_list( sut_id ) if sut_exists?( sut_id )
|
56
|
+
end
|
71
57
|
|
72
|
-
|
73
|
-
|
58
|
+
@_sut_list[ id ][ :sut ]
|
59
|
+
|
60
|
+
end
|
74
61
|
|
75
|
-
|
76
|
-
raise ArgumentError, "#{ sut_id.to_s } not defined in TDriver parameters XML" if sut.nil?
|
77
|
-
|
78
|
-
# retrieve sut type from parameters
|
79
|
-
sut_type = sut[ :type, nil ]
|
80
|
-
|
81
|
-
# raise exception if sut type was not found
|
82
|
-
raise RuntimeError, "SUT parameter 'type' not defined for #{ sut_id.to_s } in TDriver parameters/templates XML" if sut_type.nil?
|
62
|
+
def sut_exists?( sut_id )
|
83
63
|
|
84
|
-
|
64
|
+
@_sut_list.has_key?( sut_id )
|
85
65
|
|
86
|
-
|
87
|
-
sut_plugin = sut[ :sut_plugin, nil ]
|
66
|
+
end
|
88
67
|
|
89
|
-
|
90
|
-
sut_env = sut[ :env, '*' ]
|
68
|
+
def retrieve_sut_id_from_hash( sut_attributes )
|
91
69
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# flag to determine that should exception be raised; allow one retry, then set flag to true if error still occures
|
96
|
-
raise_exception = false
|
70
|
+
# usability improvement: threat sut_attribute as SUT id if it is type of Symbol or String
|
71
|
+
sut_attributes = { :id => sut_attributes.to_sym } if [ String, Symbol ].include?( sut_attributes.class )
|
97
72
|
|
98
|
-
|
73
|
+
# verify that sut_attributes is type of Hash
|
74
|
+
sut_attributes.check_type( [ Hash, Symbol, String ], "Wrong argument type $1 for 'sut_attributes' (expected $2)" )
|
99
75
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
# create sut object
|
104
|
-
created_sut = TDriver::PluginService.call_plugin_method( sut_plugin, :make_sut, sut_id )
|
76
|
+
# legacy support: support also :Id
|
77
|
+
sut_attributes[ :id ] = sut_attributes.delete( :Id ) if sut_attributes.has_key?( :Id )
|
105
78
|
|
106
|
-
|
79
|
+
sut_attributes.require_key( :id, "Required SUT identification key $1 not defined in 'sut_attributes'" )
|
107
80
|
|
108
|
-
|
109
|
-
raise NotImplementedError, "No plugin implementation found for SUT type: #{ sut_type }"
|
81
|
+
sut_attributes[ :id ].to_sym
|
110
82
|
|
111
83
|
end
|
112
84
|
|
113
|
-
|
85
|
+
# Finds the sut definition matching the id, either directly or via a mapping
|
86
|
+
#
|
87
|
+
# === params
|
88
|
+
# sut_id:: Symbol defining the id of the sut to search for
|
89
|
+
# === returns
|
90
|
+
# Symbol:: Either id if it was found in the parameter file or the id of a sut mapped to this id, or nil if no direct or mapped match was found
|
91
|
+
# === raises
|
92
|
+
# ArgumentError:: The id argument was not a Symbol
|
93
|
+
def find_sut_or_mapping( sut_id )
|
114
94
|
|
115
|
-
|
116
|
-
TDriver::PluginService.load_plugin( sut_plugin ) if exception.kind_of?( NotImplementedError )
|
95
|
+
sut_id.check_type Symbol, 'Wrong argument type $1 for SUT id (expected $2)'
|
117
96
|
|
118
|
-
|
97
|
+
begin
|
119
98
|
|
120
|
-
|
99
|
+
# check if direct match exists
|
100
|
+
return sut_id if $parameters[ sut_id ]
|
121
101
|
|
122
|
-
|
123
|
-
|
124
|
-
else
|
102
|
+
rescue MobyUtil::ParameterNotFoundError
|
125
103
|
|
126
|
-
|
127
|
-
|
104
|
+
# check if a mapping is defined for the id
|
105
|
+
begin
|
128
106
|
|
129
|
-
|
107
|
+
# return nil if no mapping exists
|
108
|
+
return nil if ( mapped_id = $parameters[ :mappings ][ sut_id ] ).nil?
|
130
109
|
|
131
|
-
|
110
|
+
# check if the mapped to sut id exists
|
111
|
+
return mapped_id if $parameters[ ( mapped_id = mapped_id.to_sym ) ]
|
132
112
|
|
133
|
-
|
134
|
-
created_sut.instance_variable_set( :@ui_type, sut_type )
|
113
|
+
rescue MobyUtil::ParameterNotFoundError
|
135
114
|
|
136
|
-
|
137
|
-
|
115
|
+
# no mappings defined in tdriver_parameters.xml or the mapped to sut was not found
|
116
|
+
return nil
|
138
117
|
|
139
|
-
|
140
|
-
created_sut.instance_variable_set( :@input, $parameters[ sut_id ][ :input_type, nil ] )
|
118
|
+
end # check if mapping exists
|
141
119
|
|
142
|
-
|
143
|
-
# sut type version, default: nil
|
144
|
-
created_sut.instance_eval{
|
120
|
+
end # check if direct match exists
|
145
121
|
|
146
|
-
|
147
|
-
@ui_version = $parameters[ sut_id ][ :version, nil ]
|
148
|
-
@input = $parameters[ sut_id ][ :input_type, nil ]
|
122
|
+
end # find_sut_or_mapping
|
149
123
|
|
150
|
-
|
151
|
-
=end
|
152
|
-
|
153
|
-
# retrieve list of optional extension plugins
|
154
|
-
@extension_plugins = $parameters[ sut_id ][ :extension_plugins, "" ].split( ";" )
|
124
|
+
end # self
|
155
125
|
|
156
|
-
#
|
157
|
-
|
126
|
+
# Create/reset hash to store sut ids for all current suts
|
127
|
+
def self.reset
|
158
128
|
|
159
|
-
@
|
129
|
+
@_sut_list = {}
|
160
130
|
|
161
|
-
|
131
|
+
end
|
162
132
|
|
163
|
-
|
133
|
+
# TODO: document me
|
134
|
+
def self.disconnect_sut( sut_attributes )
|
164
135
|
|
165
|
-
|
166
|
-
unless TDriver::PluginService.plugin_registered?( plugin_name, :extension )
|
136
|
+
sut_id = retrieve_sut_id_from_hash( sut_attributes )
|
167
137
|
|
168
|
-
|
169
|
-
|
138
|
+
raise RuntimeError, "Unable disconnect SUT due to #{ sut_id.to_s } is not connected" unless sut_exists?( sut_id ) && @_sut_list[ sut_id ][ :is_connected ]
|
139
|
+
|
140
|
+
@_sut_list[ sut_id ][ :sut ].disconnect
|
141
|
+
|
142
|
+
@_sut_list[ sut_id ][ :is_connected ] = false
|
170
143
|
|
171
|
-
|
144
|
+
end
|
172
145
|
|
173
|
-
|
146
|
+
def self.reboot_sut( sut_attributes )
|
174
147
|
|
175
|
-
|
176
|
-
TDriver::PluginService.load_plugin( plugin_name ) if exception.kind_of?( NotImplementedError )
|
148
|
+
sut_id = retrieve_sut_id_from_hash( sut_attributes )
|
177
149
|
|
178
|
-
|
150
|
+
raise RuntimeError, "Unable to reboot SUT due to #{ sut_id.to_s } is not connected" unless sut_exists?( sut_id ) && @_sut_list[ sut_id ][ :is_connected ]
|
179
151
|
|
180
|
-
|
152
|
+
@_sut_list[ sut_id ][ :sut ].reboot
|
181
153
|
|
182
|
-
|
154
|
+
disconnect_sut( sut_id )
|
183
155
|
|
184
|
-
|
156
|
+
end
|
185
157
|
|
186
|
-
|
187
|
-
|
158
|
+
# TODO: document me
|
159
|
+
def self.connected_suts
|
188
160
|
|
189
|
-
|
161
|
+
@_sut_list
|
190
162
|
|
191
|
-
|
163
|
+
end
|
192
164
|
|
193
|
-
|
165
|
+
# Function to create the actual SUT objects based on the 'sut' attribute.
|
166
|
+
# === params
|
167
|
+
# sut_type:: sut_type - sut type, supportes all types defined by SUTFactory constants
|
168
|
+
# id:: id - unique identifier for identifying particular SUT from each other. Is propagated to proper initializers.
|
169
|
+
# === returns
|
170
|
+
# return:: SUT object
|
171
|
+
# raise::
|
172
|
+
# ArgumentError:: <name> not defined in TDriver parameters XML
|
173
|
+
def self.make( sut_attributes )
|
194
174
|
|
195
|
-
|
175
|
+
sut_id = retrieve_sut_id_from_hash( sut_attributes )
|
196
176
|
|
197
|
-
|
198
|
-
TDriver::BehaviourFactory.apply_behaviour(
|
177
|
+
sut_id = get_mapped_sut( sut_id ) if mapped_sut?( sut_id )
|
199
178
|
|
200
|
-
|
201
|
-
|
202
|
-
:sut_type => [ '*', created_sut.ui_type ],
|
203
|
-
:input_type => [ '*', created_sut.input.to_s ],
|
204
|
-
:env => [ '*', *sut_env.to_s.split(";") ],
|
205
|
-
:version => [ '*', created_sut.ui_version.to_s ]
|
179
|
+
# if sut is already connected, return existing sut
|
180
|
+
return get_sut_from_list( sut_id ) if sut_exists?( sut_id )
|
206
181
|
|
207
|
-
|
182
|
+
# retrieve sut from parameters
|
183
|
+
sut = $parameters[ sut_id, nil ]
|
208
184
|
|
209
|
-
|
185
|
+
# raise exception if sut was not found
|
186
|
+
raise ArgumentError, "#{ sut_id.to_s } not defined in TDriver parameters XML" if sut.nil?
|
187
|
+
|
188
|
+
# retrieve sut type from parameters
|
189
|
+
sut_type = sut[ :type, nil ]
|
190
|
+
|
191
|
+
# raise exception if sut type was not found
|
192
|
+
raise RuntimeError, "SUT parameter type not defined for #{ sut_id.to_s } in TDriver parameters/templates XML" if sut_type.nil?
|
210
193
|
|
211
|
-
|
194
|
+
sut_type_symbol = sut_type.downcase.to_sym
|
212
195
|
|
213
|
-
|
196
|
+
# retrieve plugin name that implements given sut
|
197
|
+
sut_plugin = sut[ :sut_plugin, nil ]
|
214
198
|
|
215
|
-
|
199
|
+
# retrieve enviroment value from sut, use '*' as default
|
200
|
+
sut_env = sut[ :env, '*' ]
|
216
201
|
|
217
|
-
|
202
|
+
# verify that sut plugin is defined in sut configuration
|
203
|
+
raise RuntimeError, "SUT parameter 'sut_plugin' not defined for #{ sut_id.to_s } (#{ sut_type.to_s })" if sut_plugin.nil?
|
204
|
+
|
205
|
+
# flag to determine that should exception be raised; allow one retry, then set flag to true if error still occures
|
206
|
+
raise_exception = false
|
218
207
|
|
219
|
-
|
220
|
-
|
221
|
-
@_sut_list[ sut_id ][ :sut ].disconnect
|
222
|
-
|
223
|
-
@_sut_list[ sut_id ][ :is_connected ] = false
|
208
|
+
begin
|
224
209
|
|
225
|
-
|
210
|
+
# verify that sut plugin is registered
|
211
|
+
if TDriver::PluginService.plugin_registered?( sut_plugin, :sut )
|
212
|
+
|
213
|
+
# create sut object
|
214
|
+
created_sut = TDriver::PluginService.call_plugin_method( sut_plugin, :make_sut, sut_id )
|
226
215
|
|
227
|
-
|
216
|
+
else
|
228
217
|
|
229
|
-
|
218
|
+
# raise error if sut was not registered
|
219
|
+
raise NotImplementedError, "No plugin implementation found for SUT type: #{ sut_type }"
|
230
220
|
|
231
|
-
|
232
|
-
|
233
|
-
"Unable to reboot SUT due to %s is not connected" % [ sut_id ]
|
234
|
-
|
235
|
-
) unless sut_exists?( sut_id ) && @_sut_list[ sut_id ][ :is_connected ]
|
236
|
-
|
237
|
-
@_sut_list[ sut_id ][ :sut ].reboot
|
221
|
+
end
|
238
222
|
|
239
|
-
|
223
|
+
rescue Exception => exception
|
240
224
|
|
241
|
-
|
225
|
+
# if sut was not registered, try to load it
|
226
|
+
TDriver::PluginService.load_plugin( sut_plugin ) if exception.kind_of?( NotImplementedError )
|
242
227
|
|
243
|
-
|
228
|
+
if !raise_exception
|
244
229
|
|
245
|
-
|
230
|
+
raise_exception = true
|
246
231
|
|
247
|
-
|
232
|
+
retry
|
233
|
+
|
234
|
+
else
|
248
235
|
|
249
|
-
|
236
|
+
# still errors, raise original exception
|
237
|
+
raise exception
|
250
238
|
|
251
|
-
|
239
|
+
end
|
252
240
|
|
253
|
-
|
254
|
-
sut_attributes = { :id => sut_attributes.to_sym } if [ String, Symbol ].include?( sut_attributes.class )
|
241
|
+
end
|
255
242
|
|
256
|
-
#
|
257
|
-
|
243
|
+
# store SUT type to sut object
|
244
|
+
created_sut.instance_variable_set( :@ui_type, sut_type )
|
258
245
|
|
259
|
-
#
|
260
|
-
|
246
|
+
# store SUT UI version to sut object
|
247
|
+
created_sut.instance_variable_set( :@ui_version, $parameters[ sut_id ][ :version, nil ] )
|
261
248
|
|
262
|
-
|
249
|
+
# store SUT input type to sut object
|
250
|
+
created_sut.instance_variable_set( :@input, $parameters[ sut_id ][ :input_type, nil ] )
|
263
251
|
|
264
|
-
|
252
|
+
# retrieve list of optional extension plugins
|
253
|
+
@extension_plugins = $parameters[ sut_id ][ :extension_plugins, "" ].split( ";" )
|
265
254
|
|
266
|
-
|
255
|
+
# load optional extension plugins
|
256
|
+
if @extension_plugins.count > 0
|
267
257
|
|
268
|
-
|
269
|
-
def get_sut_from_list( id )
|
258
|
+
@extension_plugins.each{ | plugin_name |
|
270
259
|
|
271
|
-
|
260
|
+
raise_exception = false
|
272
261
|
|
273
|
-
|
274
|
-
@_sut_list[ id ][ :is_connected ] = true
|
262
|
+
begin
|
275
263
|
|
276
|
-
|
264
|
+
# verify that extension plugin is registered
|
265
|
+
unless TDriver::PluginService.plugin_registered?( plugin_name, :extension )
|
277
266
|
|
278
|
-
|
279
|
-
|
267
|
+
# raise error if sut was not registered
|
268
|
+
raise NotImplementedError, "Extension plugin not found #{ plugin_name }"
|
280
269
|
|
281
|
-
|
270
|
+
end
|
282
271
|
|
283
|
-
|
272
|
+
rescue Exception => exception
|
284
273
|
|
285
|
-
|
274
|
+
# if sut was not registered, try to load it
|
275
|
+
TDriver::PluginService.load_plugin( plugin_name ) if exception.kind_of?( NotImplementedError )
|
286
276
|
|
287
|
-
|
288
|
-
#
|
289
|
-
# === params
|
290
|
-
# sut_id:: Symbol defining the id of the sut to search for
|
291
|
-
# === returns
|
292
|
-
# Symbol:: Either id if it was found in the parameter file or the id of a sut mapped to this id, or nil if no direct or mapped match was found
|
293
|
-
# === raises
|
294
|
-
# ArgumentError:: The id argument was not a Symbol
|
295
|
-
def find_sut_or_mapping( sut_id )
|
277
|
+
if !raise_exception
|
296
278
|
|
297
|
-
|
298
|
-
|
299
|
-
#Kernel::raise ArgumentError.new( "The id argument was not a Symbol." ) unless sut_id.kind_of?( Symbol )
|
279
|
+
raise_exception = true
|
300
280
|
|
301
|
-
|
281
|
+
retry
|
302
282
|
|
303
|
-
|
304
|
-
return sut_id if $parameters[ sut_id ]
|
283
|
+
else
|
305
284
|
|
306
|
-
|
285
|
+
# still errors, raise original exception
|
286
|
+
raise exception
|
307
287
|
|
308
|
-
|
309
|
-
begin
|
288
|
+
end
|
310
289
|
|
311
|
-
|
312
|
-
|
290
|
+
end
|
291
|
+
|
292
|
+
}
|
313
293
|
|
314
|
-
|
315
|
-
return mapped_id if $parameters[ ( mapped_id = mapped_id.to_sym ) ]
|
294
|
+
end
|
316
295
|
|
317
|
-
|
296
|
+
# apply sut generic behaviours
|
297
|
+
TDriver::BehaviourFactory.apply_behaviour(
|
318
298
|
|
319
|
-
|
320
|
-
|
299
|
+
:object => created_sut,
|
300
|
+
:object_type => [ 'sut' ],
|
301
|
+
:sut_type => [ '*', created_sut.ui_type ],
|
302
|
+
:input_type => [ '*', created_sut.input.to_s ],
|
303
|
+
:env => [ '*', *sut_env.to_s.split(";") ],
|
304
|
+
:version => [ '*', created_sut.ui_version.to_s ]
|
321
305
|
|
322
|
-
|
306
|
+
)
|
323
307
|
|
324
|
-
|
308
|
+
@_sut_list[ sut_id ] = { :sut => created_sut, :is_connected => true }
|
325
309
|
|
326
|
-
|
310
|
+
created_sut
|
327
311
|
|
328
|
-
|
329
|
-
|
312
|
+
end
|
313
|
+
|
314
|
+
# enable hooking for performance measurement & debug logging
|
315
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
330
316
|
|
317
|
+
# initialize plugin service
|
318
|
+
initialize_class
|
319
|
+
|
331
320
|
end # SUTFactory
|
332
321
|
|
322
|
+
end # TDriver
|
323
|
+
|
324
|
+
# for backwards compatibility
|
325
|
+
module MobyBase
|
326
|
+
|
327
|
+
class SUTFactory
|
328
|
+
|
329
|
+
def self.instance
|
330
|
+
|
331
|
+
warn_caller '$1:$2 deprecated class MobyBase::SUTFactory, please use static class TDriver::SUTFactory instead'
|
332
|
+
|
333
|
+
TDriver::SUTFactory
|
334
|
+
|
335
|
+
end
|
336
|
+
|
337
|
+
end # SUTFactory
|
338
|
+
|
333
339
|
end # MobyBase
|