5
5
from test .ClientServerTest import ClientServerTest
6
6
import time
7
7
8
+
8
9
class TestClient (ClientServerTest ):
9
10
def __init__ (self , * args , ** kwargs ):
10
11
ClientServerTest .__init__ (self , * args , ** kwargs )
@@ -13,7 +14,7 @@ def test_timeout_override(self):
13
14
pass
14
15
15
16
def _test_timeout_override (self ):
16
- req = Request (service = services .TesterPresent , subfunction = 0 )
17
+ req = Request (service = services .TesterPresent , subfunction = 0 )
17
18
timeout = 0.5
18
19
try :
19
20
t1 = time .time ()
@@ -22,43 +23,43 @@ def _test_timeout_override(self):
22
23
except TimeoutException as e :
23
24
diff = time .time () - t1
24
25
self .assertGreater (diff , timeout , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
25
- self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
26
+ self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
26
27
27
28
# Server does not respond. Overall timeout is set smaller than P2 timeout. Overall timeout should trig
28
29
def test_no_response_overall_timeout (self ):
29
30
pass
30
31
31
32
def _test_no_response_overall_timeout (self ):
32
- req = Request (service = services .TesterPresent , subfunction = 0 )
33
+ req = Request (service = services .TesterPresent , subfunction = 0 )
33
34
timeout = 0.5
34
- self .udsclient .set_configs ({'request_timeout' : timeout , 'p2_timeout' : 2 , 'p2_star_timeout' :2 })
35
+ self .udsclient .set_configs ({'request_timeout' : timeout , 'p2_timeout' : 2 , 'p2_star_timeout' : 2 })
35
36
try :
36
37
t1 = time .time ()
37
38
response = self .udsclient .send_request (req )
38
39
raise Exception ('Request did not raise a TimeoutException' )
39
40
except TimeoutException as e :
40
41
diff = time .time () - t1
41
42
self .assertGreater (diff , timeout , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
42
- self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
43
+ self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
43
44
44
45
# Server does not respond. P2 timeout is smaller than overall timeout. P2 timeout should trig
45
46
def test_no_response_p2_timeout (self ):
46
47
pass
47
48
48
49
def _test_no_response_p2_timeout (self ):
49
- req = Request (service = services .TesterPresent , subfunction = 0 )
50
+ req = Request (service = services .TesterPresent , subfunction = 0 )
50
51
timeout = 0.5
51
- self .udsclient .set_configs ({'request_timeout' : 2 , 'p2_timeout' : timeout , 'p2_star_timeout' :2 })
52
+ self .udsclient .set_configs ({'request_timeout' : 2 , 'p2_timeout' : timeout , 'p2_star_timeout' : 2 })
52
53
try :
53
54
t1 = time .time ()
54
55
response = self .udsclient .send_request (req )
55
56
raise Exception ('Request did not raise a TimeoutException' )
56
57
except TimeoutException as e :
57
58
diff = time .time () - t1
58
59
self .assertGreater (diff , timeout , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
59
- self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
60
+ self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
60
61
61
- # Overall timeout is set to 0.5. Server respond "pendingResponse" for 1 sec.
62
+ # Overall timeout is set to 0.5. Server respond "pendingResponse" for 1 sec.
62
63
# Client should timeout first as we are setting respect_overall_timeout True.
63
64
def test_overall_timeout_pending_response (self ):
64
65
if not hasattr (self , 'completed' ):
@@ -71,9 +72,9 @@ def test_overall_timeout_pending_response(self):
71
72
time .sleep (0.1 )
72
73
73
74
def _test_overall_timeout_pending_response (self ):
74
- req = Request (service = services .TesterPresent , subfunction = 0 )
75
+ req = Request (service = services .TesterPresent , subfunction = 0 )
75
76
timeout = 0.5
76
- self .udsclient .set_configs ({'request_timeout' : timeout , 'p2_timeout' : 2 , 'p2_star_timeout' :2 })
77
+ self .udsclient .set_configs ({'request_timeout' : timeout , 'p2_timeout' : 2 , 'p2_star_timeout' : 2 })
77
78
try :
78
79
t1 = time .time ()
79
80
response = self .udsclient .send_request (req )
@@ -83,7 +84,7 @@ def _test_overall_timeout_pending_response(self):
83
84
self .completed = True
84
85
diff = time .time () - t1
85
86
self .assertGreater (diff , timeout , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
86
- self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
87
+ self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
87
88
88
89
# Sends 2 "pending response" response to switch to P2* timeout.
89
90
def test_p2_star_timeout (self ):
@@ -94,9 +95,9 @@ def test_p2_star_timeout(self):
94
95
self .conn .fromuserqueue .put (response .get_payload ())
95
96
96
97
def _test_p2_star_timeout (self ):
97
- req = Request (service = services .TesterPresent , subfunction = 0 )
98
+ req = Request (service = services .TesterPresent , subfunction = 0 )
98
99
timeout = 2
99
- self .udsclient .set_configs ({'request_timeout' : 5 , 'p2_timeout' : 0.5 , 'p2_star_timeout' :timeout })
100
+ self .udsclient .set_configs ({'request_timeout' : 5 , 'p2_timeout' : 0.5 , 'p2_star_timeout' : timeout })
100
101
try :
101
102
t1 = time .time ()
102
103
response = self .udsclient .send_request (req )
@@ -106,12 +107,12 @@ def _test_p2_star_timeout(self):
106
107
self .completed = True
107
108
diff = time .time () - t1
108
109
self .assertGreater (diff , timeout , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
109
- self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
110
+ self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
110
111
111
112
# send RequestCorrectlyReceived_ResponsePending responses until well beyond overall_timeout to check response
112
113
# This function is used in 2 tests:
113
114
# * checking there is a timeout when the overall_timeout is repected
114
- # * checking that the full transaction is allowed to complete with the overall_timeout is ignored
115
+ # * checking that the full transaction is allowed to complete with the overall_timeout is ignored
115
116
def RCRRP_responses (self ):
116
117
self .conn .touserqueue .get (timeout = 0.2 )
117
118
response = Response (service = services .TesterPresent , code = Response .Code .RequestCorrectlyReceived_ResponsePending )
@@ -121,15 +122,15 @@ def RCRRP_responses(self):
121
122
time .sleep (0.1 )
122
123
response = Response (service = services .TesterPresent , code = Response .Code .PositiveResponse , data = bytes (2 ))
123
124
self .conn .fromuserqueue .put (response .get_payload ())
124
-
125
+
125
126
def RCRRP_responses_check (self , respect_overall_timeout ):
126
- req = Request (service = services .TesterPresent , subfunction = 0 )
127
+ req = Request (service = services .TesterPresent , subfunction = 0 )
127
128
overall_timeout = 2.0
128
129
if not respect_overall_timeout :
129
130
overall_timeout = None
130
131
p2_star_timeout = 1.0
131
132
132
- self .udsclient .set_configs ({'request_timeout' : overall_timeout , 'p2_timeout' : 0.5 , 'p2_star_timeout' :p2_star_timeout })
133
+ self .udsclient .set_configs ({'request_timeout' : overall_timeout , 'p2_timeout' : 0.5 , 'p2_star_timeout' : p2_star_timeout })
133
134
134
135
# Record our expectation on how long the timeout wlil be
135
136
if respect_overall_timeout :
@@ -145,7 +146,7 @@ def RCRRP_responses_check(self, respect_overall_timeout):
145
146
if respect_overall_timeout :
146
147
diff = time .time () - t1
147
148
self .assertGreater (diff , timeout , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
148
- self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
149
+ self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
149
150
self .assertIsNotNone (self .udsclient .last_response , 'Client never received the PendingResponse message' )
150
151
else :
151
152
raise Exception ('Request raised a TimeoutException' )
@@ -170,15 +171,15 @@ def _test_RCRRP_no_overall_timeout(self):
170
171
def test_p2_star_timeout_overrided_by_diagnostic_session_control (self ):
171
172
self .conn .touserqueue .get (timeout = 0.2 )
172
173
self .conn .fromuserqueue .put (b"\x50 \x01 \x03 \xE8 \x00 \xC8 " ) # Respond to diagnostic session control with timeout of 2 sec
173
-
174
+
174
175
response = Response (service = services .TesterPresent , code = Response .Code .RequestCorrectlyReceived_ResponsePending )
175
176
self .conn .fromuserqueue .put (response .get_payload ())
176
177
time .sleep (0.1 )
177
178
self .conn .fromuserqueue .put (response .get_payload ())
178
179
179
180
def _test_p2_star_timeout_overrided_by_diagnostic_session_control (self ):
180
- req = Request (service = services .TesterPresent , subfunction = 0 )
181
- self .udsclient .set_configs ({'request_timeout' : 5 , 'p2_timeout' : 0.5 , 'p2_star_timeout' :1 })
181
+ req = Request (service = services .TesterPresent , subfunction = 0 )
182
+ self .udsclient .set_configs ({'request_timeout' : 5 , 'p2_timeout' : 0.5 , 'p2_star_timeout' : 1 })
182
183
self .udsclient .change_session (1 )
183
184
timeout = 2
184
185
try :
@@ -190,20 +191,19 @@ def _test_p2_star_timeout_overrided_by_diagnostic_session_control(self):
190
191
self .completed = True
191
192
diff = time .time () - t1
192
193
self .assertGreater (diff , timeout , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
193
- self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
194
+ self .assertLess (diff , timeout + 0.5 , 'Timeout raised after %.3f seconds when it should be %.3f sec' % (diff , timeout ))
194
195
195
196
def test_payload_override_literal (self ):
196
197
request = self .conn .touserqueue .get (timeout = 0.2 )
197
198
self .assertEqual (request , b'\x12 \x34 \x56 \x78 ' )
198
199
self .conn .fromuserqueue .put (b"\x7E \x00 " )
199
200
200
201
def _test_payload_override_literal (self ):
201
- req = Request (service = services .TesterPresent , subfunction = 0 )
202
+ req = Request (service = services .TesterPresent , subfunction = 0 )
202
203
with self .udsclient .payload_override (b'\x12 \x34 \x56 \x78 ' ):
203
204
response = self .udsclient .send_request (req )
204
205
self .assertEqual (response .original_payload , b'\x7E \x00 ' )
205
206
206
-
207
207
def test_payload_override_func (self ):
208
208
request = self .conn .touserqueue .get (timeout = 0.2 )
209
209
self .assertEqual (request , b'\x99 \x88 \x77 \x66 ' )
@@ -213,7 +213,16 @@ def _test_payload_override_func(self):
213
213
def func (payload ):
214
214
return b'\x99 \x88 \x77 \x66 '
215
215
216
- req = Request (service = services .TesterPresent , subfunction = 0 )
216
+ req = Request (service = services .TesterPresent , subfunction = 0 )
217
217
with self .udsclient .payload_override (func ):
218
218
response = self .udsclient .send_request (req )
219
- self .assertEqual (response .original_payload , b'\x7E \x00 ' )
219
+ self .assertEqual (response .original_payload , b'\x7E \x00 ' )
220
+
221
+ def test_request_in_response (self ):
222
+ self .conn .touserqueue .get (timeout = 0.2 )
223
+ self .conn .fromuserqueue .put (b"\x7E \x00 " )
224
+
225
+ def _test_request_in_response (self ):
226
+ req = Request (service = services .TesterPresent , subfunction = 0 )
227
+ response = self .udsclient .send_request (req )
228
+ self .assertIs (response .original_request , req )
0 commit comments