Skip to content

Commit fafd979

Browse files
committed
CI: Add RTC test coverage
This change adds CI tests to verify RTC functionality, covering the following cases: 1. Verify that /dev/rtc0 is present and logged in dmesg. 2. Ensure /dev/rtc0 is interactable: - Use rtc_settime to set the year to both before(1980) and after(2030) the current year, then verify that the RTC retains the changes. - Use rtc_alarm to confirm that the alarm_IRQ status transitions correctly: no -> yes -> no. 3. Validate alignment of the UTC year between host and guest using the date command.
1 parent c5c6095 commit fafd979

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

.ci/boot-linux.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ function ASSERT
2424

2525
cleanup
2626

27+
# To test RTC clock
28+
HOST_UTC_YEAR=$(LC_ALL=C date -u +%Y)
29+
2730
ENABLE_VBLK=1
2831
VBLK_IMG=build/disk.img
2932
[ -f "${VBLK_IMG}" ] || ENABLE_VBLK=0
@@ -35,10 +38,93 @@ OPTS_BASE+=" -i build/linux-image/rootfs.cpio"
3538
TEST_OPTIONS=("base (${OPTS_BASE})")
3639
EXPECT_CMDS=('
3740
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
41+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
42+
expect "rtc0" { } timeout { exit 3 }
43+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
44+
expect "${host_utc_year}" { } timeout { exit 3 }
3845
expect "# " { send "uname -a\n" } timeout { exit 2 }
3946
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
4047
')
4148

49+
# RTC alarm and settime tests
50+
TEST_OPTIONS+=("base (${OPTS_BASE})")
51+
EXPECT_CMDS+=('
52+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
53+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
54+
expect "rtc0" { } timeout { exit 3 }
55+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
56+
expect "${host_utc_year}" { } timeout { exit 3 }
57+
expect "# " { send "uname -a\n" } timeout { exit 2 }
58+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
59+
expect "# " { send "rtc_alarm\n" } timeout { exit 3 }
60+
expect "alarm_IRQ : no" { } timeout { exit 3 }
61+
expect "alarm_IRQ : yes" { } timeout { exit 3 }
62+
expect "alarm_IRQ : no" { } timeout { exit 3 }
63+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
64+
')
65+
YEAR1=1980
66+
YEAR2=2030
67+
TEST_OPTIONS+=("base (${OPTS_BASE})")
68+
EXPECT_CMDS+=('
69+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
70+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
71+
expect "rtc0" { } timeout { exit 3 }
72+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
73+
expect "${host_utc_year}" { } timeout { exit 3 }
74+
expect "# " { send "uname -a\n" } timeout { exit 2 }
75+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
76+
expect "# " { send "rtc_settime ${year1}\n" } timeout { exit 3 }
77+
expect "rtc_date : ${year1}-01-01" { } timeout { exit 3 }
78+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
79+
')
80+
TEST_OPTIONS+=("base (${OPTS_BASE})")
81+
EXPECT_CMDS+=('
82+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
83+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
84+
expect "rtc0" { } timeout { exit 3 }
85+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
86+
expect "${host_utc_year}" { } timeout { exit 3 }
87+
expect "# " { send "uname -a\n" } timeout { exit 2 }
88+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
89+
expect "# " { send "rtc_settime ${year2}\n" } timeout { exit 3 }
90+
expect "rtc_date : ${year2}-01-01" { } timeout { exit 3 }
91+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
92+
')
93+
TEST_OPTIONS+=("base (${OPTS_BASE})")
94+
EXPECT_CMDS+=('
95+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
96+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
97+
expect "rtc0" { } timeout { exit 3 }
98+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
99+
expect "${host_utc_year}" { } timeout { exit 3 }
100+
expect "# " { send "uname -a\n" } timeout { exit 2 }
101+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
102+
expect "# " { send "rtc_settime ${year1}\n" } timeout { exit 3 }
103+
expect "rtc_date : ${year1}-01-01" { } timeout { exit 3 }
104+
expect "# " { send "rtc_alarm\n" } timeout { exit 3 }
105+
expect "alarm_IRQ : no" { } timeout { exit 3 }
106+
expect "alarm_IRQ : yes" { } timeout { exit 3 }
107+
expect "alarm_IRQ : no" { } timeout { exit 3 }
108+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
109+
')
110+
TEST_OPTIONS+=("base (${OPTS_BASE})")
111+
EXPECT_CMDS+=('
112+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
113+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
114+
expect "rtc0" { } timeout { exit 3 }
115+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
116+
expect "${host_utc_year}" { } timeout { exit 3 }
117+
expect "# " { send "uname -a\n" } timeout { exit 2 }
118+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
119+
expect "# " { send "rtc_settime ${year2}\n" } timeout { exit 3 }
120+
expect "rtc_date : ${year2}-01-01" { } timeout { exit 3 }
121+
expect "# " { send "rtc_alarm\n" } timeout { exit 3 }
122+
expect "alarm_IRQ : no" { } timeout { exit 3 }
123+
expect "alarm_IRQ : yes" { } timeout { exit 3 }
124+
expect "alarm_IRQ : no" { } timeout { exit 3 }
125+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
126+
')
127+
42128
COLOR_G='\e[32;01m' # Green
43129
COLOR_R='\e[31;01m' # Red
44130
COLOR_Y='\e[33;01m' # Yellow
@@ -56,6 +142,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
56142
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG},readonly")
57143
EXPECT_CMDS+=('
58144
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
145+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
146+
expect "rtc0" { } timeout { exit 3 }
147+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
148+
expect "${host_utc_year}" { } timeout { exit 3 }
59149
expect "# " { send "uname -a\n" } timeout { exit 2 }
60150
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
61151
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -67,6 +157,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
67157
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG},readonly -x vblk:${BLK_DEV},readonly")
68158
EXPECT_CMDS+=('
69159
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
160+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
161+
expect "rtc0" { } timeout { exit 3 }
162+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
163+
expect "${host_utc_year}" { } timeout { exit 3 }
70164
expect "# " { send "uname -a\n" } timeout { exit 2 }
71165
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
72166
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -81,6 +175,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
81175
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG}")
82176
VBLK_EXPECT_CMDS='
83177
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
178+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
179+
expect "rtc0" { } timeout { exit 3 }
180+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
181+
expect "${host_utc_year}" { } timeout { exit 3 }
84182
expect "# " { send "uname -a\n" } timeout { exit 2 }
85183
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
86184
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -98,6 +196,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
98196
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG} -x vblk:${BLK_DEV}")
99197
VBLK_EXPECT_CMDS='
100198
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
199+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
200+
expect "rtc0" { } timeout { exit 3 }
201+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
202+
expect "${host_utc_year}" { } timeout { exit 3 }
101203
expect "# " { send "uname -a\n" } timeout { exit 2 }
102204
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
103205
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -123,6 +225,9 @@ for i in "${!TEST_OPTIONS[@]}"; do
123225
RUN_LINUX="build/rv32emu ${OPTS}"
124226

125227
ASSERT expect <<- DONE
228+
set host_utc_year ${HOST_UTC_YEAR}
229+
set year1 ${YEAR1}
230+
set year2 ${YEAR2}
126231
set timeout ${TIMEOUT}
127232
spawn ${RUN_LINUX}
128233
${EXPECT_CMDS[$i]}

0 commit comments

Comments
 (0)