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.
test_wake.py ADDED
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/python3
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """
5
+ This module contains unit tests for the wake GPIO and IRQ functions 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.wake import WakeGPIO, WakeIRQ
13
+
14
+
15
+ class TestWakeGPIO(unittest.TestCase):
16
+ """Test WakeGPIO class"""
17
+
18
+ @classmethod
19
+ def setUpClass(cls):
20
+ logging.basicConfig(filename="/dev/null", level=logging.DEBUG)
21
+
22
+ def test_wake_gpio_initialization(self):
23
+ """Test initialization of WakeGPIO class"""
24
+ gpio = WakeGPIO(5)
25
+ self.assertEqual(gpio.num, 5)
26
+ self.assertEqual(gpio.name, "")
27
+
28
+ def test_wake_gpio_str(self):
29
+ """Test string representation of WakeGPIO class"""
30
+ gpio = WakeGPIO(5)
31
+ self.assertEqual(str(gpio), "5")
32
+ gpio.name = "Test GPIO"
33
+ self.assertEqual(str(gpio), "5 (Test GPIO)")
34
+
35
+
36
+ class TestWakeIRQ(unittest.TestCase):
37
+ """Test WakeIRQ class"""
38
+
39
+ @classmethod
40
+ def setUpClass(cls):
41
+ logging.basicConfig(filename="/dev/null", level=logging.DEBUG)
42
+
43
+ @patch("amd_debug.wake.read_file")
44
+ @patch("os.path.exists")
45
+ @patch("os.listdir")
46
+ @patch("os.walk")
47
+ def test_wake_irq_initialization(
48
+ self, mock_os_walk, mock_os_listdir, mock_os_path_exists, mock_read_file
49
+ ):
50
+ """Test initialization of WakeIRQ class"""
51
+ # Mocking file reads
52
+ mock_read_file.side_effect = lambda path: {
53
+ "/sys/kernel/irq/10/chip_name": "amd_gpio",
54
+ "/sys/kernel/irq/10/actions": "test_action",
55
+ "/sys/kernel/irq/10/wakeup": "enabled",
56
+ "/sys/kernel/irq/10/hwirq": "42",
57
+ }.get(path, "")
58
+
59
+ # Mocking os.path.exists
60
+ mock_os_path_exists.return_value = False
61
+
62
+ # Mocking os.listdir and os.walk
63
+ mock_os_listdir.return_value = []
64
+ mock_os_walk.return_value = []
65
+
66
+ irq = WakeIRQ(10)
67
+ self.assertEqual(irq.num, 10)
68
+ self.assertEqual(irq.chip_name, "amd_gpio")
69
+ self.assertEqual(irq.name, "GPIO 42")
70
+
71
+ @patch("amd_debug.wake.read_file")
72
+ @patch("os.path.exists")
73
+ @patch("os.listdir")
74
+ @patch("os.walk")
75
+ def test_wake_irq_disabled_interrupt(
76
+ self, _mock_os_walk, _mock_os_listdir, mock_os_path_exists, mock_read_file
77
+ ):
78
+ """Test initialization of WakeIRQ class with disabled interrupt"""
79
+ # Mocking file reads
80
+ mock_read_file.side_effect = lambda path: {
81
+ "/sys/kernel/irq/20/chip_name": "",
82
+ "/sys/kernel/irq/20/actions": "",
83
+ "/sys/kernel/irq/20/wakeup": "disabled",
84
+ }.get(path, "")
85
+
86
+ # Mocking os.path.exists
87
+ mock_os_path_exists.return_value = False
88
+
89
+ irq = WakeIRQ(20)
90
+ self.assertEqual(irq.name, "Disabled interrupt")
91
+
92
+ @patch("amd_debug.wake.read_file")
93
+ @patch("os.path.exists")
94
+ @patch("os.listdir")
95
+ @patch("os.walk")
96
+ @patch("pyudev.Context.list_devices")
97
+ def test_wake_irq_pci_msi(
98
+ self,
99
+ mock_list_devices,
100
+ _mock_os_walk,
101
+ _mock_os_listdir,
102
+ _mock_os_path_exists,
103
+ mock_read_file,
104
+ ):
105
+ """Test initialization of WakeIRQ class with PCI-MSI"""
106
+ # Mocking file reads
107
+ mock_read_file.side_effect = lambda path: {
108
+ "/sys/kernel/irq/30/chip_name": "PCI-MSI-0000:00:1f.2",
109
+ "/sys/kernel/irq/30/actions": "",
110
+ "/sys/kernel/irq/30/wakeup": "enabled",
111
+ }.get(path, "")
112
+
113
+ # Mocking pyudev context
114
+ mock_device = MagicMock()
115
+ mock_device.device_path = "/devices/pci0000:00/0000:00:1f.2"
116
+ mock_device.properties = {
117
+ "ID_VENDOR_FROM_DATABASE": "Intel Corporation",
118
+ "ID_PCI_CLASS_FROM_DATABASE": "SATA controller",
119
+ "PCI_SLOT_NAME": "0000:00:1f.2",
120
+ "DRIVER": "ahci",
121
+ }
122
+ mock_list_devices.return_value = [mock_device]
123
+
124
+ irq = WakeIRQ(30)
125
+ self.assertEqual(irq.name, "Intel Corporation SATA controller (0000:00:1f.2)")
126
+ self.assertEqual(irq.driver, "ahci")
127
+
128
+ @patch("amd_debug.wake.read_file")
129
+ @patch("os.path.exists")
130
+ @patch("os.listdir")
131
+ @patch("os.walk")
132
+ @patch("pyudev.Context.list_devices")
133
+ def test_wake_irq_legacy_irq(
134
+ self,
135
+ _mock_list_devices,
136
+ _mock_os_walk,
137
+ mock_os_listdir,
138
+ mock_os_path_exists,
139
+ mock_read_file,
140
+ ):
141
+ """Test initialization of WakeIRQ class with legacy IRQs"""
142
+ # Mocking file reads
143
+ mock_read_file.side_effect = lambda path: {
144
+ "/sys/kernel/irq/40/chip_name": "IR-IO-APIC",
145
+ "/sys/kernel/irq/40/actions": "acpi",
146
+ "/sys/kernel/irq/40/wakeup": "enabled",
147
+ }.get(path, "")
148
+
149
+ # Mocking os.path.exists
150
+ mock_os_path_exists.return_value = False
151
+
152
+ # Mocking os.listdir
153
+ mock_os_listdir.return_value = []
154
+
155
+ irq = WakeIRQ(40)
156
+ self.assertEqual(irq.name, "ACPI SCI")
157
+
158
+ @patch("amd_debug.wake.read_file")
159
+ @patch("os.path.exists")
160
+ @patch("os.listdir")
161
+ @patch("os.walk")
162
+ def test_wake_irq_acpi_device(
163
+ self, mock_os_walk, mock_os_listdir, mock_os_path_exists, mock_read_file
164
+ ):
165
+ """Test initialization of WakeIRQ class with ACPI device"""
166
+ # Mocking file reads
167
+ mock_read_file.side_effect = lambda path: {
168
+ "/sys/kernel/irq/50/chip_name": "",
169
+ "/sys/kernel/irq/50/actions": "acpi_device",
170
+ "/sys/kernel/irq/50/wakeup": "enabled",
171
+ "/sys/bus/acpi/devices/acpi_device/physical_node/name": "ACPI Device Name",
172
+ }.get(path, "")
173
+
174
+ # Mocking os.path.exists
175
+ def exists_side_effect(path):
176
+ return path in [
177
+ "/sys/bus/acpi/devices/acpi_device",
178
+ "/sys/bus/acpi/devices/acpi_device/physical_node",
179
+ "/sys/bus/acpi/devices/acpi_device/physical_node/name",
180
+ ]
181
+
182
+ mock_os_path_exists.side_effect = exists_side_effect
183
+
184
+ # Mocking os.listdir
185
+ mock_os_listdir.return_value = ["physical_node"]
186
+
187
+ # Mocking os.walk
188
+ mock_os_walk.return_value = [
189
+ ("/sys/bus/acpi/devices/acpi_device/physical_node", [], ["name"])
190
+ ]
191
+
192
+ irq = WakeIRQ(50)
193
+ self.assertEqual(irq.name, "ACPI Device Name")
194
+
195
+ @patch("amd_debug.wake.read_file")
196
+ @patch("os.path.exists")
197
+ @patch("os.listdir")
198
+ @patch("os.walk")
199
+ def test_wake_irq_i2c_hid_device(
200
+ self, _mock_os_walk, _mock_os_listdir, mock_os_path_exists, mock_read_file
201
+ ):
202
+ """Test initialization of WakeIRQ class with I2C HID device"""
203
+ # Mocking file reads
204
+ mock_read_file.side_effect = lambda path: {
205
+ "/sys/kernel/irq/60/chip_name": "",
206
+ "/sys/kernel/irq/60/actions": "i2c_hid_device",
207
+ "/sys/kernel/irq/60/wakeup": "enabled",
208
+ }.get(path, "")
209
+
210
+ # Mocking os.path.exists
211
+ mock_os_path_exists.return_value = False
212
+
213
+ irq = WakeIRQ(60)
214
+ irq.driver = "i2c_hid_acpi"
215
+ irq.name = "i2c_hid_device"
216
+ self.assertEqual(irq.name, "i2c_hid_device")
@@ -1,27 +0,0 @@
1
- amd_debug/__init__.py,sha256=aOtpIEKGLUStrh0e4qgilHW7HgF4Od-r9pOoZ87NwAM,1105
2
- amd_debug/acpi.py,sha256=fkD3Sov8cRT5ryPlakRlT7Z9jiCLT9x_MPWxt3xU_tc,3161
3
- amd_debug/battery.py,sha256=WN-6ys9PHCZIwg7PdwyBOa62GjBp8WKG0v1YZt5_W5s,3122
4
- amd_debug/bios.py,sha256=wmPKDsTZeQqsHjWpv-YHdgRNlCtFdzHQ6jJf0H3hjN8,3971
5
- amd_debug/common.py,sha256=Xi47CAutEAE6mPz3IkdUnU0ayGEkJo30OXr9DIHhu_0,8822
6
- amd_debug/database.py,sha256=GkRg3cmaNceyQ2_hy0MBAlMbnTDPHo2co2o4ObWpnQg,10621
7
- amd_debug/failures.py,sha256=QV3wxl9NYxUV5e0VmMy-pNLg4PoLeCVy0RvBux1pnZM,22536
8
- amd_debug/installer.py,sha256=fSUGLGElpVdUyYJjD4LWntVSmcF_faU6hRCM9t4kNAU,12154
9
- amd_debug/kernel.py,sha256=xzAy-sDY5-sd4jxyU7EaBokS7YsvEjoWRuexaTJNRBc,11851
10
- amd_debug/prerequisites.py,sha256=Tu6tDMXTptSSlkDtY_39SGLiJn8MDhUKUE2GLDtmRNI,46731
11
- amd_debug/pstate.py,sha256=akGdJkIxBp0bx3AeGv6ictNxwv8m0j9vQ2IZB0Jx3dM,9518
12
- amd_debug/s2idle-hook,sha256=LLiaqPtGd0qetu9n6EYxKHZaIdHpVQDONdOuSc0pfFg,1695
13
- amd_debug/s2idle.py,sha256=S6IAf87K16-G2xGIXCR6oym7GHGi1TZjxlFiz3s7bU4,12461
14
- amd_debug/sleep_report.py,sha256=dRoE21nkPMFoa5L9i5XrzPug4KesLfAf1RpPFB7Xpt0,15555
15
- amd_debug/validator.py,sha256=VomxJOp6ZYBp3oYEaNsD-rvio_b346VSRz7-hyhCS_c,33234
16
- amd_debug/wake.py,sha256=xT8WrFrN6voCmXWo5dsn4mQ7iR2QJxHrrYBd3EREG-Q,3936
17
- amd_debug/bash/amd-s2idle,sha256=g_cle1ElCJpwE4wcLezL6y-BdasDKTnNMhrtzKLE9ks,1142
18
- amd_debug/templates/html,sha256=tnpqHDZF5FfhC6YNRUfOG6Vn9ZtISFr10kEXSB476Mw,14518
19
- amd_debug/templates/md,sha256=F0xt7m-lOsSz1VeucHA6a-1gsOH7rrik15biXnDgd54,904
20
- amd_debug/templates/stdout,sha256=hyoOJ96K2dJfnWRWhyCuariLKbEHXvs9mstV_g5aMdI,469
21
- amd_debug/templates/txt,sha256=nNdsvbPFOhGdL7VA-_4k5aN3nB-6ouGQt6AsWst7T3w,649
22
- amd_debug_tools-0.2.0.dist-info/licenses/LICENSE,sha256=RBlZI6r3MRGzymI2VDX2iW__D2APDbMhu_Xg5t6BWeo,1066
23
- amd_debug_tools-0.2.0.dist-info/METADATA,sha256=iyX-wpq8WWdx619aSLbeUd8knAdfm_UCcamPu5mLQVE,6783
24
- amd_debug_tools-0.2.0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
25
- amd_debug_tools-0.2.0.dist-info/entry_points.txt,sha256=HC11T2up0pPfroAn6Pg5M2jOZXhkWIipToJ1YPTKqu8,116
26
- amd_debug_tools-0.2.0.dist-info/top_level.txt,sha256=7yUDU3ZY79gqXz0vl4TJzoTfngMPfQhrYFRU8PR2CB4,10
27
- amd_debug_tools-0.2.0.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- amd_debug