amd-debug-tools 0.2.0__py3-none-any.whl → 0.2.2__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.
- amd_debug/common.py +48 -0
- amd_debug/display.py +34 -0
- amd_debug/failures.py +13 -1
- amd_debug/installer.py +69 -5
- amd_debug/prerequisites.py +157 -56
- amd_debug/s2idle.py +46 -17
- amd_debug/sleep_report.py +2 -2
- amd_debug/templates/md +0 -7
- amd_debug/validator.py +3 -5
- {amd_debug_tools-0.2.0.dist-info → amd_debug_tools-0.2.2.dist-info}/METADATA +4 -3
- amd_debug_tools-0.2.2.dist-info/RECORD +45 -0
- {amd_debug_tools-0.2.0.dist-info → amd_debug_tools-0.2.2.dist-info}/WHEEL +1 -1
- amd_debug_tools-0.2.2.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 +444 -0
- test_database.py +284 -0
- test_display.py +143 -0
- test_failures.py +146 -0
- test_installer.py +281 -0
- test_kernel.py +205 -0
- test_launcher.py +53 -0
- test_prerequisites.py +1935 -0
- test_pstate.py +164 -0
- test_s2idle.py +868 -0
- test_sleep_report.py +167 -0
- test_validator.py +723 -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.2.dist-info}/entry_points.txt +0 -0
- {amd_debug_tools-0.2.0.dist-info → amd_debug_tools-0.2.2.dist-info}/licenses/LICENSE +0 -0
test_pstate.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
This module contains unit tests for the pstate tool in the amd-debug-tools package.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
import unittest
|
|
10
|
+
from unittest.mock import patch, MagicMock
|
|
11
|
+
|
|
12
|
+
from amd_debug.pstate import (
|
|
13
|
+
AmdPstateTriage,
|
|
14
|
+
amd_cppc_cap_lowest_perf,
|
|
15
|
+
amd_cppc_cap_lownonlin_perf,
|
|
16
|
+
amd_cppc_cap_nominal_perf,
|
|
17
|
+
amd_cppc_cap_highest_perf,
|
|
18
|
+
amd_cppc_max_perf,
|
|
19
|
+
amd_cppc_min_perf,
|
|
20
|
+
amd_cppc_des_perf,
|
|
21
|
+
amd_cppc_epp_perf,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestAmdPstateTriage(unittest.TestCase):
|
|
26
|
+
"""Test AmdPstateTriage class"""
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def setUpClass(cls):
|
|
30
|
+
logging.basicConfig(filename="/dev/null", level=logging.DEBUG)
|
|
31
|
+
|
|
32
|
+
@patch("amd_debug.pstate.relaunch_sudo")
|
|
33
|
+
@patch("amd_debug.pstate.get_pretty_distro", return_value="Test Distro")
|
|
34
|
+
@patch("amd_debug.pstate.print_color")
|
|
35
|
+
@patch("amd_debug.pstate.Context")
|
|
36
|
+
def test_init(
|
|
37
|
+
self,
|
|
38
|
+
_mock_context,
|
|
39
|
+
mock_print_color,
|
|
40
|
+
mock_get_pretty_distro,
|
|
41
|
+
mock_relaunch_sudo,
|
|
42
|
+
):
|
|
43
|
+
"""Test initialization of AmdPstateTriage class"""
|
|
44
|
+
triage = AmdPstateTriage(logging=True)
|
|
45
|
+
mock_relaunch_sudo.assert_called_once()
|
|
46
|
+
mock_get_pretty_distro.assert_called_once()
|
|
47
|
+
mock_print_color.assert_called_with("Test Distro", "🐧")
|
|
48
|
+
self.assertIsNotNone(triage.context)
|
|
49
|
+
|
|
50
|
+
@patch("amd_debug.pstate.os.path.exists", return_value=True)
|
|
51
|
+
@patch("amd_debug.pstate.read_file", return_value="test_value")
|
|
52
|
+
@patch("amd_debug.pstate.print_color")
|
|
53
|
+
@patch("amd_debug.pstate.relaunch_sudo")
|
|
54
|
+
def test_gather_amd_pstate_info(
|
|
55
|
+
self, _mock_relaunch_sudo, mock_print_color, mock_read_file, mock_path_exists
|
|
56
|
+
):
|
|
57
|
+
"""Test gather_amd_pstate_info method"""
|
|
58
|
+
triage = AmdPstateTriage(logging=False)
|
|
59
|
+
triage.gather_amd_pstate_info()
|
|
60
|
+
mock_path_exists.assert_called()
|
|
61
|
+
mock_read_file.assert_called()
|
|
62
|
+
mock_print_color.assert_any_call("'status':\ttest_value", "○")
|
|
63
|
+
mock_print_color.assert_any_call("'prefcore':\ttest_value", "○")
|
|
64
|
+
|
|
65
|
+
@patch(
|
|
66
|
+
"amd_debug.pstate.os.uname",
|
|
67
|
+
return_value=MagicMock(sysname="Linux", release="5.15.0"),
|
|
68
|
+
)
|
|
69
|
+
@patch("amd_debug.pstate.print_color")
|
|
70
|
+
@patch("amd_debug.pstate.relaunch_sudo")
|
|
71
|
+
def test_gather_kernel_info(
|
|
72
|
+
self, _mock_relaunch_sudo, mock_print_color, mock_uname
|
|
73
|
+
):
|
|
74
|
+
"""Test gather_kernel_info method"""
|
|
75
|
+
triage = AmdPstateTriage(logging=False)
|
|
76
|
+
triage.gather_kernel_info()
|
|
77
|
+
mock_uname.assert_called()
|
|
78
|
+
mock_print_color.assert_called_with("Kernel:\t5.15.0", "🐧")
|
|
79
|
+
|
|
80
|
+
@patch("amd_debug.pstate.os.path.exists", return_value=True)
|
|
81
|
+
@patch("amd_debug.pstate.read_file", return_value="1")
|
|
82
|
+
@patch("amd_debug.pstate.print_color")
|
|
83
|
+
@patch("amd_debug.pstate.relaunch_sudo")
|
|
84
|
+
def test_gather_scheduler_info(
|
|
85
|
+
self, _mock_relaunch_sudo, mock_print_color, mock_read_file, mock_path_exists
|
|
86
|
+
):
|
|
87
|
+
"""Test gather_scheduler_info method"""
|
|
88
|
+
triage = AmdPstateTriage(logging=False)
|
|
89
|
+
triage.gather_scheduler_info()
|
|
90
|
+
mock_path_exists.assert_called()
|
|
91
|
+
mock_read_file.assert_called()
|
|
92
|
+
mock_print_color.assert_any_call("ITMT:\t1", "🐧")
|
|
93
|
+
|
|
94
|
+
@patch("amd_debug.pstate.read_msr")
|
|
95
|
+
@patch("amd_debug.pstate.print_color")
|
|
96
|
+
@patch("amd_debug.pstate.Context")
|
|
97
|
+
@patch("amd_debug.pstate.relaunch_sudo")
|
|
98
|
+
def test_gather_msrs(
|
|
99
|
+
self, _mock_relaunch_sudo, mock_context, mock_print_color, mock_read_msr
|
|
100
|
+
):
|
|
101
|
+
"""Test gather_msrs method"""
|
|
102
|
+
# Mock the list of CPUs
|
|
103
|
+
mock_context.return_value.list_devices.return_value = [
|
|
104
|
+
MagicMock(sys_name="cpu0"),
|
|
105
|
+
MagicMock(sys_name="cpu1"),
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
# Mock MSR values for the CPUs
|
|
109
|
+
mock_read_msr.side_effect = [
|
|
110
|
+
0x1, # MSR_AMD_CPPC_ENABLE for cpu0
|
|
111
|
+
0x2, # MSR_AMD_CPPC_STATUS for cpu0
|
|
112
|
+
0x12345678, # MSR_AMD_CPPC_CAP1 for cpu0
|
|
113
|
+
0x87654321, # MSR_AMD_CPPC_CAP2 for cpu0
|
|
114
|
+
0xABCDEF, # MSR_AMD_CPPC_REQ for cpu0
|
|
115
|
+
0x1, # MSR_AMD_CPPC_ENABLE for cpu1
|
|
116
|
+
0x2, # MSR_AMD_CPPC_STATUS for cpu1
|
|
117
|
+
0x12345678, # MSR_AMD_CPPC_CAP1 for cpu1
|
|
118
|
+
0x87654321, # MSR_AMD_CPPC_CAP2 for cpu1
|
|
119
|
+
0xABCDEF, # MSR_AMD_CPPC_REQ for cpu1
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
triage = AmdPstateTriage(logging=False)
|
|
123
|
+
result = triage.gather_msrs()
|
|
124
|
+
|
|
125
|
+
# Assert that MSR values were read for both CPUs
|
|
126
|
+
self.assertEqual(mock_read_msr.call_count, 10)
|
|
127
|
+
|
|
128
|
+
# Assert that print_color was called to display the MSR information
|
|
129
|
+
self.assertTrue(mock_print_color.called)
|
|
130
|
+
|
|
131
|
+
# Assert that the method returned True (indicating success)
|
|
132
|
+
self.assertIsNone(result)
|
|
133
|
+
|
|
134
|
+
def test_amd_cppc_cap_lowest_perf(self):
|
|
135
|
+
"""Test amd_cppc_cap_lowest_perf function"""
|
|
136
|
+
self.assertEqual(amd_cppc_cap_lowest_perf(0x12345678), 0x78)
|
|
137
|
+
|
|
138
|
+
def test_amd_cppc_cap_lownonlin_perf(self):
|
|
139
|
+
"""Test amd_cppc_cap_lownonlin_perf function"""
|
|
140
|
+
self.assertEqual(amd_cppc_cap_lownonlin_perf(0x12345678), 0x56)
|
|
141
|
+
|
|
142
|
+
def test_amd_cppc_cap_nominal_perf(self):
|
|
143
|
+
"""Test amd_cppc_cap_nominal_perf function"""
|
|
144
|
+
self.assertEqual(amd_cppc_cap_nominal_perf(0x12345678), 0x34)
|
|
145
|
+
|
|
146
|
+
def test_amd_cppc_cap_highest_perf(self):
|
|
147
|
+
"""Test amd_cppc_cap_highest_perf function"""
|
|
148
|
+
self.assertEqual(amd_cppc_cap_highest_perf(0x12345678), 0x12)
|
|
149
|
+
|
|
150
|
+
def test_amd_cppc_max_perf(self):
|
|
151
|
+
"""Test amd_cppc_max_perf function"""
|
|
152
|
+
self.assertEqual(amd_cppc_max_perf(0x12345678), 0x78)
|
|
153
|
+
|
|
154
|
+
def test_amd_cppc_min_perf(self):
|
|
155
|
+
"""Test amd_cppc_min_perf function"""
|
|
156
|
+
self.assertEqual(amd_cppc_min_perf(0x12345678), 0x56)
|
|
157
|
+
|
|
158
|
+
def test_amd_cppc_des_perf(self):
|
|
159
|
+
"""Test amd_cppc_des_perf function"""
|
|
160
|
+
self.assertEqual(amd_cppc_des_perf(0x12345678), 0x34)
|
|
161
|
+
|
|
162
|
+
def test_amd_cppc_epp_perf(self):
|
|
163
|
+
"""Test amd_cppc_epp_perf function"""
|
|
164
|
+
self.assertEqual(amd_cppc_epp_perf(0x12345678), 0x12)
|