Skip to contentSkip to conversation

thermal: Introduce a debugfs-based testing facility

PATCH In review Rafael J. Wysocki 2 participants 2 messages Aug 2, 2024 – Aug 19, 2024 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: Introduce a debugfs-based testing facility

From: Rafael J. Wysocki <[email protected]>

Introduce a facility allowing the thermal core functionality to be exercised in a controlled way in order to verify its behavior, without affecting its regular users noticeably.

It is based on the idea of preparing thermal zone templates along with their trip points by writing to files in debugfs. When ready, those templates can be used for registering test thermal zones with the thermal core.

The temperature of a test thermal zone created this way can be adjusted via debugfs, which also triggers a __thermal_zone_device_update() call for it. By manipulating the temperature of a test thermal zone, one can check if the thermal core reacts to the changes of it as expected.

Concise "howto" documentation is included in one of the source files.

---

In its current form, this is quite limited, but still quite useful at least for me. In the future, it can be extended to allow "mock" test cooling devices to be registered and bound to trip points in "mock" test thermal zones, so that governor response can be tested at least in some scenarios. On top of that, a test scripts can be developed for automated testing of the thermal core. IOW, it's just a start.

---
 drivers/thermal/Kconfig                   |    9 
 drivers/thermal/Makefile                  |    1 
 drivers/thermal/testing/Makefile          |    7 
 drivers/thermal/testing/command.c         |  221 ++++++++++++++
 drivers/thermal/testing/thermal_testing.h |   11 
 drivers/thermal/testing/zone.c            |  469 ++++++++++++++++++++++++++++++
 6 files changed, 718 insertions(+)
drivers/thermal/Kconfig +9 -0
Index: linux-pm/drivers/thermal/Kconfig
===================================================================
@@ -40,6 +40,15 @@ config THERMAL_DEBUGFS
 	  Say Y to allow the thermal subsystem to collect diagnostic
 	  information that can be accessed via debugfs.
 
+config THERMAL_CORE_TESTING
+	tristate "Thermal core testing facility"
+	depends on DEBUG_FS
+	help
+	  Say Y to add a debugfs-based thermal core testing facility.
+	  It allows test thermal zones to be created and populated
+	  with trip points in order to exercise the thermal core
+	  functionality in a controlled way.
+
 config THERMAL_EMERGENCY_POWEROFF_DELAY_MS
 	int "Emergency poweroff delay in milli-seconds"
 	default 0
drivers/thermal/Makefile +1 -0
Index: linux-pm/drivers/thermal/Makefile
===================================================================
@@ -63,3 +63,4 @@ obj-$(CONFIG_AMLOGIC_THERMAL)     += aml
 obj-$(CONFIG_SPRD_THERMAL)	+= sprd_thermal.o
 obj-$(CONFIG_KHADAS_MCU_FAN_THERMAL)	+= khadas_mcu_fan.o
 obj-$(CONFIG_LOONGSON2_THERMAL)	+= loongson2_thermal.o
+obj-$(CONFIG_THERMAL_CORE_TESTING)	+= testing/
drivers/thermal/testing/Makefile new file +7 -0
Index: linux-pm/drivers/thermal/testing/Makefile
===================================================================
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Thermal core testing facility.
+
+obj-$(CONFIG_THERMAL_CORE_TESTING) += thermal-testing.o
+
+thermal-testing-y := command.o zone.o
drivers/thermal/testing/command.c new file +221 -0

221 lines not on this page · raw message

drivers/thermal/testing/thermal_testing.h new file +11 -0
Index: linux-pm/drivers/thermal/testing/thermal_testing.h
===================================================================
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+extern struct dentry *d_testing;
+
+int tt_add_tz(void);
+int tt_del_tz(const char *arg);
+int tt_zone_add_trip(const char *arg);
+int tt_zone_reg(const char *arg);
+int tt_zone_unreg(const char *arg);
+
+void tt_zone_cleanup(void);
drivers/thermal/testing/zone.c new file +469 -0

469 lines not on this page · raw message

#1 lore raw
Quoted 20 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Introduce a facility allowing the thermal core functionality to be exercised in a controlled way in order to verify its behavior, without affecting its regular users noticeably.

It is based on the idea of preparing thermal zone templates along with their trip points by writing to files in debugfs. When ready, those templates can be used for registering test thermal zones with the thermal core.

The temperature of a test thermal zone created this way can be adjusted via debugfs, which also triggers a __thermal_zone_device_update() call for it. By manipulating the temperature of a test thermal zone, one can check if the thermal core reacts to the changes of it as expected.

Concise "howto" documentation is included in one of the source files.

Quoted 8 lines

---

In its current form, this is quite limited, but still quite useful at least for me. In the future, it can be extended to allow "mock" test cooling devices to be registered and bound to trip points in "mock" test thermal zones, so that governor response can be tested at least in some scenarios. On top of that, a test scripts can be developed for automated testing of the thermal core. IOW, it's just a start.

Due to the lack of comments for the last 2 weeks I gather that this is not controversial.

Since I want it in, I'll go ahead and put it into my linux-next branch, but if there are any comments still, please let me know.