Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,42 @@ def mode(self):
return self._read_node(self.mode_node)


def get_thermal_zone_name(type):
for thermal in Path(SYS_THERMAL_PATH).glob("thermal_zone*"):
type_node = thermal.joinpath("type")
if not type_node.exists():
continue

try:
type_value = type_node.read_text().strip()
if type_value == type:
return thermal.name
except Exception as e:
raise SystemExit(
"Failed to read node: {}\n{}".format(type_node, e)
)

raise FileNotFoundError(
"Thermal zone with type '{}' not found".format(type)
)


def check_temperature(current, initial):
logging.info("Initial value: %s, current value: %s", initial, current)
return int(current) != 0 and current != initial


def thermal_monitor_test(args):

if args.name is None:
if args.type is None:
raise SystemExit("Error: Either --name or --type must be provided")
args.name = get_thermal_zone_name(args.type)

logging.info(
"# Monitor the temperature of %s thermal around %s seconds",
"# Monitor the temperature of %s (%s) thermal around %s seconds",
args.name,
args.type,
args.duration,
)

Expand Down Expand Up @@ -167,7 +194,8 @@ def register_arguments():
)

monitor_parser = sub_parsers.add_parser("monitor")
monitor_parser.add_argument("-n", "--name", required=True, type=str)
monitor_parser.add_argument("-t", "--type", type=str)
monitor_parser.add_argument("-n", "--name", type=str)
monitor_parser.add_argument(
"-d",
"--duration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_thermal_node_available(self, mock_file, mock_text):
mock_file.return_value = True
mock_text.side_effect = mock_results

thermal_node = thermal_sensor_test.ThermalMonitor("fake-thermal")
thermal_node = thermal_sensor_test.ThermalMonitor(name="fake-thermal")
self.assertListEqual(
[
thermal_node.name,
Expand All @@ -39,7 +39,9 @@ def test_thermal_node_not_available(self, mock_file):
"""
mock_file.return_value = False
with self.assertRaises(FileNotFoundError):
thermal_node = thermal_sensor_test.ThermalMonitor("fake-thermal")
thermal_node = thermal_sensor_test.ThermalMonitor(
name="fake-thermal"
)
thermal_node.type

@mock.patch("thermal_sensor_test.check_temperature")
Expand All @@ -54,7 +56,10 @@ def test_thermal_monitor_test_passed(
"""
mock_args = mock.Mock(
return_value=argparse.Namespace(
name="fake-thermal", duration=30, extra_commands="stress-ng"
name="fake-thermal",
type=None,
duration=30,
extra_commands="stress-ng",
)
)
mock_text.side_effect = ["30000", "30000", "31000"]
Expand All @@ -76,7 +81,10 @@ def test_thermal_monitor_with_fixed_temperature(
):
mock_args = mock.Mock(
return_value=argparse.Namespace(
name="fake-thermal", duration=2, extra_commands="stress-ng"
name="fake-thermal",
type=None,
duration=2,
extra_commands="stress-ng",
)
)
mock_text.return_value = "30000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ user: root
estimated_duration: 5m
flags: also-after-suspend
command:
thermal_sensor_test.py monitor -n {name}
thermal_sensor_test.py monitor -t {type}
Loading