From ce8cacd06ed5517add5576e57d77f5510ebbd56d Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran Date: Tue, 13 Oct 2020 16:22:11 +0530 Subject: [PATCH 1/6] [pcieutil] Add 'pcie-aer' sub-command to display AER stats --- pcieutil/main.py | 147 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/pcieutil/main.py b/pcieutil/main.py index ca1dd0fb96..8e8c0bc750 100644 --- a/pcieutil/main.py +++ b/pcieutil/main.py @@ -8,10 +8,13 @@ try: import os import sys + from collections import OrderedDict import click from sonic_py_common import device_info, logger + from swsssdk import SonicV2Connector from tabulate import tabulate + import utilities_common.cli as clicommon except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -105,6 +108,150 @@ def pcie_show(): Id = item["id"] click.echo("bus:dev.fn %s:%s.%s - dev_id=0x%s, %s" % (Bus, Dev, Fn, Id, Name)) +# Show PCIe AER status + + +@cli.group(cls=clicommon.AliasedGroup) +def pcie_aer(): + '''Display PCIe AER status''' + pass + + +@pcie_aer.command() +def correctable(): + '''Show PCIe AER correctable attributes''' + + statedb = SonicV2Connector() + statedb.connect(statedb.STATE_DB) + header = ['AER - CORRECTABLE'] + + # AER - Correctable fields (9) + fields = ['RxErr', 'BadTLP', 'BadDLLP', 'Rollover', 'Timeout', 'NonFatalErr', 'CorrIntErr', 'HeaderOF', 'TOTAL_ERR_COR'] + table = OrderedDict() + for field in fields: + table[field] = [field] + + resultInfo = platform_pcieutil.get_pcie_check() + for item in resultInfo: + if item["result"] == "Failed": + continue + + Bus = item["bus"] + Dev = item["dev"] + Fn = item["fn"] + Id = item["id"] + + pcie_dev_key = "PCIE_DEVICE|0x%s|%s:%s.%s" % (Id, Bus, Dev, Fn) + aer_attribute = statedb.get_all(statedb.STATE_DB, pcie_dev_key) + if not aer_attribute: + continue + + # Tabulate Header + device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) + header.append(device_name) + + # Tabulate Row + for field in fields: + key = "correctable|" + field + table[field].append(aer_attribute.get(key, 'NA')) + + click.echo(tabulate(list(table.values()), header, tablefmt="grid")) + + +@pcie_aer.command() +def fatal(): + '''Show PCIe AER fatal attributes''' + statedb = SonicV2Connector() + statedb.connect(statedb.STATE_DB) + header = ['AER - FATAL'] + + # AER - Fatal fields (18) + fields = ['Undefined', 'DLP', 'SDES', 'TLP', 'FCP', 'CmpltTO', 'CmpltAbrt', 'UnxCmplt', 'RxOF', 'MalfTLP', 'ECRC', 'UnsupReq', 'ACSViol', 'UncorrIntErr', 'BlockedTLP', 'AtomicOpBlocked', 'TLPBlockedErr', 'TOTAL_ERR_FATAL'] + table = OrderedDict() + for field in fields: + table[field] = [field] + + resultInfo = platform_pcieutil.get_pcie_check() + for item in resultInfo: + if item["result"] == "Failed": + continue + + Bus = item["bus"] + Dev = item["dev"] + Fn = item["fn"] + Id = item["id"] + + pcie_dev_key = "PCIE_DEVICE|0x%s|%s:%s.%s" % (Id, Bus, Dev, Fn) + aer_attribute = statedb.get_all(statedb.STATE_DB, pcie_dev_key) + if not aer_attribute: + continue + + # Tabulate Header + device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) + header.append(device_name) + + # Tabulate Row + for field in fields: + key = "fatal|" + field + table[field].append(aer_attribute.get(key, 'NA')) + + click.echo(tabulate(list(table.values()), header, tablefmt="grid")) + + +@pcie_aer.command() +def non_fatal(): + '''Show PCIe AER non-fatal attributes ''' + statedb = SonicV2Connector() + statedb.connect(statedb.STATE_DB) + aer_attribute = {} + header = ['AER - NONFATAL'] + + # AER - Non-Fatal fields (18) + fields = ['Undefined', 'DLP', 'SDES', 'TLP', 'FCP', 'CmpltTO', 'CmpltAbrt', 'UnxCmplt', 'RxOF', 'MalfTLP', 'ECRC', 'UnsupReq', 'ACSViol', 'UncorrIntErr', 'BlockedTLP', 'AtomicOpBlocked', 'TLPBlockedErr', 'TOTAL_ERR_NONFATAL'] + table = OrderedDict() + for field in fields: + table[field] = [field] + + resultInfo = platform_pcieutil.get_pcie_check() + for item in resultInfo: + if item["result"] == "Failed": + continue + + Bus = item["bus"] + Dev = item["dev"] + Fn = item["fn"] + Id = item["id"] + + pcie_dev_key = "PCIE_DEVICE|0x%s|%s:%s.%s" % (Id, Bus, Dev, Fn) + aer_attribute = statedb.get_all(statedb.STATE_DB, pcie_dev_key) + if not aer_attribute: + continue + + # Tabulate Header + device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) + header.append(device_name) + + # Tabulate Row + for field in fields: + key = "non_fatal|" + field + table[field].append(aer_attribute.get(key, 'NA')) + + click.echo(tabulate(list(table.values()), header, tablefmt="grid")) + + +@pcie_aer.command() +@click.pass_context +def all(ctx): + '''Show all PCIe AER attributes ''' + ctx.invoke(correctable) + click.echo("") + + ctx.invoke(fatal) + click.echo("") + + ctx.invoke(non_fatal) + click.echo("") + # Show PCIE Vender ID and Device ID @cli.command() From 40fb5043a73bfd96385b60465e1c6f9fe09a5fe7 Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran Date: Tue, 24 Nov 2020 11:18:34 +0530 Subject: [PATCH 2/6] Add UT for pcieutil pcie-aer commands --- tests/mock_tables/state_db.json | 47 +++++++++ tests/pcieutil_test.py | 165 ++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 tests/pcieutil_test.py diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 5a9595b09a..c254d5eb18 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -300,5 +300,52 @@ "desc": "fabric-card", "oper_status": "Offline", "slot": "18" + }, + "PCIE_DEVICE|0x0001|00:01.0": { + "correctable|BadDLLP": "0", + "correctable|BadTLP": "0", + "correctable|CorrIntErr": "0", + "correctable|HeaderOF": "0", + "correctable|NonFatalErr": "0", + "correctable|Rollover": "0", + "correctable|RxErr": "0", + "correctable|TOTAL_ERR_COR": "0", + "correctable|Timeout": "0", + "fatal|ACSViol": "0", + "fatal|AtomicOpBlocked": "0", + "fatal|BlockedTLP": "0", + "fatal|CmpltAbrt": "0", + "fatal|CmpltTO": "0", + "fatal|DLP": "0", + "fatal|ECRC": "0", + "fatal|FCP": "0", + "fatal|MalfTLP": "0", + "fatal|RxOF": "0", + "fatal|SDES": "0", + "fatal|TLP": "0", + "fatal|TLPBlockedErr": "0", + "fatal|TOTAL_ERR_FATAL": "0", + "fatal|UncorrIntErr": "0", + "fatal|Undefined": "0", + "fatal|UnsupReq": "0", + "fatal|UnxCmplt": "0", + "non_fatal|ACSViol": "0", + "non_fatal|AtomicOpBlocked": "0", + "non_fatal|BlockedTLP": "0", + "non_fatal|CmpltAbrt": "0", + "non_fatal|CmpltTO": "0", + "non_fatal|DLP": "0", + "non_fatal|ECRC": "0", + "non_fatal|FCP": "0", + "non_fatal|MalfTLP": "0", + "non_fatal|RxOF": "0", + "non_fatal|SDES": "0", + "non_fatal|TLP": "0", + "non_fatal|TLPBlockedErr": "0", + "non_fatal|TOTAL_ERR_NONFATAL": "0", + "non_fatal|UncorrIntErr": "0", + "non_fatal|Undefined": "0", + "non_fatal|UnsupReq": "0", + "non_fatal|UnxCmplt": "0" } } diff --git a/tests/pcieutil_test.py b/tests/pcieutil_test.py new file mode 100644 index 0000000000..63401a0473 --- /dev/null +++ b/tests/pcieutil_test.py @@ -0,0 +1,165 @@ +import sys +import os +from unittest import mock + +from click.testing import CliRunner + +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 | +| | 0x0001 | ++=====================+===========+ +| RxErr | 0 | ++---------------------+-----------+ +| BadTLP | 0 | ++---------------------+-----------+ +| BadDLLP | 0 | ++---------------------+-----------+ +| Rollover | 0 | ++---------------------+-----------+ +| Timeout | 0 | ++---------------------+-----------+ +| NonFatalErr | 0 | ++---------------------+-----------+ +| CorrIntErr | 0 | ++---------------------+-----------+ +| HeaderOF | 0 | ++---------------------+-----------+ +| TOTAL_ERR_COR | 0 | ++---------------------+-----------+ +""" + +pcieutil_pcie_aer_non_fatal_output = """\ ++--------------------+-----------+ +| AER - NONFATAL | 00:01.0 | +| | 0x0001 | ++====================+===========+ +| Undefined | 0 | ++--------------------+-----------+ +| DLP | 0 | ++--------------------+-----------+ +| SDES | 0 | ++--------------------+-----------+ +| TLP | 0 | ++--------------------+-----------+ +| FCP | 0 | ++--------------------+-----------+ +| CmpltTO | 0 | ++--------------------+-----------+ +| CmpltAbrt | 0 | ++--------------------+-----------+ +| UnxCmplt | 0 | ++--------------------+-----------+ +| RxOF | 0 | ++--------------------+-----------+ +| MalfTLP | 0 | ++--------------------+-----------+ +| ECRC | 0 | ++--------------------+-----------+ +| UnsupReq | 0 | ++--------------------+-----------+ +| ACSViol | 0 | ++--------------------+-----------+ +| UncorrIntErr | 0 | ++--------------------+-----------+ +| BlockedTLP | 0 | ++--------------------+-----------+ +| AtomicOpBlocked | 0 | ++--------------------+-----------+ +| TLPBlockedErr | 0 | ++--------------------+-----------+ +| TOTAL_ERR_NONFATAL | 0 | ++--------------------+-----------+ +""" + +pcieutil_pcie_aer_fatal_output = """\ ++-----------------+-----------+ +| AER - FATAL | 00:01.0 | +| | 0x0001 | ++=================+===========+ +| Undefined | 0 | ++-----------------+-----------+ +| DLP | 0 | ++-----------------+-----------+ +| SDES | 0 | ++-----------------+-----------+ +| TLP | 0 | ++-----------------+-----------+ +| FCP | 0 | ++-----------------+-----------+ +| CmpltTO | 0 | ++-----------------+-----------+ +| CmpltAbrt | 0 | ++-----------------+-----------+ +| UnxCmplt | 0 | ++-----------------+-----------+ +| RxOF | 0 | ++-----------------+-----------+ +| MalfTLP | 0 | ++-----------------+-----------+ +| ECRC | 0 | ++-----------------+-----------+ +| UnsupReq | 0 | ++-----------------+-----------+ +| ACSViol | 0 | ++-----------------+-----------+ +| UncorrIntErr | 0 | ++-----------------+-----------+ +| BlockedTLP | 0 | ++-----------------+-----------+ +| AtomicOpBlocked | 0 | ++-----------------+-----------+ +| TLPBlockedErr | 0 | ++-----------------+-----------+ +| TOTAL_ERR_FATAL | 0 | ++-----------------+-----------+ +""" + + +class MockPcieUtil(object): + def __init__(self): + self.confInfo = [ + {'bus': '00', 'dev': '01', 'name': 'PCIe Device 1', 'fn': '0', 'id': '0001'} + ] + + def get_pcie_check(self): + for item in self.confInfo: + item['result'] = "Passed" + + return self.confInfo + + +class TestPcieUtil(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["UTILITIES_UNIT_TESTING"] = "1" + + def test_aer_correctable(self): + with mock.patch("pcieutil.main.platform_pcieutil", new_callable=MockPcieUtil): + runner = CliRunner() + result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], []) + assert pcieutil_pcie_aer_correctable_output == result.output + + def test_aer_non_fatal(self): + with mock.patch("pcieutil.main.platform_pcieutil", new_callable=MockPcieUtil): + runner = CliRunner() + result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["non-fatal"], []) + assert pcieutil_pcie_aer_non_fatal_output == result.output + + def test_aer_fatal(self): + with mock.patch("pcieutil.main.platform_pcieutil", new_callable=MockPcieUtil): + runner = CliRunner() + result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["fatal"], []) + assert pcieutil_pcie_aer_fatal_output == result.output + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ["UTILITIES_UNIT_TESTING"] = "0" From 310d79f6abc50ae7ec68a3bc35d41a90e2a9293b Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran Date: Tue, 24 Nov 2020 15:13:52 +0530 Subject: [PATCH 3/6] Add '-nz/--no-zero' option to display only devices with non zero AER stats --- pcieutil/main.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pcieutil/main.py b/pcieutil/main.py index 5068f550f9..1f004a64fe 100644 --- a/pcieutil/main.py +++ b/pcieutil/main.py @@ -118,7 +118,8 @@ def pcie_aer(): @pcie_aer.command() -def correctable(): +@click.option('-nz', '--no-zero', is_flag=True) +def correctable(no_zero): '''Show PCIe AER correctable attributes''' statedb = SonicV2Connector() @@ -146,6 +147,9 @@ def correctable(): if not aer_attribute: continue + if no_zero and all(val=='0' for key, val in aer_attribute.items() if key.startswith('correctable')): + continue + # Tabulate Header device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) header.append(device_name) @@ -159,7 +163,8 @@ def correctable(): @pcie_aer.command() -def fatal(): +@click.option('-nz', '--no-zero', is_flag=True) +def fatal(no_zero): '''Show PCIe AER fatal attributes''' statedb = SonicV2Connector() statedb.connect(statedb.STATE_DB) @@ -186,6 +191,9 @@ def fatal(): if not aer_attribute: continue + if no_zero and all(val=='0' for key, val in aer_attribute.items() if key.startswith('fatal')): + continue + # Tabulate Header device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) header.append(device_name) @@ -199,7 +207,8 @@ def fatal(): @pcie_aer.command() -def non_fatal(): +@click.option('-nz', '--no-zero', is_flag=True) +def non_fatal(no_zero): '''Show PCIe AER non-fatal attributes ''' statedb = SonicV2Connector() statedb.connect(statedb.STATE_DB) @@ -227,6 +236,9 @@ def non_fatal(): if not aer_attribute: continue + if no_zero and all(val=='0' for key, val in aer_attribute.items() if key.startswith('non_fatal')): + continue + # Tabulate Header device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) header.append(device_name) @@ -239,17 +251,18 @@ def non_fatal(): click.echo(tabulate(list(table.values()), header, tablefmt="grid")) -@pcie_aer.command() +@pcie_aer.command(name='all') +@click.option('-nz', '--no-zero', is_flag=True) @click.pass_context -def all(ctx): +def all_errors(ctx, no_zero): '''Show all PCIe AER attributes ''' - ctx.invoke(correctable) + ctx.forward(correctable) click.echo("") - ctx.invoke(fatal) + ctx.forward(fatal) click.echo("") - ctx.invoke(non_fatal) + ctx.forward(non_fatal) click.echo("") From 586bc7513250594de9d1aa36348a121239a7be57 Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran Date: Thu, 10 Dec 2020 14:15:22 +0530 Subject: [PATCH 4/6] - Add '-d/--device' option for displaying AER stats of specified device - Include UT cases for device, no-zero options --- pcieutil/main.py | 211 +++++++++++------------ tests/mock_tables/state_db.json | 53 +++++- tests/pcieutil_test.py | 285 +++++++++++++++++++------------- 3 files changed, 328 insertions(+), 221 deletions(-) diff --git a/pcieutil/main.py b/pcieutil/main.py index 1f004a64fe..882487adac 100644 --- a/pcieutil/main.py +++ b/pcieutil/main.py @@ -7,6 +7,7 @@ try: import os + import re import sys from collections import OrderedDict @@ -108,162 +109,162 @@ def pcie_show(): Id = item["id"] click.echo("bus:dev.fn %s:%s.%s - dev_id=0x%s, %s" % (Bus, Dev, Fn, Id, Name)) -# Show PCIe AER status +# PCIe AER stats helpers -@cli.group(cls=clicommon.AliasedGroup) -def pcie_aer(): - '''Display PCIe AER status''' - pass +aer_fields = { + "correctable": ['RxErr', 'BadTLP', 'BadDLLP', 'Rollover', 'Timeout', 'NonFatalErr', 'CorrIntErr', 'HeaderOF', 'TOTAL_ERR_COR'], + "fatal": ['Undefined', 'DLP', 'SDES', 'TLP', 'FCP', 'CmpltTO', 'CmpltAbrt', 'UnxCmplt', 'RxOF', 'MalfTLP', 'ECRC', 'UnsupReq', + 'ACSViol', 'UncorrIntErr', 'BlockedTLP', 'AtomicOpBlocked', 'TLPBlockedErr', 'TOTAL_ERR_FATAL'], + "non_fatal": ['Undefined', 'DLP', 'SDES', 'TLP', 'FCP', 'CmpltTO', 'CmpltAbrt', 'UnxCmplt', 'RxOF', 'MalfTLP', 'ECRC', 'UnsupReq', + 'ACSViol', 'UncorrIntErr', 'BlockedTLP', 'AtomicOpBlocked', 'TLPBlockedErr', 'TOTAL_ERR_NONFATAL'] +} -@pcie_aer.command() -@click.option('-nz', '--no-zero', is_flag=True) -def correctable(no_zero): - '''Show PCIe AER correctable attributes''' +class PcieDevice(click.ParamType): + name = ":." - statedb = SonicV2Connector() - statedb.connect(statedb.STATE_DB) - header = ['AER - CORRECTABLE'] + def convert(self, value, param, ctx): + match = re.match(r'([0-9A-Fa-f]{1,2}):([0-9A-Fa-f]{1,2})\.([0-9A-Fa-f])', value) - # AER - Correctable fields (9) - fields = ['RxErr', 'BadTLP', 'BadDLLP', 'Rollover', 'Timeout', 'NonFatalErr', 'CorrIntErr', 'HeaderOF', 'TOTAL_ERR_COR'] - table = OrderedDict() - for field in fields: - table[field] = [field] + if not match: + self.fail('{} is not in :. format'.format(value), param, ctx) - resultInfo = platform_pcieutil.get_pcie_check() - for item in resultInfo: - if item["result"] == "Failed": - continue + Bus, Dev, Fn = [int(val, 16) for val in match.groups()] + if Bus > 255: + self.fail('Invalid Bus number', param, ctx) - Bus = item["bus"] - Dev = item["dev"] - Fn = item["fn"] - Id = item["id"] + if Dev > 31: + self.fail('Invalid Dev number', param, ctx) - pcie_dev_key = "PCIE_DEVICE|0x%s|%s:%s.%s" % (Id, Bus, Dev, Fn) - aer_attribute = statedb.get_all(statedb.STATE_DB, pcie_dev_key) - if not aer_attribute: - continue + if Fn > 7: + self.fail('Invalid Fn number', param, ctx) - if no_zero and all(val=='0' for key, val in aer_attribute.items() if key.startswith('correctable')): - continue + return "%02x:%02x.%d" % (Bus, Dev, Fn) - # Tabulate Header - device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) - header.append(device_name) - # Tabulate Row - for field in fields: - key = "correctable|" + field - table[field].append(aer_attribute.get(key, 'NA')) +_pcie_aer_click_options = [ + click.option('-d', '--device', 'device_key', + type=PcieDevice(), + help="Display stats only for the specified device"), + click.option('-nz', '--no-zero', + is_flag=True, + help="Display non-zero AER stats") +] - click.echo(tabulate(list(table.values()), header, tablefmt="grid")) +def pcie_aer_click_options(func): + for option in reversed(_pcie_aer_click_options): + func = option(func) + return func + + +def pcie_aer_display(ctx, severity): + device_key = ctx.params['device_key'] + no_zero = ctx.params['no_zero'] + header = ["AER - " + severity.upper().replace("_", "")] + fields = aer_fields[severity] + pcie_dev_list = list() + dev_found = False -@pcie_aer.command() -@click.option('-nz', '--no-zero', is_flag=True) -def fatal(no_zero): - '''Show PCIe AER fatal attributes''' statedb = SonicV2Connector() statedb.connect(statedb.STATE_DB) - header = ['AER - FATAL'] - # AER - Fatal fields (18) - fields = ['Undefined', 'DLP', 'SDES', 'TLP', 'FCP', 'CmpltTO', 'CmpltAbrt', 'UnxCmplt', 'RxOF', 'MalfTLP', 'ECRC', 'UnsupReq', 'ACSViol', 'UncorrIntErr', 'BlockedTLP', 'AtomicOpBlocked', 'TLPBlockedErr', 'TOTAL_ERR_FATAL'] table = OrderedDict() for field in fields: table[field] = [field] - resultInfo = platform_pcieutil.get_pcie_check() - for item in resultInfo: - if item["result"] == "Failed": - continue - - Bus = item["bus"] - Dev = item["dev"] - Fn = item["fn"] - Id = item["id"] + if device_key: + pcie_dev_list = ["PCIE_DEVICE|%s" % device_key] + else: + keys = statedb.keys(statedb.STATE_DB, "PCIE_DEVICE|*") + if keys: + pcie_dev_list = sorted(keys) - pcie_dev_key = "PCIE_DEVICE|0x%s|%s:%s.%s" % (Id, Bus, Dev, Fn) + for pcie_dev_key in pcie_dev_list: aer_attribute = statedb.get_all(statedb.STATE_DB, pcie_dev_key) if not aer_attribute: continue - if no_zero and all(val=='0' for key, val in aer_attribute.items() if key.startswith('fatal')): + if device_key: + dev_found = True + + if no_zero and all(val == '0' for key, val in aer_attribute.items() if key.startswith(severity)): continue + pcie_dev = pcie_dev_key.split("|")[1] + Id = aer_attribute['id'] + # Tabulate Header - device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) + device_name = "%s\n%s" % (pcie_dev, Id) header.append(device_name) # Tabulate Row for field in fields: - key = "fatal|" + field + key = severity + "|" + field table[field].append(aer_attribute.get(key, 'NA')) - click.echo(tabulate(list(table.values()), header, tablefmt="grid")) + if device_key and not dev_found: + ctx.exit("Device not found in DB") + # Strip fields with no non-zero value + if no_zero: + for field in fields: + if all(val == '0' for val in table[field][1:]): + del table[field] -@pcie_aer.command() -@click.option('-nz', '--no-zero', is_flag=True) -def non_fatal(no_zero): - '''Show PCIe AER non-fatal attributes ''' - statedb = SonicV2Connector() - statedb.connect(statedb.STATE_DB) - aer_attribute = {} - header = ['AER - NONFATAL'] + if not (no_zero and (len(header) == 1)): + if ctx.obj: + click.echo("") - # AER - Non-Fatal fields (18) - fields = ['Undefined', 'DLP', 'SDES', 'TLP', 'FCP', 'CmpltTO', 'CmpltAbrt', 'UnxCmplt', 'RxOF', 'MalfTLP', 'ECRC', 'UnsupReq', 'ACSViol', 'UncorrIntErr', 'BlockedTLP', 'AtomicOpBlocked', 'TLPBlockedErr', 'TOTAL_ERR_NONFATAL'] - table = OrderedDict() - for field in fields: - table[field] = [field] + click.echo(tabulate(list(table.values()), header, tablefmt="grid")) + ctx.obj = True + else: + ctx.obj = False - resultInfo = platform_pcieutil.get_pcie_check() - for item in resultInfo: - if item["result"] == "Failed": - continue - Bus = item["bus"] - Dev = item["dev"] - Fn = item["fn"] - Id = item["id"] +# Show PCIe AER status +@cli.group(cls=clicommon.AliasedGroup) +@click.pass_context +def pcie_aer(ctx): + '''Display PCIe AER status''' + # Set True to insert a line between severities in 'all' context + ctx.obj = False + pass - pcie_dev_key = "PCIE_DEVICE|0x%s|%s:%s.%s" % (Id, Bus, Dev, Fn) - aer_attribute = statedb.get_all(statedb.STATE_DB, pcie_dev_key) - if not aer_attribute: - continue - if no_zero and all(val=='0' for key, val in aer_attribute.items() if key.startswith('non_fatal')): - continue +@pcie_aer.command() +@pcie_aer_click_options +@click.pass_context +def correctable(ctx, no_zero, device_key): + '''Show PCIe AER correctable attributes''' + pcie_aer_display(ctx, "correctable") - # Tabulate Header - device_name = "%s:%s.%s\n0x%s" % (Bus, Dev, Fn, Id) - header.append(device_name) - # Tabulate Row - for field in fields: - key = "non_fatal|" + field - table[field].append(aer_attribute.get(key, 'NA')) +@pcie_aer.command() +@pcie_aer_click_options +@click.pass_context +def fatal(ctx, no_zero, device_key): + '''Show PCIe AER fatal attributes''' + pcie_aer_display(ctx, "fatal") + - click.echo(tabulate(list(table.values()), header, tablefmt="grid")) +@pcie_aer.command() +@pcie_aer_click_options +@click.pass_context +def non_fatal(ctx, no_zero, device_key): + '''Show PCIe AER non-fatal attributes ''' + pcie_aer_display(ctx, "non_fatal") @pcie_aer.command(name='all') -@click.option('-nz', '--no-zero', is_flag=True) +@pcie_aer_click_options @click.pass_context -def all_errors(ctx, no_zero): +def all_errors(ctx, no_zero, device_key): '''Show all PCIe AER attributes ''' - ctx.forward(correctable) - click.echo("") - - ctx.forward(fatal) - click.echo("") - - ctx.forward(non_fatal) - click.echo("") + pcie_aer_display(ctx, "correctable") + pcie_aer_display(ctx, "fatal") + pcie_aer_display(ctx, "non_fatal") # Show PCIE Vender ID and Device ID diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 4c302621ee..6729f7c93b 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -328,15 +328,17 @@ "MUX_CABLE_TABLE|Ethernet12": { "state": "unknown" }, - "PCIE_DEVICE|0x0001|00:01.0": { + "PCIE_DEVICE|00:01.0": { "correctable|BadDLLP": "0", "correctable|BadTLP": "0", + "correctable|BadTLP": "1", "correctable|CorrIntErr": "0", "correctable|HeaderOF": "0", "correctable|NonFatalErr": "0", "correctable|Rollover": "0", "correctable|RxErr": "0", "correctable|TOTAL_ERR_COR": "0", + "correctable|TOTAL_ERR_COR": "1", "correctable|Timeout": "0", "fatal|ACSViol": "0", "fatal|AtomicOpBlocked": "0", @@ -356,6 +358,55 @@ "fatal|Undefined": "0", "fatal|UnsupReq": "0", "fatal|UnxCmplt": "0", + "id": "0x0001", + "non_fatal|ACSViol": "0", + "non_fatal|AtomicOpBlocked": "0", + "non_fatal|BlockedTLP": "0", + "non_fatal|CmpltAbrt": "0", + "non_fatal|CmpltTO": "0", + "non_fatal|DLP": "0", + "non_fatal|ECRC": "0", + "non_fatal|FCP": "0", + "non_fatal|MalfTLP": "1", + "non_fatal|RxOF": "0", + "non_fatal|SDES": "0", + "non_fatal|TLP": "0", + "non_fatal|TLPBlockedErr": "0", + "non_fatal|TOTAL_ERR_NONFATAL": "1", + "non_fatal|UncorrIntErr": "0", + "non_fatal|Undefined": "0", + "non_fatal|UnsupReq": "0", + "non_fatal|UnxCmplt": "0" + }, + "PCIE_DEVICE|01:00.0": { + "correctable|BadDLLP": "0", + "correctable|BadTLP": "0", + "correctable|CorrIntErr": "0", + "correctable|HeaderOF": "0", + "correctable|NonFatalErr": "0", + "correctable|Rollover": "0", + "correctable|RxErr": "1", + "correctable|TOTAL_ERR_COR": "1", + "correctable|Timeout": "0", + "fatal|ACSViol": "0", + "fatal|AtomicOpBlocked": "0", + "fatal|BlockedTLP": "0", + "fatal|CmpltAbrt": "0", + "fatal|CmpltTO": "0", + "fatal|DLP": "0", + "fatal|ECRC": "0", + "fatal|FCP": "0", + "fatal|MalfTLP": "0", + "fatal|RxOF": "0", + "fatal|SDES": "0", + "fatal|TLP": "0", + "fatal|TLPBlockedErr": "0", + "fatal|TOTAL_ERR_FATAL": "0", + "fatal|UncorrIntErr": "0", + "fatal|Undefined": "0", + "fatal|UnsupReq": "0", + "fatal|UnxCmplt": "0", + "id": "0x0002", "non_fatal|ACSViol": "0", "non_fatal|AtomicOpBlocked": "0", "non_fatal|BlockedTLP": "0", diff --git a/tests/pcieutil_test.py b/tests/pcieutil_test.py index 63401a0473..6b777fdd5e 100644 --- a/tests/pcieutil_test.py +++ b/tests/pcieutil_test.py @@ -11,13 +11,148 @@ 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 | ++---------------------+-----------+-----------+ +| 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_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_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_nozero_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_nozero_output = """\ ++--------------------+-----------+ +| AER - NONFATAL | 00:01.0 | +| | 0x0001 | ++====================+===========+ +| MalfTLP | 1 | ++--------------------+-----------+ +| TOTAL_ERR_NONFATAL | 1 | ++--------------------+-----------+ +""" + +pcieutil_pcie_aer_correctable_dev_output = """\ +---------------------+-----------+ | AER - CORRECTABLE | 00:01.0 | | | 0x0001 | +=====================+===========+ | RxErr | 0 | +---------------------+-----------+ -| BadTLP | 0 | +| BadTLP | 1 | +---------------------+-----------+ | BadDLLP | 0 | +---------------------+-----------+ @@ -31,133 +166,53 @@ +---------------------+-----------+ | HeaderOF | 0 | +---------------------+-----------+ -| TOTAL_ERR_COR | 0 | +| TOTAL_ERR_COR | 1 | +---------------------+-----------+ """ -pcieutil_pcie_aer_non_fatal_output = """\ -+--------------------+-----------+ -| AER - NONFATAL | 00:01.0 | -| | 0x0001 | -+====================+===========+ -| Undefined | 0 | -+--------------------+-----------+ -| DLP | 0 | -+--------------------+-----------+ -| SDES | 0 | -+--------------------+-----------+ -| TLP | 0 | -+--------------------+-----------+ -| FCP | 0 | -+--------------------+-----------+ -| CmpltTO | 0 | -+--------------------+-----------+ -| CmpltAbrt | 0 | -+--------------------+-----------+ -| UnxCmplt | 0 | -+--------------------+-----------+ -| RxOF | 0 | -+--------------------+-----------+ -| MalfTLP | 0 | -+--------------------+-----------+ -| ECRC | 0 | -+--------------------+-----------+ -| UnsupReq | 0 | -+--------------------+-----------+ -| ACSViol | 0 | -+--------------------+-----------+ -| UncorrIntErr | 0 | -+--------------------+-----------+ -| BlockedTLP | 0 | -+--------------------+-----------+ -| AtomicOpBlocked | 0 | -+--------------------+-----------+ -| TLPBlockedErr | 0 | -+--------------------+-----------+ -| TOTAL_ERR_NONFATAL | 0 | -+--------------------+-----------+ -""" - -pcieutil_pcie_aer_fatal_output = """\ -+-----------------+-----------+ -| AER - FATAL | 00:01.0 | -| | 0x0001 | -+=================+===========+ -| Undefined | 0 | -+-----------------+-----------+ -| DLP | 0 | -+-----------------+-----------+ -| SDES | 0 | -+-----------------+-----------+ -| TLP | 0 | -+-----------------+-----------+ -| FCP | 0 | -+-----------------+-----------+ -| CmpltTO | 0 | -+-----------------+-----------+ -| CmpltAbrt | 0 | -+-----------------+-----------+ -| UnxCmplt | 0 | -+-----------------+-----------+ -| RxOF | 0 | -+-----------------+-----------+ -| MalfTLP | 0 | -+-----------------+-----------+ -| ECRC | 0 | -+-----------------+-----------+ -| UnsupReq | 0 | -+-----------------+-----------+ -| ACSViol | 0 | -+-----------------+-----------+ -| UncorrIntErr | 0 | -+-----------------+-----------+ -| BlockedTLP | 0 | -+-----------------+-----------+ -| AtomicOpBlocked | 0 | -+-----------------+-----------+ -| TLPBlockedErr | 0 | -+-----------------+-----------+ -| TOTAL_ERR_FATAL | 0 | -+-----------------+-----------+ -""" - - -class MockPcieUtil(object): - def __init__(self): - self.confInfo = [ - {'bus': '00', 'dev': '01', 'name': 'PCIe Device 1', 'fn': '0', 'id': '0001'} - ] - - def get_pcie_check(self): - for item in self.confInfo: - item['result'] = "Passed" - - return self.confInfo - - class TestPcieUtil(object): @classmethod def setup_class(cls): print("SETUP") os.environ["UTILITIES_UNIT_TESTING"] = "1" + def test_aer_non_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_fatal_output + "\n"\ + + pcieutil_pcie_aer_nonfatal_output) + def test_aer_correctable(self): - with mock.patch("pcieutil.main.platform_pcieutil", new_callable=MockPcieUtil): - runner = CliRunner() - result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], []) - assert pcieutil_pcie_aer_correctable_output == result.output + 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 == pcieutil_pcie_aer_fatal_output def test_aer_non_fatal(self): - with mock.patch("pcieutil.main.platform_pcieutil", new_callable=MockPcieUtil): - runner = CliRunner() - result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["non-fatal"], []) - assert pcieutil_pcie_aer_non_fatal_output == result.output + runner = CliRunner() + result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["non-fatal"], []) + assert result.output == pcieutil_pcie_aer_nonfatal_output - def test_aer_fatal(self): - with mock.patch("pcieutil.main.platform_pcieutil", new_callable=MockPcieUtil): - runner = CliRunner() - result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["fatal"], []) - assert pcieutil_pcie_aer_fatal_output == result.output + def test_aer_option_non_zero(self): + runner = CliRunner() + result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], ["-nz"]) + assert result.output == pcieutil_pcie_aer_correctable_nozero_output + + result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["fatal"], ["-nz"]) + assert result.output == "" + + result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["non-fatal"], ["-nz"]) + assert result.output == pcieutil_pcie_aer_nonfatal_nozero_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 @classmethod def teardown_class(cls): From 497123c39205d072a948b05a032632c891c906b0 Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran Date: Thu, 10 Dec 2020 14:55:15 +0530 Subject: [PATCH 5/6] Fix LGTM alert --- pcieutil/main.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pcieutil/main.py b/pcieutil/main.py index 882487adac..183581ce91 100644 --- a/pcieutil/main.py +++ b/pcieutil/main.py @@ -219,8 +219,6 @@ def pcie_aer_display(ctx, severity): click.echo(tabulate(list(table.values()), header, tablefmt="grid")) ctx.obj = True - else: - ctx.obj = False # Show PCIe AER status @@ -230,7 +228,6 @@ def pcie_aer(ctx): '''Display PCIe AER status''' # Set True to insert a line between severities in 'all' context ctx.obj = False - pass @pcie_aer.command() From a48fe18b6bb4e6b8cd15a17749533c72c8d40227 Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran Date: Wed, 13 Jan 2021 16:34:23 +0530 Subject: [PATCH 6/6] - Display only 'non-zero' stats by default (Removed '-nz/--no-zero' option) - Add '-v/--verbose' option for PCIe AER subcommands --- pcieutil/main.py | 56 +++++++++++++++------------ tests/pcieutil_test.py | 87 +++++++++++++++++------------------------- 2 files changed, 68 insertions(+), 75 deletions(-) diff --git a/pcieutil/main.py b/pcieutil/main.py index 9a1c15c9e8..3a8ca57194 100644 --- a/pcieutil/main.py +++ b/pcieutil/main.py @@ -144,24 +144,36 @@ def convert(self, value, param, ctx): _pcie_aer_click_options = [ - click.option('-d', '--device', 'device_key', + click.Option(['-d', '--device', 'device_key'], type=PcieDevice(), help="Display stats only for the specified device"), - click.option('-nz', '--no-zero', + click.Option(['-v', '--verbose'], is_flag=True, - help="Display non-zero AER stats") + help="Display all stats") ] -def pcie_aer_click_options(func): - for option in reversed(_pcie_aer_click_options): - func = option(func) - return func +class PcieAerCommand(click.Command): + '''This subclass of click.Command provides common options, help + and short help text for PCIe AER commands''' + + def __init__(self, *args, **kwargs): + super(PcieAerCommand, self).__init__(*args, **kwargs) + self.params = _pcie_aer_click_options + + def format_help_text(self, ctx, formatter): + formatter.write_paragraph() + with formatter.indentation(): + formatter.write_text("Show {} PCIe AER attributes".format(self.name.replace("_", "-"))) + formatter.write_text("(Default: Display only non-zero attributes)") + + def get_short_help_str(self, limit): + return "Show {} PCIe AER attributes".format(self.name.replace("_", "-")) def pcie_aer_display(ctx, severity): device_key = ctx.params['device_key'] - no_zero = ctx.params['no_zero'] + no_zero = not ctx.params['verbose'] header = ["AER - " + severity.upper().replace("_", "")] fields = aer_fields[severity] pcie_dev_list = list() @@ -230,35 +242,31 @@ def pcie_aer(ctx): ctx.obj = False -@pcie_aer.command() -@pcie_aer_click_options +@pcie_aer.command(cls=PcieAerCommand) @click.pass_context -def correctable(ctx, no_zero, device_key): - '''Show PCIe AER correctable attributes''' +def correctable(ctx, device_key, verbose): + '''Show correctable PCIe AER attributes''' pcie_aer_display(ctx, "correctable") -@pcie_aer.command() -@pcie_aer_click_options +@pcie_aer.command(cls=PcieAerCommand) @click.pass_context -def fatal(ctx, no_zero, device_key): - '''Show PCIe AER fatal attributes''' +def fatal(ctx, device_key, verbose): + '''Show fatal PCIe AER attributes''' pcie_aer_display(ctx, "fatal") -@pcie_aer.command() -@pcie_aer_click_options +@pcie_aer.command(cls=PcieAerCommand) @click.pass_context -def non_fatal(ctx, no_zero, device_key): - '''Show PCIe AER non-fatal attributes ''' +def non_fatal(ctx, device_key, verbose): + '''Show non-fatal PCIe AER attributes''' pcie_aer_display(ctx, "non_fatal") -@pcie_aer.command(name='all') -@pcie_aer_click_options +@pcie_aer.command(name='all', cls=PcieAerCommand) @click.pass_context -def all_errors(ctx, no_zero, device_key): - '''Show all PCIe AER attributes ''' +def all_errors(ctx, device_key, verbose): + '''Show all PCIe AER attributes''' pcie_aer_display(ctx, "correctable") pcie_aer_display(ctx, "fatal") pcie_aer_display(ctx, "non_fatal") diff --git a/tests/pcieutil_test.py b/tests/pcieutil_test.py index 6b777fdd5e..cee1feec88 100644 --- a/tests/pcieutil_test.py +++ b/tests/pcieutil_test.py @@ -19,6 +19,30 @@ +---------------------+-----------+-----------+ | 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 | @@ -35,7 +59,7 @@ +---------------------+-----------+-----------+ """ -pcieutil_pcie_aer_fatal_output = """\ +pcieutil_pcie_aer_fatal_verbose_output = """\ +-----------------+-----------+-----------+ | AER - FATAL | 00:01.0 | 01:00.0 | | | 0x0001 | 0x0002 | @@ -78,7 +102,7 @@ +-----------------+-----------+-----------+ """ -pcieutil_pcie_aer_nonfatal_output = """\ +pcieutil_pcie_aer_nonfatal_verbose_output = """\ +--------------------+-----------+-----------+ | AER - NONFATAL | 00:01.0 | 01:00.0 | | | 0x0001 | 0x0002 | @@ -121,51 +145,13 @@ +--------------------+-----------+-----------+ """ -pcieutil_pcie_aer_correctable_nozero_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_nozero_output = """\ -+--------------------+-----------+ -| AER - NONFATAL | 00:01.0 | -| | 0x0001 | -+====================+===========+ -| MalfTLP | 1 | -+--------------------+-----------+ -| TOTAL_ERR_NONFATAL | 1 | -+--------------------+-----------+ -""" - pcieutil_pcie_aer_correctable_dev_output = """\ +---------------------+-----------+ | AER - CORRECTABLE | 00:01.0 | | | 0x0001 | +=====================+===========+ -| RxErr | 0 | -+---------------------+-----------+ | BadTLP | 1 | +---------------------+-----------+ -| BadDLLP | 0 | -+---------------------+-----------+ -| Rollover | 0 | -+---------------------+-----------+ -| Timeout | 0 | -+---------------------+-----------+ -| NonFatalErr | 0 | -+---------------------+-----------+ -| CorrIntErr | 0 | -+---------------------+-----------+ -| HeaderOF | 0 | -+---------------------+-----------+ | TOTAL_ERR_COR | 1 | +---------------------+-----------+ """ @@ -176,11 +162,10 @@ def setup_class(cls): print("SETUP") os.environ["UTILITIES_UNIT_TESTING"] = "1" - def test_aer_non_all(self): + 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_fatal_output + "\n"\ + assert result.output == (pcieutil_pcie_aer_correctable_output + "\n" + pcieutil_pcie_aer_nonfatal_output) def test_aer_correctable(self): @@ -191,23 +176,23 @@ def test_aer_correctable(self): def test_aer_fatal(self): runner = CliRunner() result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["fatal"], []) - assert result.output == pcieutil_pcie_aer_fatal_output + 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_non_zero(self): + def test_aer_option_verbose(self): runner = CliRunner() - result = runner.invoke(pcieutil.cli.commands["pcie-aer"].commands["correctable"], ["-nz"]) - assert result.output == pcieutil_pcie_aer_correctable_nozero_output + 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"], ["-nz"]) - assert result.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"], ["-nz"]) - assert result.output == pcieutil_pcie_aer_nonfatal_nozero_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()