Skip to contentSkip to conversation

selftest: rtc: Add support rtc alarm content check

PATCH In review Joseph Jang 2 participants 6 messages May 3, 2024 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover selftest: rtc: Add support rtc alarm content check

In order to make sure SET/GET WAKEUP services as optional patch has been integrated correctly, we have created a shell script to validate /proc/driver/rtc when it is not empty and then check the absence of alarm content in RTC metadata according to the rtc wakealarm is supported or not.

Joseph Jang (1):
selftest: rtc: Add support rtc alarm content check

 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/rtc/property/Makefile |  5 ++++
 .../selftests/rtc/property/rtc-alarm-test.sh  | 27 +++++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 tools/testing/selftests/rtc/property/Makefile
 create mode 100755 tools/testing/selftests/rtc/property/rtc-alarm-test.sh
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 selftest: rtc: Add support rtc alarm content check

Some platforms do not support WAKEUP service by default, we use a shell script to check the absence of alarm content in /proc/driver/rtc.

The script will validate /proc/driver/rtc when it is not empty and then check if could find alarm content in it according to the rtc wakealarm is supported or not.

Requires commit 101ca8d05913b ("rtc: efi: Enable SET/GET WAKEUP services as optional")

---
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/rtc/property/Makefile |  5 ++++
 .../selftests/rtc/property/rtc-alarm-test.sh  | 27 +++++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 tools/testing/selftests/rtc/property/Makefile
 create mode 100755 tools/testing/selftests/rtc/property/rtc-alarm-test.sh
tools/testing/selftests/Makefile +1 -0
index e1504833654d..f5d43e2132e8 100644
@@ -80,6 +80,7 @@ TARGETS += riscv
 TARGETS += rlimits
 TARGETS += rseq
 TARGETS += rtc
+TARGETS += rtc/property
 TARGETS += rust
 TARGETS += seccomp
 TARGETS += sgx
tools/testing/selftests/rtc/property/Makefile new file +5 -0
new file mode 100644
index 000000000000..c6f7aa4f0e29
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS := rtc-alarm-test.sh
+
+include ../../lib.mk
+
tools/testing/selftests/rtc/property/rtc-alarm-test.sh new file +27 -0
new file mode 100755
index 000000000000..3bee1dd5fbd0
@@ -0,0 +1,27 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if [ ! -f /proc/driver/rtc ]; then
+	echo "SKIP: the /proc/driver/rtc is empty."
+	exit 4
+fi
+
+# Check if could find alarm content in /proc/driver/rtc according to
+# the rtc wakealarm is supported or not.
+if [ -n "$(ls /sys/class/rtc/rtc* | grep -i wakealarm)" ]; then
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		exit 0
+	else
+		echo "ERROR: The alarm content is not found."
+		cat /proc/driver/rtc
+		exit 1
+	fi
+else
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		echo "ERROR: The alarm content is found."
+		cat /proc/driver/rtc
+		exit 1
+	else
+		exit 0
+	fi
+fi
Signature · 1 line
2.34.1
#2 lore raw
Quoted 2 lines · Joseph Jang

Some platforms do not support WAKEUP service by default, we use a shell script to check the absence of alarm content in /proc/driver/rtc.

procfs for the RTC has been deprecated for a while, don't use it.

Instead, you can use the RTC_PARAM_GET ioctl to get RTC_PARAM_FEATURES and then look at RTC_FEATURE_ALARM.
See https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc.c

Quoted 77 lines

The script will validate /proc/driver/rtc when it is not empty and then check if could find alarm content in it according to the rtc wakealarm is supported or not.

Requires commit 101ca8d05913b ("rtc: efi: Enable SET/GET WAKEUP services as optional")

---
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/rtc/property/Makefile |  5 ++++
 .../selftests/rtc/property/rtc-alarm-test.sh  | 27 +++++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 tools/testing/selftests/rtc/property/Makefile
 create mode 100755 tools/testing/selftests/rtc/property/rtc-alarm-test.sh
tools/testing/selftests/Makefile +1 -0
index e1504833654d..f5d43e2132e8 100644
@@ -80,6 +80,7 @@ TARGETS += riscv
 TARGETS += rlimits
 TARGETS += rseq
 TARGETS += rtc
+TARGETS += rtc/property
 TARGETS += rust
 TARGETS += seccomp
 TARGETS += sgx
tools/testing/selftests/rtc/property/Makefile new file +5 -0
new file mode 100644
index 000000000000..c6f7aa4f0e29
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS := rtc-alarm-test.sh
+
+include ../../lib.mk
+
tools/testing/selftests/rtc/property/rtc-alarm-test.sh new file +27 -0
new file mode 100755
index 000000000000..3bee1dd5fbd0
@@ -0,0 +1,27 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if [ ! -f /proc/driver/rtc ]; then
+	echo "SKIP: the /proc/driver/rtc is empty."
+	exit 4
+fi
+
+# Check if could find alarm content in /proc/driver/rtc according to
+# the rtc wakealarm is supported or not.
+if [ -n "$(ls /sys/class/rtc/rtc* | grep -i wakealarm)" ]; then
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		exit 0
+	else
+		echo "ERROR: The alarm content is not found."
+		cat /proc/driver/rtc
+		exit 1
+	fi
+else
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		echo "ERROR: The alarm content is found."
+		cat /proc/driver/rtc
+		exit 1
+	else
+		exit 0
+	fi
+fi
Signature · 1 line
2.34.1
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw
Quoted 10 lines · Alexandre Belloni
Quoted 2 lines · Joseph Jang

Some platforms do not support WAKEUP service by default, we use a shell script to check the absence of alarm content in /proc/driver/rtc.

procfs for the RTC has been deprecated for a while, don't use it.

Instead, you can use the RTC_PARAM_GET ioctl to get RTC_PARAM_FEATURES and then look at RTC_FEATURE_ALARM.
See https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc.c

I found old version kernel doesn't support RTC_PARAM_GET ioctl. In order support old version kernel testing, is it possible to use rtc procfs to validate wakealarm function for old version kernel ?

Can I move this rtc alarm validation to <linux_root>/tools/testing/selftests/rtc/rtctest.c ? So we could try to use RTC_PARAM_GET ioctl first and then roll back to use rtc procfs if RTC_PARAM_GET ioctl was not supported.

Thank you,
Joseph.

Quoted 78 lines
Quoted 77 lines

The script will validate /proc/driver/rtc when it is not empty and then check if could find alarm content in it according to the rtc wakealarm is supported or not.

Requires commit 101ca8d05913b ("rtc: efi: Enable SET/GET WAKEUP services as optional")

---
  tools/testing/selftests/Makefile              |  1 +
  tools/testing/selftests/rtc/property/Makefile |  5 ++++
  .../selftests/rtc/property/rtc-alarm-test.sh  | 27 +++++++++++++++++++
  3 files changed, 33 insertions(+)

create mode 100644 tools/testing/selftests/rtc/property/Makefile create mode 100755 tools/testing/selftests/rtc/property/rtc-alarm-test.sh

tools/testing/selftests/Makefile +1 -0
index e1504833654d..f5d43e2132e8 100644
@@ -80,6 +80,7 @@ TARGETS += riscv
  TARGETS += rlimits
  TARGETS += rseq
  TARGETS += rtc
+TARGETS += rtc/property
  TARGETS += rust
  TARGETS += seccomp
  TARGETS += sgx
tools/testing/selftests/rtc/property/Makefile new file +5 -0
new file mode 100644
index 000000000000..c6f7aa4f0e29
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS := rtc-alarm-test.sh
+
+include ../../lib.mk
+
tools/testing/selftests/rtc/property/rtc-alarm-test.sh new file +27 -0
new file mode 100755
index 000000000000..3bee1dd5fbd0
@@ -0,0 +1,27 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if [ ! -f /proc/driver/rtc ]; then
+	echo "SKIP: the /proc/driver/rtc is empty."
+	exit 4
+fi
+
+# Check if could find alarm content in /proc/driver/rtc according to
+# the rtc wakealarm is supported or not.
+if [ -n "$(ls /sys/class/rtc/rtc* | grep -i wakealarm)" ]; then
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		exit 0
+	else
+		echo "ERROR: The alarm content is not found."
+		cat /proc/driver/rtc
+		exit 1
+	fi
+else
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		echo "ERROR: The alarm content is found."
+		cat /proc/driver/rtc
+		exit 1
+	else
+		exit 0
+	fi
+fi
Signature · 1 line
2.34.1
#4 lore raw
In reply to Alexandre Belloni

Hi Alexandre,

Thanks for your promptly response, I try to re-send the email again and avoid the security scanner to disrupt the external link.

Quoted 4 lines

procfs for the RTC has been deprecated for a while, don't use it.

Instead, you can use the RTC_PARAM_GET ioctl to get RTC_PARAM_FEATURES and then look at RTC_FEATURE_ALARM.

I found old version kernel doesn't support RTC_PARAM_GET ioctl. In order support old version kernel testing, is it possible to use rtc procfs to validate wakealarm function for old version kernel ?

Can I move this rtc alarm validation to
<linux_root>/tools/testing/selftests/rtc/rtctest.c ? So we could try to
use RTC_PARAM_GET ioctl first and then roll back to use rtc procfs if RTC_PARAM_GET ioctl was not supported.

Thank you,
Joseph.

Quoted 88 lines · Alexandre Belloni
Quoted 2 lines · Joseph Jang

Some platforms do not support WAKEUP service by default, we use a shell script to check the absence of alarm content in /proc/driver/rtc.

procfs for the RTC has been deprecated for a while, don't use it.

Instead, you can use the RTC_PARAM_GET ioctl to get RTC_PARAM_FEATURES and then look at RTC_FEATURE_ALARM.
See https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc.c

Quoted 77 lines

The script will validate /proc/driver/rtc when it is not empty and then check if could find alarm content in it according to the rtc wakealarm is supported or not.

Requires commit 101ca8d05913b ("rtc: efi: Enable SET/GET WAKEUP services as optional")

---
  tools/testing/selftests/Makefile              |  1 +
  tools/testing/selftests/rtc/property/Makefile |  5 ++++
  .../selftests/rtc/property/rtc-alarm-test.sh  | 27 +++++++++++++++++++
  3 files changed, 33 insertions(+)

create mode 100644 tools/testing/selftests/rtc/property/Makefile create mode 100755 tools/testing/selftests/rtc/property/rtc-alarm-test.sh

tools/testing/selftests/Makefile +1 -0
index e1504833654d..f5d43e2132e8 100644
@@ -80,6 +80,7 @@ TARGETS += riscv
  TARGETS += rlimits
  TARGETS += rseq
  TARGETS += rtc
+TARGETS += rtc/property
  TARGETS += rust
  TARGETS += seccomp
  TARGETS += sgx
tools/testing/selftests/rtc/property/Makefile new file +5 -0
new file mode 100644
index 000000000000..c6f7aa4f0e29
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS := rtc-alarm-test.sh
+
+include ../../lib.mk
+
tools/testing/selftests/rtc/property/rtc-alarm-test.sh new file +27 -0
new file mode 100755
index 000000000000..3bee1dd5fbd0
@@ -0,0 +1,27 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if [ ! -f /proc/driver/rtc ]; then
+	echo "SKIP: the /proc/driver/rtc is empty."
+	exit 4
+fi
+
+# Check if could find alarm content in /proc/driver/rtc according to
+# the rtc wakealarm is supported or not.
+if [ -n "$(ls /sys/class/rtc/rtc* | grep -i wakealarm)" ]; then
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		exit 0
+	else
+		echo "ERROR: The alarm content is not found."
+		cat /proc/driver/rtc
+		exit 1
+	fi
+else
+	if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+		echo "ERROR: The alarm content is found."
+		cat /proc/driver/rtc
+		exit 1
+	else
+		exit 0
+	fi
+fi
Signature · 1 line
2.34.1

A message that is not in the archive (sent off-list or not yet received): IA0PR12MB83745321F32B6FA0DE041D10C01F2@IA0PR12MB8374.namprd12.prod.outlook.com

#6 lore raw

Hi Alexandre,

Thanks for your promptly response, I try to remove all HTML links and
resend the email again to avoid the security scanner to disrupt the external link. Hope you can see this email without problems.

Quoted 10 lines · Joseph Jang
Quoted 2 lines · Joseph Jang

Some platforms do not support WAKEUP service by default, we use a shell script to check the absence of alarm content in /proc/driver/rtc.

procfs for the RTC has been deprecated for a while, don't use it.

Instead, you can use the RTC_PARAM_GET ioctl to get RTC_PARAM_FEATURES and then look at RTC_FEATURE_ALARM.

I found old version kernel doesn't support RTC_PARAM_GET ioctl. In order support old version kernel testing, is it possible to use rtc procfs to validate wakealarm function for old version kernel ?

Can I move this rtc alarm validation to <linux_root>/tools/testing/selftests/rtc/rtctest.c ? So, we could try to use RTC_PARAM_GET ioctl first and then roll back to use rtc procfs if new RTC_PARAM_GET ioctl was not supported.

Thank you,
Joseph

Quoted 84 lines

Review

Quoted 31 lines

The script will validate /proc/driver/rtc when it is not empty and then check if could find alarm content in it according to the rtc wakealarm is supported or not.

Requires commit 101ca8d05913b ("rtc: efi: Enable SET/GET WAKEUP services as optional")

---
 tools/testing/selftests/Makefile              |  1 +
 tools/testing/selftests/rtc/property/Makefile |  5 ++++
 .../selftests/rtc/property/rtc-alarm-test.sh  | 27 +++++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 tools/testing/selftests/rtc/property/Makefile
 create mode 100755 tools/testing/selftests/rtc/property/rtc-alarm-test.sh
tools/testing/selftests/Makefile +1 -0
index e1504833654d..f5d43e2132e8 100644
@@ -80,6 +80,7 @@ TARGETS += riscv
 TARGETS += rlimits
 TARGETS += rseq
 TARGETS += rtc
+TARGETS += rtc/property
 TARGETS += rust
 TARGETS += seccomp
 TARGETS += sgx
(quoted diff) +0 -0

b/tools/testing/selftests/rtc/property/Makefile

Review

Quoted 11 lines

new file mode 100644
index 000000000000..c6f7aa4f0e29

tools/testing/selftests/rtc/property/Makefile new file +5 -0
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS := rtc-alarm-test.sh
+
+include ../../lib.mk
+
(quoted diff) +0 -0

b/tools/testing/selftests/rtc/property/rtc-alarm-test.sh

Quoted 33 lines

new file mode 100755
index 000000000000..3bee1dd5fbd0

tools/testing/selftests/rtc/property/rtc-alarm-test.sh new file +27 -1
@@ -0,0 +1,27 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if [ ! -f /proc/driver/rtc ]; then
+     echo "SKIP: the /proc/driver/rtc is empty."
+     exit 4
+fi
+
+# Check if could find alarm content in /proc/driver/rtc according to
+# the rtc wakealarm is supported or not.
+if [ -n "$(ls /sys/class/rtc/rtc* | grep -i wakealarm)" ]; then
+     if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+             exit 0
+     else
+             echo "ERROR: The alarm content is not found."
+             cat /proc/driver/rtc
+             exit 1
+     fi
+else
+     if [ -n "$(grep -i alarm /proc/driver/rtc)" ]; then
+             echo "ERROR: The alarm content is found."
+             cat /proc/driver/rtc
+             exit 1
+     else
+             exit 0
+     fi
+fi
--
Quoted 2 lines

2.34.1

--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering