[PATCH v1 11/31] testcases: sysfs: Add sys_clockevents01
Cyril Hrubis <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
A test for /sys/devices/system/clockevents/* files. Signed-off-by: Cyril Hrubis <[email protected]> --- runtest/sysfs | 1 + .../devices/system/clockevents/.gitignore | 1 + .../sysfs/devices/system/clockevents/Makefile | 7 ++ .../system/clockevents/sys_clockevents01.c | 88 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 testcases/kernel/sysfs/devices/system/clockevents/.gitignore create mode 100644 testcases/kernel/sysfs/devices/system/clockevents/Makefile create mode 100644 testcases/kernel/sysfs/devices/system/clockevents/sys_clockevents01.c diff --git a/runtest/sysfs b/runtest/sysfs index 928b85928..3015c03f5 100644 --- a/runtest/sysfs +++ b/runtest/sysfs @@ -7,3 +7,4 @@ sys_cpu_topology02 sys_cpu_topology02 sys_cpu_vulnerabilities01 sys_cpu_vulnerabilities01 sys_cpu_smt01 sys_cpu_smt01 sys_cpu_cache01 sys_cpu_cache01 +sys_clockevents01 sys_clockevents01 diff --git a/testcases/kernel/sysfs/devices/system/clockevents/.gitignore b/testcases/kernel/sysfs/devices/system/clockevents/.gitignore new file mode 100644 index 000000000..9379d10dd --- /dev/null +++ b/testcases/kernel/sysfs/devices/system/clockevents/.gitignore @@ -0,0 +1 @@ +/sys_clockevents01 diff --git a/testcases/kernel/sysfs/devices/system/clockevents/Makefile b/testcases/kernel/sysfs/devices/system/clockevents/Makefile new file mode 100644 index 000000000..781865569 --- /dev/null +++ b/testcases/kernel/sysfs/devices/system/clockevents/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/devices/system/clockevents/sys_clockevents01.c b/testcases/kernel/sysfs/devices/system/clockevents/sys_clockevents01.c new file mode 100644 index 000000000..3e1a46a50 --- /dev/null +++ b/testcases/kernel/sysfs/devices/system/clockevents/sys_clockevents01.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 Cyril Hrubis <[email protected]> + */ + +/*\ + * Sanity checks for the per-CPU clock event devices exported under + * /sys/devices/system/clockevents/clockeventN/. + * + * The kernel registers one clock event device per online CPU (broadcast is a + * separate, additional entry used for CPUs whose local timer stops in idle). + * On platforms without a per-CPU timer, secondary CPUs may instead rely + * entirely on a broadcast IPI from a single shared timer without ever + * getting their own clockeventN entry, so the number of clockeventN + * directories is only asserted not to exceed the number of online CPUs + * rather than to match it exactly. The test verifies that: + * + * - there is at least one clockeventN directory + * - the number of clockeventN directories does not exceed the number of + * online CPUs + * - each clockeventN/current_device names a non-empty clock event device + * + * The test skips with TCONF when no clockevents directory is present. + */ + +#include <string.h> +#include <dirent.h> +#include "tst_test.h" +#include "tst_sysfs_assert.h" + +#define CLOCKEVENTS "/sys/devices/system/clockevents" +#define SYS_CPU "/sys/devices/system/cpu" + +static void check_clockevent(const char *name) +{ + char device[64] = ""; + + TST_SYSFS_READ_STR(device, sizeof(device), + CLOCKEVENTS "/%s/current_device", name); + + if (device[0] != '\0') + tst_res(TPASS, "%s/current_device = '%s'", name, device); + else + tst_res(TFAIL, "%s/current_device is empty", name); +} + +static void do_test(void) +{ + DIR *d; + struct dirent *ent; + int nclockevents = 0; + int online_count, max_id; + + d = SAFE_OPENDIR(CLOCKEVENTS); + + while ((ent = SAFE_READDIR(d))) { + if (strncmp(ent->d_name, "clockevent", 10)) + continue; + + nclockevents++; + check_clockevent(ent->d_name); + } + + SAFE_CLOSEDIR(d); + + if (!nclockevents) { + tst_res(TCONF, "No clockevent directory found"); + return; + } + + if (TST_SYSFS_ASSERT_PARSE_LIST(&online_count, &max_id, + SYS_CPU "/online")) + return; + + if (nclockevents <= online_count) { + tst_res(TPASS, + "number of clockevent devices (%d) does not exceed online CPUs (%d)", + nclockevents, online_count); + } else { + tst_res(TFAIL, + "number of clockevent devices (%d) exceeds online CPUs (%d)", + nclockevents, online_count); + } +} + +static struct tst_test test = { + .test_all = do_test, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp