forked from cimryan/teslausb
-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test for backing files creation
Basic test that checks that create-backingfiles.sh does not fail for many combination of disk images. Does not check that the created images are actually valid.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
if [[ $EUID -ne 0 ]] | ||
then | ||
echo "STOP: Run this script as root." | ||
exit 1 | ||
fi | ||
|
||
if [ "$(systemd-detect-virt)" == "none" ] | ||
then | ||
echo "WARNING, it is recommended to run this script in a VM." | ||
echo "Press enter to continue, or ctrl-c to abort." | ||
read | ||
fi | ||
|
||
BACKINGFILES_FOLDER=$(mktemp -d backingfilestestXXX) | ||
LOG="$BACKINGFILES_FOLDER-log.txt" | ||
|
||
function checksuccess { | ||
name=$(printf '%6s %6s %6s %6s %6s' "$1" "$2" "$3" "$4" "$6") | ||
if ../setup/pi/create-backingfiles.sh "$@" | ||
then | ||
printf '%-45s %s\n' "$name" OK | ||
printf '%-45s %s\n' "$name" OK > /dev/tty | ||
else | ||
printf '%-45s %s\n' "$name" FAIL | ||
printf '%-45s %s\n' "$name" FAIL > /dev/tty | ||
SUCCESS=false | ||
fi | ||
} | ||
|
||
SUCCESS=true | ||
|
||
FALLOCATE=$(which fallocate) | ||
|
||
function fallocate { | ||
if [ "$1" != "-l" ] | ||
then | ||
echo "Can't emulate fallocate invocation with args " "$@" | ||
exit 1 | ||
fi | ||
truncate -s "$2" "$3" | ||
} | ||
|
||
if ! $FALLOCATE -l 1M "$BACKINGFILES_FOLDER/test.bin" | ||
then | ||
echo "emulating fallocate using truncate" | ||
export -f fallocate | ||
fi | ||
rm "$BACKINGFILES_FOLDER/test.bin" | ||
|
||
{ | ||
for cam in 30G 40G | ||
do | ||
for music in 0 4G | ||
do | ||
for lightshow in 0 100M 1G | ||
do | ||
for boombox in 0 100M | ||
do | ||
for exfat in true false | ||
do | ||
checksuccess "$cam" "$music" "$lightshow" "$boombox" "$BACKINGFILES_FOLDER" "$exfat" < /dev/null | ||
find "$BACKINGFILES_FOLDER" -type f | xargs rm | ||
done | ||
done | ||
done | ||
done | ||
done | ||
|
||
|
||
} &>> "$LOG" | ||
|
||
if [ "$SUCCESS" = "true" ] | ||
then | ||
rm -rf "$BACKINGFILES_FOLDER" "$LOG" | ||
else | ||
echo "One or more tests failed, see $LOG for details." | ||
exit 1 | ||
fi |