Debian Codegraph @

tests/test_intel_therm.py

raw symbols SCIP
1 """Tests for Intel IA32_THERM_STATUS decoder."""
2
3 from s_tui.sources.intel_therm import (
4 CRITICAL_STATUS,
5 CROSS_DOMAIN_STATUS,
6 CURRENT_LIMIT_STATUS,
7 POWER_LIMIT_STATUS,
8 PROCHOT_STATUS,
9 THERMAL_STATUS,
10 ThrottleStatus,
11 available,
12 read_therm_status,
13 )
14
15
16 class TestThrottleStatus:
17 def test_no_throttle(self):
18 s = ThrottleStatus(False, False, False, False, False, False)
19 assert s.any_active is False
20 assert s.label == ""
21
22 def test_single_reason(self):
23 s = ThrottleStatus(
24 thermal=True,
25 prochot=False,
26 critical=False,
27 power_limit=False,
28 current_limit=False,
29 cross_domain=False,
30 )
31 assert s.any_active is True
32 assert s.label == "T"
33
34 def test_multiple_reasons(self):
35 s = ThrottleStatus(
36 thermal=True,
37 prochot=False,
38 critical=False,
39 power_limit=True,
40 current_limit=False,
41 cross_domain=False,
42 )
43 assert s.label == "T/W"
44
45 def test_all_reasons(self):
46 s = ThrottleStatus(True, True, True, True, True, True)
47 assert s.label == "T/H/C/W/A/X"
48
49
50 class TestReadThermStatus:
51 def test_decodes_thermal_and_power(self, mocker):
52 val = THERMAL_STATUS | POWER_LIMIT_STATUS
53 mocker.patch("s_tui.sources.intel_therm.read_msr", return_value=val)
54 status = read_therm_status(0)
55 assert status.thermal is True
56 assert status.power_limit is True
57 assert status.prochot is False
58 assert status.label == "T/W"
59
60 def test_decodes_prochot(self, mocker):
61 mocker.patch("s_tui.sources.intel_therm.read_msr", return_value=PROCHOT_STATUS)
62 status = read_therm_status(2)
63 assert status.prochot is True
64 assert status.label == "H"
65
66 def test_no_bits_set(self, mocker):
67 mocker.patch("s_tui.sources.intel_therm.read_msr", return_value=0)
68 status = read_therm_status(0)
69 assert status.any_active is False
70
71 def test_all_status_bits(self, mocker):
72 val = (
73 THERMAL_STATUS
74 | PROCHOT_STATUS
75 | CRITICAL_STATUS
76 | POWER_LIMIT_STATUS
77 | CURRENT_LIMIT_STATUS
78 | CROSS_DOMAIN_STATUS
79 )
80 mocker.patch("s_tui.sources.intel_therm.read_msr", return_value=val)
81 status = read_therm_status(0)
82 assert status.label == "T/H/C/W/A/X"
83
84
85 class TestAvailable:
86 def test_available_when_msr_works(self, mocker):
87 mocker.patch("s_tui.sources.intel_therm.msr_available", return_value=True)
88 mocker.patch("s_tui.sources.intel_therm.read_msr", return_value=0)
89 assert available() is True
90
91 def test_unavailable_without_msr(self, mocker):
92 mocker.patch("s_tui.sources.intel_therm.msr_available", return_value=False)
93 assert available() is False
94
95 def test_unavailable_on_read_error(self, mocker):
96 mocker.patch("s_tui.sources.intel_therm.msr_available", return_value=True)
97 mocker.patch("s_tui.sources.intel_therm.read_msr", side_effect=OSError)
98 assert available() is False