[LTP] [PATCH v2 18/31] testcases: sysfs: Add sys_thermal01
Cyril Hrubis <[email protected]>
| Newsgroups | it.linux.lists.ltp |
|---|---|
| Message-ID | <[email protected]> |
A test for /sys/class/thermal/cooling_device*/* files. Signed-off-by: Cyril Hrubis <[email protected]> --- runtest/sysfs | 1 + .../kernel/sysfs/class/thermal/.gitignore | 1 + testcases/kernel/sysfs/class/thermal/Makefile | 7 ++ .../sysfs/class/thermal/sys_thermal01.c | 73 +++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 testcases/kernel/sysfs/class/thermal/.gitignore create mode 100644 testcases/kernel/sysfs/class/thermal/Makefile create mode 100644 testcases/kernel/sysfs/class/thermal/sys_thermal01.c diff --git a/runtest/sysfs b/runtest/sysfs index de58499be..454042ed0 100644 --- a/runtest/sysfs +++ b/runtest/sysfs @@ -14,3 +14,4 @@ sys_hwmon01 sys_hwmon01 sys_leds01 sys_leds01 sys_wakeup01 sys_wakeup01 sys_rtc01 sys_rtc01 +sys_thermal01 sys_thermal01 diff --git a/testcases/kernel/sysfs/class/thermal/.gitignore b/testcases/kernel/sysfs/class/thermal/.gitignore new file mode 100644 index 000000000..c551a2cde --- /dev/null +++ b/testcases/kernel/sysfs/class/thermal/.gitignore @@ -0,0 +1 @@ +/sys_thermal01 diff --git a/testcases/kernel/sysfs/class/thermal/Makefile b/testcases/kernel/sysfs/class/thermal/Makefile new file mode 100644 index 000000000..034038061 --- /dev/null +++ b/testcases/kernel/sysfs/class/thermal/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2026 Cyril Hrubis <[email protected]> + +top_srcdir ?= ../../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/sysfs/class/thermal/sys_thermal01.c b/testcases/kernel/sysfs/class/thermal/sys_thermal01.c new file mode 100644 index 000000000..2ed1167ab --- /dev/null +++ b/testcases/kernel/sysfs/class/thermal/sys_thermal01.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 Cyril Hrubis <[email protected]> + */ + +/*\ + * Sanity checks for the thermal cooling devices exported under + * /sys/class/thermal/cooling_deviceN/. + * + * For every cooling device the test verifies that: + * + * - type is a non-empty string + * - max_state is non-negative + * - cur_state is in the range [0, max_state] + * + * The test skips with TCONF when no cooling device is present. + */ + +#include <string.h> +#include <dirent.h> +#include <limits.h> +#include "tst_test.h" +#include "tst_sysfs_assert.h" + +#define THERMAL "/sys/class/thermal" + +static void check_cooling_device(const char *name) +{ + char type[64] = ""; + + tst_res(TINFO, "Checking %s", name); + + TST_SYSFS_READ_STR(type, sizeof(type), THERMAL "/%s/type", name); + + if (type[0] != '\0') + tst_res(TPASS, "%s: type = '%s'", name, type); + else + tst_res(TFAIL, "%s: type is empty", name); + + TST_SYSFS_ASSERT_RANGELL(0, LONG_MAX, THERMAL "/%s/max_state", name); + + TST_SYSFS_ASSERT_RANGELF(0, "cur_state", "max_state", + THERMAL "/%s/", name); +} + +static void do_test(void) +{ + DIR *d; + struct dirent *ent; + int found = 0; + + if (!tst_sysfs_exists(THERMAL)) + tst_brk(TCONF, THERMAL ": not present"); + + d = SAFE_OPENDIR(THERMAL); + + while ((ent = SAFE_READDIR(d))) { + if (strncmp(ent->d_name, "cooling_device", 14)) + continue; + + found = 1; + check_cooling_device(ent->d_name); + } + + SAFE_CLOSEDIR(d); + + if (!found) + tst_res(TCONF, "No cooling device found"); +} + +static struct tst_test test = { + .test_all = do_test, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp