@@ -30,7 +30,7 @@ conf.debug_dissector = False
3030
3131= Define Testfunction
3232
33- def executeScannerInVirtualEnvironment(supported_responses, enumerators, unstable_socket=True, **kwargs):
33+ def executeScannerInVirtualEnvironment(supported_responses, enumerators, unstable_socket=True, software_reset=False, **kwargs):
3434 tester_obj_pipe = ObjectPipe(name="TesterPipe")
3535 ecu_obj_pipe = ObjectPipe(name="ECUPipe")
3636 TesterSocket = UnstableSocket if unstable_socket else TestSocket
@@ -58,11 +58,26 @@ def executeScannerInVirtualEnvironment(supported_responses, enumerators, unstabl
5858 sim = threading.Thread(target=answering_machine_thread)
5959 try:
6060 sim.start()
61- scanner = UDS_Scanner(
62- tester, reset_handler=reset, reconnect_handler=reconnect,
63- test_cases=enumerators, timeout=0.1,
64- retry_if_none_received=True, unittest=True,
65- **kwargs)
61+ if software_reset:
62+ scanner = UDS_Scanner(
63+ tester,
64+ software_reset_handler=uds_software_reset,
65+ reconnect_handler=reconnect,
66+ test_cases=enumerators,
67+ timeout=0.1,
68+ retry_if_none_received=True,
69+ unittest=True,
70+ **kwargs)
71+ else:
72+ scanner = UDS_Scanner(
73+ tester,
74+ reset_handler=reset,
75+ reconnect_handler=reconnect,
76+ test_cases=enumerators,
77+ timeout=0.1,
78+ retry_if_none_received=True,
79+ unittest=True,
80+ **kwargs)
6681 for i in range(12):
6782 print("Starting scan")
6883 scanner.scan(timeout=10)
@@ -258,6 +273,170 @@ assert "serviceNotSupported received 75 times" in result
258273assert "serviceNotSupportedInActiveSession received 19 times" in result
259274assert "securityAccessDenied received 2 times" in result
260275
276+ = Simulate ECU and run Scanner with software resert
277+
278+ responses = ([EcuResponse(None, [UDS()/UDS_DSCPR(b"\x01")])]
279+ + mEcu.supported_responses)
280+
281+ scanner = executeScannerInVirtualEnvironment(
282+ responses,
283+ [UDS_SA_XOR_Enumerator, UDS_DSCEnumerator, UDS_ServiceEnumerator],
284+ software_reset=True,
285+ UDS_DSCEnumerator_kwargs={"scan_range": range(5), "delay_state_change": 0,
286+ "overwrite_timeout": False},
287+ UDS_SA_XOR_Enumerator_kwargs={"scan_range": range(5)},
288+ UDS_ServiceEnumerator_kwargs={"scan_range": [0x10, 0x11, 0x14, 0x19, 0x22,
289+ 0x23, 0x24, 0x27, 0x28, 0x29,
290+ 0x2A, 0x2C, 0x2E, 0x2F, 0x31,
291+ 0x34, 0x35, 0x36, 0x37, 0x38,
292+ 0x3D, 0x3E, 0x83, 0x84, 0x85,
293+ 0x87],
294+ "request_length": 1})
295+
296+ scanner.show_testcases()
297+ scanner.show_testcases_status()
298+ assert len(scanner.state_paths) == 6
299+ assert scanner.scan_completed
300+ assert scanner.progress() > 0.95
301+
302+ assert EcuState(session=1) in scanner.final_states
303+ assert EcuState(session=2, tp=1) in scanner.final_states
304+ assert EcuState(session=1, tp=1) in scanner.final_states
305+ assert EcuState(session=3, tp=1) in scanner.final_states
306+ assert EcuState(session=2, tp=1, security_level=2) in scanner.final_states
307+ assert EcuState(session=3, tp=1, security_level=2) in scanner.final_states
308+
309+ #################### UDS_SA_XOR_Enumerator ################
310+ tc = scanner.configuration.test_cases[0]
311+
312+ assert len(tc.results_without_response) < 10
313+ if tc.results_without_response:
314+ tc.show()
315+
316+ assert len(tc.results_with_negative_response) == 24
317+ assert len(tc.results_with_positive_response) >= 6
318+ assert len(tc.scanned_states) == 6
319+
320+ result = tc.show(dump=True)
321+
322+ assert "serviceNotSupportedInActiveSession received 5 times" in result
323+ assert "incorrectMessageLengthOrInvalidFormat received 14 times" in result
324+
325+ ################# UDS_DSCEnumerator #####################
326+ tc = scanner.configuration.test_cases[1]
327+
328+ assert len(tc.results_without_response) < 10
329+ if tc.results_without_response:
330+ tc.show()
331+
332+ assert len(tc.results_with_negative_response) == 17
333+ assert len(tc.results_with_positive_response) == 13
334+ assert len(tc.scanned_states) == 6
335+
336+ result = tc.show(dump=True)
337+
338+ assert "incorrectMessageLengthOrInvalidFormat received 14 times" in result
339+
340+ ###################### UDS_ServiceEnumerator ###################
341+ tc = scanner.configuration.test_cases[2]
342+
343+ assert len(tc.results_without_response) < 10
344+ if tc.results_without_response:
345+ tc.show()
346+
347+ assert len(tc.results_with_negative_response) == 156
348+ assert len(tc.results_with_positive_response) == 0
349+ assert len(tc.scanned_states) == 6
350+
351+ result = tc.show(dump=True)
352+
353+ assert "incorrectMessageLengthOrInvalidFormat received 34 times" in result
354+ assert "serviceNotSupported received 75 times" in result
355+ assert "serviceNotSupportedInActiveSession received 19 times" in result
356+ assert "securityAccessDenied received 2 times" in result
357+
358+ = Simulate ECU and run Scanner with software resert 2
359+
360+ responses = ([EcuResponse(None, [UDS()/UDS_ERPR(b"\x01")])]
361+ + mEcu.supported_responses)
362+
363+ scanner = executeScannerInVirtualEnvironment(
364+ responses,
365+ [UDS_SA_XOR_Enumerator, UDS_DSCEnumerator, UDS_ServiceEnumerator],
366+ software_reset=True,
367+ UDS_DSCEnumerator_kwargs={"scan_range": range(5), "delay_state_change": 0,
368+ "overwrite_timeout": False},
369+ UDS_SA_XOR_Enumerator_kwargs={"scan_range": range(5)},
370+ UDS_ServiceEnumerator_kwargs={"scan_range": [0x10, 0x11, 0x14, 0x19, 0x22,
371+ 0x23, 0x24, 0x27, 0x28, 0x29,
372+ 0x2A, 0x2C, 0x2E, 0x2F, 0x31,
373+ 0x34, 0x35, 0x36, 0x37, 0x38,
374+ 0x3D, 0x3E, 0x83, 0x84, 0x85,
375+ 0x87],
376+ "request_length": 1})
377+
378+ scanner.show_testcases()
379+ scanner.show_testcases_status()
380+ assert len(scanner.state_paths) == 5
381+ assert scanner.scan_completed
382+ assert scanner.progress() > 0.95
383+
384+ assert EcuState(session=1) in scanner.final_states
385+ assert EcuState(session=2, tp=1) in scanner.final_states
386+ assert EcuState(session=3, tp=1) in scanner.final_states
387+ assert EcuState(session=2, tp=1, security_level=2) in scanner.final_states
388+ assert EcuState(session=3, tp=1, security_level=2) in scanner.final_states
389+
390+ #################### UDS_SA_XOR_Enumerator ################
391+ tc = scanner.configuration.test_cases[0]
392+
393+ assert len(tc.results_without_response) < 10
394+ if tc.results_without_response:
395+ tc.show()
396+
397+ assert len(tc.results_with_negative_response) == 19
398+ assert len(tc.results_with_positive_response) >= 6
399+ assert len(tc.scanned_states) == 5
400+
401+ result = tc.show(dump=True)
402+
403+ assert "serviceNotSupportedInActiveSession received 5 times" in result
404+ assert "incorrectMessageLengthOrInvalidFormat received 14 times" in result
405+
406+ ################# UDS_DSCEnumerator #####################
407+ tc = scanner.configuration.test_cases[1]
408+
409+ assert len(tc.results_without_response) < 10
410+ if tc.results_without_response:
411+ tc.show()
412+
413+ assert len(tc.results_with_negative_response) == 20
414+ assert len(tc.results_with_positive_response) == 5
415+ assert len(tc.scanned_states) == 5
416+
417+ result = tc.show(dump=True)
418+
419+ assert "incorrectMessageLengthOrInvalidFormat received 20 times" in result
420+
421+ ###################### UDS_ServiceEnumerator ###################
422+ tc = scanner.configuration.test_cases[2]
423+
424+ assert len(tc.results_without_response) < 10
425+ if tc.results_without_response:
426+ tc.show()
427+
428+ assert len(tc.results_with_negative_response) == 130
429+ assert len(tc.results_with_positive_response) == 0
430+ assert len(tc.scanned_states) == 5
431+
432+ result = tc.show(dump=True)
433+
434+ assert "incorrectMessageLengthOrInvalidFormat received 34 times" in result
435+ assert "serviceNotSupported received 75 times" in result
436+ assert "serviceNotSupportedInActiveSession received 19 times" in result
437+ assert "securityAccessDenied received 2 times" in result
438+
439+
261440= UDS_ServiceEnumerator
262441
263442def req_handler(resp, req):
0 commit comments