• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1% Regression tests for automotive scanner test_case
2
3+ Load general modules
4
5= Load contribution layer
6
7from scapy.contrib.automotive.scanner.test_case import AutomotiveTestCase
8from scapy.contrib.automotive.ecu import EcuState
9
10+ Basic checks
11
12= Definition of Test class
13
14class MyTestCase(AutomotiveTestCase):
15    _description = "MyTestCase"
16    _supported_kwargs = {"testarg": (int, None)}
17    def supported_responses(self):
18        return []
19
20= Check supported kwargs
21
22try:
23    MyTestCase.check_kwargs({"testarg": 5})
24except Scapy_Exception as e:
25    assert False
26
27try:
28    MyTestCase.check_kwargs({"test": 5})
29    assert False
30except Scapy_Exception as e:
31    assert "Keyword-Argument test not supported" in str(e)
32
33try:
34    MyTestCase.check_kwargs({"testarg": 5.5})
35    assert False
36except Scapy_Exception as e:
37    assert "Keyword-Value" in str(e)
38    assert "is not instance of type <class 'int'>" in str(e) or \
39           "is not instance of type <type 'int'>" in str(e)
40
41= Create instance of test class
42
43mt = MyTestCase()
44
45mt._state_completed[EcuState(session=1)] = True
46mt._state_completed[EcuState(session=2)] = True
47mt._state_completed[EcuState(session=3)] = False
48
49= Tests of has_completed
50
51assert mt.completed is False
52assert mt.has_completed(EcuState(session=1))
53assert mt.has_completed(EcuState(session=3)) is False
54
55assert len(mt.scanned_states) == 3
56
57= Tests of has_completed with new state
58
59assert mt.completed is False
60assert mt.has_completed(EcuState(session=4)) is False
61assert mt.has_completed(EcuState(session=3)) is False
62
63assert len(mt.scanned_states) == 4
64
65= Tests of completed
66
67mt._state_completed[EcuState(session=3)] = True
68mt._state_completed[EcuState(session=4)] = True
69
70assert mt.completed
71
72= Test of show
73
74header = mt._show_header(dump=True)
75
76assert "MyTestCase" in header
77
78state_info = mt._show_state_information(dump=True)
79
80assert "session" in state_info
81assert "False" not in state_info
82assert "True" in state_info
83
84mt._state_completed[EcuState(session=3)] = False
85state_info = mt._show_state_information(dump=True)
86
87assert "session" in state_info
88assert "False" in state_info
89assert "True" in state_info
90
91dump = mt.show(dump=True, verbose=True)
92
93assert "session" in dump
94assert "MyTestCase" in dump
95
96
97
98
99
100
101
102