| 1 |
% Regression tests for gmlanutil |
| 2 |
~ scanner |
| 3 |
|
| 4 |
+ Configuration |
| 5 |
~ conf |
| 6 |
|
| 7 |
|
| 8 |
= Imports |
| 9 |
|
| 10 |
from scapy.contrib.automotive import log_automotive |
| 11 |
from test.testsocket import TestSocket, cleanup_testsockets |
| 12 |
import logging |
| 13 |
|
| 14 |
############ |
| 15 |
############ |
| 16 |
+ Load general modules |
| 17 |
|
| 18 |
= Load contribution layer |
| 19 |
|
| 20 |
load_layer("can", globals_dict=globals()) |
| 21 |
load_contrib("automotive.gm.gmlan", globals_dict=globals()) |
| 22 |
load_contrib("automotive.gm.gmlanutils", globals_dict=globals()) |
| 23 |
|
| 24 |
log_automotive.setLevel(logging.DEBUG) |
| 25 |
|
| 26 |
= Define test sockets |
| 27 |
|
| 28 |
isotpsock2 = TestSocket(GMLAN) |
| 29 |
isotpsock = TestSocket(GMLAN) |
| 30 |
isotpsock2.pair(isotpsock) |
| 31 |
|
| 32 |
############################################################################## |
| 33 |
+ GMLAN_RequestDownload Tests |
| 34 |
############################################################################## |
| 35 |
= Positive, immediate positive response |
| 36 |
|
| 37 |
ecusimSuccessfullyExecuted = False |
| 38 |
started = threading.Event() |
| 39 |
|
| 40 |
def ecusim(): |
| 41 |
global ecusimSuccessfullyExecuted |
| 42 |
ecusimSuccessfullyExecuted= True |
| 43 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 44 |
pkt = GMLAN()/GMLAN_RD(memorySize=4) |
| 45 |
if bytes(requ[0]) != bytes(pkt): |
| 46 |
ecusimSuccessfullyExecuted = False |
| 47 |
else: |
| 48 |
ecusimSuccessfullyExecuted = True |
| 49 |
ack = b"\x74" |
| 50 |
isotpsock2.send(ack) |
| 51 |
|
| 52 |
thread = threading.Thread(target=ecusim) |
| 53 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 54 |
thread.start() |
| 55 |
started.wait(timeout=5) |
| 56 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=1) == True |
| 57 |
thread.join(timeout=5) |
| 58 |
|
| 59 |
assert res |
| 60 |
assert ecusimSuccessfullyExecuted == True |
| 61 |
|
| 62 |
= Negative, immediate negative response |
| 63 |
|
| 64 |
started = threading.Event() |
| 65 |
def ecusim(): |
| 66 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 67 |
nr = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x22) |
| 68 |
isotpsock2.send(nr) |
| 69 |
|
| 70 |
thread = threading.Thread(target=ecusim) |
| 71 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 72 |
thread.start() |
| 73 |
started.wait(timeout=5) |
| 74 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=1) == False |
| 75 |
thread.join(timeout=5) |
| 76 |
assert res |
| 77 |
|
| 78 |
= Negative, timeout |
| 79 |
assert GMLAN_RequestDownload(isotpsock, 4, timeout=0.01) == False |
| 80 |
|
| 81 |
############################ Response pending |
| 82 |
= Positive, after response pending |
| 83 |
started = threading.Event() |
| 84 |
|
| 85 |
def ecusim(): |
| 86 |
isotpsock2.sniff(count=1, timeout=2, started_callback=started.set) |
| 87 |
pending = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x78) |
| 88 |
isotpsock2.send(pending) |
| 89 |
ack = b"\x74" |
| 90 |
isotpsock2.send(ack) |
| 91 |
|
| 92 |
thread = threading.Thread(target=ecusim) |
| 93 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 94 |
thread.start() |
| 95 |
started.wait(timeout=5) |
| 96 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=2) == True |
| 97 |
thread.join(timeout=5) |
| 98 |
assert res |
| 99 |
|
| 100 |
= Positive, hold response pending for several messages |
| 101 |
tout = 0.1 |
| 102 |
repeats = 4 |
| 103 |
started = threading.Event() |
| 104 |
|
| 105 |
def ecusim(): |
| 106 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 107 |
ack = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x78) |
| 108 |
for i in range(repeats): |
| 109 |
isotpsock2.send(ack) |
| 110 |
time.sleep(tout) |
| 111 |
ack = b"\x74" |
| 112 |
isotpsock2.send(ack) |
| 113 |
|
| 114 |
thread = threading.Thread(target=ecusim) |
| 115 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 116 |
thread.start() |
| 117 |
started.wait(timeout=5) |
| 118 |
starttime = time.time() # may be inaccurate -> on some systems only seconds precision |
| 119 |
result = GMLAN_RequestDownload(isotpsock, 4, timeout=repeats*tout+0.5) |
| 120 |
endtime = time.time() + 1 |
| 121 |
thread.join(timeout=5) |
| 122 |
assert result |
| 123 |
print(endtime - starttime) |
| 124 |
print(tout * (repeats - 1)) |
| 125 |
assert (endtime - starttime) >= tout * (repeats - 1) |
| 126 |
|
| 127 |
|
| 128 |
= Negative, negative response after response pending |
| 129 |
started = threading.Event() |
| 130 |
def ecusim(): |
| 131 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 132 |
pending = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x78) |
| 133 |
isotpsock2.send(pending) |
| 134 |
nr = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x22) |
| 135 |
isotpsock2.send(nr) |
| 136 |
|
| 137 |
thread = threading.Thread(target=ecusim) |
| 138 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 139 |
thread.start() |
| 140 |
started.wait(timeout=5) |
| 141 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=0.1) == False |
| 142 |
thread.join(timeout=5) |
| 143 |
assert res |
| 144 |
|
| 145 |
|
| 146 |
= Negative, timeout after response pending |
| 147 |
started = threading.Event() |
| 148 |
def ecusim(): |
| 149 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 150 |
pending = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x78) |
| 151 |
isotpsock2.send(pending) |
| 152 |
|
| 153 |
thread = threading.Thread(target=ecusim) |
| 154 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 155 |
thread.start() |
| 156 |
started.wait(timeout=5) |
| 157 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=0.1) == False |
| 158 |
thread.join(timeout=5) |
| 159 |
assert res |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
= Positive, pending message from different service interferes while pending |
| 164 |
started = threading.Event() |
| 165 |
def ecusim(): |
| 166 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 167 |
pending = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x78) |
| 168 |
isotpsock2.send(pending) |
| 169 |
wrongservice = GMLAN()/GMLAN_NR(requestServiceId=0x36, returnCode=0x78) |
| 170 |
isotpsock2.send(wrongservice) |
| 171 |
isotpsock2.send(pending) |
| 172 |
ack = b"\x74" |
| 173 |
isotpsock2.send(ack) |
| 174 |
|
| 175 |
thread = threading.Thread(target=ecusim) |
| 176 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 177 |
thread.start() |
| 178 |
started.wait(timeout=5) |
| 179 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=0.1) == True |
| 180 |
thread.join(timeout=5) |
| 181 |
assert res |
| 182 |
|
| 183 |
= Positive, negative response from different service interferes while pending |
| 184 |
started = threading.Event() |
| 185 |
|
| 186 |
def ecusim(): |
| 187 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 188 |
pending = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x78) |
| 189 |
isotpsock2.send(pending) |
| 190 |
wrongservice = GMLAN()/GMLAN_NR(requestServiceId=0x36, returnCode=0x22) |
| 191 |
isotpsock2.send(wrongservice) |
| 192 |
isotpsock2.send(pending) |
| 193 |
ack = b"\x74" |
| 194 |
isotpsock2.send(ack) |
| 195 |
|
| 196 |
thread = threading.Thread(target=ecusim) |
| 197 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 198 |
thread.start() |
| 199 |
started.wait(timeout=5) |
| 200 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=0.1) == True |
| 201 |
thread.join(timeout=5) |
| 202 |
assert res |
| 203 |
|
| 204 |
################### RETRY |
| 205 |
= Positive, first: immediate negative response, retry: Positive |
| 206 |
started = threading.Event() |
| 207 |
def ecusim(): |
| 208 |
global ecusimSuccessfullyExecuted |
| 209 |
ecusimSuccessfullyExecuted= True |
| 210 |
# negative |
| 211 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 212 |
pkt = GMLAN()/GMLAN_RD(memorySize=4) |
| 213 |
if bytes(requ[0]) != bytes(pkt): |
| 214 |
ecusimSuccessfullyExecuted = False |
| 215 |
nr = GMLAN()/GMLAN_NR(requestServiceId=0x34, returnCode=0x22) |
| 216 |
# positive retry |
| 217 |
print("retry") |
| 218 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(nr)) |
| 219 |
pkt = GMLAN()/GMLAN_RD(memorySize=4) |
| 220 |
print(requ) |
| 221 |
if bytes(requ[0]) != bytes(pkt): |
| 222 |
ecusimSuccessfullyExecuted = False |
| 223 |
ack = b"\x74" |
| 224 |
isotpsock2.send(ack) |
| 225 |
|
| 226 |
thread = threading.Thread(target=ecusim) |
| 227 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 228 |
thread.start() |
| 229 |
started.wait(timeout=5) |
| 230 |
res = GMLAN_RequestDownload(isotpsock, 4, timeout=0.1, retry=1) == True |
| 231 |
thread.join(timeout=5) |
| 232 |
assert res |
| 233 |
assert ecusimSuccessfullyExecuted == True |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
############################################################################## |
| 238 |
+ GMLAN_TransferData Tests |
| 239 |
############################################################################## |
| 240 |
= Positive, short payload, scheme = 4 |
| 241 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 242 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 243 |
ecusimSuccessfullyExecuted = True |
| 244 |
started = threading.Event() |
| 245 |
def ecusim(): |
| 246 |
global ecusimSuccessfullyExecuted |
| 247 |
ecusimSuccessfullyExecuted= True |
| 248 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 249 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x40000000, |
| 250 |
dataRecord=payload) |
| 251 |
if bytes(requ[0]) != bytes(pkt): |
| 252 |
ecusimSuccessfullyExecuted = False |
| 253 |
ack = b"\x76" |
| 254 |
isotpsock2.send(ack) |
| 255 |
|
| 256 |
thread = threading.Thread(target=ecusim) |
| 257 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 258 |
thread.start() |
| 259 |
started.wait(timeout=5) |
| 260 |
res = GMLAN_TransferData(isotpsock, 0x40000000, payload, timeout=1) == True |
| 261 |
thread.join(timeout=5) |
| 262 |
assert res |
| 263 |
assert ecusimSuccessfullyExecuted == True |
| 264 |
|
| 265 |
= Positive, short payload, scheme = 3 |
| 266 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 3 |
| 267 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 268 |
ecusimSuccessfullyExecuted = True |
| 269 |
started = threading.Event() |
| 270 |
def ecusim(): |
| 271 |
global ecusimSuccessfullyExecuted |
| 272 |
ecusimSuccessfullyExecuted= True |
| 273 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 274 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x400000, |
| 275 |
dataRecord=payload) |
| 276 |
if bytes(requ[0]) != bytes(pkt): |
| 277 |
ecusimSuccessfullyExecuted = False |
| 278 |
ack = b"\x76" |
| 279 |
isotpsock2.send(ack) |
| 280 |
|
| 281 |
thread = threading.Thread(target=ecusim) |
| 282 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 283 |
thread.start() |
| 284 |
started.wait(timeout=5) |
| 285 |
res = GMLAN_TransferData(isotpsock, 0x400000, payload, timeout=1) == True |
| 286 |
thread.join(timeout=5) |
| 287 |
assert res |
| 288 |
assert ecusimSuccessfullyExecuted == True |
| 289 |
|
| 290 |
= Positive, short payload, scheme = 2 |
| 291 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 2 |
| 292 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 293 |
ecusimSuccessfullyExecuted = True |
| 294 |
started = threading.Event() |
| 295 |
def ecusim(): |
| 296 |
global ecusimSuccessfullyExecuted |
| 297 |
ecusimSuccessfullyExecuted = True |
| 298 |
requ = isotpsock2.sniff(count=1, timeout=2, started_callback=started.set) |
| 299 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x4000, dataRecord=payload) |
| 300 |
if bytes(requ[0]) != bytes(pkt): |
| 301 |
ecusimSuccessfullyExecuted = False |
| 302 |
ack = b"\x76" |
| 303 |
isotpsock2.send(ack) |
| 304 |
|
| 305 |
thread = threading.Thread(target=ecusim) |
| 306 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 307 |
thread.start() |
| 308 |
started.wait(timeout=5) |
| 309 |
res = GMLAN_TransferData(isotpsock, 0x4000, payload, timeout=2) == True |
| 310 |
thread.join(timeout=5) |
| 311 |
assert res |
| 312 |
assert ecusimSuccessfullyExecuted == True |
| 313 |
|
| 314 |
= Negative, short payload |
| 315 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 316 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 317 |
ecusimSuccessfullyExecuted = True |
| 318 |
started = threading.Event() |
| 319 |
def ecusim(): |
| 320 |
global ecusimSuccessfullyExecuted |
| 321 |
ecusimSuccessfullyExecuted= True |
| 322 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 323 |
nr = GMLAN() / GMLAN_NR(requestServiceId=0x36, returnCode=0x22) |
| 324 |
isotpsock2.send(nr) |
| 325 |
|
| 326 |
thread = threading.Thread(target=ecusim) |
| 327 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 328 |
thread.start() |
| 329 |
started.wait(timeout=5) |
| 330 |
res = GMLAN_TransferData(isotpsock, 0x40000000, payload, timeout=1) == False |
| 331 |
thread.join(timeout=5) |
| 332 |
assert res |
| 333 |
|
| 334 |
= Negative, timeout |
| 335 |
|
| 336 |
assert GMLAN_TransferData(isotpsock, 0x4000, payload, timeout=0.1) == False |
| 337 |
|
| 338 |
|
| 339 |
= Positive, long payload |
| 340 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 341 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 342 |
ecusimSuccessfullyExecuted = True |
| 343 |
started = threading.Event() |
| 344 |
def ecusim(): |
| 345 |
global ecusimSuccessfullyExecuted |
| 346 |
ecusimSuccessfullyExecuted= True |
| 347 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 348 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x40000000, |
| 349 |
dataRecord=payload*2) |
| 350 |
if bytes(requ[0]) != bytes(pkt): |
| 351 |
ecusimSuccessfullyExecuted = False |
| 352 |
ack = b"\x76" |
| 353 |
# second package with inscreased address |
| 354 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 355 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x40000010, |
| 356 |
dataRecord=payload * 2) |
| 357 |
if bytes(requ[0]) != bytes(pkt): |
| 358 |
ecusimSuccessfullyExecuted = False |
| 359 |
ack = b"\x76" |
| 360 |
isotpsock2.send(ack) |
| 361 |
|
| 362 |
thread = threading.Thread(target=ecusim) |
| 363 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 364 |
thread.start() |
| 365 |
started.wait(timeout=5) |
| 366 |
res = GMLAN_TransferData(isotpsock, 0x40000000, payload*4, maxmsglen=16, timeout=1) == True |
| 367 |
thread.join(timeout=5) |
| 368 |
assert res |
| 369 |
assert ecusimSuccessfullyExecuted == True |
| 370 |
|
| 371 |
|
| 372 |
# |
| 373 |
= Positive, first part of payload succeeds, second pending, then fails, retry succeeds |
| 374 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 375 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 376 |
started = threading.Event() |
| 377 |
def ecusim(): |
| 378 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 379 |
ack = b"\x76" |
| 380 |
# second package with inscreased address |
| 381 |
isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 382 |
pending = GMLAN() / GMLAN_NR(requestServiceId=0x36, returnCode=0x78) |
| 383 |
isotpsock2.send(pending) |
| 384 |
nr = GMLAN() / GMLAN_NR(requestServiceId=0x36, returnCode=0x22) |
| 385 |
isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(nr)) |
| 386 |
ack = b"\x76" |
| 387 |
isotpsock2.send(ack) |
| 388 |
|
| 389 |
thread = threading.Thread(target=ecusim) |
| 390 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 391 |
thread.start() |
| 392 |
started.wait(timeout=5) |
| 393 |
res = GMLAN_TransferData(isotpsock, 0x40000000, payload*4, maxmsglen=16, timeout=0.1, retry=1) == True |
| 394 |
thread.join(timeout=5) |
| 395 |
assert res |
| 396 |
|
| 397 |
############ |
| 398 |
= Positive, maxmsglen length check -> message is split automatically |
| 399 |
|
| 400 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 401 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 402 |
ecusimSuccessfullyExecuted = True |
| 403 |
sim_started = threading.Event() |
| 404 |
def ecusim(): |
| 405 |
global ecusimSuccessfullyExecuted |
| 406 |
ecusimSuccessfullyExecuted= True |
| 407 |
requ = isotpsock2.sniff(count=1, timeout=3, started_callback=sim_started.set) |
| 408 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x40000000, |
| 409 |
dataRecord=payload*511+payload[:1]) |
| 410 |
if len(requ) == 0 or bytes(requ[0]) != bytes(pkt): |
| 411 |
ecusimSuccessfullyExecuted = False |
| 412 |
return |
| 413 |
ack = b"\x76" |
| 414 |
# second package with inscreased address |
| 415 |
requ = isotpsock2.sniff(count=1, timeout=3, started_callback=lambda: isotpsock2.send(ack)) |
| 416 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x40000FF9, |
| 417 |
dataRecord=payload[1:]) |
| 418 |
if len(requ) == 0 or bytes(requ[0]) != bytes(pkt): |
| 419 |
ecusimSuccessfullyExecuted = False |
| 420 |
return |
| 421 |
ack = b"\x76" |
| 422 |
isotpsock2.send(ack) |
| 423 |
|
| 424 |
thread = threading.Thread(target=ecusim) |
| 425 |
thread.name = "EcuSimulator" + thread.name |
| 426 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 427 |
thread.start() |
| 428 |
sim_started.wait(timeout=5) |
| 429 |
res = GMLAN_TransferData(isotpsock, 0x40000000, payload*512, maxmsglen=0x1000000, timeout=8) == True |
| 430 |
thread.join(timeout=5) |
| 431 |
assert res |
| 432 |
assert ecusimSuccessfullyExecuted == True |
| 433 |
|
| 434 |
############ Address boundary checks |
| 435 |
= Positive, highest possible address for scheme |
| 436 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 437 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 438 |
started = threading.Event() |
| 439 |
def ecusim(): |
| 440 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 441 |
ack = b"\x76" |
| 442 |
isotpsock2.send(ack) |
| 443 |
|
| 444 |
thread = threading.Thread(target=ecusim) |
| 445 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 446 |
thread.start() |
| 447 |
started.wait(timeout=5) |
| 448 |
res = GMLAN_TransferData(isotpsock, 2**32 - 1, payload, timeout=1) == True |
| 449 |
thread.join(timeout=5) |
| 450 |
assert res |
| 451 |
|
| 452 |
= Negative, invalid address (too large for addressing scheme) |
| 453 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 454 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 455 |
started = threading.Event() |
| 456 |
def ecusim(): |
| 457 |
isotpsock2.sniff(count=1, timeout=0.1, started_callback=started.set) |
| 458 |
ack = b"\x76" |
| 459 |
isotpsock2.send(ack) |
| 460 |
|
| 461 |
thread = threading.Thread(target=ecusim) |
| 462 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 463 |
thread.start() |
| 464 |
started.wait(timeout=5) |
| 465 |
res = GMLAN_TransferData(isotpsock, 2**32, payload, timeout=0.1) == False |
| 466 |
thread.join(timeout=5) |
| 467 |
assert res |
| 468 |
|
| 469 |
= Positive, address zero |
| 470 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 471 |
ecusimSuccessfullyExecuted = True |
| 472 |
started = threading.Event() |
| 473 |
def ecusim(): |
| 474 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 475 |
ack = b"\x76" |
| 476 |
isotpsock2.send(ack) |
| 477 |
|
| 478 |
thread = threading.Thread(target=ecusim) |
| 479 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 480 |
thread.start() |
| 481 |
started.wait(timeout=5) |
| 482 |
res = GMLAN_TransferData(isotpsock, 0x00, payload, timeout=1) == True |
| 483 |
thread.join(timeout=5) |
| 484 |
assert res |
| 485 |
|
| 486 |
= Negative, negative address |
| 487 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 488 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 489 |
started = threading.Event() |
| 490 |
def ecusim(): |
| 491 |
isotpsock2.sniff(count=1, timeout=0.1, started_callback=started.set) |
| 492 |
ack = b"\x76" |
| 493 |
isotpsock2.send(ack) |
| 494 |
|
| 495 |
thread = threading.Thread(target=ecusim) |
| 496 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 497 |
thread.start() |
| 498 |
started.wait(timeout=5) |
| 499 |
res = GMLAN_TransferData(isotpsock, -1, payload, timeout=0.1) == False |
| 500 |
thread.join(timeout=5) |
| 501 |
assert res |
| 502 |
|
| 503 |
############################################ |
| 504 |
+ GMLAN_TransferPayload Tests |
| 505 |
############################################ |
| 506 |
= Positive, short payload |
| 507 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 508 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 509 |
ecusimSuccessfullyExecuted = True |
| 510 |
started = threading.Event() |
| 511 |
def ecusim(): |
| 512 |
global ecusimSuccessfullyExecuted |
| 513 |
ecusimSuccessfullyExecuted= True |
| 514 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 515 |
pkt = GMLAN()/GMLAN_RD(memorySize=len(payload)) |
| 516 |
if bytes(requ[0]) != bytes(pkt): |
| 517 |
ecusimSuccessfullyExecuted = False |
| 518 |
ack = b"\x74" |
| 519 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 520 |
pkt = GMLAN() / GMLAN_TD(startingAddress=0x40000000, |
| 521 |
dataRecord=payload) |
| 522 |
if bytes(requ[0]) != bytes(pkt): |
| 523 |
ecusimSuccessfullyExecuted = False |
| 524 |
ack = b"\x76" |
| 525 |
isotpsock2.send(ack) |
| 526 |
|
| 527 |
thread = threading.Thread(target=ecusim) |
| 528 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 529 |
thread.start() |
| 530 |
started.wait(timeout=5) |
| 531 |
res = GMLAN_TransferPayload(isotpsock, 0x40000000, payload, timeout=1) == True |
| 532 |
thread.join(timeout=5) |
| 533 |
assert res |
| 534 |
assert ecusimSuccessfullyExecuted == True |
| 535 |
|
| 536 |
|
| 537 |
############################################ |
| 538 |
+ GMLAN_GetSecurityAccess Tests |
| 539 |
############################################ |
| 540 |
= KeyFunction |
| 541 |
keyfunc = lambda seed : seed - 0x1FBE |
| 542 |
|
| 543 |
= Positive scenario, level 1, tests if keyfunction applied properly |
| 544 |
ecusimSuccessfullyExecuted = True |
| 545 |
started = threading.Event() |
| 546 |
def ecusim(): |
| 547 |
global ecusimSuccessfullyExecuted |
| 548 |
ecusimSuccessfullyExecuted= True |
| 549 |
# wait for request |
| 550 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 551 |
pkt = GMLAN()/GMLAN_SA(subfunction=1) |
| 552 |
if bytes(requ[0]) != bytes(pkt): |
| 553 |
ecusimSuccessfullyExecuted = False |
| 554 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=1, securitySeed=0xdead) |
| 555 |
# wait for key |
| 556 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(seedmsg)) |
| 557 |
pkt = GMLAN()/GMLAN_SA(subfunction=2, securityKey=0xbeef) |
| 558 |
if bytes(requ[0]) != bytes(pkt): |
| 559 |
ecusimSuccessfullyExecuted = False |
| 560 |
nr = GMLAN() / GMLAN_NR(requestServiceId=0x27, returnCode=0x35) |
| 561 |
isotpsock2.send(nr) |
| 562 |
else: |
| 563 |
pr = GMLAN()/GMLAN_SAPR(subfunction=2) |
| 564 |
isotpsock2.send(pr) |
| 565 |
|
| 566 |
thread = threading.Thread(target=ecusim) |
| 567 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 568 |
thread.start() |
| 569 |
started.wait(timeout=5) |
| 570 |
res = GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=1, timeout=0.1) == True |
| 571 |
thread.join(timeout=5) |
| 572 |
assert res |
| 573 |
assert ecusimSuccessfullyExecuted == True |
| 574 |
|
| 575 |
= Positive scenario, level 3 |
| 576 |
ecusimSuccessfullyExecuted = True |
| 577 |
started = threading.Event() |
| 578 |
def ecusim(): |
| 579 |
global ecusimSuccessfullyExecuted |
| 580 |
ecusimSuccessfullyExecuted= True |
| 581 |
# wait for request |
| 582 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 583 |
pkt = GMLAN()/GMLAN_SA(subfunction=3) |
| 584 |
if bytes(requ[0]) != bytes(pkt): |
| 585 |
ecusimSuccessfullyExecuted = False |
| 586 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=3, securitySeed=0xdead) |
| 587 |
# wait for key |
| 588 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(seedmsg)) |
| 589 |
pkt = GMLAN()/GMLAN_SA(subfunction=4, securityKey=0xbeef) |
| 590 |
if bytes(requ[0]) != bytes(pkt): |
| 591 |
ecusimSuccessfullyExecuted = False |
| 592 |
nr = GMLAN() / GMLAN_NR(requestServiceId=0x27, returnCode=0x35) |
| 593 |
isotpsock2.send(nr) |
| 594 |
else: |
| 595 |
pr = GMLAN()/GMLAN_SAPR(subfunction=4) |
| 596 |
isotpsock2.send(pr) |
| 597 |
|
| 598 |
thread = threading.Thread(target=ecusim) |
| 599 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 600 |
thread.start() |
| 601 |
started.wait(timeout=5) |
| 602 |
res = GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=3, timeout=0.1) == True |
| 603 |
thread.join(timeout=5) |
| 604 |
assert res |
| 605 |
assert ecusimSuccessfullyExecuted == True |
| 606 |
|
| 607 |
|
| 608 |
= Negative scenario, invalid password |
| 609 |
ecusimSuccessfullyExecuted = True |
| 610 |
started = threading.Event() |
| 611 |
def ecusim(): |
| 612 |
global ecusimSuccessfullyExecuted |
| 613 |
ecusimSuccessfullyExecuted= True |
| 614 |
# wait for request |
| 615 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 616 |
pkt = GMLAN()/GMLAN_SA(subfunction=1) |
| 617 |
if bytes(requ[0]) != bytes(pkt): |
| 618 |
ecusimSuccessfullyExecuted = False |
| 619 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=1, securitySeed=0xdead) |
| 620 |
# wait for key |
| 621 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(seedmsg)) |
| 622 |
pkt = GMLAN()/GMLAN_SA(subfunction=2, securityKey=0xbabe) |
| 623 |
if bytes(requ[0]) != bytes(pkt): |
| 624 |
nr = GMLAN() / GMLAN_NR(requestServiceId=0x27, returnCode=0x35) |
| 625 |
isotpsock2.send(nr) |
| 626 |
else: |
| 627 |
ecusimSuccessfullyExecuted = False |
| 628 |
pr = GMLAN()/GMLAN_SAPR(subfunction=2) |
| 629 |
isotpsock2.send(pr) |
| 630 |
|
| 631 |
thread = threading.Thread(target=ecusim) |
| 632 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 633 |
thread.start() |
| 634 |
started.wait(timeout=5) |
| 635 |
res = GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=1, timeout=0.1) == False |
| 636 |
thread.join(timeout=5) |
| 637 |
assert res |
| 638 |
assert ecusimSuccessfullyExecuted == True |
| 639 |
|
| 640 |
= invalid level (not an odd number) |
| 641 |
assert GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=2, timeout=1) == False |
| 642 |
|
| 643 |
= zero seed |
| 644 |
started = threading.Event() |
| 645 |
def ecusim(): |
| 646 |
# wait for request |
| 647 |
isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 648 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=1, securitySeed=0x0000) |
| 649 |
isotpsock2.send(seedmsg) |
| 650 |
|
| 651 |
thread = threading.Thread(target=ecusim) |
| 652 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 653 |
thread.start() |
| 654 |
started.wait(timeout=5) |
| 655 |
res = GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=1, timeout=0.1) == True |
| 656 |
thread.join(timeout=5) |
| 657 |
assert res |
| 658 |
|
| 659 |
############### retry |
| 660 |
= Positive scenario, request timeout, retry works |
| 661 |
started = threading.Event() |
| 662 |
def ecusim(): |
| 663 |
# timeout |
| 664 |
requ = isotpsock2.sniff(count=1, timeout=0.1, started_callback=started.set) |
| 665 |
# wait for request |
| 666 |
requ = isotpsock2.sniff(count=1, timeout=3) |
| 667 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=1, securitySeed=0xdead) |
| 668 |
# wait for key |
| 669 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(seedmsg)) |
| 670 |
pkt = GMLAN()/GMLAN_SA(subfunction=2, securityKey=0xbeef) |
| 671 |
pr = GMLAN()/GMLAN_SAPR(subfunction=2) |
| 672 |
isotpsock2.send(pr) |
| 673 |
|
| 674 |
thread = threading.Thread(target=ecusim) |
| 675 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 676 |
thread.start() |
| 677 |
started.wait(timeout=5) |
| 678 |
res = GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=1, timeout=0.1, retry=1) == True |
| 679 |
thread.join(timeout=5) |
| 680 |
assert res |
| 681 |
|
| 682 |
= Positive scenario, keysend timeout, retry works |
| 683 |
started = threading.Event() |
| 684 |
def ecusim(): |
| 685 |
# wait for request |
| 686 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 687 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=1, securitySeed=0xdead) |
| 688 |
# timeout |
| 689 |
requ = isotpsock2.sniff(count=1, timeout=0.1, started_callback=lambda:isotpsock2.send(seedmsg)) |
| 690 |
# retry from start |
| 691 |
requ = isotpsock2.sniff(count=1, timeout=3) |
| 692 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=1, securitySeed=0xdead) |
| 693 |
# wait for key |
| 694 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(seedmsg)) |
| 695 |
pr = GMLAN()/GMLAN_SAPR(subfunction=2) |
| 696 |
isotpsock2.send(pr) |
| 697 |
|
| 698 |
thread = threading.Thread(target=ecusim) |
| 699 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 700 |
thread.start() |
| 701 |
started.wait(timeout=5) |
| 702 |
res = GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=1, timeout=0.1, retry=1) == True |
| 703 |
thread.join(timeout=5) |
| 704 |
assert res |
| 705 |
|
| 706 |
|
| 707 |
= Positive scenario, request error, retry works |
| 708 |
started = threading.Event() |
| 709 |
def ecusim(): |
| 710 |
# wait for request |
| 711 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 712 |
nr = GMLAN() / GMLAN_NR(requestServiceId=0x27, returnCode=0x37) |
| 713 |
# wait for request |
| 714 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(nr)) |
| 715 |
seedmsg = GMLAN()/GMLAN_SAPR(subfunction=1, securitySeed=0xdead) |
| 716 |
# wait for key |
| 717 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(seedmsg)) |
| 718 |
pkt = GMLAN()/GMLAN_SA(subfunction=2, securityKey=0xbeef) |
| 719 |
pr = GMLAN()/GMLAN_SAPR(subfunction=2) |
| 720 |
isotpsock2.send(pr) |
| 721 |
|
| 722 |
thread = threading.Thread(target=ecusim) |
| 723 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 724 |
thread.start() |
| 725 |
started.wait(timeout=5) |
| 726 |
res = GMLAN_GetSecurityAccess(isotpsock, keyfunc, level=1, timeout=0.1, retry=1) == True |
| 727 |
thread.join(timeout=5) |
| 728 |
assert res |
| 729 |
|
| 730 |
|
| 731 |
############################################################################## |
| 732 |
+ GMLAN_InitDiagnostics Tests |
| 733 |
############################################################################## |
| 734 |
= sequence of the correct messages |
| 735 |
ecusimSuccessfullyExecuted = True |
| 736 |
started = threading.Event() |
| 737 |
def ecusim(): |
| 738 |
global ecusimSuccessfullyExecuted |
| 739 |
ecusimSuccessfullyExecuted= True |
| 740 |
# DisableNormalCommunication |
| 741 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 742 |
pkt = GMLAN(b"\x28") |
| 743 |
if bytes(requ[0]) != bytes(pkt): |
| 744 |
ecusimSuccessfullyExecuted = False |
| 745 |
ack = b"\x68" |
| 746 |
# ReportProgrammedState |
| 747 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 748 |
pkt = GMLAN(b"\xa2") |
| 749 |
if bytes(requ[0]) != bytes(pkt): |
| 750 |
ecusimSuccessfullyExecuted = False |
| 751 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 752 |
# ProgrammingMode requestProgramming |
| 753 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 754 |
pkt = GMLAN() / GMLAN_PM(subfunction=0x1) |
| 755 |
if bytes(requ[0]) != bytes(pkt): |
| 756 |
ecusimSuccessfullyExecuted = False |
| 757 |
ack = GMLAN(b"\xe5") |
| 758 |
# InitiateProgramming enableProgramming |
| 759 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 760 |
pkt = GMLAN() / GMLAN_PM(subfunction=0x3) |
| 761 |
if bytes(requ[0]) != bytes(pkt): |
| 762 |
ecusimSuccessfullyExecuted = False |
| 763 |
|
| 764 |
thread = threading.Thread(target=ecusim) |
| 765 |
|
| 766 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 767 |
thread.start() |
| 768 |
started.wait(timeout=5) |
| 769 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, unittest=True) == True |
| 770 |
thread.join(timeout=5) |
| 771 |
assert res |
| 772 |
assert ecusimSuccessfullyExecuted == True |
| 773 |
|
| 774 |
|
| 775 |
= sequence of the correct messages, disablenormalcommunication as broadcast |
| 776 |
ecusimSuccessfullyExecuted = True |
| 777 |
started = threading.Event() |
| 778 |
|
| 779 |
broadcastsender = TestSocket(CAN) |
| 780 |
broadcastrcv = TestSocket(CAN) |
| 781 |
broadcastsender.pair(broadcastrcv) |
| 782 |
def ecusim(): |
| 783 |
global ecusimSuccessfullyExecuted |
| 784 |
ecusimSuccessfullyExecuted= True |
| 785 |
print("DisableNormalCommunication") |
| 786 |
requ = broadcastrcv.sniff(count=1, timeout=2, started_callback=started.set) |
| 787 |
assert len(requ) >= 1 |
| 788 |
if bytes(requ[0].data)[0:3] != b"\xfe\x01\x28": |
| 789 |
ecusimSuccessfullyExecuted = False |
| 790 |
print("ReportProgrammedState") |
| 791 |
requ = isotpsock2.sniff(count=1, timeout=2) |
| 792 |
pkt = GMLAN(b"\xa2") |
| 793 |
if bytes(requ[0]) != bytes(pkt): |
| 794 |
ecusimSuccessfullyExecuted = False |
| 795 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 796 |
print("ProgrammingMode requestProgramming") |
| 797 |
requ = isotpsock2.sniff(count=1, timeout=3, started_callback=lambda: isotpsock2.send(ack)) |
| 798 |
pkt = GMLAN() / GMLAN_PM(subfunction=0x1) |
| 799 |
if bytes(requ[0]) != bytes(pkt): |
| 800 |
ecusimSuccessfullyExecuted = False |
| 801 |
ack = GMLAN(b"\xe5") |
| 802 |
print("InitiateProgramming enableProgramming") |
| 803 |
requ = isotpsock2.sniff(count=1, timeout=3, started_callback=lambda: isotpsock2.send(ack)) |
| 804 |
pkt = GMLAN() / GMLAN_PM(subfunction=0x3) |
| 805 |
if bytes(requ[0]) != bytes(pkt): |
| 806 |
ecusimSuccessfullyExecuted = False |
| 807 |
|
| 808 |
thread = threading.Thread(target=ecusim) |
| 809 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 810 |
thread.start() |
| 811 |
started.wait(timeout=5) |
| 812 |
res = GMLAN_InitDiagnostics(isotpsock, broadcast_socket=GMLAN_BroadcastSocket(broadcastsender), timeout=5, unittest=True) == True |
| 813 |
thread.join(timeout=5) |
| 814 |
assert res |
| 815 |
assert ecusimSuccessfullyExecuted == True |
| 816 |
|
| 817 |
|
| 818 |
######## timeout |
| 819 |
= timeout DisableNormalCommunication |
| 820 |
ecusimSuccessfullyExecuted = True |
| 821 |
started = threading.Event() |
| 822 |
def ecusim(): |
| 823 |
global ecusimSuccessfullyExecuted |
| 824 |
ecusimSuccessfullyExecuted= True |
| 825 |
# DisableNormalCommunication |
| 826 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 827 |
pkt = GMLAN(b"\x28") |
| 828 |
if bytes(requ[0]) != bytes(pkt): |
| 829 |
ecusimSuccessfullyExecuted = False |
| 830 |
|
| 831 |
thread = threading.Thread(target=ecusim) |
| 832 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 833 |
thread.start() |
| 834 |
started.wait(timeout=5) |
| 835 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, unittest=True) == False |
| 836 |
thread.join(timeout=5) |
| 837 |
assert res |
| 838 |
assert ecusimSuccessfullyExecuted == True |
| 839 |
|
| 840 |
|
| 841 |
= timeout ReportProgrammedState |
| 842 |
ecusimSuccessfullyExecuted = True |
| 843 |
started = threading.Event() |
| 844 |
def ecusim(): |
| 845 |
global ecusimSuccessfullyExecuted |
| 846 |
ecusimSuccessfullyExecuted= True |
| 847 |
# DisableNormalCommunication |
| 848 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 849 |
pkt = GMLAN(b"\x28") |
| 850 |
if bytes(requ[0]) != bytes(pkt): |
| 851 |
ecusimSuccessfullyExecuted = False |
| 852 |
ack = b"\x68" |
| 853 |
# ReportProgrammedState |
| 854 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 855 |
pkt = GMLAN(b"\xa2") |
| 856 |
if bytes(requ[0]) != bytes(pkt): |
| 857 |
ecusimSuccessfullyExecuted = False |
| 858 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 859 |
isotpsock2.send(ack) |
| 860 |
|
| 861 |
thread = threading.Thread(target=ecusim) |
| 862 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 863 |
thread.start() |
| 864 |
started.wait(timeout=5) |
| 865 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, unittest=True) == False |
| 866 |
thread.join(timeout=5) |
| 867 |
assert res |
| 868 |
assert ecusimSuccessfullyExecuted == True |
| 869 |
|
| 870 |
|
| 871 |
= timeout ProgrammingMode requestProgramming |
| 872 |
ecusimSuccessfullyExecuted = True |
| 873 |
started = threading.Event() |
| 874 |
def ecusim(): |
| 875 |
global ecusimSuccessfullyExecuted |
| 876 |
ecusimSuccessfullyExecuted= True |
| 877 |
# DisableNormalCommunication |
| 878 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 879 |
pkt = GMLAN(b"\x28") |
| 880 |
if bytes(requ[0]) != bytes(pkt): |
| 881 |
ecusimSuccessfullyExecuted = False |
| 882 |
ack = b"\x68" |
| 883 |
# ReportProgrammedState |
| 884 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 885 |
pkt = GMLAN(b"\xa2") |
| 886 |
if bytes(requ[0]) != bytes(pkt): |
| 887 |
ecusimSuccessfullyExecuted = False |
| 888 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 889 |
# ProgrammingMode requestProgramming |
| 890 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 891 |
pkt = GMLAN() / GMLAN_PM(subfunction=0x1) |
| 892 |
if bytes(requ[0]) != bytes(pkt): |
| 893 |
ecusimSuccessfullyExecuted = False |
| 894 |
|
| 895 |
thread = threading.Thread(target=ecusim) |
| 896 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 897 |
thread.start() |
| 898 |
started.wait(timeout=5) |
| 899 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, unittest=True) == False |
| 900 |
thread.join(timeout=5) |
| 901 |
assert res |
| 902 |
assert ecusimSuccessfullyExecuted == True |
| 903 |
|
| 904 |
###### negative response |
| 905 |
= timeout DisableNormalCommunication |
| 906 |
ecusimSuccessfullyExecuted = True |
| 907 |
started = threading.Event() |
| 908 |
def ecusim(): |
| 909 |
global ecusimSuccessfullyExecuted |
| 910 |
ecusimSuccessfullyExecuted= True |
| 911 |
# DisableNormalCommunication |
| 912 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 913 |
pkt = GMLAN(b"\x28") |
| 914 |
if bytes(requ[0]) != bytes(pkt): |
| 915 |
ecusimSuccessfullyExecuted = False |
| 916 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0x28, returnCode=0x12) |
| 917 |
isotpsock2.send(ack) |
| 918 |
|
| 919 |
thread = threading.Thread(target=ecusim) |
| 920 |
|
| 921 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 922 |
thread.start() |
| 923 |
started.wait(timeout=5) |
| 924 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, unittest=True) == False |
| 925 |
thread.join(timeout=5) |
| 926 |
assert res |
| 927 |
assert ecusimSuccessfullyExecuted == True |
| 928 |
|
| 929 |
###### retry tests |
| 930 |
= sequence of the correct messages, retry set |
| 931 |
started = threading.Event() |
| 932 |
def ecusim(): |
| 933 |
# DisableNormalCommunication |
| 934 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 935 |
ack = b"\x68" |
| 936 |
# ReportProgrammedState |
| 937 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 938 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 939 |
# ProgrammingMode requestProgramming |
| 940 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 941 |
ack = GMLAN(b"\xe5") |
| 942 |
# InitiateProgramming enableProgramming |
| 943 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 944 |
|
| 945 |
thread = threading.Thread(target=ecusim) |
| 946 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 947 |
thread.start() |
| 948 |
started.wait(timeout=5) |
| 949 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=1, retry=0, unittest=True) == True |
| 950 |
assert res |
| 951 |
thread.join(timeout=5) |
| 952 |
|
| 953 |
|
| 954 |
= negative response, make sure no retries are made |
| 955 |
ecusimSuccessfullyExecuted = True |
| 956 |
started = threading.Event() |
| 957 |
def ecusim(): |
| 958 |
global ecusimSuccessfullyExecuted |
| 959 |
ecusimSuccessfullyExecuted= True |
| 960 |
requ = isotpsock2.sniff(count=1, timeout=0.1, started_callback=started.set) |
| 961 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0x28, returnCode=0x12) |
| 962 |
requ = isotpsock2.sniff(count=1, timeout=0.1, started_callback=lambda:isotpsock2.send(ack)) |
| 963 |
if len(requ) != 0: |
| 964 |
ecusimSuccessfullyExecuted = False |
| 965 |
|
| 966 |
thread = threading.Thread(target=ecusim) |
| 967 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 968 |
thread.start() |
| 969 |
started.wait(timeout=5) |
| 970 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, retry=0, unittest=True) == False |
| 971 |
thread.join(timeout=5) |
| 972 |
assert res |
| 973 |
assert ecusimSuccessfullyExecuted == True |
| 974 |
|
| 975 |
|
| 976 |
= first fail at DisableNormalCommunication, then sequence of the correct messages |
| 977 |
started = threading.Event() |
| 978 |
def ecusim(): |
| 979 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 980 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0x28, returnCode=0x12) |
| 981 |
# DisableNormalCommunication |
| 982 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 983 |
ack = b"\x68" |
| 984 |
# ReportProgrammedState |
| 985 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 986 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 987 |
# ProgrammingMode requestProgramming |
| 988 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 989 |
ack = GMLAN(b"\xe5") |
| 990 |
# InitiateProgramming enableProgramming |
| 991 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 992 |
|
| 993 |
thread = threading.Thread(target=ecusim) |
| 994 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 995 |
thread.start() |
| 996 |
started.wait(timeout=5) |
| 997 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, retry=1, unittest=True) == True |
| 998 |
thread.join(timeout=5) |
| 999 |
assert res |
| 1000 |
|
| 1001 |
= first fail at ReportProgrammedState, then sequence of the correct messages |
| 1002 |
started = threading.Event() |
| 1003 |
def ecusim(): |
| 1004 |
# DisableNormalCommunication |
| 1005 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 1006 |
ack = b"\x68" |
| 1007 |
# Fail |
| 1008 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1009 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0xA2, returnCode=0x12) |
| 1010 |
# DisableNormalCommunication |
| 1011 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1012 |
ack = b"\x68" |
| 1013 |
# ReportProgrammedState |
| 1014 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1015 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 1016 |
# ProgrammingMode requestProgramming |
| 1017 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1018 |
ack = GMLAN(b"\xe5") |
| 1019 |
# InitiateProgramming enableProgramming |
| 1020 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1021 |
|
| 1022 |
thread = threading.Thread(target=ecusim) |
| 1023 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 1024 |
thread.start() |
| 1025 |
started.wait(timeout=5) |
| 1026 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=1, retry=1, unittest=True) == True |
| 1027 |
thread.join(timeout=5) |
| 1028 |
assert res |
| 1029 |
|
| 1030 |
= first fail at ProgrammingMode requestProgramming, then sequence of the correct messages |
| 1031 |
started = threading.Event() |
| 1032 |
def ecusim(): |
| 1033 |
# DisableNormalCommunication |
| 1034 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 1035 |
ack = b"\x68" |
| 1036 |
# ReportProgrammedState |
| 1037 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1038 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 1039 |
# Fail |
| 1040 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1041 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0xA5, returnCode=0x12) |
| 1042 |
# DisableNormalCommunication |
| 1043 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1044 |
ack = b"\x68" |
| 1045 |
# ReportProgrammedState |
| 1046 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1047 |
ack = GMLAN()/GMLAN_RPSPR(programmedState=0) |
| 1048 |
# ProgrammingMode requestProgramming |
| 1049 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1050 |
ack = GMLAN(b"\xe5") |
| 1051 |
isotpsock2.send(ack) |
| 1052 |
# InitiateProgramming enableProgramming |
| 1053 |
requ = isotpsock2.sniff(count=1, timeout=1) |
| 1054 |
|
| 1055 |
thread = threading.Thread(target=ecusim) |
| 1056 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 1057 |
thread.start() |
| 1058 |
started.wait(timeout=5) |
| 1059 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=1, retry=1, unittest=True) == True |
| 1060 |
thread.join(timeout=5) |
| 1061 |
assert res |
| 1062 |
|
| 1063 |
= fail twice |
| 1064 |
ecusimSuccessfullyExecuted = True |
| 1065 |
started = threading.Event() |
| 1066 |
def ecusim(): |
| 1067 |
global ecusimSuccessfullyExecuted |
| 1068 |
ecusimSuccessfullyExecuted= True |
| 1069 |
requ = isotpsock2.sniff(count=1, timeout=0.1, started_callback=started.set) |
| 1070 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0x28, returnCode=0x12) |
| 1071 |
requ = isotpsock2.sniff(count=1, timeout=0.1, started_callback=lambda:isotpsock2.send(ack)) |
| 1072 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0x28, returnCode=0x12) |
| 1073 |
requ = isotpsock2.sniff(count=1, timeout=0.1, started_callback=lambda:isotpsock2.send(ack)) |
| 1074 |
if len(requ) != 0: |
| 1075 |
ecusimSuccessfullyExecuted = False |
| 1076 |
|
| 1077 |
thread = threading.Thread(target=ecusim) |
| 1078 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 1079 |
thread.start() |
| 1080 |
started.wait(timeout=5) |
| 1081 |
res = GMLAN_InitDiagnostics(isotpsock, timeout=0.1, retry=1, unittest=True) == False |
| 1082 |
thread.join(timeout=5) |
| 1083 |
assert res |
| 1084 |
assert ecusimSuccessfullyExecuted == True |
| 1085 |
|
| 1086 |
############################################################################## |
| 1087 |
+ GMLAN_ReadMemoryByAddress Tests |
| 1088 |
############################################################################## |
| 1089 |
= Positive, short length, scheme = 4 |
| 1090 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 1091 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 1092 |
ecusimSuccessfullyExecuted = True |
| 1093 |
started = threading.Event() |
| 1094 |
def ecusim(): |
| 1095 |
global ecusimSuccessfullyExecuted |
| 1096 |
ecusimSuccessfullyExecuted= True |
| 1097 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 1098 |
pkt = GMLAN() / GMLAN_RMBA(memoryAddress=0x0, memorySize=0x8) |
| 1099 |
if bytes(requ[0]) != bytes(pkt): |
| 1100 |
ecusimSuccessfullyExecuted = False |
| 1101 |
ack = GMLAN() / GMLAN_RMBAPR(memoryAddress=0x0, dataRecord=payload) |
| 1102 |
isotpsock2.send(ack) |
| 1103 |
|
| 1104 |
thread = threading.Thread(target=ecusim) |
| 1105 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 1106 |
thread.start() |
| 1107 |
started.wait(timeout=5) |
| 1108 |
res = GMLAN_ReadMemoryByAddress(isotpsock, 0x0, 0x8, timeout=1) == payload |
| 1109 |
thread.join(timeout=5) |
| 1110 |
assert res |
| 1111 |
assert ecusimSuccessfullyExecuted == True |
| 1112 |
|
| 1113 |
|
| 1114 |
= Negative, negative response |
| 1115 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 1116 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 1117 |
started = threading.Event() |
| 1118 |
def ecusim(): |
| 1119 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 1120 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0x23, returnCode=0x31) |
| 1121 |
isotpsock2.send(ack) |
| 1122 |
|
| 1123 |
thread = threading.Thread(target=ecusim) |
| 1124 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 1125 |
thread.start() |
| 1126 |
started.wait(timeout=5) |
| 1127 |
res = GMLAN_ReadMemoryByAddress(isotpsock, 0x0, 0x8, timeout=1) is None |
| 1128 |
thread.join(timeout=5) |
| 1129 |
assert res |
| 1130 |
|
| 1131 |
= Negative, timeout |
| 1132 |
assert GMLAN_ReadMemoryByAddress(isotpsock, 0x0, 0x8, timeout=0.01) is None |
| 1133 |
|
| 1134 |
###### RETRY |
| 1135 |
= Positive, negative response, retry succeeds |
| 1136 |
conf.contribs['GMLAN']['GMLAN_ECU_AddressingScheme'] = 4 |
| 1137 |
payload = b"\x00\x11\x22\x33\x44\x55\x66\x77" |
| 1138 |
started = threading.Event() |
| 1139 |
def ecusim(): |
| 1140 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=started.set) |
| 1141 |
ack = GMLAN() / GMLAN_NR(requestServiceId=0x23, returnCode=0x31) |
| 1142 |
requ = isotpsock2.sniff(count=1, timeout=1, started_callback=lambda:isotpsock2.send(ack)) |
| 1143 |
ack = GMLAN() / GMLAN_RMBAPR(memoryAddress=0x0, dataRecord=payload) |
| 1144 |
isotpsock2.send(ack) |
| 1145 |
|
| 1146 |
thread = threading.Thread(target=ecusim) |
| 1147 |
sniff(timeout=0.01, opened_socket=[isotpsock, isotpsock2]) |
| 1148 |
thread.start() |
| 1149 |
started.wait(timeout=5) |
| 1150 |
res = GMLAN_ReadMemoryByAddress(isotpsock, 0x0, 0x8, timeout=1, retry=1) == payload |
| 1151 |
thread.join(timeout=5) |
| 1152 |
assert res |
| 1153 |
|
| 1154 |
+ Cleanup |
| 1155 |
|
| 1156 |
= Delete TestSockets |
| 1157 |
|
| 1158 |
cleanup_testsockets() |