Skip to content

Commit

Permalink
Fully test start and stop
Browse files Browse the repository at this point in the history
Because of the custom image and emulated RPi, it is not really possible
to do a full SystemD test and check for changes across reboots, so this
implements the best substitute being simply making sure the behavior
works properly when run manually

Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Dec 9, 2024
1 parent 4cba6dd commit 9c14a28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 55 deletions.
2 changes: 1 addition & 1 deletion tests/image.bash
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [[ $1 == "setup" ]]; then
qemu-img resize -f raw "$3" 4G
echo ", +" | sfdisk -N 2 "$3"
imageFile "mount" "$3"
sed -i -e "s|DATESED|$(date)|g" tests/run.exp
sed -i -e "s|DATESED|$(date)|" tests/run.exp
rsync -avr --exclude="*.img" --exclude="*.sig" --exclude="tests/fs" --exclude="tests/dtb" --exclude="tests/kernel" ./ tests/fs/opt/zram-config
systemd-nspawn --directory="tests/fs" /opt/zram-config/tests/install-packages.bash
echo "set enable-bracketed-paste off" >> tests/fs/etc/inputrc # Prevents weird character output
Expand Down
65 changes: 11 additions & 54 deletions tests/run.exp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ spawn qemu-system-aarch64 -machine "raspi3b" -cpu arm1176 -m 1G -drive "format=r
# Setup user
expect "root@(none):/# "
send "mount -o remount,rw /dev/mmcblk0p2 /\r"
# expect "root@(none):/# "
# send "passwd pi\r"
# expect "New password:"
# send "$loginPassword\r"
# expect "Retype new password:"
# send "$loginPassword\r"
expect "root@(none):/# "
send "passwd pi\r"
expect "New password:"
send "$loginPassword\r"
expect "Retype new password:"
send "$loginPassword\r"
expect "root@(none):/# "
send "sync\r"
expect "root@(none):/# "
send "exec /usr/lib/raspberrypi-sys-mods/firstboot\r"
send "exec /sbin/init\r"

# Login process
expect {
Expand All @@ -39,7 +39,7 @@ expect {
}
}

# Run tests
# Install tests
expect "pi@raspberrypi:~$ "
send "sudo /opt/zram-config/install.bash\r"
expect "pi@raspberrypi:~$ "
Expand All @@ -53,54 +53,10 @@ expect {
send "sudo touch /var/log/test.txt\r"
}
}
expect "pi@raspberrypi:~$ "
send "sync\r"
expect "pi@raspberrypi:~$ "
send "sudo shutdown -r now\r"

# Login process
expect "root@(none):/# "
send "mount -o remount,rw /dev/mmcblk0p2 /\r"
expect "root@(none):/# "
send "sync\r"
expect "root@(none):/# "
send "exec /sbin/init\r"
expect {
"raspberrypi login: " {
send "$loginUser\r"
exp_continue
}
"Password: " {
send "$loginPassword\r"
exp_continue
}
"pi@raspberrypi:~$ " {
send "sudo date -s \"DATESED\"\r"
}
"Login incorrect" {
exit 1
}
}
# Uninstall tests
expect "pi@raspberrypi:~$ "
send "test -f /var/log/test.txt || echo Failed\r"
expect {
"Failed" {
set retval 1
exp_continue
}
"pi@raspberrypi:~$ " {
send "/opt/zram-config/tests/test-zram-devices.bash\r"
}
}
expect {
-re "Test failed:.*$" {
set retval 1
exp_continue
}
"pi@raspberrypi:~$ " {
send "sudo /opt/zram-config/uninstall.bash\r"
}
}
send "sudo /opt/zram-config/uninstall.bash\r"
expect "pi@raspberrypi:~$ "
send "/opt/zram-config/tests/test-zram-devices.bash removal\r"
expect {
Expand All @@ -113,6 +69,7 @@ expect {
}
}

# Shutdown
expect "pi@raspberrypi:~$ "
send "sudo shutdown -h now\r"

Expand Down
1 change: 1 addition & 0 deletions tests/test-zram-devices.bash
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ check_zram_removal() {

if [[ $1 == "removal" ]]; then
check_zram_removal || exit 1
test -f /var/log/test.txt || echo "Test failed: /var/log/test.txt not found."
else
check_zram_mounts || exit 1
fi

0 comments on commit 9c14a28

Please sign in to comment.