| 1 |
% Regression tests for GMLAN Scanners |
| 2 |
~ scanner |
| 3 |
|
| 4 |
+ Configuration |
| 5 |
~ conf |
| 6 |
|
| 7 |
= Imports |
| 8 |
|
| 9 |
import itertools |
| 10 |
import logging |
| 11 |
import threading |
| 12 |
import time |
| 13 |
from scapy.contrib.isotp import ISOTPMessageBuilder |
| 14 |
|
| 15 |
from test.testsocket import TestSocket, cleanup_testsockets, open_test_sockets |
| 16 |
|
| 17 |
|
| 18 |
############ |
| 19 |
############ |
| 20 |
+ Load general modules |
| 21 |
|
| 22 |
= Load contribution layer |
| 23 |
|
| 24 |
from scapy.contrib.automotive.gm.gmlan import * |
| 25 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 26 |
from scapy.contrib.automotive.gm.gmlan_scanner import * |
| 27 |
from scapy.contrib.automotive.ecu import * |
| 28 |
load_layer("can") |
| 29 |
|
| 30 |
log_automotive.setLevel(logging.DEBUG) |
| 31 |
|
| 32 |
|
| 33 |
= Define Testfunction |
| 34 |
|
| 35 |
def executeScannerInVirtualEnvironment(supported_responses, enumerators, **kwargs): |
| 36 |
tester = TestSocket(GMLAN) |
| 37 |
ecu = TestSocket(GMLAN) |
| 38 |
tester.pair(ecu) |
| 39 |
answering_machine = EcuAnsweringMachine(supported_responses=supported_responses, main_socket=ecu, basecls=GMLAN, verbose=False) |
| 40 |
def reset(): |
| 41 |
answering_machine.reset_state() |
| 42 |
sniff(timeout=0.001, opened_socket=[ecu, tester]) |
| 43 |
sim = threading.Thread(target=answering_machine, kwargs={ |
| 44 |
"timeout": 30, "stop_filter": lambda x: bytes(x) == b"\xff\xff\xff"}) |
| 45 |
sim.start() |
| 46 |
try: |
| 47 |
scanner = GMLAN_Scanner( |
| 48 |
tester, reset_handler=reset, |
| 49 |
test_cases=enumerators, timeout=0.2, retry_if_none_received=True, |
| 50 |
unittest=True, **kwargs) |
| 51 |
def scanner_thread(): |
| 52 |
for i in range(3): |
| 53 |
print("Starting scan") |
| 54 |
scanner.scan(timeout=10) |
| 55 |
if scanner.scan_completed: |
| 56 |
print("Scan completed after %d iterations" % i) |
| 57 |
return |
| 58 |
scanner_t = threading.Thread(target=scanner_thread) |
| 59 |
scanner_t.start() |
| 60 |
scanner_t.join(timeout=120) |
| 61 |
if scanner_t.is_alive(): |
| 62 |
scanner.stop_scan() |
| 63 |
finally: |
| 64 |
tester.send(Raw(b"\xff\xff\xff")) |
| 65 |
sim.join(timeout=2) |
| 66 |
assert not sim.is_alive() |
| 67 |
cleanup_testsockets() |
| 68 |
return scanner |
| 69 |
|
| 70 |
= Load packets from candump |
| 71 |
|
| 72 |
conf.contribs['CAN']['swap-bytes'] = True |
| 73 |
pkts = rdpcap(scapy_path("test/pcaps/candump_gmlan_scanner.pcap.gz")) |
| 74 |
assert len(pkts) |
| 75 |
|
| 76 |
= Create GMLAN messages from packets |
| 77 |
|
| 78 |
builder = ISOTPMessageBuilder(basecls=GMLAN, use_ext_address=False, rx_id=[0x241, 0x641]) |
| 79 |
msgs = list() |
| 80 |
|
| 81 |
for p in pkts: |
| 82 |
if p.data == b"ECURESET": |
| 83 |
msgs.append(p) |
| 84 |
else: |
| 85 |
builder.feed(p) |
| 86 |
if len(builder): |
| 87 |
msgs.append(builder.pop()) |
| 88 |
|
| 89 |
assert len(msgs) |
| 90 |
|
| 91 |
= Create ECU-Clone from packets |
| 92 |
|
| 93 |
mEcu = Ecu(logging=False, verbose=False, store_supported_responses=True) |
| 94 |
|
| 95 |
for p in msgs: |
| 96 |
if isinstance(p, CAN) and p.data == b"ECURESET": |
| 97 |
mEcu.reset() |
| 98 |
else: |
| 99 |
mEcu.update(p) |
| 100 |
|
| 101 |
assert len(mEcu.supported_responses) |
| 102 |
|
| 103 |
= Test GMLAN_SAEnumerator evaluate_response |
| 104 |
|
| 105 |
e = GMLAN_SAEnumerator() |
| 106 |
|
| 107 |
config = {} |
| 108 |
|
| 109 |
s = EcuState(session=1) |
| 110 |
|
| 111 |
debug_dissector_backup = conf.debug_dissector |
| 112 |
|
| 113 |
# This tests involves corrupted Packets, therefore we need to disable the debug_dissector |
| 114 |
conf.debug_dissector = False |
| 115 |
|
| 116 |
assert False == e._evaluate_response(s, GMLAN(b"\x27\x01"), None, **config) |
| 117 |
config = {"exit_if_service_not_supported": True} |
| 118 |
assert not e._retry_pkt[s] |
| 119 |
assert True == e._evaluate_response(s, GMLAN(b"\x27\x01"), GMLAN(b"\x7f\x27\x11"), **config) |
| 120 |
assert not e._retry_pkt[s] |
| 121 |
assert True == e._evaluate_response(s, GMLAN(b"\x27\x01"), GMLAN(b"\x7f\x27\x22"), **config) |
| 122 |
assert e._retry_pkt[s] == GMLAN(b"\x27\x01") |
| 123 |
assert False == e._evaluate_response(s, GMLAN(b"\x27\x02"), GMLAN(b"\x7f\x27\x22"), **config) |
| 124 |
assert not e._retry_pkt[s] |
| 125 |
assert True == e._evaluate_response(s, GMLAN(b"\x27\x01"), GMLAN(b"\x7f\x27\x37"), **config) |
| 126 |
assert e._retry_pkt[s] == GMLAN(b"\x27\x01") |
| 127 |
assert False == e._evaluate_response(s, GMLAN(b"\x27\x01"), GMLAN(b"\x7f\x27\x37"), **config) |
| 128 |
assert not e._retry_pkt[s] |
| 129 |
assert True == e._evaluate_response(s, GMLAN(b"\x27\x01"), GMLAN(b"\x67\x01ab"), **config) |
| 130 |
assert not e._retry_pkt[s] |
| 131 |
assert False == e._evaluate_response(s, GMLAN(b"\x27\x01"), GMLAN(b"\x67\x02ab"), **config) |
| 132 |
assert not e._retry_pkt[s] |
| 133 |
conf.debug_dissector = debug_dissector_backup |
| 134 |
|
| 135 |
|
| 136 |
= Simulate ECU and run Scanner |
| 137 |
|
| 138 |
def securityAccess_Algorithm1(seed): |
| 139 |
return 0x5F51 |
| 140 |
|
| 141 |
keyfunction = securityAccess_Algorithm1 |
| 142 |
|
| 143 |
scanner = executeScannerInVirtualEnvironment( |
| 144 |
mEcu.supported_responses, |
| 145 |
[GMLAN_IDOEnumerator, GMLAN_PMEnumerator, GMLAN_RDEnumerator, GMLAN_SAEnumerator], |
| 146 |
GMLAN_SAEnumerator_kwargs={"keyfunction": keyfunction, "scan_range": range(2)}, |
| 147 |
GMLAN_PMEnumerator_kwargs={"unittest": True}) |
| 148 |
|
| 149 |
assert len(scanner.state_paths) == 9 |
| 150 |
assert scanner.scan_completed |
| 151 |
|
| 152 |
assert EcuState(session=1) in scanner.final_states |
| 153 |
assert EcuState(session=1, security_level=2) in scanner.final_states |
| 154 |
assert EcuState(session=3, tp=1) in scanner.final_states |
| 155 |
assert EcuState(session=2, tp=1, communication_control=1) in scanner.final_states |
| 156 |
assert EcuState(session=2, tp=1, communication_control=1, security_level=2) in scanner.final_states |
| 157 |
assert EcuState(session=3, tp=1, security_level=2) in scanner.final_states |
| 158 |
assert EcuState(session=2, tp=1, communication_control=1, security_level=2, request_download=1) in scanner.final_states |
| 159 |
|
| 160 |
= Simulate ECU and test GMLAN_RDBIEnumerator |
| 161 |
|
| 162 |
resps = [EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=1)/Raw(b"asdfbeef1")]), |
| 163 |
EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=2)/Raw(b"beef2")]), |
| 164 |
EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=3)/Raw(b"beef3")]), |
| 165 |
EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=0xff)/Raw(b"beefff")]), |
| 166 |
EcuResponse(None, [GMLAN()/GMLAN_NR(returnCode="SubFunctionNotSupported", requestServiceId="ReadDataByIdentifier")])] |
| 167 |
|
| 168 |
es = [GMLAN_RDBIEnumerator] |
| 169 |
|
| 170 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 171 |
|
| 172 |
assert scanner.scan_completed |
| 173 |
tc = scanner.configuration.test_cases[0] |
| 174 |
|
| 175 |
assert len(tc.results_without_response) < 10 |
| 176 |
if tc.results_without_response: |
| 177 |
tc.show() |
| 178 |
|
| 179 |
|
| 180 |
assert len(tc.results_with_negative_response) == 256 - 4 |
| 181 |
assert len(tc.results_with_positive_response) == 4 |
| 182 |
assert len(tc.scanned_states) == 1 |
| 183 |
|
| 184 |
result = tc.show(dump=True) |
| 185 |
|
| 186 |
assert "asdfbeef1" in result |
| 187 |
assert "beef2" in result |
| 188 |
assert "beef3" in result |
| 189 |
assert "beefff" in result |
| 190 |
assert "SubFunctionNotSupported received" in result |
| 191 |
|
| 192 |
ids = [t.req.dataIdentifier for t in tc.results_with_positive_response] |
| 193 |
|
| 194 |
assert 1 in ids |
| 195 |
assert 2 in ids |
| 196 |
assert 3 in ids |
| 197 |
assert 0xff in ids |
| 198 |
|
| 199 |
|
| 200 |
= Simulate ECU and test GMLAN_WDBIEnumerator |
| 201 |
|
| 202 |
def wdbi_handler(resp, req): |
| 203 |
if req.service != 0x3b: |
| 204 |
return False |
| 205 |
assert req.dataIdentifier in [1, 2, 3, 0xff] |
| 206 |
resp.dataIdentifier = req.dataIdentifier |
| 207 |
if req.dataIdentifier == 1: |
| 208 |
assert req.dataRecord == b'asdfbeef1' |
| 209 |
return True |
| 210 |
if req.dataIdentifier == 2: |
| 211 |
assert req.dataRecord == b'beef2' |
| 212 |
return True |
| 213 |
if req.dataIdentifier == 3: |
| 214 |
assert req.dataRecord == b"beef3" |
| 215 |
return True |
| 216 |
if req.dataIdentifier == 0xff: |
| 217 |
assert req.dataRecord == b"beefff" |
| 218 |
return True |
| 219 |
return False |
| 220 |
|
| 221 |
resps = [EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=1)/Raw(b"asdfbeef1")]), |
| 222 |
EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=2)/Raw(b"beef2")]), |
| 223 |
EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=3)/Raw(b"beef3")]), |
| 224 |
EcuResponse(None, [GMLAN()/GMLAN_RDBIPR(dataIdentifier=0xff)/Raw(b"beefff")]), |
| 225 |
EcuResponse(None, [GMLAN()/GMLAN_WDBIPR()], answers=wdbi_handler), |
| 226 |
EcuResponse(None, [GMLAN()/GMLAN_NR(returnCode="SubFunctionNotSupported", requestServiceId="ReadDataByIdentifier")])] |
| 227 |
|
| 228 |
es = [GMLAN_WDBISelectiveEnumerator] |
| 229 |
|
| 230 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 231 |
|
| 232 |
assert scanner.scan_completed |
| 233 |
tc = scanner.configuration.test_cases[0][0] |
| 234 |
|
| 235 |
assert len(tc.results_without_response) < 10 |
| 236 |
if tc.results_without_response: |
| 237 |
tc.show() |
| 238 |
|
| 239 |
|
| 240 |
assert len(tc.results_with_negative_response) == 256 - 4 |
| 241 |
assert len(tc.results_with_positive_response) == 4 |
| 242 |
assert len(tc.scanned_states) == 1 |
| 243 |
|
| 244 |
result = tc.show(dump=True) |
| 245 |
|
| 246 |
assert "asdfbeef1" in result |
| 247 |
assert "beef2" in result |
| 248 |
assert "beef3" in result |
| 249 |
assert "beefff" in result |
| 250 |
assert "SubFunctionNotSupported received" in result |
| 251 |
|
| 252 |
ids = [t.req.dataIdentifier for t in tc.results_with_positive_response] |
| 253 |
|
| 254 |
assert 1 in ids |
| 255 |
assert 2 in ids |
| 256 |
assert 3 in ids |
| 257 |
assert 0xff in ids |
| 258 |
|
| 259 |
######################### WDBI ############################# |
| 260 |
tc = scanner.configuration.test_cases[0][1] |
| 261 |
|
| 262 |
assert len(tc.results_without_response) < 10 |
| 263 |
if tc.results_without_response: |
| 264 |
tc.show() |
| 265 |
|
| 266 |
|
| 267 |
assert len(tc.results_with_negative_response) == 0 |
| 268 |
assert len(tc.results_with_positive_response) == 4 |
| 269 |
assert len(tc.scanned_states) == 1 |
| 270 |
|
| 271 |
result = tc.show(dump=True) |
| 272 |
|
| 273 |
ids = [t.req.dataIdentifier for t in tc.results_with_positive_response] |
| 274 |
|
| 275 |
assert 1 in ids |
| 276 |
assert 2 in ids |
| 277 |
assert 3 in ids |
| 278 |
assert 0xff in ids |
| 279 |
|
| 280 |
|
| 281 |
= Simulate ECU and test GMLAN_RDBPIEnumerator |
| 282 |
|
| 283 |
resps = [EcuResponse(None, [GMLAN()/GMLAN_RDBPIPR(parameterIdentifier=1)/Raw(b"asdfbeef1")]), |
| 284 |
EcuResponse(None, [GMLAN()/GMLAN_RDBPIPR(parameterIdentifier=2)/Raw(b"asdfbeef2")]), |
| 285 |
EcuResponse(None, [GMLAN()/GMLAN_RDBPIPR(parameterIdentifier=3)/Raw(b"beef3")]), |
| 286 |
EcuResponse(None, [GMLAN()/GMLAN_RDBPIPR(parameterIdentifier=0xffff)/Raw(b"beefffff")]), |
| 287 |
EcuResponse(None, [GMLAN()/GMLAN_NR(returnCode="SubFunctionNotSupported", requestServiceId="ReadDataByParameterIdentifier")])] |
| 288 |
|
| 289 |
es = [GMLAN_RDBPIEnumerator] |
| 290 |
|
| 291 |
scanner = executeScannerInVirtualEnvironment(resps, es, GMLAN_RDBPIEnumerator_kwargs={"scan_range":list(range(0x100)) + list(range(0xff00, 0x10000))}) |
| 292 |
|
| 293 |
assert scanner.scan_completed |
| 294 |
tc = scanner.configuration.test_cases[0] |
| 295 |
|
| 296 |
assert len(tc.results_without_response) < 10 |
| 297 |
if tc.results_without_response: |
| 298 |
tc.show() |
| 299 |
|
| 300 |
|
| 301 |
assert len(tc.results_with_negative_response) == 0x200 - 4 |
| 302 |
assert len(tc.results_with_positive_response) == 4 |
| 303 |
assert len(tc.scanned_states) == 1 |
| 304 |
|
| 305 |
result = tc.show(dump=True) |
| 306 |
|
| 307 |
assert "asdfbeef1" in result |
| 308 |
assert "asdfbeef2" in result |
| 309 |
assert "beef3" in result |
| 310 |
assert "beefffff" in result |
| 311 |
assert "SubFunctionNotSupported received" in result |
| 312 |
|
| 313 |
ids = [t.req.identifiers[0] for t in tc.results_with_positive_response] |
| 314 |
|
| 315 |
assert 1 in ids |
| 316 |
assert 2 in ids |
| 317 |
assert 3 in ids |
| 318 |
assert 0xffff in ids |
| 319 |
|
| 320 |
= Simulate ECU and test GMLAN_TPEnumerator |
| 321 |
|
| 322 |
resps = [EcuResponse(None, [GMLAN(service=0x7e)])] |
| 323 |
|
| 324 |
es = [GMLAN_TPEnumerator] |
| 325 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 326 |
|
| 327 |
assert scanner.scan_completed |
| 328 |
tc = scanner.configuration.test_cases[0] |
| 329 |
|
| 330 |
assert len(tc.results_without_response) < 10 |
| 331 |
if tc.results_without_response: |
| 332 |
tc.show() |
| 333 |
|
| 334 |
|
| 335 |
assert len(tc.results_with_negative_response) == 0 |
| 336 |
assert len(tc.results_with_positive_response) == 2 |
| 337 |
assert len(tc.scanned_states) == 2 |
| 338 |
|
| 339 |
|
| 340 |
= Simulate ECU and test GMLAN_DCEnumerator |
| 341 |
|
| 342 |
resps = [EcuResponse(None, [GMLAN()/GMLAN_DCPR(CPIDNumber=1)]), |
| 343 |
EcuResponse(None, [GMLAN()/GMLAN_DCPR(CPIDNumber=2)]), |
| 344 |
EcuResponse(None, [GMLAN()/GMLAN_DCPR(CPIDNumber=3)/Raw(b"beef3")]), |
| 345 |
EcuResponse(None, [GMLAN()/GMLAN_DCPR(CPIDNumber=0xff)/Raw(b"beefff")]), |
| 346 |
EcuResponse(None, [GMLAN()/GMLAN_NR(returnCode="SubFunctionNotSupported", requestServiceId="DeviceControl")])] |
| 347 |
|
| 348 |
es = [GMLAN_DCEnumerator] |
| 349 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 350 |
|
| 351 |
assert scanner.scan_completed |
| 352 |
tc = scanner.configuration.test_cases[0] |
| 353 |
|
| 354 |
assert len(tc.results_without_response) < 10 |
| 355 |
if tc.results_without_response: |
| 356 |
tc.show() |
| 357 |
|
| 358 |
|
| 359 |
assert len(tc.results_with_negative_response) == 256 - 4 |
| 360 |
assert len(tc.results_with_positive_response) == 4 |
| 361 |
assert len(tc.scanned_states) == 1 |
| 362 |
|
| 363 |
ids = [t.req.CPIDNumber for t in tc.results_with_positive_response] |
| 364 |
|
| 365 |
assert 1 in ids |
| 366 |
assert 2 in ids |
| 367 |
assert 3 in ids |
| 368 |
assert 255 in ids |
| 369 |
|
| 370 |
result = tc.show(dump=True) |
| 371 |
|
| 372 |
assert "SubFunctionNotSupported received " in result |
| 373 |
|
| 374 |
= Simulate ECU and test GMLAN_TDEnumerator |
| 375 |
|
| 376 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 377 |
|
| 378 |
positive_responses_left = 4 |
| 379 |
|
| 380 |
def answers_td(resp, req): |
| 381 |
global positive_responses_left |
| 382 |
if req.service != 0x36: |
| 383 |
return False |
| 384 |
if not positive_responses_left: |
| 385 |
return False |
| 386 |
positive_responses_left -= 1 |
| 387 |
resp.service = 0x76 |
| 388 |
return True |
| 389 |
|
| 390 |
resps = [EcuResponse(None, [GMLAN(service="TransferDataPositiveResponse")], answers=answers_td), |
| 391 |
EcuResponse(None, [GMLAN()/GMLAN_NR(returnCode="RequestOutOfRange", requestServiceId="TransferData")])] |
| 392 |
|
| 393 |
es = [GMLAN_TDEnumerator] |
| 394 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 395 |
|
| 396 |
assert scanner.scan_completed |
| 397 |
tc = scanner.configuration.test_cases[0] |
| 398 |
|
| 399 |
assert len(tc.results_without_response) < 10 |
| 400 |
if tc.results_without_response: |
| 401 |
tc.show() |
| 402 |
|
| 403 |
|
| 404 |
assert len(tc.results_with_negative_response) == 0x1ff - 4 |
| 405 |
assert len(tc.results_with_positive_response) == 4 |
| 406 |
assert len(tc.scanned_states) == 1 |
| 407 |
|
| 408 |
result = tc.show(dump=True) |
| 409 |
|
| 410 |
assert "RequestOutOfRange received " in result |
| 411 |
|
| 412 |
= Simulate ECU and test GMLAN_RMBAEnumerator 1 |
| 413 |
~ not_pypy |
| 414 |
|
| 415 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 2 |
| 416 |
|
| 417 |
memory = dict() |
| 418 |
|
| 419 |
mem_areas = [(0x100, 0x1f00), (0xd000, 0xff00), (0xa000, 0xc000), (0x3000, 0x5f00)] |
| 420 |
|
| 421 |
mem_ranges = [range(s, e) for s, e in mem_areas] |
| 422 |
|
| 423 |
mem_inner_borders = [s for s, _ in mem_areas] |
| 424 |
mem_inner_borders += [e - 1 for _, e in mem_areas] |
| 425 |
|
| 426 |
mem_outer_borders = [s - 1 for s, _ in mem_areas] |
| 427 |
mem_outer_borders += [e for _, e in mem_areas] |
| 428 |
|
| 429 |
mem_random_test_points = [] |
| 430 |
for _ in range(100): |
| 431 |
mem_random_test_points += [random.choice(list(itertools.chain(*mem_ranges)))] |
| 432 |
|
| 433 |
for addr in itertools.chain(*mem_ranges): |
| 434 |
memory[addr] = addr & 0xff |
| 435 |
|
| 436 |
def answers_rmba(resp, req): |
| 437 |
global memory |
| 438 |
if req.service != 0x23: |
| 439 |
return False |
| 440 |
if req.memoryAddress not in memory.keys(): |
| 441 |
return False |
| 442 |
out_mem = list() |
| 443 |
for i in range(req.memoryAddress, req.memoryAddress + req.memorySize): |
| 444 |
try: |
| 445 |
out_mem.append(memory[i]) |
| 446 |
except KeyError: |
| 447 |
pass |
| 448 |
resp.memoryAddress = req.memoryAddress |
| 449 |
resp.dataRecord = bytes(out_mem) |
| 450 |
return True |
| 451 |
|
| 452 |
resps = [EcuResponse(None, [GMLAN()/GMLAN_RMBAPR(memoryAddress=0, dataRecord=b'')], answers=answers_rmba), |
| 453 |
EcuResponse(None, [GMLAN()/GMLAN_NR(returnCode="RequestOutOfRange", requestServiceId="ReadMemoryByAddress")])] |
| 454 |
|
| 455 |
####################################################### |
| 456 |
scanner = executeScannerInVirtualEnvironment(resps, [GMLAN_RMBAEnumerator]) |
| 457 |
|
| 458 |
assert scanner.scan_completed |
| 459 |
tc1 = scanner.configuration.test_cases[0] |
| 460 |
|
| 461 |
assert len(tc1.results_without_response) < 10 |
| 462 |
assert len(tc1.results_with_negative_response) > 10 |
| 463 |
assert len(tc1.results_with_positive_response) > 50 |
| 464 |
assert len(tc1.scanned_states) == 1 |
| 465 |
|
| 466 |
result = tc1.show(dump=True) |
| 467 |
|
| 468 |
assert "RequestOutOfRange received " in result |
| 469 |
|
| 470 |
|
| 471 |
def _get_memory_addresses_from_results(results): |
| 472 |
mem_areas = [ |
| 473 |
range(tup.req.memoryAddress, tup.req.memoryAddress + tup.req.memorySize) |
| 474 |
for tup in results] |
| 475 |
return set(list(itertools.chain.from_iterable(mem_areas))) |
| 476 |
|
| 477 |
############################################################ |
| 478 |
|
| 479 |
addrs = _get_memory_addresses_from_results(tc1.results_with_positive_response) |
| 480 |
|
| 481 |
print([tp in addrs for tp in mem_inner_borders].count(True) / len(mem_inner_borders)) |
| 482 |
assert [tp in addrs for tp in mem_inner_borders].count(True) / len(mem_inner_borders) > 0.8 |
| 483 |
print([tp in addrs for tp in mem_random_test_points].count(True) / len(mem_random_test_points)) |
| 484 |
assert [tp in addrs for tp in mem_random_test_points].count(True) / len(mem_random_test_points) > 0.8 |
| 485 |
print([tp not in addrs for tp in mem_outer_borders].count(True) / len(mem_outer_borders)) |
| 486 |
assert [tp not in addrs for tp in mem_outer_borders].count(True) / len(mem_outer_borders) > 0.8 |
| 487 |
|
| 488 |
|
| 489 |
= Simulate ECU and test GMLAN_RMBAEnumerator 2 |
| 490 |
* This test takes very long to execute |
| 491 |
|
| 492 |
~ disabled |
| 493 |
|
| 494 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 3 |
| 495 |
|
| 496 |
memory = dict() |
| 497 |
|
| 498 |
for addr in itertools.chain(range(0x10000), range(0xf00000, 0xf0f000)): |
| 499 |
memory[addr] = addr & 0xff |
| 500 |
|
| 501 |
resps = [EcuResponse(None, [GMLAN()/GMLAN_RMBAPR(memoryAddress=0, dataRecord=b'')], answers=answers_rmba), |
| 502 |
EcuResponse(None, [GMLAN()/GMLAN_NR(returnCode="RequestOutOfRange", requestServiceId="ReadMemoryByAddress")])] |
| 503 |
|
| 504 |
scanner = executeScannerInVirtualEnvironment(resps, [GMLAN_RMBAEnumerator]) |
| 505 |
|
| 506 |
assert scanner.scan_completed |
| 507 |
tc = scanner.configuration.test_cases[0] |
| 508 |
|
| 509 |
assert len(tc.results_without_response) < 10 |
| 510 |
if tc.results_without_response: |
| 511 |
tc.show() |
| 512 |
|
| 513 |
|
| 514 |
assert len(tc.results_with_negative_response) > 350 |
| 515 |
assert len(tc.results_with_positive_response) > 50 |
| 516 |
assert len(tc.scanned_states) == 1 |
| 517 |
|
| 518 |
addrs = [t.req.memoryAddress for t in tc.results_with_positive_response] |
| 519 |
|
| 520 |
assert 0 in addrs |
| 521 |
assert 0x10 in addrs |
| 522 |
assert 0xf0 in addrs |
| 523 |
assert 0x3000 in addrs |
| 524 |
assert 0x3090 in addrs |
| 525 |
assert 0xa100 in addrs |
| 526 |
assert 0xa1f0 in addrs |
| 527 |
assert 0xa200 in addrs |
| 528 |
assert 0xa2f0 in addrs |
| 529 |
assert 0xf000 in addrs |
| 530 |
assert 0xf0f0 in addrs |
| 531 |
|
| 532 |
result = tc.show(dump=True) |
| 533 |
|
| 534 |
assert "RequestOutOfRange received " in result |
| 535 |
|
| 536 |
+ Cleanup |
| 537 |
|
| 538 |
= Delete TestSockets |
| 539 |
|
| 540 |
cleanup_testsockets() |