[PATCH v1 09/31] testcases: sysfs: Add sys_cpu_smt01
Cyril Hrubis <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
A test for /sys/devices/system/cpu/smt/* files. Signed-off-by: Cyril Hrubis <[email protected]> --- runtest/sysfs | 1 + .../sysfs/devices/system/cpu/.gitignore | 1 + .../sysfs/devices/system/cpu/sys_cpu_smt01.c | 65 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c diff --git a/runtest/sysfs b/runtest/sysfs index 663c1d203..4cc2360c6 100644 --- a/runtest/sysfs +++ b/runtest/sysfs @@ -5,3 +5,4 @@ sys_node01 sys_node01 sys_cpu_topology01 sys_cpu_topology01 sys_cpu_topology02 sys_cpu_topology02 sys_cpu_vulnerabilities01 sys_cpu_vulnerabilities01 +sys_cpu_smt01 sys_cpu_smt01 diff --git a/testcases/kernel/sysfs/devices/system/cpu/.gitignore b/testcases/kernel/sysfs/devices/system/cpu/.gitignore index 3ae5f494f..d0f8a6dab 100644 --- a/testcases/kernel/sysfs/devices/system/cpu/.gitignore +++ b/testcases/kernel/sysfs/devices/system/cpu/.gitignore @@ -1,3 +1,4 @@ /sys_cpu_topology01 /sys_cpu_topology02 /sys_cpu_vulnerabilities01 +/sys_cpu_smt01 diff --git a/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c new file mode 100644 index 000000000..ae9612955 --- /dev/null +++ b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 Cyril Hrubis <[email protected]> + */ + +/*\ + * Sanity checks for the SMT (simultaneous multithreading) control exported + * under /sys/devices/system/cpu/smt/. + * + * The test verifies that: + * + * - active is a boolean (0 or 1) + * - control is one of the known states (on, off, forceoff, notsupported, + * notimplemented) + * - when SMT is not usable (control is notsupported or notimplemented) active + * reads back as 0 + * + * The test skips with TCONF when the smt directory is not present. + */ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include "tst_test.h" +#include "tst_sysfs_assert.h" + +#define SMT "/sys/devices/system/cpu/smt" + +static const char *const control_allowed[] = { + "on", "off", "forceoff", "notsupported", "notimplemented", NULL +}; + +static void do_test(void) +{ + char control[32]; + long active; + + if (access(SMT, F_OK)) { + tst_res(TCONF, SMT " is not available"); + return; + } + + TST_SYSFS_ASSERT_BOOL(SMT "/active"); + + TST_SYSFS_ASSERT_ONEOF(control_allowed, SMT "/control"); + + TST_SYSFS_READ_STR(control, sizeof(control), SMT "/control"); + active = TST_SYSFS_READ_LI(SMT "/active"); + + if (!strcmp(control, "notsupported") || + !strcmp(control, "notimplemented")) { + if (active == 0) { + tst_res(TPASS, + "active is 0 while SMT control is '%s'", control); + } else { + tst_res(TFAIL, + "active is %ld while SMT control is '%s'", + active, control); + } + } +} + +static struct tst_test test = { + .test_all = do_test, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp