forked from Azure/sonic-utilities.msft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcieutil_test.py
More file actions
218 lines (197 loc) · 8.63 KB
/
pcieutil_test.py
File metadata and controls
218 lines (197 loc) · 8.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import sys
import os
from unittest import mock
from click.testing import CliRunner
from io import StringIO
test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
sys.path.insert(0, modules_path)
import pcieutil.main as pcieutil
pcieutil_pcie_aer_correctable_output = """\
+---------------------+-----------+-----------+
| AER - CORRECTABLE | 00:01.0 | 01:00.0 |
| | 0x0001 | 0x0002 |
+=====================+===========+===========+
| RxErr | 0 | 1 |
+---------------------+-----------+-----------+
| BadTLP | 1 | 0 |
+---------------------+-----------+-----------+
| TOTAL_ERR_COR | 1 | 1 |
+---------------------+-----------+-----------+
"""
pcieutil_pcie_aer_nonfatal_output = """\
+--------------------+-----------+
| AER - NONFATAL | 00:01.0 |
| | 0x0001 |
+====================+===========+
| MalfTLP | 1 |
+--------------------+-----------+
| TOTAL_ERR_NONFATAL | 1 |
+--------------------+-----------+
"""
pcieutil_pcie_aer_correctable_verbose_output = """\
+---------------------+-----------+-----------+
| AER - CORRECTABLE | 00:01.0 | 01:00.0 |
| | 0x0001 | 0x0002 |
+=====================+===========+===========+
| RxErr | 0 | 1 |
+---------------------+-----------+-----------+
| BadTLP | 1 | 0 |
+---------------------+-----------+-----------+
| BadDLLP | 0 | 0 |
+---------------------+-----------+-----------+
| Rollover | 0 | 0 |
+---------------------+-----------+-----------+
| Timeout | 0 | 0 |
+---------------------+-----------+-----------+
| NonFatalErr | 0 | 0 |
+---------------------+-----------+-----------+
| CorrIntErr | 0 | 0 |
+---------------------+-----------+-----------+
| HeaderOF | 0 | 0 |
+---------------------+-----------+-----------+
| TOTAL_ERR_COR | 1 | 1 |
+---------------------+-----------+-----------+
"""
pcieutil_pcie_aer_fatal_verbose_output = """\
+-----------------+-----------+-----------+
| AER - FATAL | 00:01.0 | 01:00.0 |
| | 0x0001 | 0x0002 |
+=================+===========+===========+
| Undefined | 0 | 0 |
+-----------------+-----------+-----------+
| DLP | 0 | 0 |
+-----------------+-----------+-----------+
| SDES | 0 | 0 |
+-----------------+-----------+-----------+
| TLP | 0 | 0 |
+-----------------+-----------+-----------+
| FCP | 0 | 0 |
+-----------------+-----------+-----------+
| CmpltTO | 0 | 0 |
+-----------------+-----------+-----------+
| CmpltAbrt | 0 | 0 |
+-----------------+-----------+-----------+
| UnxCmplt | 0 | 0 |
+-----------------+-----------+-----------+
| RxOF | 0 | 0 |
+-----------------+-----------+-----------+
| MalfTLP | 0 | 0 |
+-----------------+-----------+-----------+
| ECRC | 0 | 0 |
+-----------------+-----------+-----------+
| UnsupReq | 0 | 0 |
+-----------------+-----------+-----------+
| ACSViol | 0 | 0 |
+-----------------+-----------+-----------+
| UncorrIntErr | 0 | 0 |
+-----------------+-----------+-----------+
| BlockedTLP | 0 | 0 |
+-----------------+-----------+-----------+
| AtomicOpBlocked | 0 | 0 |
+-----------------+-----------+-----------+
| TLPBlockedErr | 0 | 0 |
+-----------------+-----------+-----------+
| TOTAL_ERR_FATAL | 0 | 0 |
+-----------------+-----------+-----------+
"""
pcieutil_pcie_aer_nonfatal_verbose_output = """\
+--------------------+-----------+-----------+
| AER - NONFATAL | 00:01.0 | 01:00.0 |
| | 0x0001 | 0x0002 |
+====================+===========+===========+
| Undefined | 0 | 0 |
+--------------------+-----------+-----------+
| DLP | 0 | 0 |
+--------------------+-----------+-----------+
| SDES | 0 | 0 |
+--------------------+-----------+-----------+
| TLP | 0 | 0 |
+--------------------+-----------+-----------+
| FCP | 0 | 0 |
+--------------------+-----------+-----------+
| CmpltTO | 0 | 0 |
+--------------------+-----------+-----------+
| CmpltAbrt | 0 | 0 |
+--------------------+-----------+-----------+
| UnxCmplt | 0 | 0 |
+--------------------+-----------+-----------+
| RxOF | 0 | 0 |
+--------------------+-----------+-----------+
| MalfTLP | 1 | 0 |
+--------------------+-----------+-----------+
| ECRC | 0 | 0 |
+--------------------+-----------+-----------+
| UnsupReq | 0 | 0 |
+--------------------+-----------+-----------+
| ACSViol | 0 | 0 |
+--------------------+-----------+-----------+
| UncorrIntErr | 0 | 0 |
+--------------------+-----------+-----------+
| BlockedTLP | 0 | 0 |
+--------------------+-----------+-----------+
| AtomicOpBlocked | 0 | 0 |
+--------------------+-----------+-----------+
| TLPBlockedErr | 0 | 0 |
+--------------------+-----------+-----------+
| TOTAL_ERR_NONFATAL | 1 | 0 |
+--------------------+-----------+-----------+
"""
pcieutil_pcie_aer_correctable_dev_output = """\
+---------------------+-----------+
| AER - CORRECTABLE | 00:01.0 |
| | 0x0001 |
+=====================+===========+
| BadTLP | 1 |
+---------------------+-----------+
| TOTAL_ERR_COR | 1 |
+---------------------+-----------+
"""
pcieutil_load_module_warning_msg = "Failed to load platform Pcie module. Warning : No module named 'sonic_platform.pcie', fallback to load Pcie common utility."
class TestPcieUtil(object):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ["UTILITIES_UNIT_TESTING"] = "1"
def test_aer_all(self):
runner = CliRunner()
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["all"], [])
assert result.output == (pcieutil_pcie_aer_correctable_output + "\n"
+ pcieutil_pcie_aer_nonfatal_output)
def test_aer_correctable(self):
runner = CliRunner()
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], [])
assert result.output == pcieutil_pcie_aer_correctable_output
def test_aer_fatal(self):
runner = CliRunner()
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["fatal"], [])
assert result.output == ""
def test_aer_non_fatal(self):
runner = CliRunner()
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["non-fatal"], [])
assert result.output == pcieutil_pcie_aer_nonfatal_output
def test_aer_option_verbose(self):
runner = CliRunner()
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], ["-v"])
assert result.output == pcieutil_pcie_aer_correctable_verbose_output
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["fatal"], ["-v"])
assert result.output == pcieutil_pcie_aer_fatal_verbose_output
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["non-fatal"], ["-v"])
assert result.output == pcieutil_pcie_aer_nonfatal_verbose_output
def test_aer_option_device(self):
runner = CliRunner()
result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], ["-d", "0:1.0"])
assert result.output == pcieutil_pcie_aer_correctable_dev_output
def test_load_pcie_module_warning(self):
stdout = sys.stdout
sys.stdout = result = StringIO()
try:
pcieutil.load_platform_pcieutil()
except ImportError:
pass
sys.stdout = stdout
assert pcieutil_load_module_warning_msg not in result.getvalue()
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["UTILITIES_UNIT_TESTING"] = "0"