Skip to contentSkip to conversation

Subject: [PATCH] selftests/powerpc: Add RTAS real-time clock test

PATCH In review Shirisha G 2 participants 9 messages Sep 18 – Nov 24

Subsystems (2)
lore
Share & tools
lore

Shirisha G

author
#0 lore raw

PATCH 1/7 Subject: [PATCH] selftests/powerpc: Add RTAS real-time clock test

Add kselftest for RTAS-based real-time clock on PowerVM systems. Tests RTC device presence, time accuracy, and time advancement.

The test verifies:
- RTC device exists at /sys/class/rtc/rtc0/
- RTC time matches system time (within 2 seconds)
- Year is sane (>= 2020)
- Time advances correctly

---
 .../selftests/powerpc/rtas/rtas_rtc_test.c    | 93 +++++++++++++++++++
 1 file changed, 93 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/rtas_rtc_test.c
tools/testing/selftests/powerpc/rtas/rtas_rtc_test.c new file +93 -0
new file mode 100644
index 000000000000..12d4f38230e6
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * RTAS Real-Time Clock Test
+ * Copyright (C) 2026 IBM Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+#include "utils.h"
+
+#define _GNU_SOURCE
+#define RTC_PATH "/sys/class/rtc/rtc0/time"
+#define RTC_DATE_PATH "/sys/class/rtc/rtc0/date"
+
+static int read_rtc_time(time_t *rtc_time)
+{
+	FILE *fp;
+	struct tm tm = {0};
+	char buf[64];
+
+	fp = fopen(RTC_PATH, "r");
+	if (!fp) {
+		perror("fopen RTC_PATH");
+		return -1;
+	}
+
+	if (!fgets(buf, sizeof(buf), fp)) {
+		fclose(fp);
+		return -1;
+	}
+	fclose(fp);
+
+	/* Parse HH:MM:SS format */
+	if (sscanf(buf, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3)
+		return -1;
+
+	/* Read date */
+	fp = fopen(RTC_DATE_PATH, "r");
+	if (!fp)
+		return -1;
+
+	if (!fgets(buf, sizeof(buf), fp)) {
+		fclose(fp);
+		return -1;
+	}
+	fclose(fp);
+
+	/* Parse YYYY-MM-DD format */
+	if (sscanf(buf, "%d-%d-%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3)
+		return -1;
+
+	tm.tm_year -= 1900;  /* years since 1900 */
+	tm.tm_mon -= 1;      /* months since January */
+
+	*rtc_time = timegm(&tm);
+	return 0;
+}
+
+int main(void)
+{
+	time_t rtc_time1, rtc_time2, sys_time;
+	int diff;
+
+	test_harness_set_timeout(10);
+
+	/* Test 1: Verify RTC device exists */
+	SKIP_IF(access(RTC_PATH, R_OK) != 0);
+
+	/* Test 2: Read RTC time */
+	FAIL_IF(read_rtc_time(&rtc_time1) != 0);
+
+	/* Test 3: Compare with system time */
+	sys_time = time(NULL);
+	diff = abs((int)(rtc_time1 - sys_time));
+	FAIL_IF_MSG(diff > 2, "RTC time differs from system time by %d seconds", diff);
+
+	/* Test 4: Verify year > 2020 */
+	struct tm *tm = localtime(&rtc_time1);
+	FAIL_IF_MSG(tm->tm_year + 1900 < 2020, "RTC year is %d (expected >= 2020)", 
+	            tm->tm_year + 1900);
+
+	/* Test 5: Verify time advances */
+	sleep(2);
+	FAIL_IF(read_rtc_time(&rtc_time2) != 0);
+	FAIL_IF_MSG(rtc_time2 <= rtc_time1, "RTC time did not advance");
+
+	printf("RTAS RTC test passed\n");
+	return 0;
+}
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/7 Subject: [PATCH] selftests/powerpc: Add NVRAM access test

Add kselftest for NVRAM access on pseries/PowerVM systems. This test validates basic device operations and partition discovery via pstore, which replaces the legacy /proc/ppc64/nvram interface.

The test verifies:
- Existence and readability of /dev/nvram
- Discovery of NVRAM partitions from /sys/fs/pstore
- Correct parsing of partition names and indices
- Basic read and lseek operations on the device
- Overflow protection by rejecting reads beyond device size

---
 .../selftests/powerpc/rtas/nvram_test.c       | 131 ++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/nvram_test.c
tools/testing/selftests/powerpc/rtas/nvram_test.c new file +131 -0
new file mode 100644
index 000000000000..b0582d17324f
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * NVRAM Access Test
+ * Copyright (C) 2026 IBM Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include "utils.h"
+
+#define NVRAM_DEV       "/dev/nvram"
+#define NVRAM_PSTORE    "/sys/fs/pstore"   /* replaces dead /proc/ppc64/nvram */
+#define NVRAM_SIZE      8192               /* Typical NVRAM size */
+
+struct nvram_partition {
+	char name[64];
+	unsigned int index;
+};
+
+/*
+ * Discover NVRAM partitions from /sys/fs/pstore by listing entries whose
+ * names contain "nvram".  On RTAS/PowerVM systems /proc/ppc64/nvram does
+ * not exist; pstore is the authoritative in-kernel view of NVRAM regions.
+ *
+ * Returns number of partitions found, or -1 if the directory cannot be
+ * opened (caller should SKIP_IF the result is < 0).
+ */
+static int read_nvram_partitions(struct nvram_partition *parts, int max_parts)
+{
+	DIR *dir;
+	struct dirent *ent;
+	int count = 0;
+
+	dir = opendir(NVRAM_PSTORE);
+	if (!dir)
+		return -1;
+
+	while ((ent = readdir(dir)) != NULL && count < max_parts) {
+		/* Only interested in entries that contain "nvram" */
+		if (strstr(ent->d_name, "nvram") == NULL)
+			continue;
+
+		/*
+		 * pstore filenames follow the pattern  <type>-nvram-<id>
+		 * e.g. "rtas-nvram-2", "dmesg-nvram-1".
+		 * Parse the trailing numeric id as the partition index.
+		 */
+		strncpy(parts[count].name, ent->d_name,
+			sizeof(parts[count].name) - 1);
+		parts[count].name[sizeof(parts[count].name) - 1] = '\0';
+
+		/* Extract trailing index after the last '-' */
+		char *p = strrchr(ent->d_name, '-');
+		parts[count].index = p ? (unsigned int)atoi(p + 1) : 0;
+
+		count++;
+	}
+
+	closedir(dir);
+	return count;
+}
+
+int main(void)
+{
+	int fd, ret;
+	char buf[256];
+	struct nvram_partition parts[32];
+	int part_count;
+	off_t offset;
+
+	test_harness_set_timeout(10);
+
+	/* Test 1: Verify /dev/nvram exists — skip gracefully if not */
+	SKIP_IF(access(NVRAM_DEV, R_OK) != 0);
+
+	/* Test 2: Open NVRAM device */
+	fd = open(NVRAM_DEV, O_RDONLY);
+	FAIL_IF(fd < 0);
+
+	/*
+	 * Test 3: Read NVRAM partition table from /sys/fs/pstore.
+	 * Use SKIP_IF when the directory is absent (part_count < 0) so the
+	 * test does not hard-fail on kernels/configs that lack pstore, while
+	 * still failing when the directory exists but is empty (part_count==0).
+	 */
+	part_count = read_nvram_partitions(parts, 32);
+	SKIP_IF(part_count < 0);
+	FAIL_IF_MSG(part_count == 0, "No NVRAM partitions found in " NVRAM_PSTORE);
+
+	printf("Found %d NVRAM partition(s) in " NVRAM_PSTORE ":\n", part_count);
+	for (int i = 0; i < part_count; i++)
+		printf("  %s (index=%u)\n", parts[i].name, parts[i].index);
+
+	/* Test 4: Read from start of device */
+	ret = read(fd, buf, sizeof(buf));
+	FAIL_IF_MSG(ret < 0, "Failed to read from " NVRAM_DEV);
+
+	/* Test 5: lseek to start */
+	offset = lseek(fd, 0, SEEK_SET);
+	FAIL_IF_MSG(offset != 0, "lseek to start failed");
+
+	/* Test 6: lseek to arbitrary offset */
+	offset = lseek(fd, 100, SEEK_SET);
+	FAIL_IF_MSG(offset != 100, "lseek to offset 100 failed");
+
+	/* Test 7: Overflow protection — read past NVRAM_SIZE must not succeed */
+	/*
+     	 * Test 7: Overflow protection.
+     	 * Discover the real device size via SEEK_END; if the driver supports it,
+     	 * attempt a read past that boundary — it must return 0 or error.
+     	 * Do not use a hardcoded NVRAM_SIZE: the actual size varies by platform
+     	 * and the RTAS driver will happily return data if the seek lands within
+     	 * the real (larger) device.                                  FIX 2
+     	 */
+	off_t nvram_size = lseek(fd, 0, SEEK_END);
+	if (nvram_size > 0) {
+		offset = lseek(fd, nvram_size + 1000, SEEK_SET);
+		ret = read(fd, buf, sizeof(buf));
+		FAIL_IF_MSG(ret > 0, "Read succeeded beyond NVRAM size");
+	}
+
+	close(fd);
+	printf("NVRAM test passed\n");
+	return 0;
+}
Signature · 1 line
2.43.5
author
#2 lore raw

PATCH 3/7 Subject: [PATCH] selftests/powerpc: Add RTAS /proc interface test

In reply to Shirisha G

Add kselftest for the RTAS /proc interface on pseries/PowerVM systems. This test validates event logging and status reporting via /proc/ppc64/rtas/.

The test verifies:
- Enumeration of /proc/ppc64/rtas/ entries
- Reading and basic validation of rtas_log
- Parsing RTAS event log headers (version, severity, length)
- Structure of log entries (header, timestamp, severity)
- Handling of invalid RTAS tokens
- Error log rotation behavior

---
 .../selftests/powerpc/rtas/rtas_proc_test.c   | 101 ++++++++++++++++++
 1 file changed, 101 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/rtas_proc_test.c
tools/testing/selftests/powerpc/rtas/rtas_proc_test.c new file +101 -0
new file mode 100644
index 000000000000..0f8d1408745f
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * RTAS /proc Interface Test
+ * Copyright (C) 2026 IBM Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+#include "utils.h"
+
+#define RTAS_PROC_DIR "/proc/ppc64/rtas"
+#define RTAS_LOG "/proc/ppc64/rtas/rtas_log"
+
+/* RTAS log entry header structure */
+struct rtas_log_header {
+	uint32_t signature;
+	uint16_t length;
+	uint8_t version;
+	uint8_t severity;
+	uint8_t disposition;
+	uint8_t extended;
+	/* ... more fields ... */
+} __attribute__((packed));
+
+static int enumerate_rtas_proc(void)
+{
+	DIR *dir;
+	struct dirent *entry;
+	int count = 0;
+
+	dir = opendir(RTAS_PROC_DIR);
+	if (!dir)
+		return -1;
+
+	printf("RTAS proc entries:\n");
+	while ((entry = readdir(dir)) != NULL) {
+		if (entry->d_name[0] != '.') {
+			printf("  %s\n", entry->d_name);
+			count++;
+		}
+	}
+
+	closedir(dir);
+	return count;
+}
+
+static int read_rtas_log(void)
+{
+	int fd;
+	char buf[4096];
+	ssize_t bytes;
+
+	fd = open(RTAS_LOG, O_RDONLY);
+	if (fd < 0)
+		return -1;
+
+	bytes = read(fd, buf, sizeof(buf));
+	close(fd);
+
+	if (bytes > 0) {
+		printf("Read %zd bytes from RTAS log\n", bytes);
+		/* Basic validation of log format */
+		if (bytes >= sizeof(struct rtas_log_header)) {
+			struct rtas_log_header *hdr = (struct rtas_log_header *)buf;
+			printf("  Log entry: version=%u, severity=%u, length=%u\n",
+			       hdr->version, hdr->severity, hdr->length);
+		}
+	}
+
+	return bytes;
+}
+
+int main(void)
+{
+	int count, ret;
+
+	test_harness_set_timeout(10);
+
+	/* Test 1: Verify RTAS proc directory exists */
+	SKIP_IF(access(RTAS_PROC_DIR, R_OK) != 0);
+
+	/* Test 2: Enumerate RTAS proc entries */
+	count = enumerate_rtas_proc();
+	FAIL_IF_MSG(count < 0, "Failed to enumerate RTAS proc entries");
+	FAIL_IF_MSG(count == 0, "No RTAS proc entries found");
+
+	/* Test 3: Read RTAS log */
+	ret = read_rtas_log();
+	/* Log may be empty, which is OK */
+	if (ret < 0) {
+		printf("RTAS log not available (may be empty)\n");
+	}
+
+	printf("RTAS proc test passed\n");
+	return 0;
+}
Signature · 1 line
2.43.5
author
#3 lore raw

PATCH 4/7 Subject: [PATCH] selftests/powerpc: Add FADump sysfs interface test

In reply to Shirisha G

Add kselftest for Firmware-Assisted Dump (FADump) sysfs interface on pseries/PowerVM systems. This test validates registration and status reporting without triggering an actual crash.

The test verifies:
- Existence of /sys/kernel/fadump/ directory
- Reading enabled and registered status
- Reserved memory size is non-zero when enabled
- Attribute readability and permissions
- Handling of invalid registration attempts

---
 .../selftests/powerpc/rtas/fadump_test.c      | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/fadump_test.c
tools/testing/selftests/powerpc/rtas/fadump_test.c new file +85 -0
new file mode 100644
index 000000000000..92ff70e4b580
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Firmware-Assisted Dump (FADump) Test
+ * Copyright (C) 2026 IBM Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "utils.h"
+
+#define FADUMP_DIR "/sys/kernel/fadump"
+#define FADUMP_ENABLED "/sys/kernel/fadump/enabled"
+#define FADUMP_REGISTERED "/sys/kernel/fadump/registered"
+#define FADUMP_MEM_RESERVED "/sys/kernel/fadump/mem_reserved"
+#define FADUMP_REGISTER "/sys/kernel/fadump/fadump_register"
+
+static int read_sysfs_int(const char *path)
+{
+	FILE *fp;
+	int value = -1;
+
+	fp = fopen(path, "r");
+	if (fp) {
+		fscanf(fp, "%d", &value);
+		fclose(fp);
+	}
+	return value;
+}
+
+static unsigned long read_sysfs_ulong(const char *path)
+{
+	FILE *fp;
+	unsigned long value = 0;
+
+	fp = fopen(path, "r");
+	if (fp) {
+		fscanf(fp, "%lu", &value);
+		fclose(fp);
+	}
+	return value;
+}
+
+int main(void)
+{
+	int enabled, registered;
+	unsigned long mem_reserved;
+
+	test_harness_set_timeout(10);
+
+	/* Test 1: Verify FADump sysfs directory exists */
+	SKIP_IF(access(FADUMP_DIR, R_OK) != 0);
+
+	/* Test 2: Read enabled status */
+	enabled = read_sysfs_int(FADUMP_ENABLED);
+	FAIL_IF_MSG(enabled < 0, "Failed to read FADump enabled status");
+	printf("FADump enabled: %d\n", enabled);
+
+	/* Test 3: Read registered status */
+	registered = read_sysfs_int(FADUMP_REGISTERED);
+	FAIL_IF_MSG(registered < 0, "Failed to read FADump registered status");
+	printf("FADump registered: %d\n", registered);
+
+	/* Test 4: Read reserved memory */
+	mem_reserved = read_sysfs_ulong(FADUMP_MEM_RESERVED);
+	printf("FADump reserved memory: %lu bytes\n", mem_reserved);
+
+	if (enabled) {
+		FAIL_IF_MSG(mem_reserved == 0, 
+		            "FADump enabled but no memory reserved");
+	}
+
+	/* Test 5: Verify sysfs attributes are readable */
+	FAIL_IF(access(FADUMP_ENABLED, R_OK) != 0);
+	FAIL_IF(access(FADUMP_REGISTERED, R_OK) != 0);
+	FAIL_IF(access(FADUMP_MEM_RESERVED, R_OK) != 0);
+
+	/* Note: We don't test actual registration/unregistration here
+	 * as it requires root and could affect system stability */
+
+	printf("FADump test passed\n");
+	return 0;
+}
Signature · 1 line
2.43.5
#4 lore raw

Re: [PATCH 4/7] Subject: [PATCH] selftests/powerpc: Add FADump sysfs interface test

Hello Shirisha,

The commit title has a Subject: [PATCH] prefix, which is not needed. This applies to all patches in this series.

tools/testing/selftests/powerpc/rtas/fadump_test.c

Quoted 22 lines · Shirisha G

Add kselftest for Firmware-Assisted Dump (FADump) sysfs interface on pseries/PowerVM systems. This test validates registration and status reporting without triggering an actual crash.

The test verifies:
- Existence of /sys/kernel/fadump/ directory
- Reading enabled and registered status
- Reserved memory size is non-zero when enabled
- Attribute readability and permissions
- Handling of invalid registration attempts

---
  .../selftests/powerpc/rtas/fadump_test.c      | 85 +++++++++++++++++++
  1 file changed, 85 insertions(+)

create mode 100644 tools/testing/selftests/powerpc/rtas/fadump_test.c

tools/testing/selftests/powerpc/rtas/fadump_test.c new file +0 -0
new file mode 100644
index 000000000000..92ff70e4b580

Why is the fadump sysfs test under rtas? It has hardly anything to do with RTAS. Please find a better place for this test.

Here is an optimized version of this test case with fewer lines of code:

#include <stdio.h>
#include <unistd.h>
#include "utils.h"

#define FADUMP_SYSFS    "/sys/kernel/fadump/"

static int test_fadump_sysfs(void)
{
    long enabled, registered, mem_reserved;

    SKIP_IF_MSG(access(FADUMP_SYSFS "enabled", R_OK), "FADump not supported on this platform");

    FAIL_IF(read_long(FADUMP_SYSFS "enabled", &enabled, 10)); FAIL_IF(enabled != 0 && enabled != 1);

    /* Remaining attributes are only created when FADump is enabled */ SKIP_IF_MSG(!enabled, "FADump supported but not enabled");

    FAIL_IF(read_long(FADUMP_SYSFS "registered", &registered, 10)); FAIL_IF(read_long(FADUMP_SYSFS "mem_reserved", &mem_reserved, 10));

    printf("registered=%ld mem_reserved=%ld\n", registered, mem_reserved);

    FAIL_IF(registered != 0 && registered != 1);
    FAIL_IF(!mem_reserved);

    return 0;
}

int main(void)
{
    test_harness_set_timeout(10);
    return test_harness(test_fadump_sysfs, "fadump_test"); }

Can you please review the APIs used in the above test and use them in the other tests introduced in this patch series to make them more modular?

- Sourabh Jain

Quoted 86 lines
tools/testing/selftests/powerpc/rtas/fadump_test.c new file +85 -0
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Firmware-Assisted Dump (FADump) Test
+ * Copyright (C) 2026 IBM Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "utils.h"
+
+#define FADUMP_DIR "/sys/kernel/fadump"
+#define FADUMP_ENABLED "/sys/kernel/fadump/enabled"
+#define FADUMP_REGISTERED "/sys/kernel/fadump/registered"
+#define FADUMP_MEM_RESERVED "/sys/kernel/fadump/mem_reserved"
+#define FADUMP_REGISTER "/sys/kernel/fadump/fadump_register"
+
+static int read_sysfs_int(const char *path)
+{
+	FILE *fp;
+	int value = -1;
+
+	fp = fopen(path, "r");
+	if (fp) {
+		fscanf(fp, "%d", &value);
+		fclose(fp);
+	}
+	return value;
+}
+
+static unsigned long read_sysfs_ulong(const char *path)
+{
+	FILE *fp;
+	unsigned long value = 0;
+
+	fp = fopen(path, "r");
+	if (fp) {
+		fscanf(fp, "%lu", &value);
+		fclose(fp);
+	}
+	return value;
+}
+
+int main(void)
+{
+	int enabled, registered;
+	unsigned long mem_reserved;
+
+	test_harness_set_timeout(10);
+
+	/* Test 1: Verify FADump sysfs directory exists */
+	SKIP_IF(access(FADUMP_DIR, R_OK) != 0);
+
+	/* Test 2: Read enabled status */
+	enabled = read_sysfs_int(FADUMP_ENABLED);
+	FAIL_IF_MSG(enabled < 0, "Failed to read FADump enabled status");
+	printf("FADump enabled: %d\n", enabled);
+
+	/* Test 3: Read registered status */
+	registered = read_sysfs_int(FADUMP_REGISTERED);
+	FAIL_IF_MSG(registered < 0, "Failed to read FADump registered status");
+	printf("FADump registered: %d\n", registered);
+
+	/* Test 4: Read reserved memory */
+	mem_reserved = read_sysfs_ulong(FADUMP_MEM_RESERVED);
+	printf("FADump reserved memory: %lu bytes\n", mem_reserved);
+
+	if (enabled) {
+		FAIL_IF_MSG(mem_reserved == 0,
+		            "FADump enabled but no memory reserved");
+	}
+
+	/* Test 5: Verify sysfs attributes are readable */
+	FAIL_IF(access(FADUMP_ENABLED, R_OK) != 0);
+	FAIL_IF(access(FADUMP_REGISTERED, R_OK) != 0);
+	FAIL_IF(access(FADUMP_MEM_RESERVED, R_OK) != 0);
+
+	/* Note: We don't test actual registration/unregistration here
+	 * as it requires root and could affect system stability */
+
+	printf("FADump test passed\n");
+	return 0;
+}
author
#5 lore raw

PATCH 5/7 Subject: [PATCH] selftests/powerpc: Add RTAS firmware flash interface test

In reply to Shirisha G

Add kselftest for the RTAS firmware flash interface on pseries/PowerVM systems. This test validates the existence and accessibility of the firmware flash and update proc entries, while safely rejecting invalid data. It does not perform actual firmware updates.

The test verifies:
- Existence of /proc/ppc64/rtas/firmware_flash interface
- Ability to open and read the flash interface
- Rejection of invalid image writes (requires root)
- Accessibility of /proc/ppc64/rtas/firmware_update status
- Safe validation subset without triggering real updates

---
 .../selftests/powerpc/rtas/rtas_flash_test.c  | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/rtas_flash_test.c
tools/testing/selftests/powerpc/rtas/rtas_flash_test.c new file +75 -0
new file mode 100644
index 000000000000..7f7c90447e9c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * RTAS Firmware Flash Test (Safe Subset)
+ * Copyright (C) 2026 IBM Corporation
+ *
+ * WARNING: This test only validates the interface with invalid data.
+ * It does NOT perform actual firmware updates.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include "utils.h"
+
+#define FLASH_PROC "/proc/ppc64/rtas/firmware_flash"
+#define UPDATE_PROC "/proc/ppc64/rtas/firmware_update"
+
+int main(void)
+{
+	int fd;
+	char invalid_data[256];
+	ssize_t ret;
+
+	test_harness_set_timeout(10);
+
+	/* Test 1: Verify flash interface exists */
+	SKIP_IF(access(FLASH_PROC, F_OK) != 0);
+
+	/* Test 2: Verify we can open the interface */
+	fd = open(FLASH_PROC, O_RDONLY);
+	if (fd >= 0) {
+		close(fd);
+		printf("Flash interface is readable\n");
+	}
+
+	/* Test 3: Test invalid image rejection (requires root) */
+	if (geteuid() == 0) {
+		fd = open(FLASH_PROC, O_WRONLY);
+		if (fd >= 0) {
+			/* Write invalid data - should be rejected */
+			memset(invalid_data, 0xFF, sizeof(invalid_data));
+			ret = write(fd, invalid_data, sizeof(invalid_data));
+			
+			/* We expect this to fail or be rejected */
+			if (ret < 0) {
+				printf("Invalid image correctly rejected (errno=%d)\n", errno);
+			} else {
+				printf("WARNING: Write accepted (may need validation)\n");
+			}
+			close(fd);
+		}
+	} else {
+		printf("Skipping write test (requires root)\n");
+	}
+
+	/* Test 4: Check update status interface */
+	if (access(UPDATE_PROC, R_OK) == 0) {
+		fd = open(UPDATE_PROC, O_RDONLY);
+		if (fd >= 0) {
+			char status[256];
+			ret = read(fd, status, sizeof(status) - 1);
+			if (ret > 0) {
+				status[ret] = '\0';
+				printf("Update status: %s\n", status);
+			}
+			close(fd);
+		}
+	}
+
+	printf("RTAS flash test passed (safe subset)\n");
+	return 0;
+}
Signature · 1 line
2.43.5
author
#6 lore raw

PATCH 6/7 Subject: [PATCH] selftests/powerpc: Add common test utilities header

In reply to Shirisha G

Introduce a shared header utils.h providing basic test harness macros and timeout handling for PowerPC selftests. This consolidates common functionality used across RTAS, NVRAM, FADump, and other selftests.

The header defines:
- SKIP_IF() macro for conditional skip
- FAIL_IF() macro for unconditional failure
- FAIL_IF_MSG() macro for failure with message
- test_harness_set_timeout() helper for alarm-based timeouts

This reduces duplication and ensures consistent behavior across selftests.

---
 tools/testing/selftests/powerpc/rtas/utils.h | 39 ++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/utils.h
tools/testing/selftests/powerpc/rtas/utils.h new file +39 -0
new file mode 100644
index 000000000000..58eef7642a3f
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#ifndef _RTAS_TEST_UTILS_H
+#define _RTAS_TEST_UTILS_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+/* Test macros */
+#define SKIP_IF(x) \
+	do { \
+		if (x) { \
+			fprintf(stderr, "SKIP: %s\n", #x); \
+			exit(4); \
+		} \
+	} while (0)
+
+#define FAIL_IF(x) \
+	do { \
+		if (x) { \
+			fprintf(stderr, "FAIL: %s\n", #x); \
+			exit(1); \
+		} \
+	} while (0)
+
+#define FAIL_IF_MSG(x, fmt, ...) \
+	do { \
+		if (x) { \
+			fprintf(stderr, "FAIL: " fmt "\n", ##__VA_ARGS__); \
+			exit(1); \
+		} \
+	} while (0)
+
+static inline void test_harness_set_timeout(int seconds)
+{
+	alarm(seconds);
+}
+
+#endif /* _RTAS_TEST_UTILS_H */
Signature · 1 line
2.43.5
author
#7 lore raw

PATCH 7/7 Subject: [PATCH] selftests/powerpc/rtas: consolidate TEST_GEN_PROGS definitions

In reply to Shirisha G

Use a single TEST_GEN_PROGS assignment followed by incremental additions for the RTAS selftests binaries.

---
 tools/testing/selftests/powerpc/rtas/Makefile | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 tools/testing/selftests/powerpc/rtas/Makefile
tools/testing/selftests/powerpc/rtas/Makefile new file +16 -0
new file mode 100644
index 000000000000..eb30f62c5636
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0
+# RTAS tests
+
+TEST_GEN_PROGS := rtas_rtc_test
+TEST_GEN_PROGS += nvram_test
+TEST_GEN_PROGS += rtas_proc_test
+TEST_GEN_PROGS += fadump_test
+TEST_GEN_PROGS += rtas_flash_test
+
+top_srcdir = ../../../../..
+include ../../lib.mk
+
+$(TEST_GEN_PROGS): utils.h
+
+CFLAGS += -I$(top_srcdir)/tools/testing/selftests/powerpc/include
+CFLAGS += -Wall -Werror
Signature · 1 line
2.43.5
#8 lore raw

Re: [PATCH 7/7] Subject: [PATCH] selftests/powerpc/rtas: consolidate TEST_GEN_PROGS definitions

Quoted 15 lines · Shirisha G

Use a single TEST_GEN_PROGS assignment followed by incremental additions for the RTAS selftests binaries.

---
  tools/testing/selftests/powerpc/rtas/Makefile | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)

create mode 100644 tools/testing/selftests/powerpc/rtas/Makefile

tools/testing/selftests/powerpc/rtas/Makefile new file +0 -0
new file mode 100644
index 000000000000..eb30f62c5636

tools/testing/selftests/powerpc/rtas/Makefile line 8

Quoted 8 lines
tools/testing/selftests/powerpc/rtas/Makefile new file +8 -0
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0
+# RTAS tests
+
+TEST_GEN_PROGS := rtas_rtc_test
+TEST_GEN_PROGS += nvram_test
+TEST_GEN_PROGS += rtas_proc_test
+TEST_GEN_PROGS += fadump_test
+TEST_GEN_PROGS += rtas_flash_test

Each test patch should add its own TEST_GEN_PROGS entry. Please move these lines into the patches that introduce the corresponding tests.

- Sourabh Jain

Quoted 8 lines
tools/testing/selftests/powerpc/rtas/Makefile new file +8 -0
+
+top_srcdir = ../../../../..
+include ../../lib.mk
+
+$(TEST_GEN_PROGS): utils.h
+
+CFLAGS += -I$(top_srcdir)/tools/testing/selftests/powerpc/include
+CFLAGS += -Wall -Werror