|
| 1 | +import unittest |
| 2 | +from unittest.mock import patch, mock_open |
| 3 | +import subprocess |
| 4 | + |
| 5 | +from acpi_bios_error import check_acpi_bios_errors, main |
| 6 | + |
| 7 | + |
| 8 | +class TestAcpiBiosError(unittest.TestCase): |
| 9 | + |
| 10 | + @patch("subprocess.check_output") |
| 11 | + def test_check_acpi_bios_errors_no_errors(self, mock_subprocess): |
| 12 | + """Test when no ACPI BIOS errors are found.""" |
| 13 | + mock_subprocess.return_value = """Sep 18 17:17:37 test-host kernel: ACPI: 28 ACPI AML tables successfully acquired and loaded |
| 14 | +Sep 18 17:17:37 test-host kernel: ACPI Error: No pointer back to namespace node in package (___ptrval___) (20240827/dsargs-301) |
| 15 | +Sep 18 17:17:37 test-host kernel: ACPI Error: No pointer back to namespace node in package (___ptrval___) (20240827/dsargs-301) |
| 16 | +Sep 18 17:17:37 test-host kernel: ACPI: EC: EC started |
| 17 | +Sep 18 17:17:37 test-host kernel: ACPI: EC: interrupt blocked |
| 18 | +Sep 18 17:17:37 test-host kernel: ACPI: EC: EC_CMD/EC_SC=0x66, EC_DATA=0x62 |
| 19 | +Sep 18 17:17:37 test-host kernel: ACPI: EC: Boot ECDT EC used to handle transactions |
| 20 | +Sep 18 17:17:37 test-host kernel: ACPI: [Firmware Bug]: BIOS _OSI(Linux) query ignored |
| 21 | +Sep 18 17:17:37 test-host kernel: ACPI: USB4 _OSC: OS supports USB3+ DisplayPort+ PCIe+ XDomain+ |
| 22 | +Sep 18 17:17:37 test-host kernel: ACPI: USB4 _OSC: OS controls USB3+ DisplayPort+ PCIe+ XDomain+""" |
| 23 | + |
| 24 | + check_acpi_bios_errors() |
| 25 | + mock_subprocess.assert_called_once_with( |
| 26 | + ["journalctl", "-b", "-k"], |
| 27 | + universal_newlines=True, |
| 28 | + stderr=subprocess.STDOUT, |
| 29 | + ) |
| 30 | + |
| 31 | + @patch("acpi_bios_error.print_bios_info") |
| 32 | + @patch("subprocess.check_output") |
| 33 | + def test_check_acpi_bios_errors_found( |
| 34 | + self, mock_subprocess, mock_print_bios |
| 35 | + ): |
| 36 | + """Test when ACPI BIOS errors are detected.""" |
| 37 | + mock_subprocess.return_value = """Sep 18 17:17:37 test-host kernel: ACPI BIOS Error (bug): Failure creating named object [_SB.PC00.TXHC.RHUB.SS01._UPC], AE_ALREADY_EXISTS (20240827/dswload2-326) |
| 38 | +Sep 18 17:17:37 test-host kernel: ACPI Error: AE_ALREADY_EXISTS, During name lookup/catalog (20240827/psobject-220) |
| 39 | +Sep 18 17:17:37 test-host kernel: ACPI: Skipping parse of AML opcode: Method (0x0014) |
| 40 | +Sep 18 17:17:37 test-host kernel: ACPI BIOS Error (bug): Failure creating named object [_SB.PC00.TXHC.RHUB.SS01._PLD], AE_ALREADY_EXISTS (20240827/dswload2-326) |
| 41 | +Sep 18 17:17:37 test-host kernel: ACPI Error: AE_ALREADY_EXISTS, During name lookup/catalog (20240827/psobject-220) |
| 42 | +Sep 18 17:17:37 test-host kernel: ACPI: Skipping parse of AML opcode: Method (0x0014) |
| 43 | +Sep 18 17:17:37 test-host kernel: ACPI BIOS Error (bug): Could not resolve symbol [_SB.PC02.RP21.PXSX.TBDU.XHCI.RHUB.SS01], AE_NOT_FOUND (20240827/dswload2-162) |
| 44 | +Sep 18 17:17:37 test-host kernel: ACPI Error: AE_NOT_FOUND, During name lookup/catalog (20240827/psobject-220) |
| 45 | +Sep 18 17:17:37 test-host kernel: ACPI: Skipping parse of AML opcode: Scope (0x0010) |
| 46 | +Sep 18 17:17:37 test-host kernel: ACPI: 28 ACPI AML tables successfully acquired and loaded""" |
| 47 | + |
| 48 | + with self.assertRaises(SystemExit): |
| 49 | + check_acpi_bios_errors() |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + unittest.main() |
0 commit comments