testability-driver-qt-sut-plugin 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/installer/extconf.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/action.rb +5 -5
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/application.rb +174 -236
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/attribute.rb +3 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/behaviour.rb +5 -5
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/configure_behaviour.rb +7 -7
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/events.rb +7 -7
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/file_transfer.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/find.rb +3 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fixture.rb +5 -5
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/gesture.rb +73 -60
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/infologger.rb +3 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/key_press.rb +6 -6
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/locale_db.rb +8 -8
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/method.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/multitouch.rb +348 -329
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/os.rb +5 -5
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/qt_api_method.rb +3 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/record.rb +7 -7
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/screen_capture.rb +9 -9
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/sut.rb +79 -27
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/synchronization.rb +3 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/treewidgetitemcolumn.rb +5 -5
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/type_text.rb +3 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/view_item.rb +5 -5
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/webkit.rb +13 -11
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/widget.rb +70 -67
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/qt.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/configure_command.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/find_object.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/fixture.rb +2 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/group.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/infologger_command.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/key_sequence.rb +3 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/screen_capture.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/tap.rb +1 -1
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/widget.rb +30 -14
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/plugin.rb +8 -3
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/adapter.rb +160 -29
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb +6 -8
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/controller.rb +13 -2
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/find_object_generator.rb +50 -35
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/message_composer.rb +129 -95
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/widget.rb +4 -4
- data/xml/behaviour/qt.xml +8 -12
- metadata +53 -72
data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/find_object.rb
CHANGED
@@ -40,7 +40,7 @@ module MobyController
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# enable hooking for performance measurement & debug logging
|
43
|
-
|
43
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
44
44
|
|
45
45
|
end #module FindObjectCommand
|
46
46
|
|
@@ -31,7 +31,7 @@ module MobyController
|
|
31
31
|
# == raises
|
32
32
|
# NotImplementedError: raised if unsupported command type
|
33
33
|
def execute
|
34
|
-
Kernel::raise ArgumentError.new( "Fixture '%s' not found for sut id '%s'" % [ @name, @sut_adapter.sut_id ] ) if ( plugin_params =
|
34
|
+
Kernel::raise ArgumentError.new( "Fixture '%s' not found for sut id '%s'" % [ @name, @sut_adapter.sut_id ] ) if ( plugin_params = $parameters[ @sut_adapter.sut_id.to_sym ][ :fixtures ][ @params[:name].to_sym, nil ] ).nil?
|
35
35
|
|
36
36
|
fixture_plugin = plugin_params.kind_of?(String) ? plugin_params : plugin_params[:plugin]
|
37
37
|
@sut_adapter.send_service_request(Comms::MessageGenerator.generate(make_fixture_message(fixture_plugin, @params)))
|
@@ -43,8 +43,7 @@ module MobyController
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# enable hooking for performance measurement & debug logging
|
46
|
-
|
47
|
-
|
46
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
48
47
|
|
49
48
|
end # Fixture
|
50
49
|
|
@@ -43,7 +43,7 @@ module MobyController
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# enable hooking for performance measurement & debug logging
|
46
|
-
|
46
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
47
47
|
|
48
48
|
end #module Group
|
49
49
|
|
@@ -52,7 +52,7 @@ module MobyController
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# enable hooking for performance measurement & debug logging
|
55
|
-
|
55
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
56
56
|
|
57
57
|
|
58
58
|
end # InfoLoggerCommand
|
data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/key_sequence.rb
CHANGED
@@ -64,10 +64,10 @@ module MobyController
|
|
64
64
|
Kernel::raise ArgumentError.new( "Wrong argument type %s for key (Expected: %s)" % [ key.class, "Symbol/Fixnum" ] ) unless [ Fixnum, Symbol ].include?( key.class )
|
65
65
|
|
66
66
|
# verify that keymap is defined for sut if symbol used.
|
67
|
-
Kernel::raise ArgumentError.new("Symbol #{ key.inspect } cannot be used due to no keymap defined for #{ sut.id } in TDriver configuration file.") if key.kind_of?( Symbol ) &&
|
67
|
+
Kernel::raise ArgumentError.new("Symbol #{ key.inspect } cannot be used due to no keymap defined for #{ sut.id } in TDriver configuration file.") if key.kind_of?( Symbol ) && $parameters[ sut.id ][ :keymap ].nil?
|
68
68
|
|
69
69
|
# retrieve corresponding scan code (type of string, convert to fixnum) for symbol from keymap if available
|
70
|
-
key =
|
70
|
+
key = $parameters[ sut.id ][ :keymap ][ key ].hex unless $parameters[ sut.id ][ :keymap ][ key ].nil?
|
71
71
|
|
72
72
|
# raise exception if value is other than fixnum
|
73
73
|
Kernel::raise ArgumentError.new( "Scan code for :%s not defined in keymap" % key ) unless key.kind_of?( Fixnum )
|
@@ -90,7 +90,7 @@ module MobyController
|
|
90
90
|
end
|
91
91
|
|
92
92
|
# enable hooking for performance measurement & debug logging
|
93
|
-
|
93
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
94
94
|
|
95
95
|
end #class
|
96
96
|
|
data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/screen_capture.rb
CHANGED
@@ -44,7 +44,7 @@ module MobyController
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# enable hooking for performance measurement & debug logging
|
47
|
-
|
47
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
48
48
|
|
49
49
|
|
50
50
|
end # ScreenCapture
|
@@ -42,7 +42,7 @@ module MobyController
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# enable hooking for performance measurement & debug logging
|
45
|
-
|
45
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
46
46
|
|
47
47
|
end # Tap
|
48
48
|
|
@@ -32,37 +32,53 @@ module MobyController
|
|
32
32
|
# == raises
|
33
33
|
# NotImplementedError: raised if unsupported command type
|
34
34
|
def execute
|
35
|
-
|
36
|
-
command_params
|
35
|
+
|
36
|
+
command_params = { :eventType => get_event_type, :name => get_command_name }
|
37
|
+
|
38
|
+
command_params.merge!( get_command_params ) if get_command_params
|
37
39
|
|
38
40
|
builder = Nokogiri::XML::Builder.new{
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
|
42
|
+
TasCommands( :id => get_application_id, :transitions => get_transitions, :service => get_service || 'uiCommand' ) {
|
43
|
+
|
44
|
+
Target( :TasId => get_object_id, :type => get_object_type ) {
|
45
|
+
|
46
|
+
if get_command_value.kind_of?( Array )
|
47
|
+
|
48
|
+
get_command_value.each do | command_part |
|
49
|
+
Command( command_part[ :value ], command_part[ :params ] )
|
50
|
+
end
|
51
|
+
|
52
|
+
elsif get_command_value
|
53
|
+
|
54
|
+
Command( get_command_value, command_params )
|
55
|
+
|
56
|
+
else
|
57
|
+
|
58
|
+
Command( command_params )
|
59
|
+
|
44
60
|
end
|
45
|
-
|
46
|
-
|
47
|
-
end
|
61
|
+
|
62
|
+
}
|
48
63
|
}
|
49
|
-
}
|
50
64
|
}
|
51
65
|
|
52
66
|
if @sut_adapter.group?
|
53
|
-
|
67
|
+
@sut_adapter.append_command( builder.doc.root.children )
|
54
68
|
else
|
55
|
-
|
69
|
+
@sut_adapter.send_service_request( Comms::MessageGenerator.generate( builder.to_xml ) )
|
56
70
|
end
|
57
71
|
|
58
72
|
end
|
59
73
|
|
60
74
|
def set_adapter( adapter )
|
75
|
+
|
61
76
|
@sut_adapter = adapter
|
77
|
+
|
62
78
|
end
|
63
79
|
|
64
80
|
# enable hooking for performance measurement & debug logging
|
65
|
-
|
81
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
66
82
|
|
67
83
|
|
68
84
|
end #module Action
|
@@ -20,6 +20,11 @@
|
|
20
20
|
# verify that TDriver is loaded
|
21
21
|
Kernel::raise RuntimeError.new( "This SUT plugin requires Testability Driver and cannot be launched in standalone mode" ) unless (defined?( MATTI ) || defined?( TDriver ))
|
22
22
|
|
23
|
+
include TDriverVerify
|
24
|
+
|
25
|
+
require 'socket'
|
26
|
+
require 'zlib'
|
27
|
+
|
23
28
|
module MobyPlugin
|
24
29
|
|
25
30
|
module QT
|
@@ -95,8 +100,8 @@ module MobyPlugin
|
|
95
100
|
def self.make_sut( sut_id )
|
96
101
|
|
97
102
|
# tcp/ip read/write timeouts, default: 15 (seconds)
|
98
|
-
socket_read_timeout =
|
99
|
-
socket_write_timeout =
|
103
|
+
socket_read_timeout = $parameters[ sut_id ][ :socket_read_timeout, "15" ].to_i
|
104
|
+
socket_write_timeout = $parameters[ sut_id ][ :socket_write_timeout, "15" ].to_i
|
100
105
|
|
101
106
|
MobyBase::SUT.new(
|
102
107
|
MobyBase::SutController.new( "QT", MobyController::QT::SutAdapter.new( sut_id, socket_read_timeout, socket_write_timeout ) ),
|
@@ -107,7 +112,7 @@ module MobyPlugin
|
|
107
112
|
end
|
108
113
|
|
109
114
|
# enable hooking for performance measurement & debug logging
|
110
|
-
|
115
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
111
116
|
|
112
117
|
# register plugin
|
113
118
|
MobyUtil::PluginService.instance.register_plugin( self ) # Note: self is MobyPlugin::QT::SUT
|
@@ -24,16 +24,18 @@ module MobyController
|
|
24
24
|
# Sut adapter that used TCP/IP connections to send and receive data from QT side.
|
25
25
|
class SutAdapter < MobyController::SutAdapter
|
26
26
|
|
27
|
-
attr_reader
|
27
|
+
attr_reader(
|
28
|
+
:sut_id,
|
29
|
+
:socket_received_bytes,
|
30
|
+
:socket_sent_bytes,
|
31
|
+
:socket_received_packets,
|
32
|
+
:socket_sent_packets
|
33
|
+
)
|
28
34
|
|
29
35
|
attr_accessor(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
:socket_received_bytes,
|
34
|
-
:socket_sent_bytes
|
35
|
-
|
36
|
-
)
|
36
|
+
:socket_read_timeout,
|
37
|
+
:socket_write_timeout
|
38
|
+
)
|
37
39
|
|
38
40
|
# TODO: better way to set the host and port parameters
|
39
41
|
# Initialize the tcp adapter for communicating with the device.
|
@@ -47,8 +49,12 @@ module MobyController
|
|
47
49
|
|
48
50
|
@socket = nil
|
49
51
|
@connected = false
|
50
|
-
|
51
|
-
@
|
52
|
+
|
53
|
+
@socket_received_bytes = 0
|
54
|
+
@socket_sent_bytes = 0
|
55
|
+
|
56
|
+
@socket_received_packets = 0
|
57
|
+
@socket_sent_packets = 0
|
52
58
|
|
53
59
|
@sut_id = sut_id
|
54
60
|
|
@@ -56,6 +62,7 @@ module MobyController
|
|
56
62
|
@socket_read_timeout = receive_timeout
|
57
63
|
@socket_write_timeout = send_timeout
|
58
64
|
|
65
|
+
|
59
66
|
@counter = rand( 1000 )
|
60
67
|
|
61
68
|
# connect socket
|
@@ -63,6 +70,7 @@ module MobyController
|
|
63
70
|
|
64
71
|
end
|
65
72
|
|
73
|
+
# TODO: document me
|
66
74
|
def disconnect
|
67
75
|
|
68
76
|
@socket.close if @connected
|
@@ -71,18 +79,19 @@ module MobyController
|
|
71
79
|
|
72
80
|
end
|
73
81
|
|
82
|
+
# TODO: document me
|
74
83
|
def connect( id = nil )
|
75
84
|
|
76
85
|
id ||= @sut_id
|
77
86
|
|
78
87
|
begin
|
79
88
|
|
80
|
-
@socket = TCPSocket.open(
|
89
|
+
@socket = TCPSocket.open( $parameters[ id ][ :qttas_server_ip ], $parameters[ id ][ :qttas_server_port ].to_i )
|
81
90
|
|
82
91
|
rescue => ex
|
83
92
|
|
84
|
-
ip = "no ip" if ( ip =
|
85
|
-
port = "no port" if ( port =
|
93
|
+
ip = "no ip" if ( ip = $parameters[ id ][ :qttas_server_ip, "" ] ).empty?
|
94
|
+
port = "no port" if ( port = $parameters[ id ][ :qttas_server_port, "" ] ).empty?
|
86
95
|
|
87
96
|
Kernel::raise IOError.new("Unable to connect QTTAS server, verify that it is running properly (#{ ip }:#{ port }): .\nException: #{ ex.message }")
|
88
97
|
end
|
@@ -91,18 +100,27 @@ module MobyController
|
|
91
100
|
|
92
101
|
end
|
93
102
|
|
103
|
+
# TODO: document me
|
94
104
|
def group?
|
105
|
+
|
95
106
|
@_group
|
107
|
+
|
96
108
|
end
|
97
109
|
|
98
110
|
# Set the document builder for the grouped behaviour message.
|
99
111
|
def set_message_builder(builder)
|
112
|
+
|
100
113
|
@_group = true
|
114
|
+
|
101
115
|
@_builder = builder
|
116
|
+
|
102
117
|
end
|
103
118
|
|
119
|
+
# TODO: document me
|
104
120
|
def append_command(node_list)
|
121
|
+
|
105
122
|
node_list.each {|ch| @_builder.doc.root.add_child(ch)}
|
123
|
+
|
106
124
|
end
|
107
125
|
|
108
126
|
# Sends a grouped command message to the server. Sets group to false and nils the builder
|
@@ -110,11 +128,17 @@ module MobyController
|
|
110
128
|
# == returns
|
111
129
|
# the amout of commands grouped (and send)
|
112
130
|
def send_grouped_request
|
131
|
+
|
113
132
|
@_group = false
|
133
|
+
|
114
134
|
size = @_builder.doc.root.children.size
|
135
|
+
|
115
136
|
send_service_request(Comms::MessageGenerator.generate(@_builder.to_xml))
|
137
|
+
|
116
138
|
@_builder = nil
|
139
|
+
|
117
140
|
size
|
141
|
+
|
118
142
|
end
|
119
143
|
|
120
144
|
# Send the message to the qt server
|
@@ -131,7 +155,7 @@ module MobyController
|
|
131
155
|
message.message_id = ( @counter += 1 )
|
132
156
|
|
133
157
|
# write request message to socket
|
134
|
-
write_socket( message.make_binary_message(@counter) )
|
158
|
+
write_socket( message.make_binary_message( @counter ) )
|
135
159
|
|
136
160
|
# read response to determine was the message handled properly and parse the header
|
137
161
|
# header[ 0 ] = command_flag
|
@@ -141,6 +165,7 @@ module MobyController
|
|
141
165
|
# header[ 4 ] = message_id
|
142
166
|
|
143
167
|
header = nil
|
168
|
+
|
144
169
|
body = nil
|
145
170
|
|
146
171
|
read_message_id = 0
|
@@ -149,8 +174,10 @@ module MobyController
|
|
149
174
|
|
150
175
|
header = read_socket( 12 ).unpack( 'CISCI' )
|
151
176
|
|
177
|
+
body = read_socket( header[ 1 ] )
|
178
|
+
|
152
179
|
# read the message body and compare crc checksum
|
153
|
-
Kernel::raise IOError
|
180
|
+
Kernel::raise IOError, "CRC do not match, response message body may be corrupted!" if CRC::Crc16.crc16_ibm( body, 0xffff ) != header[ 2 ]
|
154
181
|
|
155
182
|
# validate response message; check that response message id matches the request
|
156
183
|
# if smaller than expected try to read the next message but if bigger raise error
|
@@ -158,14 +185,15 @@ module MobyController
|
|
158
185
|
|
159
186
|
if read_message_id < @counter
|
160
187
|
|
161
|
-
|
188
|
+
$logger.log "warning", "Response to request did not match: \"#{ header[ 4 ].to_s }\"<\"#{ @counter.to_s }\""
|
162
189
|
|
163
190
|
elsif read_message_id > @counter
|
164
191
|
|
165
|
-
|
192
|
+
$logger.log "fatal", "Response to request did not match: \"#{ header[ 4 ].to_s }\">\"#{ @counter.to_s }\""
|
166
193
|
|
167
194
|
# save to file?
|
168
|
-
|
195
|
+
$logger.log "fatal", body
|
196
|
+
|
169
197
|
Kernel::raise RuntimeError.new( "Response to request did not match: \"#{ header[ 4 ].to_s }\"!=\"#{ @counter.to_s }\"" )
|
170
198
|
|
171
199
|
end
|
@@ -174,8 +202,11 @@ module MobyController
|
|
174
202
|
|
175
203
|
# inflate the message body if compressed
|
176
204
|
if ( header[ 3 ] == 2 )
|
177
|
-
|
178
|
-
|
205
|
+
|
206
|
+
# remove leading 4 bytes
|
207
|
+
body = body[ 4 .. -1 ]
|
208
|
+
|
209
|
+
body = Zlib::Inflate.inflate( body ) unless body.empty?
|
179
210
|
|
180
211
|
end
|
181
212
|
|
@@ -184,13 +215,19 @@ module MobyController
|
|
184
215
|
# 0 -> ERROR_MSG
|
185
216
|
# 1 -> VALID_MSG
|
186
217
|
# 2 -> OK_MESSAGE
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
218
|
+
if header[ 0 ] == 0
|
219
|
+
|
220
|
+
if body =~ /The application with Id \d+ is no longer available/
|
221
|
+
|
222
|
+
Kernel::raise MobyBase::ApplicationNotAvailableError, body
|
223
|
+
|
224
|
+
else
|
225
|
+
|
226
|
+
Kernel::raise RuntimeError, body
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
194
231
|
|
195
232
|
# return the body ( and crc if required )
|
196
233
|
return_crc ? [ body, header[ 2 ] ] : body
|
@@ -199,6 +236,7 @@ module MobyController
|
|
199
236
|
|
200
237
|
private
|
201
238
|
|
239
|
+
# TODO: document me
|
202
240
|
def read_socket( bytes_count )
|
203
241
|
|
204
242
|
# store time before start receving data
|
@@ -214,26 +252,119 @@ module MobyController
|
|
214
252
|
|
215
253
|
}
|
216
254
|
|
255
|
+
# useless?
|
217
256
|
Kernel::raise IOError.new( "Socket reading error for %i bytes - No data retrieved" % [ bytes_count ] ) if read_buffer.nil?
|
218
257
|
|
219
258
|
@socket_received_bytes += read_buffer.size
|
259
|
+
|
260
|
+
@socket_received_packets += 1
|
261
|
+
|
220
262
|
read_buffer
|
263
|
+
|
264
|
+
=begin
|
265
|
+
begin
|
266
|
+
|
267
|
+
read_buffer = @socket.read_nonblock( bytes_count )
|
268
|
+
|
269
|
+
rescue Errno::EWOULDBLOCK
|
270
|
+
|
271
|
+
if TCPSocket.select( [ @socket ], nil, nil, @socket_read_timeout )
|
272
|
+
|
273
|
+
read_buffer = @socket.read_nonblock( bytes_count )
|
274
|
+
|
275
|
+
else
|
276
|
+
|
277
|
+
Kernel::raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ @socket_read_timeout, bytes_count ] )
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
read_buffer
|
284
|
+
=end
|
285
|
+
|
286
|
+
=begin
|
287
|
+
#Kernel::raise ThreadError, "Timeout within critical session" if Thread.critical
|
288
|
+
|
289
|
+
begin
|
290
|
+
|
291
|
+
# store current thread
|
292
|
+
main_thread = Thread.current
|
293
|
+
|
294
|
+
# create timeout thread
|
295
|
+
timeout_thread = Thread.new( @socket_read_timeout ){ | timeout, bytes_count |
|
296
|
+
|
297
|
+
# sleep the timeout
|
298
|
+
sleep time
|
299
|
+
|
300
|
+
# raise exception if timeout exceeds
|
301
|
+
main_thread.raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ timeout, bytes_count ] ) if main_thread.alive?
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
# read data from socket
|
306
|
+
@socket.read( bytes_count )
|
307
|
+
|
308
|
+
ensure
|
309
|
+
|
310
|
+
# ensure that timeout thread is terminated
|
311
|
+
timeout_thread.kill if timeout_thread && timeout_thread.alive?
|
312
|
+
|
313
|
+
@socket_received_bytes += bytes_count
|
314
|
+
|
315
|
+
end
|
316
|
+
=end
|
221
317
|
|
222
318
|
end
|
223
319
|
|
320
|
+
# TODO: document me
|
224
321
|
def write_socket( data )
|
225
|
-
|
322
|
+
|
226
323
|
@socket_sent_bytes += data.size
|
227
324
|
|
325
|
+
@socket_sent_packets += 1
|
326
|
+
|
228
327
|
@socket.write( data )
|
229
328
|
|
230
329
|
# verify that there is no data in writing buffer
|
231
330
|
Kernel::raise IOError.new( "Socket writing timeout (%i) exceeded for %i bytes" % [ @socket_write_timeout, data.length ] ) if TCPSocket::select( nil, [ @socket ], nil, @socket_write_timeout ).nil?
|
331
|
+
|
332
|
+
=begin
|
333
|
+
|
334
|
+
begin
|
335
|
+
|
336
|
+
# store current thread
|
337
|
+
main_thread = Thread.current
|
338
|
+
|
339
|
+
# create timeout thread
|
340
|
+
timeout_thread = Thread.new( @socket_write_timeout ){ | timeout, data.size |
|
341
|
+
|
342
|
+
# sleep the timeout
|
343
|
+
sleep time
|
344
|
+
|
345
|
+
# raise exception if timeout exceeds
|
346
|
+
main_thread.raise IOError.new( "Socket writing timeout (%i) exceeded for %i bytes" % [ timeout, bytes_count ] ) if main_thread.alive?
|
347
|
+
|
348
|
+
}
|
349
|
+
|
350
|
+
# read data from socket
|
351
|
+
@socket.write( data )
|
352
|
+
|
353
|
+
ensure
|
354
|
+
|
355
|
+
# ensure that timeout thread is terminated
|
356
|
+
timeout_thread.kill if timeout_thread and timeout_thread.alive?
|
357
|
+
|
358
|
+
@socket_sent_bytes += data.size
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
=end
|
232
363
|
|
233
364
|
end
|
234
365
|
|
235
366
|
# enable hooking for performance measurement & debug logging
|
236
|
-
|
367
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
237
368
|
|
238
369
|
end # SutAdapter
|
239
370
|
|