Debian Codegraph @

test/unit/test_sdc600.py

raw symbols SCIP
1 # pyOCD debugger
2 # Copyright (c) 2020 Arm Limited
3 # Copyright (c) 2021 Chris Reed
4 # SPDX-License-Identifier: Apache-2.0
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 import pytest
19 from unittest import mock
20
21 from .test_rom_table import (MockCoreSightComponent, MockCoreSight, MockCSSOC600Components)
22
23 from pyocd.coresight.ap import AccessPort
24 from pyocd.coresight.sdc600 import SDC600
25 from pyocd.coresight.rom_table import CoreSightComponentID
26
27 MockAP = mock.Mock(spec=AccessPort)
28
29 @pytest.fixture(scope='function')
30 def sdc():
31 cs = MockCoreSight([MockCSSOC600Components.SDC600])
32 # Add SDC-600 register values.
33 cs.write_memory_block32(0xd00, [
34 0x00000000, # VIDR = 0xD00
35 0, # 0xD04
36 0x00000411, # FIDTXR = 0xD08
37 0x00000401, # FIDRXR = 0xD0C
38 0x00000000, # ICSR = 0xD10
39 0, # 0xD14
40 0, # 0xD18
41 0, # 0xD1C
42 0x00000000, # DR = 0xD20
43 0, # 0xD24
44 0, # 0xD28
45 0x80011001, # SR = 0xD2C
46 0x00000000, # DBR = 0xD30
47 0, # 0xD34
48 0, # 0xD38
49 0x80011001, # SR_ALIAS = 0xD3C
50 ])
51 cmpid = CoreSightComponentID(None, cs, MockCSSOC600Components.SDC600_BASE)
52 sdc600 = SDC600(cs, cmpid, 0x1000)
53 sdc600.init()
54 return sdc600
55
56 # Flag bytes
57 FLAGS = [i for i in range(0xa0, 0xc0)]
58
59 class TestSDC600:
60 # Verify non-flag bytes are not escaped.
61 def test_stuff_nonflag(self, sdc):
62 print(FLAGS)
63 for i in range(256):
64 # Skip flag bytes.
65 if i in FLAGS:
66 continue
67 assert sdc._stuff([i]) == [i]
68
69 # Verify non-flag bytes are not de-escaped.
70 def test_destuff_nonflag(self, sdc):
71 for i in range(256):
72 # Skip flag bytes.
73 if i in FLAGS:
74 continue
75 assert sdc._destuff([i]) == [i]
76
77 # Test stuffing a single byte.
78 def test_stuff_flag(self, sdc):
79 for i in FLAGS:
80 assert sdc._stuff([i]) == [SDC600.Flag.ESC, i ^ 0x80]
81 assert sdc._stuff([i]) == [SDC600.Flag.ESC, i & ~0x80]
82
83 # Test destuffing a single escaped byte.
84 def test_destuff_flag(self, sdc):
85 for i in FLAGS:
86 assert sdc._destuff([SDC600.Flag.ESC, i ^ 0x80]) == [i]
87 assert sdc._destuff([SDC600.Flag.ESC, i & ~0x80]) == [i]
88
89