Skip to content

Commit dd79c76

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 72a156b commit dd79c76

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
@@ -65,6 +65,9 @@ ASSERT()
6565

6666
cleanup
6767

68+
# To test RTC clock
69+
HOST_UTC_YEAR=$(LC_ALL=C date -u +%Y)
70+
6871
ENABLE_VBLK=1
6972
VBLK_IMG=build/disk.img
7073
[ -f "${VBLK_IMG}" ] || ENABLE_VBLK=0
@@ -76,10 +79,93 @@ OPTS_BASE+=" -i build/linux-image/rootfs.cpio"
7679
TEST_OPTIONS=("base (${OPTS_BASE})")
7780
EXPECT_CMDS=('
7881
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
82+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
83+
expect "rtc0" { } timeout { exit 3 }
84+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
85+
expect "${host_utc_year}" { } timeout { exit 3 }
7986
expect "# " { send "uname -a\n" } timeout { exit 2 }
8087
expect "riscv32 GNU/Linux" { send "\x01"; send "x" } timeout { exit 3 }
8188
')
8289

90+
# RTC alarm and settime tests
91+
TEST_OPTIONS+=("base (${OPTS_BASE})")
92+
EXPECT_CMDS+=('
93+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
94+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
95+
expect "rtc0" { } timeout { exit 3 }
96+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
97+
expect "${host_utc_year}" { } timeout { exit 3 }
98+
expect "# " { send "uname -a\n" } timeout { exit 2 }
99+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
100+
expect "# " { send "rtc_alarm\n" } timeout { exit 3 }
101+
expect "alarm_IRQ : no" { } timeout { exit 3 }
102+
expect "alarm_IRQ : yes" { } timeout { exit 3 }
103+
expect "alarm_IRQ : no" { } timeout { exit 3 }
104+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
105+
')
106+
YEAR1=1980
107+
YEAR2=2030
108+
TEST_OPTIONS+=("base (${OPTS_BASE})")
109+
EXPECT_CMDS+=('
110+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
111+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
112+
expect "rtc0" { } timeout { exit 3 }
113+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
114+
expect "${host_utc_year}" { } timeout { exit 3 }
115+
expect "# " { send "uname -a\n" } timeout { exit 2 }
116+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
117+
expect "# " { send "rtc_settime ${year1}\n" } timeout { exit 3 }
118+
expect "rtc_date : ${year1}-01-01" { } timeout { exit 3 }
119+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
120+
')
121+
TEST_OPTIONS+=("base (${OPTS_BASE})")
122+
EXPECT_CMDS+=('
123+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
124+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
125+
expect "rtc0" { } timeout { exit 3 }
126+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
127+
expect "${host_utc_year}" { } timeout { exit 3 }
128+
expect "# " { send "uname -a\n" } timeout { exit 2 }
129+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
130+
expect "# " { send "rtc_settime ${year2}\n" } timeout { exit 3 }
131+
expect "rtc_date : ${year2}-01-01" { } timeout { exit 3 }
132+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
133+
')
134+
TEST_OPTIONS+=("base (${OPTS_BASE})")
135+
EXPECT_CMDS+=('
136+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
137+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
138+
expect "rtc0" { } timeout { exit 3 }
139+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
140+
expect "${host_utc_year}" { } timeout { exit 3 }
141+
expect "# " { send "uname -a\n" } timeout { exit 2 }
142+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
143+
expect "# " { send "rtc_settime ${year1}\n" } timeout { exit 3 }
144+
expect "rtc_date : ${year1}-01-01" { } timeout { exit 3 }
145+
expect "# " { send "rtc_alarm\n" } timeout { exit 3 }
146+
expect "alarm_IRQ : no" { } timeout { exit 3 }
147+
expect "alarm_IRQ : yes" { } timeout { exit 3 }
148+
expect "alarm_IRQ : no" { } timeout { exit 3 }
149+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
150+
')
151+
TEST_OPTIONS+=("base (${OPTS_BASE})")
152+
EXPECT_CMDS+=('
153+
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
154+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
155+
expect "rtc0" { } timeout { exit 3 }
156+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
157+
expect "${host_utc_year}" { } timeout { exit 3 }
158+
expect "# " { send "uname -a\n" } timeout { exit 2 }
159+
expect "riscv32 GNU/Linux" { } timeout { exit 3 }
160+
expect "# " { send "rtc_settime ${year2}\n" } timeout { exit 3 }
161+
expect "rtc_date : ${year2}-01-01" { } timeout { exit 3 }
162+
expect "# " { send "rtc_alarm\n" } timeout { exit 3 }
163+
expect "alarm_IRQ : no" { } timeout { exit 3 }
164+
expect "alarm_IRQ : yes" { } timeout { exit 3 }
165+
expect "alarm_IRQ : no" { } timeout { exit 3 }
166+
expect "# " { send "\x01"; send "x" } timeout { exit 3 }
167+
')
168+
83169
COLOR_G='\e[32;01m' # Green
84170
COLOR_R='\e[31;01m' # Red
85171
COLOR_Y='\e[33;01m' # Yellow
@@ -97,6 +183,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
97183
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG},readonly")
98184
EXPECT_CMDS+=('
99185
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
186+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
187+
expect "rtc0" { } timeout { exit 3 }
188+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
189+
expect "${host_utc_year}" { } timeout { exit 3 }
100190
expect "# " { send "uname -a\n" } timeout { exit 2 }
101191
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
102192
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -108,6 +198,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
108198
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG},readonly -x vblk:${BLK_DEV},readonly")
109199
EXPECT_CMDS+=('
110200
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
201+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
202+
expect "rtc0" { } timeout { exit 3 }
203+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
204+
expect "${host_utc_year}" { } timeout { exit 3 }
111205
expect "# " { send "uname -a\n" } timeout { exit 2 }
112206
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
113207
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -135,6 +229,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
135229
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG}")
136230
VBLK_EXPECT_CMDS='
137231
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
232+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
233+
expect "rtc0" { } timeout { exit 3 }
234+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
235+
expect "${host_utc_year}" { } timeout { exit 3 }
138236
expect "# " { send "uname -a\n" } timeout { exit 2 }
139237
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
140238
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -152,6 +250,10 @@ if [ "${ENABLE_VBLK}" -eq "1" ]; then
152250
TEST_OPTIONS+=("${OPTS_BASE} -x vblk:${VBLK_IMG} -x vblk:${BLK_DEV}")
153251
VBLK_EXPECT_CMDS='
154252
expect "buildroot login:" { send "root\n" } timeout { exit 1 }
253+
expect "# " { send "dmesg | grep rtc\n" } timeout { exit 2 }
254+
expect "rtc0" { } timeout { exit 3 }
255+
expect "# " { send "date -u +%Y\n" } timeout { exit 2 }
256+
expect "${host_utc_year}" { } timeout { exit 3 }
155257
expect "# " { send "uname -a\n" } timeout { exit 2 }
156258
expect "riscv32 GNU/Linux" { send "mkdir mnt && mount /dev/vda mnt\n" } timeout { exit 3 }
157259
expect "# " { send "echo rv32emu > mnt/emu.txt\n" } timeout { exit 3 }
@@ -180,6 +282,9 @@ for i in "${!TEST_OPTIONS[@]}"; do
180282
RUN_LINUX="build/rv32emu ${OPTS}"
181283

182284
ASSERT expect <<- DONE
285+
set host_utc_year ${HOST_UTC_YEAR}
286+
set year1 ${YEAR1}
287+
set year2 ${YEAR2}
183288
set timeout ${TIMEOUT}
184289
spawn ${RUN_LINUX}
185290
${EXPECT_CMDS[$i]}

0 commit comments

Comments
 (0)