From: Shirisha G <shirisha@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: linux-kselftest@vger.kernel.org, maddy@linux.ibm.com,
venkat88@linux.ibm.com, shirisha@linux.ibm.com
Subject: [PATCH 1/7] Subject: [PATCH] selftests/powerpc: Add RTAS real-time clock test
Date: Fri, 18 Sep 2026 10:52:36 +0530 [thread overview]
Message-ID: <20260918052321.932660-1-shirisha@linux.ibm.com> (raw)
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
Signed-off-by: Shirisha G <shirisha@linux.ibm.com>
---
.../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
diff --git a/tools/testing/selftests/powerpc/rtas/rtas_rtc_test.c b/tools/testing/selftests/powerpc/rtas/rtas_rtc_test.c
new file mode 100644
index 000000000000..12d4f38230e6
--- /dev/null
+++ b/tools/testing/selftests/powerpc/rtas/rtas_rtc_test.c
@@ -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;
+}
--
2.43.5
next reply other threads:[~2026-09-18 5:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 5:22 Shirisha G [this message]
2026-09-18 5:22 ` [PATCH 2/7] Subject: [PATCH] selftests/powerpc: Add NVRAM access test Shirisha G
2026-09-18 5:22 ` [PATCH 3/7] Subject: [PATCH] selftests/powerpc: Add RTAS /proc interface test Shirisha G
2026-09-18 5:22 ` [PATCH 4/7] Subject: [PATCH] selftests/powerpc: Add FADump sysfs " Shirisha G
2026-09-18 5:22 ` [PATCH 5/7] Subject: [PATCH] selftests/powerpc: Add RTAS firmware flash " Shirisha G
2026-09-18 5:22 ` [PATCH 6/7] Subject: [PATCH] selftests/powerpc: Add common test utilities header Shirisha G
2026-09-18 5:22 ` [PATCH 7/7] Subject: [PATCH] selftests/powerpc/rtas: consolidate TEST_GEN_PROGS definitions Shirisha G
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=20260918052321.932660-1-shirisha@linux.ibm.com \
--to=shirisha@linux.ibm.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=venkat88@linux.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox