Debian Codegraph @

test/unit/test_exceptions.py

raw symbols SCIP
1 # pyOCD debugger
2 # Copyright (c) 2020 Arm Limited
3 # SPDX-License-Identifier: Apache-2.0
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import pytest
18
19 from pyocd.core.exceptions import *
20
21 # Tests for TransferFaultError.
22 class TestFaultError:
23 def test_no_args(self):
24 e = TransferFaultError()
25 assert str(e) == 'Memory transfer fault'
26
27 def test_no_args_set_addr(self):
28 e = TransferFaultError()
29 e.fault_address = 0x1000
30 assert str(e) == 'Memory transfer fault @ 0x00001000'
31
32 def test_no_args_set_addr_len(self):
33 e = TransferFaultError()
34 e.fault_address = 0x1000
35 e.fault_length = 0x8
36 assert str(e) == 'Memory transfer fault @ 0x00001000-0x00001007'
37
38 def test_msg(self):
39 e = TransferFaultError("temporal anomaly")
40 assert str(e) == 'Memory transfer fault (temporal anomaly)'
41
42 def test_arg_tuple(self):
43 e = TransferFaultError(-1, 1234)
44 assert str(e) == 'Memory transfer fault (-1, 1234)'
45
46 def test_msg_ctor_addr(self):
47 e = TransferFaultError("my bad", fault_address=0x20008400)
48 assert e.fault_address == 0x20008400
49 assert str(e) == 'Memory transfer fault (my bad) @ 0x20008400'
50
51 def test_msg_ctor_addr_len(self):
52 e = TransferFaultError("my bad", fault_address=0x20008400, length=32)
53 assert e.fault_address == 0x20008400
54 assert str(e) == 'Memory transfer fault (my bad) @ 0x20008400-0x2000841f'
55
56 # Tests for FlashFailure.
57 class TestFlashFailure:
58 def test_no_args(self):
59 e = FlashFailure()
60 assert str(e) == ""
61 assert e.address == None
62 assert e.result_code == None
63
64 def test_msg(self):
65 e = FlashFailure("something exploded")
66 assert str(e) == "something exploded"
67 assert e.address == None
68 assert e.result_code == None
69
70 def test_addr(self):
71 e = FlashFailure(address=0x4000)
72 assert str(e) == "(address 0x00004000)"
73 assert e.address == 0x4000
74 assert e.result_code == None
75
76 def test_code(self):
77 e = FlashFailure(result_code=0x104)
78 assert str(e) == "(result code 0x104)"
79 assert e.address == None
80 assert e.result_code == 0x104
81
82 def test_addr_code(self):
83 e = FlashFailure(address=0x4000, result_code=0x104)
84 assert str(e) == "(address 0x00004000; result code 0x104)"
85 assert e.address == 0x4000
86 assert e.result_code == 0x104
87
88 def test_msg_addr_code(self):
89 e = FlashFailure("major error", address=0x4000, result_code=0x104)
90 assert str(e) == "major error (address 0x00004000; result code 0x104)"
91 assert e.address == 0x4000
92 assert e.result_code == 0x104
93