Skip to content

Commit 07d876c

Browse files
committed
Use type instead of name in thermal sensor tests (Bugfix)
Thermal zone indices can change across reboots, making name-based identification unreliable. This change uses the zone type field instead, ensuring consistent test execution. Additionally, thermal zone interfaces are sometimes repurposed for monitoring non-thermal parameters (e.g., voltages on Qualcomm RB3, RB8 platforms). These edge cases are excluded from test plans using regex patterns matched against the type field. When both pre-suspend and after-suspend tests are generated from templates, a watchdog-triggered reboot can cause zone index changes, invalidating regex exclusions based on zone names and causing previously excluded tests to run unexpectedly.
1 parent d0f126c commit 07d876c

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/thermal_sensor_test.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,38 @@ def mode(self):
8181
return self._read_node(self.mode_node)
8282

8383

84+
def get_thermal_zone_name(type):
85+
for thermal in Path(SYS_THERMAL_PATH).glob("thermal_zone*"):
86+
type_node = thermal.joinpath("type")
87+
if not type_node.exists():
88+
continue
89+
90+
try:
91+
type_value = type_node.read_text().strip()
92+
if type_value == type:
93+
return thermal.name
94+
except Exception as e:
95+
raise SystemExit(f"Failed to read node: {type_node}\n{e}")
96+
97+
raise FileNotFoundError(f"Thermal zone with type '{type}' not found")
98+
99+
84100
def check_temperature(current, initial):
85101
logging.info("Initial value: %s, current value: %s", initial, current)
86102
return int(current) != 0 and current != initial
87103

88104

89105
def thermal_monitor_test(args):
106+
107+
if args.name is None:
108+
if args.type is None:
109+
raise SystemExit("Error: Either --name or --type must be provided")
110+
args.name = get_thermal_zone_name(args.type)
111+
90112
logging.info(
91-
"# Monitor the temperature of %s thermal around %s seconds",
113+
"# Monitor the temperature of %s (%s) thermal around %s seconds",
92114
args.name,
115+
args.type,
93116
args.duration,
94117
)
95118

@@ -167,7 +190,8 @@ def register_arguments():
167190
)
168191

169192
monitor_parser = sub_parsers.add_parser("monitor")
170-
monitor_parser.add_argument("-n", "--name", required=True, type=str)
193+
monitor_parser.add_argument("-t", "--type", type=str)
194+
monitor_parser.add_argument("-n", "--name", type=str)
171195
monitor_parser.add_argument(
172196
"-d",
173197
"--duration",

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/tests/test_thermal_sensor_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_thermal_node_available(self, mock_file, mock_text):
2121
mock_file.return_value = True
2222
mock_text.side_effect = mock_results
2323

24-
thermal_node = thermal_sensor_test.ThermalMonitor("fake-thermal")
24+
thermal_node = thermal_sensor_test.ThermalMonitor(name="fake-thermal")
2525
self.assertListEqual(
2626
[
2727
thermal_node.name,
@@ -39,7 +39,7 @@ def test_thermal_node_not_available(self, mock_file):
3939
"""
4040
mock_file.return_value = False
4141
with self.assertRaises(FileNotFoundError):
42-
thermal_node = thermal_sensor_test.ThermalMonitor("fake-thermal")
42+
thermal_node = thermal_sensor_test.ThermalMonitor(name="fake-thermal")
4343
thermal_node.type
4444

4545
@mock.patch("thermal_sensor_test.check_temperature")
@@ -54,7 +54,7 @@ def test_thermal_monitor_test_passed(
5454
"""
5555
mock_args = mock.Mock(
5656
return_value=argparse.Namespace(
57-
name="fake-thermal", duration=30, extra_commands="stress-ng"
57+
name="fake-thermal", type=None, duration=30, extra_commands="stress-ng"
5858
)
5959
)
6060
mock_text.side_effect = ["30000", "30000", "31000"]
@@ -76,7 +76,7 @@ def test_thermal_monitor_with_fixed_temperature(
7676
):
7777
mock_args = mock.Mock(
7878
return_value=argparse.Namespace(
79-
name="fake-thermal", duration=2, extra_commands="stress-ng"
79+
name="fake-thermal", type=None, duration=2, extra_commands="stress-ng"
8080
)
8181
)
8282
mock_text.return_value = "30000"

contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/thermal-sensor/jobs.pxu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ user: root
1818
estimated_duration: 5m
1919
flags: also-after-suspend
2020
command:
21-
thermal_sensor_test.py monitor -n {name}
21+
thermal_sensor_test.py monitor -t {type}

0 commit comments

Comments
 (0)