mirror of
				https://gitlab.com/JBBgameich/halium-install
				synced 2025-11-04 04:55:49 +08:00 
			
		
		
		
	Add test suite
This commit is contained in:
		
							
								
								
									
										18
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,20 +1,10 @@
 | 
			
		||||
#!/usr/bin/make
 | 
			
		||||
 | 
			
		||||
TARGET = $(DESTDIR)/usr
 | 
			
		||||
 | 
			
		||||
install:
 | 
			
		||||
	mkdir -p $(TARGET)/bin/
 | 
			
		||||
	mkdir -p $(TARGET)/share/halium-scripts/
 | 
			
		||||
 | 
			
		||||
	cp launcher.sh $(TARGET)/bin/halium-tool
 | 
			
		||||
 | 
			
		||||
standalone:
 | 
			
		||||
	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:
 | 
			
		||||
	bash utils/appimage.sh
 | 
			
		||||
test:
 | 
			
		||||
	bash tests/test_install.sh
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	if [ -d bin ];then rm bin -r; fi
 | 
			
		||||
	if [ -d bin ]; then rm bin -r; fi
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,6 @@ function flash_dir() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function clean() {
 | 
			
		||||
	# Delete created files from last install
 | 
			
		||||
	sudo rm "$ROOTFS_DIR" "$IMAGE_DIR" -rf
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -70,6 +70,10 @@ while [ -n "$1" ] ; do
 | 
			
		||||
	"-v")
 | 
			
		||||
		out="cat -"
 | 
			
		||||
		;;
 | 
			
		||||
	"-tm" | "--test-mode")
 | 
			
		||||
		# provides an internal test mode
 | 
			
		||||
		TEST_MODE=true
 | 
			
		||||
		;;
 | 
			
		||||
	*)
 | 
			
		||||
		break
 | 
			
		||||
		;;
 | 
			
		||||
@@ -95,15 +99,17 @@ if ! init_checks; then
 | 
			
		||||
	exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
export ROOTFS_DIR=$(mktemp -d .halium-install-rootfs.XXXXX)
 | 
			
		||||
export IMAGE_DIR=$(mktemp -d .halium-install-imgs.XXXXX)
 | 
			
		||||
export ROOTFS_DIR="${ROOTFS_DIR:-$(mktemp -d .halium-install-rootfs.XXXXX)}"
 | 
			
		||||
export IMAGE_DIR="${IMAGE_DIR:-$(mktemp -d .halium-install-imgs.XXXXX)}"
 | 
			
		||||
 | 
			
		||||
# Logic that depends on the opts being parsed
 | 
			
		||||
source "$LOCATION/functions/distributions.sh"
 | 
			
		||||
source "$LOCATION/functions/core.sh"
 | 
			
		||||
 | 
			
		||||
# Always enforce cleanup on exit
 | 
			
		||||
trap clean_exit EXIT
 | 
			
		||||
if [ -z ${TEST_MODE} ]; then
 | 
			
		||||
	trap clean_exit EXIT
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Start installer
 | 
			
		||||
echo "Debug: Chosen rootfs is $ROOTFS_TAR"
 | 
			
		||||
@@ -143,17 +149,19 @@ case "$INSTALL_MODE" in
 | 
			
		||||
	;;
 | 
			
		||||
esac
 | 
			
		||||
 | 
			
		||||
case "$INSTALL_MODE" in
 | 
			
		||||
"img")
 | 
			
		||||
	echo "I: Pushing rootfs and android image to /data via ADB"
 | 
			
		||||
	if ! flash_img; then
 | 
			
		||||
		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"
 | 
			
		||||
	if ! flash_dir; then
 | 
			
		||||
		echo "Error: Couldn't copy the files to the device, is it connected?"
 | 
			
		||||
	fi
 | 
			
		||||
	;;
 | 
			
		||||
esac
 | 
			
		||||
if [ -z ${TEST_MODE} ]; then
 | 
			
		||||
	case "$INSTALL_MODE" in
 | 
			
		||||
	"img")
 | 
			
		||||
		echo "I: Pushing rootfs and android image to /data via ADB"
 | 
			
		||||
		if ! flash_img; then
 | 
			
		||||
			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"
 | 
			
		||||
		if ! flash_dir; then
 | 
			
		||||
			echo "Error: Couldn't copy the files to the device, is it connected?"
 | 
			
		||||
		fi
 | 
			
		||||
		;;
 | 
			
		||||
	esac
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										121
									
								
								tests/test_install.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										121
									
								
								tests/test_install.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,121 @@
 | 
			
		||||
#!/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
 | 
			
		||||
		Reference in New Issue
	
	Block a user