All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 08/31] testcases: sysfs: Add sys_cpu_vulnerabilities01
Date: Tue, 25 Aug 2026 13:36:02 +0200	[thread overview]
Message-ID: <20260825113625.1624134-9-chrubis@suse.cz> (raw)
In-Reply-To: <20260825113625.1624134-1-chrubis@suse.cz>

A test for /sys/devices/system/cpu/vulnerabilities/* files.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/sysfs                                 |  1 +
 .../sysfs/devices/system/cpu/.gitignore       |  1 +
 .../system/cpu/sys_cpu_vulnerabilities01.c    | 85 +++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 testcases/kernel/sysfs/devices/system/cpu/sys_cpu_vulnerabilities01.c

diff --git a/runtest/sysfs b/runtest/sysfs
index b1daab68f..663c1d203 100644
--- a/runtest/sysfs
+++ b/runtest/sysfs
@@ -4,3 +4,4 @@ sys_clocksource01 sys_clocksource01
 sys_node01 sys_node01
 sys_cpu_topology01 sys_cpu_topology01
 sys_cpu_topology02 sys_cpu_topology02
+sys_cpu_vulnerabilities01 sys_cpu_vulnerabilities01
diff --git a/testcases/kernel/sysfs/devices/system/cpu/.gitignore b/testcases/kernel/sysfs/devices/system/cpu/.gitignore
index a688a9b50..3ae5f494f 100644
--- a/testcases/kernel/sysfs/devices/system/cpu/.gitignore
+++ b/testcases/kernel/sysfs/devices/system/cpu/.gitignore
@@ -1,2 +1,3 @@
 /sys_cpu_topology01
 /sys_cpu_topology02
+/sys_cpu_vulnerabilities01
diff --git a/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_vulnerabilities01.c b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_vulnerabilities01.c
new file mode 100644
index 000000000..ae1bb8b7c
--- /dev/null
+++ b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_vulnerabilities01.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Sanity checks for the CPU vulnerability reports exported under
+ * /sys/devices/system/cpu/vulnerabilities/.
+ *
+ * Each file describes the status of one hardware vulnerability. The kernel
+ * always prints a human readable status that starts with one of a few known
+ * prefixes. The test verifies that every vulnerability file:
+ *
+ * - is non-empty
+ * - starts with one of the known status prefixes (Not affected, Vulnerable,
+ *   Mitigation:, Unknown, Processor vulnerable)
+ *
+ * The test skips with TCONF when the vulnerabilities directory is not present,
+ * which is the case on architectures that do not report them.
+ */
+
+#include <string.h>
+#include <dirent.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_sysfs_assert.h"
+
+#define VULN "/sys/devices/system/cpu/vulnerabilities"
+
+static const char *const known_prefixes[] = {
+	"Not affected",
+	"Vulnerable",
+	"Mitigation:",
+	"Unknown",
+	"Processor vulnerable",
+};
+
+static void check_vuln(const char *name)
+{
+	char status[256] = "";
+	unsigned int i;
+
+	TST_SYSFS_READ_STR(status, sizeof(status), VULN "/%s", name);
+
+	if (status[0] == '\0') {
+		tst_res(TFAIL, "%s/%s is empty", VULN, name);
+		return;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(known_prefixes); i++) {
+		if (!strncmp(status, known_prefixes[i],
+			     strlen(known_prefixes[i]))) {
+			tst_res(TPASS, "%s: '%s'", name, status);
+			return;
+		}
+	}
+
+	tst_res(TFAIL, "%s has unexpected status '%s'", name, status);
+}
+
+static void do_test(void)
+{
+	DIR *d;
+	struct dirent *ent;
+
+	if (access(VULN, F_OK)) {
+		tst_res(TCONF, VULN " is not available");
+		return;
+	}
+
+	d = SAFE_OPENDIR(VULN);
+
+	while ((ent = SAFE_READDIR(d))) {
+		if (ent->d_name[0] == '.')
+			continue;
+
+		check_vuln(ent->d_name);
+	}
+
+	SAFE_CLOSEDIR(d);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-08-25 11:38 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 11:35 [LTP] [PATCH v3 00/31] Add sysfs sanity tests Cyril Hrubis
2026-08-25 11:35 ` [LTP] [PATCH v3 01/31] lib: Add tst_sysfs_assert Cyril Hrubis
2026-08-25 13:19   ` [LTP] " linuxtestproject.agent
2026-08-25 11:35 ` [LTP] [PATCH v3 02/31] testcases: sysfs: Add sys_power01 Cyril Hrubis
2026-08-25 11:35 ` [LTP] [PATCH v3 03/31] testcases: sysfs: Add sys_kernel01 Cyril Hrubis
2026-08-25 11:35 ` [LTP] [PATCH v3 04/31] testcases: sysfs: Add sys_clocksource01 Cyril Hrubis
2026-08-25 11:35 ` [LTP] [PATCH v3 05/31] testcases: sysfs: Add sys_node01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 06/31] testcases: sysfs: Add sys_cpu_topology01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 07/31] testcases: sysfs: Add sys_cpu_topology02 Cyril Hrubis
2026-08-25 11:36 ` Cyril Hrubis [this message]
2026-08-25 11:36 ` [LTP] [PATCH v3 09/31] testcases: sysfs: Add sys_cpu_smt01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 10/31] testcases: sysfs: Add sys_cpu_cache01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 11/31] testcases: sysfs: Add sys_clockevents01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 12/31] testcases: sysfs: Add sys_ata01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 13/31] testcases: sysfs: Add sys_bdi01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 14/31] testcases: sysfs: sys_hwmon01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 15/31] testcases: sysfs: sys_leds01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 16/31] testcases: sysfs: Add sys_wakeup01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 17/31] testcases: sysfs: Add sys_rtc01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 18/31] testcases: sysfs: Add sys_thermal01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 19/31] tst_netdevice: Add two more helper macros Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 20/31] testcases: sysfs: Add sys_net01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 21/31] testcases: sysfs: Add sys_net02 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 22/31] testcases: sysfs: Add sys_net03 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 23/31] testcases: sysfs: Add sys_net04 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 24/31] testcases: sysfs: Add sys_block_loop01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 25/31] testcases: sysfs: Add sys_block_queue01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 26/31] testcases: sysfs: Add sys_block_size01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 27/31] testcases: sysfs: Add sys_hugepages01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 28/31] testcases: sysfs: Add sys_hugepages02 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 29/31] testcases: sysfs: Add sys_ksm01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 30/31] testcases: sysfs: Add sys_swap01 Cyril Hrubis
2026-08-25 11:36 ` [LTP] [PATCH v3 31/31] testcases: sysfs: Add sys_thp01 Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260825113625.1624134-9-chrubis@suse.cz \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.