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_sleep_report.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
This module contains unit tests for the s2idle tool in the amd-debug-tools package.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import unittest
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
from unittest.mock import patch
|
|
11
|
+
import pandas as pd
|
|
12
|
+
|
|
13
|
+
from amd_debug.sleep_report import (
|
|
14
|
+
remove_duplicates,
|
|
15
|
+
format_gpio_as_str,
|
|
16
|
+
format_irq_as_str,
|
|
17
|
+
format_as_human,
|
|
18
|
+
format_as_seconds,
|
|
19
|
+
format_watts,
|
|
20
|
+
format_percent,
|
|
21
|
+
format_timedelta,
|
|
22
|
+
parse_hw_sleep,
|
|
23
|
+
SleepReport,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from amd_debug.wake import WakeGPIO, WakeIRQ
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TestSleepReportUtils(unittest.TestCase):
|
|
30
|
+
"""Unit tests for the sleep report utilities."""
|
|
31
|
+
|
|
32
|
+
def test_remove_duplicates(self):
|
|
33
|
+
"""Test the remove_duplicates function."""
|
|
34
|
+
self.assertEqual(remove_duplicates("1, 2, 2, 3"), [1, 2, 3])
|
|
35
|
+
self.assertEqual(remove_duplicates("4 4 5 6"), [4, 5, 6])
|
|
36
|
+
self.assertEqual(remove_duplicates(""), [])
|
|
37
|
+
|
|
38
|
+
def test_format_gpio_as_str(self):
|
|
39
|
+
"""Test the format_gpio_as_str function."""
|
|
40
|
+
self.assertEqual(format_gpio_as_str("1, 2, 2, 3"), "1, 2, 3")
|
|
41
|
+
self.assertEqual(format_gpio_as_str("4 4 5 6"), "4, 5, 6")
|
|
42
|
+
self.assertEqual(format_gpio_as_str(""), "")
|
|
43
|
+
|
|
44
|
+
@patch("amd_debug.wake.read_file")
|
|
45
|
+
@patch("os.path.exists")
|
|
46
|
+
@patch("os.listdir")
|
|
47
|
+
@patch("os.walk")
|
|
48
|
+
def test_format_irq_as_str(
|
|
49
|
+
self, _mock_os_walk, _mock_os_listdir, mock_os_path_exists, mock_read_file
|
|
50
|
+
):
|
|
51
|
+
"""Test the format_irq_as_str function."""
|
|
52
|
+
mock_read_file.side_effect = lambda path: {
|
|
53
|
+
"/sys/kernel/irq/20/chip_name": "",
|
|
54
|
+
"/sys/kernel/irq/20/actions": "",
|
|
55
|
+
"/sys/kernel/irq/20/wakeup": "disabled",
|
|
56
|
+
}.get(path, "")
|
|
57
|
+
|
|
58
|
+
# Mocking os.path.exists
|
|
59
|
+
mock_os_path_exists.return_value = False
|
|
60
|
+
|
|
61
|
+
self.assertEqual(format_irq_as_str("20"), "Disabled interrupt")
|
|
62
|
+
self.assertEqual(format_irq_as_str(""), "")
|
|
63
|
+
|
|
64
|
+
def test_format_as_human(self):
|
|
65
|
+
"""Test the format_as_human function."""
|
|
66
|
+
self.assertEqual(
|
|
67
|
+
format_as_human("20231010123045"),
|
|
68
|
+
datetime(2023, 10, 10, 12, 30, 45),
|
|
69
|
+
)
|
|
70
|
+
with self.assertRaises(ValueError):
|
|
71
|
+
format_as_human("invalid_date")
|
|
72
|
+
|
|
73
|
+
def test_format_as_seconds(self):
|
|
74
|
+
"""Test the format_as_seconds function."""
|
|
75
|
+
self.assertEqual(
|
|
76
|
+
format_as_seconds("20231010123045"),
|
|
77
|
+
datetime(2023, 10, 10, 12, 30, 45).timestamp(),
|
|
78
|
+
)
|
|
79
|
+
with self.assertRaises(ValueError):
|
|
80
|
+
format_as_seconds("invalid_date")
|
|
81
|
+
|
|
82
|
+
def test_format_watts(self):
|
|
83
|
+
"""Test the format_watts function."""
|
|
84
|
+
self.assertEqual(format_watts(12.3456), "12.35W")
|
|
85
|
+
self.assertEqual(format_watts(0), "0.00W")
|
|
86
|
+
|
|
87
|
+
def test_format_percent(self):
|
|
88
|
+
"""Test the format_percent function."""
|
|
89
|
+
self.assertEqual(format_percent(12.3456), "12.35%")
|
|
90
|
+
self.assertEqual(format_percent(0), "0.00%")
|
|
91
|
+
|
|
92
|
+
def test_format_timedelta(self):
|
|
93
|
+
"""Test the format_timedelta function."""
|
|
94
|
+
self.assertEqual(format_timedelta(3600), "1:00:00")
|
|
95
|
+
self.assertEqual(format_timedelta(3661), "1:01:01")
|
|
96
|
+
|
|
97
|
+
def test_parse_hw_sleep(self):
|
|
98
|
+
"""Test the parse_hw_sleep function."""
|
|
99
|
+
self.assertEqual(parse_hw_sleep(0.5), 50)
|
|
100
|
+
self.assertEqual(parse_hw_sleep(1.0), 100)
|
|
101
|
+
self.assertEqual(parse_hw_sleep(1.5), 0)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class TestSleepReport(unittest.TestCase):
|
|
105
|
+
"""Unit tests for the SleepReport class."""
|
|
106
|
+
|
|
107
|
+
@patch("amd_debug.sleep_report.SleepDatabase")
|
|
108
|
+
def setUp(self, MockSleepDatabase):
|
|
109
|
+
"""Set up a mock SleepReport instance for testing."""
|
|
110
|
+
self.mock_db = MockSleepDatabase.return_value
|
|
111
|
+
self.mock_db.report_summary_dataframe.return_value = pd.DataFrame(
|
|
112
|
+
{
|
|
113
|
+
"t0": [datetime(2023, 10, 10, 12, 0, 0).strftime("%Y%m%d%H%M%S")],
|
|
114
|
+
"t1": [datetime(2023, 10, 10, 12, 30, 0).strftime("%Y%m%d%H%M%S")],
|
|
115
|
+
"hw": [50],
|
|
116
|
+
"requested": [1],
|
|
117
|
+
"gpio": ["1, 2"],
|
|
118
|
+
"wake_irq": ["1"],
|
|
119
|
+
"b0": [90],
|
|
120
|
+
"b1": [85],
|
|
121
|
+
"full": [100],
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
self.since = datetime(2023, 10, 9, 0, 0, 0)
|
|
125
|
+
self.until = datetime(2023, 10, 12, 0, 0, 0)
|
|
126
|
+
self.report = SleepReport(
|
|
127
|
+
since=self.since,
|
|
128
|
+
until=self.until,
|
|
129
|
+
fname=None,
|
|
130
|
+
fmt="txt",
|
|
131
|
+
tool_debug=False,
|
|
132
|
+
report_debug=False,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
def test_analyze_duration(self):
|
|
136
|
+
"""Test the analyze_duration method."""
|
|
137
|
+
self.report.analyze_duration(
|
|
138
|
+
index=0,
|
|
139
|
+
t0=datetime(2023, 10, 10, 12, 0, 0),
|
|
140
|
+
t1=datetime(2023, 10, 10, 12, 30, 0),
|
|
141
|
+
requested=20,
|
|
142
|
+
hw=50,
|
|
143
|
+
)
|
|
144
|
+
self.assertEqual(len(self.report.failures), 2)
|
|
145
|
+
|
|
146
|
+
@patch("amd_debug.sleep_report.Environment")
|
|
147
|
+
@patch("amd_debug.sleep_report.FileSystemLoader")
|
|
148
|
+
def test_build_template(self, _mock_fsl, mock_env):
|
|
149
|
+
"""Test the build_template method."""
|
|
150
|
+
mock_template = mock_env.return_value.get_template.return_value
|
|
151
|
+
mock_template.render.return_value = "Rendered Template"
|
|
152
|
+
result = self.report.build_template(inc_prereq=False)
|
|
153
|
+
self.assertEqual(result, "Rendered Template")
|
|
154
|
+
|
|
155
|
+
@patch("matplotlib.pyplot.savefig")
|
|
156
|
+
def test_build_battery_chart(self, mock_savefig):
|
|
157
|
+
"""Test the build_battery_chart method."""
|
|
158
|
+
self.report.build_battery_chart()
|
|
159
|
+
self.assertIsNotNone(self.report.battery_svg)
|
|
160
|
+
mock_savefig.assert_called_once()
|
|
161
|
+
|
|
162
|
+
@patch("matplotlib.pyplot.savefig")
|
|
163
|
+
def test_build_hw_sleep_chart(self, mock_savefig):
|
|
164
|
+
"""Test the build_hw_sleep_chart method."""
|
|
165
|
+
self.report.build_hw_sleep_chart()
|
|
166
|
+
self.assertIsNotNone(self.report.hwsleep_svg)
|
|
167
|
+
mock_savefig.assert_called_once()
|