amd-debug-tools 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of amd-debug-tools might be problematic. Click here for more details.
- amd_debug/common.py +24 -0
- amd_debug/display.py +34 -0
- amd_debug/installer.py +36 -4
- amd_debug/prerequisites.py +84 -46
- amd_debug/s2idle.py +25 -10
- {amd_debug_tools-0.2.0.dist-info → amd_debug_tools-0.2.1.dist-info}/METADATA +1 -1
- amd_debug_tools-0.2.1.dist-info/RECORD +45 -0
- {amd_debug_tools-0.2.0.dist-info → amd_debug_tools-0.2.1.dist-info}/WHEEL +1 -1
- amd_debug_tools-0.2.1.dist-info/top_level.txt +18 -0
- launcher.py +35 -0
- test_acpi.py +90 -0
- test_batteries.py +92 -0
- test_bios.py +250 -0
- test_common.py +332 -0
- test_database.py +284 -0
- test_display.py +143 -0
- test_failures.py +146 -0
- test_installer.py +279 -0
- test_kernel.py +205 -0
- test_launcher.py +53 -0
- test_prerequisites.py +1769 -0
- test_pstate.py +164 -0
- test_s2idle.py +833 -0
- test_sleep_report.py +167 -0
- test_validator.py +725 -0
- test_wake.py +216 -0
- amd_debug_tools-0.2.0.dist-info/RECORD +0 -27
- amd_debug_tools-0.2.0.dist-info/top_level.txt +0 -1
- {amd_debug_tools-0.2.0.dist-info → amd_debug_tools-0.2.1.dist-info}/entry_points.txt +0 -0
- {amd_debug_tools-0.2.0.dist-info → amd_debug_tools-0.2.1.dist-info}/licenses/LICENSE +0 -0
test_kernel.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
This module contains unit tests for the kernel log functions in the amd-debug-tools package.
|
|
6
|
+
"""
|
|
7
|
+
from unittest.mock import patch, mock_open
|
|
8
|
+
|
|
9
|
+
import unittest
|
|
10
|
+
import logging
|
|
11
|
+
|
|
12
|
+
from amd_debug.kernel import sscanf_bios_args, get_kernel_command_line, DmesgLogger
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestKernelLog(unittest.TestCase):
|
|
16
|
+
"""Test Common kernel scan functions"""
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def setUpClass(cls):
|
|
20
|
+
logging.basicConfig(filename="/dev/null", level=logging.DEBUG)
|
|
21
|
+
|
|
22
|
+
def test_get_kernel_command_line(self):
|
|
23
|
+
"""Test get_kernel_command_line function"""
|
|
24
|
+
|
|
25
|
+
# Test case with a valid kernel command line that is fully filtered
|
|
26
|
+
kernel_cmdline = "quiet splash"
|
|
27
|
+
expected_output = ""
|
|
28
|
+
with patch(
|
|
29
|
+
"builtins.open", new_callable=mock_open, read_data=kernel_cmdline
|
|
30
|
+
) as _mock_file:
|
|
31
|
+
result = get_kernel_command_line()
|
|
32
|
+
self.assertEqual(result, expected_output)
|
|
33
|
+
|
|
34
|
+
# Test case with an empty kernel command line
|
|
35
|
+
kernel_cmdline = ""
|
|
36
|
+
expected_output = ""
|
|
37
|
+
with patch(
|
|
38
|
+
"builtins.open", new_callable=mock_open, read_data=kernel_cmdline
|
|
39
|
+
) as _mock_file:
|
|
40
|
+
result = get_kernel_command_line()
|
|
41
|
+
self.assertEqual(result, expected_output)
|
|
42
|
+
|
|
43
|
+
# Test case with a kernel command line containing special characters
|
|
44
|
+
kernel_cmdline = "quiet splash --debug=1"
|
|
45
|
+
expected_output = "--debug=1"
|
|
46
|
+
with patch(
|
|
47
|
+
"builtins.open", new_callable=mock_open, read_data=kernel_cmdline
|
|
48
|
+
) as _mock_file:
|
|
49
|
+
result = get_kernel_command_line()
|
|
50
|
+
self.assertEqual(result, expected_output)
|
|
51
|
+
|
|
52
|
+
# Test case with a kernel command line containing special characters
|
|
53
|
+
kernel_cmdline = "quiet splash initrd=foo modprobe.blacklist=foo"
|
|
54
|
+
expected_output = "modprobe.blacklist=foo"
|
|
55
|
+
with patch(
|
|
56
|
+
"builtins.open", new_callable=mock_open, read_data=kernel_cmdline
|
|
57
|
+
) as _mock_file:
|
|
58
|
+
result = get_kernel_command_line()
|
|
59
|
+
self.assertEqual(result, expected_output)
|
|
60
|
+
|
|
61
|
+
def test_sscanf_bios_args(self):
|
|
62
|
+
"""Test sscanf_bios_args function"""
|
|
63
|
+
|
|
64
|
+
# Test case with a valid line
|
|
65
|
+
line = 'ex_trace_args: "format_string", 0x1234, 0x5678'
|
|
66
|
+
expected_output = "format_string"
|
|
67
|
+
result = sscanf_bios_args(line)
|
|
68
|
+
self.assertEqual(result, expected_output)
|
|
69
|
+
|
|
70
|
+
# Test case with an invalid line
|
|
71
|
+
line = 'invalid_line: "format_string", 0x1234, 0x5678'
|
|
72
|
+
result = sscanf_bios_args(line)
|
|
73
|
+
self.assertIsNone(result)
|
|
74
|
+
|
|
75
|
+
# Test case with a line containing "Unknown"
|
|
76
|
+
line = 'ex_trace_args: "format_string", Unknown, 0x5678'
|
|
77
|
+
expected_output = "format_string"
|
|
78
|
+
result = sscanf_bios_args(line)
|
|
79
|
+
self.assertEqual(result, expected_output)
|
|
80
|
+
|
|
81
|
+
# make sure that lines with ex_trace_point are not parsed
|
|
82
|
+
line = 'ex_trace_point: "format_string", 0x1234, 0x5678'
|
|
83
|
+
result = sscanf_bios_args(line)
|
|
84
|
+
self.assertTrue(result)
|
|
85
|
+
|
|
86
|
+
# test a real post code line
|
|
87
|
+
line = 'ex_trace_args: " POST CODE: %X ACPI TIMER: %X TIME: %d.%d ms\\n", b0003f33, 83528798, 0, 77, 0, 0'
|
|
88
|
+
expected_output = "POST CODE: B0003F33 ACPI TIMER: 83528798 TIME: 0.77 ms"
|
|
89
|
+
result = sscanf_bios_args(line)
|
|
90
|
+
self.assertEqual(result, expected_output)
|
|
91
|
+
|
|
92
|
+
# test a real _REG print
|
|
93
|
+
line = 'ex_trace_args: " OEM-ASL-PCIe Address (0x%X)._REG (%d %d) PCSA = %d\\n", ec303000, 2, 0, 0, 0, 0'
|
|
94
|
+
expected_output = "OEM-ASL-PCIe Address (0xEC303000)._REG (2 0) PCSA = 0"
|
|
95
|
+
result = sscanf_bios_args(line)
|
|
96
|
+
self.assertEqual(result, expected_output)
|
|
97
|
+
|
|
98
|
+
# test case of too may arguments
|
|
99
|
+
line = 'ex_trace_args : " APGE = %d\\n", 1, 0, 0, 0, 0, 0'
|
|
100
|
+
expected_output = "APGE = 1"
|
|
101
|
+
result = sscanf_bios_args(line)
|
|
102
|
+
self.assertEqual(result, expected_output)
|
|
103
|
+
|
|
104
|
+
# test case for Dispatch notify
|
|
105
|
+
line = "evmisc-0132 ev_queue_notify_reques: Dispatching Notify on [UBTC] (Device) Value 0x80 (Status Change) Node 00000000851b15c1"
|
|
106
|
+
expected_output = (
|
|
107
|
+
"Dispatching Notify on [UBTC] (Device) Value 0x80 (Status Change)"
|
|
108
|
+
)
|
|
109
|
+
result = sscanf_bios_args(line)
|
|
110
|
+
self.assertEqual(result, expected_output)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class TestDmesgLogger(unittest.TestCase):
|
|
114
|
+
"""Test Dmesg logger functions"""
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def setUpClass(cls):
|
|
118
|
+
logging.basicConfig(filename="/dev/null", level=logging.DEBUG)
|
|
119
|
+
|
|
120
|
+
def test_dmesg_logger_initialization(self):
|
|
121
|
+
"""Test initialization of DmesgLogger"""
|
|
122
|
+
|
|
123
|
+
with patch("subprocess.run") as mock_run:
|
|
124
|
+
# Mock the subprocess output for dmesg -h
|
|
125
|
+
mock_run.return_value.stdout = b"--since supported\n"
|
|
126
|
+
mock_run.return_value.returncode = 0
|
|
127
|
+
|
|
128
|
+
logger = DmesgLogger()
|
|
129
|
+
self.assertTrue(logger.since_support)
|
|
130
|
+
self.assertEqual(logger.command, ["dmesg", "-t", "-k"])
|
|
131
|
+
|
|
132
|
+
def test_dmesg_logger_refresh_head(self):
|
|
133
|
+
"""Test _refresh_head method of DmesgLogger"""
|
|
134
|
+
|
|
135
|
+
with patch("subprocess.run") as mock_run:
|
|
136
|
+
# Mock the subprocess output for dmesg
|
|
137
|
+
mock_run.return_value.stdout = b"line1\nline2\n"
|
|
138
|
+
mock_run.return_value.returncode = 0
|
|
139
|
+
|
|
140
|
+
logger = DmesgLogger()
|
|
141
|
+
logger._refresh_head() # pylint: disable=protected-access
|
|
142
|
+
self.assertEqual(logger.buffer, "line1\nline2\n")
|
|
143
|
+
|
|
144
|
+
def test_dmesg_logger_seek_tail(self):
|
|
145
|
+
"""Test seek_tail method of DmesgLogger"""
|
|
146
|
+
|
|
147
|
+
with patch("subprocess.run") as mock_run:
|
|
148
|
+
# Mock the subprocess output for dmesg
|
|
149
|
+
mock_run.return_value.stdout = b"line1\nline2\n"
|
|
150
|
+
mock_run.return_value.returncode = 0
|
|
151
|
+
|
|
152
|
+
logger = DmesgLogger()
|
|
153
|
+
logger.seek_tail()
|
|
154
|
+
self.assertEqual(logger.buffer, "line1\nline2\n")
|
|
155
|
+
|
|
156
|
+
def test_dmesg_logger_process_callback(self):
|
|
157
|
+
"""Test process_callback method of DmesgLogger"""
|
|
158
|
+
|
|
159
|
+
with patch("subprocess.run") as mock_run:
|
|
160
|
+
# Mock the subprocess output for dmesg
|
|
161
|
+
mock_run.return_value.stdout = b"line1\nline2\n"
|
|
162
|
+
mock_run.return_value.returncode = 0
|
|
163
|
+
|
|
164
|
+
logger = DmesgLogger()
|
|
165
|
+
logger._refresh_head() # pylint: disable=protected-access
|
|
166
|
+
|
|
167
|
+
mock_callback = unittest.mock.Mock()
|
|
168
|
+
logger.process_callback(mock_callback)
|
|
169
|
+
|
|
170
|
+
mock_callback.assert_any_call("line1", None)
|
|
171
|
+
mock_callback.assert_any_call("line2", None)
|
|
172
|
+
|
|
173
|
+
def test_dmesg_logger_match_line(self):
|
|
174
|
+
"""Test match_line method of DmesgLogger"""
|
|
175
|
+
|
|
176
|
+
with patch("subprocess.run") as mock_run:
|
|
177
|
+
# Mock the subprocess output for dmesg
|
|
178
|
+
mock_run.return_value.stdout = b"line1\nline2\n"
|
|
179
|
+
mock_run.return_value.returncode = 0
|
|
180
|
+
|
|
181
|
+
logger = DmesgLogger()
|
|
182
|
+
logger._refresh_head() # pylint: disable=protected-access
|
|
183
|
+
|
|
184
|
+
result = logger.match_line(["line1"])
|
|
185
|
+
self.assertEqual(result, "line1")
|
|
186
|
+
|
|
187
|
+
result = logger.match_line(["nonexistent"])
|
|
188
|
+
self.assertEqual(result, "")
|
|
189
|
+
|
|
190
|
+
def test_dmesg_logger_match_pattern(self):
|
|
191
|
+
"""Test match_pattern method of DmesgLogger"""
|
|
192
|
+
|
|
193
|
+
with patch("subprocess.run") as mock_run:
|
|
194
|
+
# Mock the subprocess output for dmesg
|
|
195
|
+
mock_run.return_value.stdout = b"line1\nline2\n"
|
|
196
|
+
mock_run.return_value.returncode = 0
|
|
197
|
+
|
|
198
|
+
logger = DmesgLogger()
|
|
199
|
+
logger._refresh_head() # pylint: disable=protected-access
|
|
200
|
+
|
|
201
|
+
result = logger.match_pattern(r"line\d")
|
|
202
|
+
self.assertEqual(result, "line1")
|
|
203
|
+
|
|
204
|
+
result = logger.match_pattern(r"nonexistent")
|
|
205
|
+
self.assertEqual(result, "")
|
test_launcher.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
This module contains unit tests for the launcher in the amd-debug-tools package.
|
|
6
|
+
"""
|
|
7
|
+
from unittest.mock import patch
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
import unittest
|
|
11
|
+
|
|
12
|
+
import amd_debug
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestLauncher(unittest.TestCase):
|
|
16
|
+
"""Test launcher functions"""
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def setUpClass(cls):
|
|
20
|
+
logging.basicConfig(filename="/dev/null", level=logging.DEBUG)
|
|
21
|
+
|
|
22
|
+
def setUp(self):
|
|
23
|
+
launcher = None
|
|
24
|
+
|
|
25
|
+
def test_launcher_unknown(self):
|
|
26
|
+
"""Test launching as unknown exe"""
|
|
27
|
+
|
|
28
|
+
with patch("builtins.print") as mock_print:
|
|
29
|
+
amd_debug.launch_tool("unknown_exe.py")
|
|
30
|
+
mock_print.assert_called_once_with(
|
|
31
|
+
"\033[91mUnknown exe: unknown_exe.py\033[0m"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def test_launcher_amd_s2idle(self):
|
|
35
|
+
"""Test launching amd_s2idle"""
|
|
36
|
+
|
|
37
|
+
with patch("amd_debug.s2idle.main") as mock_main:
|
|
38
|
+
amd_debug.launch_tool("amd_s2idle.py")
|
|
39
|
+
mock_main.assert_called_once()
|
|
40
|
+
|
|
41
|
+
def test_launcher_amd_bios(self):
|
|
42
|
+
"""Test launching amd_bios"""
|
|
43
|
+
|
|
44
|
+
with patch("amd_debug.bios.main") as mock_main:
|
|
45
|
+
amd_debug.launch_tool("amd_bios.py")
|
|
46
|
+
mock_main.assert_called_once()
|
|
47
|
+
|
|
48
|
+
def test_launcher_amd_pstate(self):
|
|
49
|
+
"""Test launching amd_pstate"""
|
|
50
|
+
|
|
51
|
+
with patch("amd_debug.pstate.main") as mock_main:
|
|
52
|
+
amd_debug.launch_tool("amd_pstate.py")
|
|
53
|
+
mock_main.assert_called_once()
|