Skip to content

Commit f9113dc

Browse files
polybassagpotter2
authored andcommitted
Minor cleanup and add utility function for Automotive Scanner
1 parent 9ca3cc9 commit f9113dc

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

scapy/contrib/automotive/scanner/executor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
3333
Callable,
3434
Type,
3535
cast,
36+
TypeVar,
3637
)
3738

39+
T = TypeVar("T")
40+
3841

3942
class AutomotiveTestCaseExecutor(metaclass=abc.ABCMeta):
4043
"""
@@ -415,6 +418,10 @@ def show_testcases_status(self):
415418
data += [(repr(s), t.__class__.__name__, t.has_completed(s))]
416419
make_lined_table(data, lambda *tup: (tup[0], tup[1], tup[2]))
417420

421+
def get_test_cases_by_class(self, cls):
422+
# type: (Type[T]) -> List[T]
423+
return [x for x in self.configuration.test_cases if isinstance(x, cls)]
424+
418425
@property
419426
def supported_responses(self):
420427
# type: () -> List[EcuResponse]

scapy/contrib/isotp/isotp_soft_socket.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class TimeoutScheduler:
228228
# use heapq functions on _handles!
229229
_handles = [] # type: List[TimeoutScheduler.Handle]
230230

231+
logger = logging.getLogger("scapy.contrib.automotive.timeout_scheduler")
232+
231233
@classmethod
232234
def schedule(cls, timeout, callback):
233235
# type: (float, Callable[[], None]) -> TimeoutScheduler.Handle
@@ -316,13 +318,13 @@ def _wait(cls, handle):
316318
# Wait until the next timeout,
317319
# or until event.set() gets called in another thread.
318320
if to_wait > 0:
319-
log_isotp.debug("TimeoutScheduler Thread going to sleep @ %f " +
320-
"for %fs", now, to_wait)
321+
cls.logger.debug("Thread going to sleep @ %f " +
322+
"for %fs", now, to_wait)
321323
interrupted = cls._event.wait(to_wait)
322324
new = cls._time()
323-
log_isotp.debug("TimeoutScheduler Thread awake @ %f, slept for" +
324-
" %f, interrupted=%d", new, new - now,
325-
interrupted)
325+
cls.logger.debug("Thread awake @ %f, slept for" +
326+
" %f, interrupted=%d", new, new - now,
327+
interrupted)
326328

327329
# Clear the event so that we can wait on it again,
328330
# Must be done before doing the callbacks to avoid losing a set().
@@ -335,7 +337,7 @@ def _task(cls):
335337
start when the first timeout is added and stop when the last timeout
336338
is removed or executed."""
337339

338-
log_isotp.debug("TimeoutScheduler Thread spawning @ %f", cls._time())
340+
cls.logger.debug("Thread spawning @ %f", cls._time())
339341

340342
time_empty = None
341343

@@ -357,7 +359,7 @@ def _task(cls):
357359
finally:
358360
# Worst case scenario: if this thread dies, the next scheduled
359361
# timeout will start a new one
360-
log_isotp.debug("TimeoutScheduler Thread died @ %f", cls._time())
362+
cls.logger.debug("Thread died @ %f", cls._time())
361363
cls._thread = None
362364

363365
@classmethod
@@ -379,7 +381,7 @@ def _poll(cls):
379381
callback = handle._cb
380382
handle._cb = True
381383

382-
# Call the callback here, outside of the mutex
384+
# Call the callback here, outside the mutex
383385
if callable(callback):
384386
try:
385387
callback()

0 commit comments

Comments
 (0)