Commit 3bf66849 authored by Jonah Brüchert's avatar Jonah Brüchert

Add test suite

parent 9b29898b
#!/usr/bin/make #!/usr/bin/make
TARGET = $(DESTDIR)/usr standalone:
install:
mkdir -p $(TARGET)/bin/
mkdir -p $(TARGET)/share/halium-scripts/
cp launcher.sh $(TARGET)/bin/halium-tool
bash utils/standalone.sh bash utils/standalone.sh
cp bin/halium-install-standalone.sh $(TARGET)/share/halium-scripts/halium-install
cp connect.py $(TARGET)/share/halium-scripts/connect.py
cp download-twrp.py $(TARGET)/share/halium-scripts/download-twrp.py
appimage: test:
bash utils/appimage.sh bash tests/test_install.sh
clean: clean:
if [ -d bin ];then rm bin -r; fi if [ -d bin ]; then rm bin -r; fi
...@@ -53,7 +53,6 @@ function flash_dir() { ...@@ -53,7 +53,6 @@ function flash_dir() {
} }
function clean() { function clean() {
# Delete created files from last install
sudo rm "$ROOTFS_DIR" "$IMAGE_DIR" -rf sudo rm "$ROOTFS_DIR" "$IMAGE_DIR" -rf
} }
......
...@@ -70,6 +70,10 @@ while [ -n "$1" ] ; do ...@@ -70,6 +70,10 @@ while [ -n "$1" ] ; do
"-v") "-v")
out="cat -" out="cat -"
;; ;;
"-tm" | "--test-mode")
# provides an internal test mode
TEST_MODE=true
;;
*) *)
break break
;; ;;
...@@ -95,15 +99,17 @@ if ! init_checks; then ...@@ -95,15 +99,17 @@ if ! init_checks; then
exit exit
fi fi
export ROOTFS_DIR=$(mktemp -d .halium-install-rootfs.XXXXX) export ROOTFS_DIR="${ROOTFS_DIR:-$(mktemp -d .halium-install-rootfs.XXXXX)}"
export IMAGE_DIR=$(mktemp -d .halium-install-imgs.XXXXX) export IMAGE_DIR="${IMAGE_DIR:-$(mktemp -d .halium-install-imgs.XXXXX)}"
# Logic that depends on the opts being parsed # Logic that depends on the opts being parsed
source "$LOCATION/functions/distributions.sh" source "$LOCATION/functions/distributions.sh"
source "$LOCATION/functions/core.sh" source "$LOCATION/functions/core.sh"
# Always enforce cleanup on exit # Always enforce cleanup on exit
trap clean_exit EXIT if [ -z ${TEST_MODE} ]; then
trap clean_exit EXIT
fi
# Start installer # Start installer
echo "Debug: Chosen rootfs is $ROOTFS_TAR" echo "Debug: Chosen rootfs is $ROOTFS_TAR"
...@@ -143,17 +149,19 @@ case "$INSTALL_MODE" in ...@@ -143,17 +149,19 @@ case "$INSTALL_MODE" in
;; ;;
esac esac
case "$INSTALL_MODE" in if [ -z ${TEST_MODE} ]; then
"img") case "$INSTALL_MODE" in
echo "I: Pushing rootfs and android image to /data via ADB" "img")
if ! flash_img; then echo "I: Pushing rootfs and android image to /data via ADB"
echo "Error: Couldn't copy the files to the device, is it connected?" if ! flash_img; then
fi echo "Error: Couldn't copy the files to the device, is it connected?"
;; fi
"dir") ;;
echo "I: Pushing rootfs and android image to /data via ADB" "dir")
if ! flash_dir; then echo "I: Pushing rootfs and android image to /data via ADB"
echo "Error: Couldn't copy the files to the device, is it connected?" if ! flash_dir; then
fi echo "Error: Couldn't copy the files to the device, is it connected?"
;; fi
esac ;;
esac
fi
#!/usr/bin/env bash
TEST_LOCATION="$(dirname "$(readlink -f "$0")")"
PATH="${TEST_LOCATION}/../:${PATH}"
TMP_PATH="${TEST_LOCATION}/tmp"
ROOTFS_PATH="${TMP_PATH}/rootfs.tar.gz"
ANDROID_IMG_PATH="${TMP_PATH}/system.img"
# Passed to halium-install
export ROOTFS_DIR="${TMP_PATH}/rootfs"
export IMAGE_DIR="${TMP_PATH}/images"
if [ ! -d "${TMP_PATH}" ]; then
mkdir "${TMP_PATH}" -p
fi
if [ ! -f "${ROOTFS_PATH}" ]; then
wget --continue \
https://archive.kaidan.im/debian-pm/images/halium/minimal/debian-halium-minimal-testing-armhf.tar.gz \
-O "${ROOTFS_PATH}"
fi
if [ ! -f "${ANDROID_IMG_PATH}" ]; then
wget --continue \
https://archive.kaidan.im/halium/hammerhead/system.img
-O "${ANDROID_IMG_PATH}"
fi
# Clean up to make test_images_exist and test_dir_exists useful
if [ -d ${ROOTFS_DIR} ]; then
sudo chown $(whoami) -R ${ROOTFS_DIR}
rm ${ROOTFS_DIR} -rf
mkdir -p ${ROOTFS_DIR}
fi
if [ -d ${IMAGE_DIR} ]; then
rm ${IMAGE_DIR} -r
mkdir -p ${IMAGE_DIR}
fi
function run_test() {
echo -n "Running $1... "
if $1; then
echo "[PASS]"
else
echo "[FAIL]"
fi
}
# Generic
function test_executable() {
[ -x "${TEST_LOCATION}/../halium-install" ]
}
# Dir mode
function test_img_exit_success() {
halium-install --test-mode -v -p debian-pm -u 1234 -r 1234 "${ROOTFS_PATH}" "${ANDROID_IMG_PATH}" > "${TMP_PATH}/log" 2>&1
}
function test_mount() {
sudo mount "${IMAGE_DIR}/rootfs.img" "${ROOTFS_DIR}"
}
function test_root_passwd() {
! sudo grep "root:\*:17904:0:99999:7:::" "${ROOTFS_DIR}/etc/shadow" >/dev/null 2>&1
}
function test_images_exist() {
[ -f "${IMAGE_DIR}/rootfs.img" ] && [ -f "${IMAGE_DIR}/system.img" ]
}
function test_ssh_hostkey_changed() {
tar -C "${TMP_PATH}" -xf "${ROOTFS_PATH}" ./etc/dropbear/dropbear_rsa_host_key
orig_sum=($(sha256sum "${TMP_PATH}/etc/dropbear/dropbear_rsa_host_key"))
new_sum=($(sudo sha256sum "${ROOTFS_DIR}/etc/dropbear/dropbear_rsa_host_key"))
[ ${orig_sum[0]} != ${new_sum[0]} ]
}
function test_qemu_not_left() {
[ ! -d "${ROOTFS_DIR}/usr/bin/qemu-arm-static" ]
}
function test_umount() {
sudo umount -l "${IMAGE_DIR}/rootfs.img"
}
# Dir mode
function test_dir_exit_success() {
halium-install --test-mode -v --mode dir -p debian-pm -u 1234 -r 1234 "${ROOTFS_PATH}" "${ANDROID_IMG_PATH}" > "${TMP_PATH}/log" 2>&1
}
function test_dir_files_exist() {
[ -d "${ROOTFS_DIR}" ] && [ -f "${ROOTFS_DIR}/var/lib/lxc/android/system.img" ]
}
function test_dir_correct_image_path() {
! grep "/data/system.img" "$ROOTFS_DIR/lib/systemd/system/system.mount"
}
echo "# Generic tests"
run_test test_executable
echo "# Image mode tests"
run_test test_img_exit_success
run_test test_images_exist
run_test test_mount
run_test test_root_passwd
run_test test_ssh_hostkey_changed
run_test test_qemu_not_left
run_test test_umount
echo "# Dir mode tests"
run_test test_dir_exit_success
run_test test_dir_files_exist
run_test test_dir_correct_image_path
trap test_umount EXIT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment