-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing using a GitHub Actions CI environment (#77)
Signed-off-by: Ethan Dye <[email protected]>
- Loading branch information
Showing
14 changed files
with
307 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Test | ||
|
||
# Trigger the workflow on push or pull request | ||
on: | ||
push: | ||
paths: | ||
- 'zram-config' | ||
- '**.bash' | ||
- 'tests/**' | ||
- '.github/workflows/test-action.yml' | ||
pull_request: | ||
paths: | ||
- 'zram-config' | ||
- '**.bash' | ||
- 'tests/**' | ||
- '.github/workflows/test-action.yml' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/[email protected] | ||
- name: Setup environment | ||
id: setup | ||
run: | | ||
sudo -E bash -c set | ||
sudo add-apt-repository ppa:canonical-server/server-backports | ||
sudo apt-get update | ||
sudo apt-get install --yes gnupg unzip expect systemd-container qemu-user-static qemu-utils qemu-system-arm | ||
echo "::set-output name=imagezip::$(basename "$(curl "https://downloads.raspberrypi.org/raspios_lite_armhf_latest" -s -L -I -o /dev/null -w '%{url_effective}')")" | ||
echo "::set-output name=image::$(echo "$(basename "$(curl "https://downloads.raspberrypi.org/raspios_lite_armhf_latest" -s -L -I -o /dev/null -w '%{url_effective}')")" | sed -e 's/.zip/.img/')" | ||
- name: Cache Raspberry Pi OS 32bit image | ||
uses: actions/[email protected] | ||
with: | ||
path: ${{ steps.setup.outputs.image }} | ||
key: ${{ steps.setup.outputs.image }}-${{ secrets.CACHE_VERSION }} | ||
- name: Build image | ||
run: sudo -E ./tests/image.bash "setup" "${{ steps.setup.outputs.imagezip }}" "${{ steps.setup.outputs.image }}" | ||
shell: bash | ||
- name: Run tests | ||
run: | | ||
cp "${{ steps.setup.outputs.image }}" raspios.img | ||
sudo expect ./tests/run.exp | ||
shell: bash | ||
- name: Copy logs | ||
if: always() | ||
run: sudo ./tests/image.bash "copy-logs" "raspios.img" | ||
- name: Upload logs | ||
if: always() | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: logs.tar | ||
path: logs.tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
.DS_Store | ||
*.zip | ||
*.img | ||
*.sig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bash | ||
|
||
mountImageFile() { | ||
local loopPrefix | ||
|
||
if [[ $1 == "mount" ]]; then | ||
loopPrefix="$(kpartx -asv "$2" | grep -oE "loop([0-9]+)" | head -n 1)" | ||
|
||
mkdir -p tests/{fs,kernel,dtb} | ||
mount -o rw -t ext4 "/dev/mapper/${loopPrefix}p2" "tests/fs" | ||
mount -o rw -t vfat "/dev/mapper/${loopPrefix}p1" "tests/fs/boot" | ||
elif [[ $1 == "umount" ]]; then | ||
umount tests/fs/boot | ||
umount tests/fs | ||
kpartx -d "$2" | ||
fi | ||
} | ||
|
||
if [[ $1 == "setup" ]]; then | ||
if ! [[ -f $3 ]]; then | ||
curl -s -L "https://downloads.raspberrypi.org/raspios_lite_armhf_latest" -o "$2" | ||
curl -s "$(curl "https://downloads.raspberrypi.org/raspios_lite_armhf_latest" -s -L -I -o /dev/null -w '%{url_effective}')".sig -o "${2}.sig" | ||
gpg -q --keyserver keyserver.ubuntu.com --recv-key 0x8738CD6B956F460C | ||
gpg -q --trust-model always --verify "${2}.sig" "$2" | ||
unzip -q "$2" -d . | ||
qemu-img resize -f raw "$3" 4G | ||
echo ", +" | sfdisk -N 2 "$3" | ||
fi | ||
mountImageFile "mount" "$3" | ||
rsync -avr --exclude="*.zip" --exclude="*.img" --exclude="*.sig" --exclude="tests/fs" --exclude="tests/dtb" --exclude="tests/kernel" ./ tests/fs/opt/zram | ||
systemd-nspawn --directory="tests/fs" /opt/zram/tests/install-packages.bash | ||
echo "set enable-bracketed-paste off" >> tests/fs/etc/inputrc # Prevents weird character output when running the image in tests | ||
cp tests/fs/boot/kernel* tests/kernel | ||
cp tests/fs/boot/*.dtb tests/dtb | ||
mountImageFile "umount" "$3" | ||
elif [[ $1 == "copy-logs" ]]; then | ||
mountImageFile "mount" "$2" | ||
cp tests/fs/opt/zram/logs.tar . | ||
mountImageFile "umount" "$2" | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
export DEBIAN_FRONTEND="noninteractive" | ||
|
||
apt-get --quiet update | ||
apt-get --quiet upgrade --yes | ||
apt-get --quiet install --fix-broken --yes | ||
apt-get --quiet install --yes gcc make libc6-dev | ||
apt-get --quiet autoremove --yes | ||
systemctl mask rpi-eeprom-update.service hciuart.service systemd-logind.service | ||
rm -f /var/lib/apt/lists/lock | ||
rm -f /var/cache/apt/archives/lock | ||
rm -f /var/lib/dpkg/lock* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/expect -f | ||
|
||
set retval 0 | ||
set timeout -1 | ||
set loginUser "pi" | ||
set loginPassword "raspberry" | ||
|
||
spawn qemu-system-arm -machine "raspi2b" -cpu arm1176 -m 1G -drive "format=raw,file=raspios.img" -dtb "./tests/dtb/bcm2710-rpi-2-b.dtb" -kernel "./tests/kernel/kernel7.img" -append "loglevel=0 quiet console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes rootwait" -nographic -serial mon:stdio | ||
|
||
# Login process | ||
expect { | ||
"raspberrypi login: " { | ||
send "$loginUser\r" | ||
exp_continue | ||
} | ||
"Password: " { | ||
send "$loginPassword\r" | ||
} | ||
} | ||
|
||
# Run tests | ||
expect "pi@raspberrypi:~$ " | ||
send "sudo /opt/zram/install.bash\r" | ||
expect "pi@raspberrypi:~$ " | ||
send "/opt/zram/tests/test-zram-devices.bash\r" | ||
expect { | ||
-re "Test failed:.*$" { | ||
set retval 1 | ||
exp_continue | ||
} | ||
"pi@raspberrypi:~$ " { | ||
send "sudo /opt/zram/uninstall.bash\r" | ||
} | ||
} | ||
expect "pi@raspberrypi:~$ " | ||
send "/opt/zram/tests/test-zram-devices.bash removal\r" | ||
expect { | ||
-re "Test failed:.*$" { | ||
set retval 1 | ||
exp_continue | ||
} | ||
"pi@raspberrypi:~$ " { | ||
send "sudo shutdown -h now\r" | ||
} | ||
} | ||
|
||
exit $retval |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env bash | ||
|
||
BASEDIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
||
check_zram_mounts() { | ||
while read -r line; do | ||
case "$line" in | ||
"#"*) | ||
# Skip comment line | ||
continue | ||
;; | ||
|
||
"") | ||
# Skip empty line | ||
continue | ||
;; | ||
|
||
*) | ||
# shellcheck disable=SC2086 | ||
set -- $line | ||
ZTYPE="$1" | ||
TARGET_DIR="$5" | ||
if [[ $ZTYPE == "swap" ]]; then | ||
if [[ "$(swapon | awk '/zram/ { print $1 }' | tr -d '0-9')" != "/dev/zram" ]]; then | ||
echo "Test failed: swap not on zram." | ||
zramctl --output-all | ||
return 1 | ||
fi | ||
elif [[ $ZTYPE == "dir" ]] || [[ $ZTYPE == "log" ]]; then | ||
if [[ "$(df "$TARGET_DIR" | awk '/overlay/ { print $1 }' | tr -d '0-9')" != "overlay" ]]; then | ||
echo "Test failed: overlay for '$TARGET_DIR' not found." | ||
zramctl --output-all | ||
return 1 | ||
fi | ||
fi | ||
;; | ||
esac | ||
done < "${BASEDIR}/../ztab" | ||
} | ||
|
||
check_zram_removal() { | ||
while read -r line; do | ||
case "$line" in | ||
"#"*) | ||
# Skip comment line | ||
continue | ||
;; | ||
|
||
"") | ||
# Skip empty line | ||
continue | ||
;; | ||
|
||
*) | ||
# shellcheck disable=SC2086 | ||
set -- $line | ||
ZTYPE="$1" | ||
TARGET_DIR="$5" | ||
if [[ $ZTYPE == "swap" ]]; then | ||
if [[ "$(swapon | awk '/zram/ { print $1 }' | tr -d '0-9')" == "/dev/zram" ]]; then | ||
echo "Test failed: swap on zram." | ||
zramctl --output-all | ||
return 1 | ||
fi | ||
elif [[ $ZTYPE == "dir" ]] || [[ $ZTYPE == "log" ]]; then | ||
if [[ "$(df "$TARGET_DIR" | awk '/overlay/ { print $1 }' | tr -d '0-9')" == "overlay" ]]; then | ||
echo "Test failed: overlay for '$TARGET_DIR' found." | ||
zramctl --output-all | ||
return 1 | ||
fi | ||
fi | ||
;; | ||
esac | ||
done < "${BASEDIR}/../ztab" | ||
} | ||
|
||
if [[ $1 == "removal" ]]; then | ||
check_zram_removal || exit 1 | ||
else | ||
check_zram_mounts || exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.