diff --git a/tests/TODO.md b/tests/TODO.md new file mode 100644 index 0000000..e2ceadd --- /dev/null +++ b/tests/TODO.md @@ -0,0 +1,39 @@ +Expectations +============ + +Having a way to run after each commit a test on a list of samples and check if +the output and the logs are the ones expected by. +Easy way to check it on the rPi itself before releases. + + +What to think about +=================== + +* Exhaustive list of files, edge cases +* Check the logfiles + +Ideas +===== + +Source keys: +- Working documents, one / multiple partitions +- Non working documents: one / multiple partitions +- different FS on different partitions +- Non working FS +- Malicious documents (very slow, might break the conversions) + +Destinations keys +- empty, big enough +- empty, too small +- broken +- not empty +- unmountable (wrong/broken fs) + + + +Things to try out +================= + + +Run the image in qemu, process USB keys from there + diff --git a/tests/mkrawfs.sh b/tests/mkrawfs.sh new file mode 100755 index 0000000..99bdcaf --- /dev/null +++ b/tests/mkrawfs.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Doc: http://wiki.osdev.org/Loopback_Device + + +set -e +set -x + +# User +#FS_EXT='ext2 ext3 ext4' +FS_VFAT='vfat' +#FS_NTFS='ntfs' +SIZE_MB='128' + +# System +FS="${FS_EXT} ${FS_VFAT} ${FS_NTFS}" + + +for f in $FS; do + # Create files of 128Mb + OUT_NAME_NORM="testcase."${f} + OUT_NAME_PART="testcase.part."${f} + dd if=/dev/zero of=${OUT_NAME_NORM} bs=516096c count=200 + dd if=/dev/zero of=${OUT_NAME_PART} bs=516096c count=200 + parted -s ${OUT_NAME_NORM} mklabel msdos + parted -s ${OUT_NAME_PART} mklabel msdos + if [ $f = ${FS_VFAT} ]; then + parted -s ${OUT_NAME_PART} mkpart primary 8192s 122879s + parted -s ${OUT_NAME_PART} mkpart primary 122880s 201599s + parted -s ${OUT_NAME_NORM} mkpart primary 8192s 201599s + lo=`losetup -f` + losetup -o$((8192 * 512)) ${lo} ${OUT_NAME_PART} + mkfs.${f} ${lo} 57344 + losetup -d ${lo} + losetup -o$((122880 * 512)) ${lo} ${OUT_NAME_PART} + mkfs.${f} ${lo} 39360 + losetup -d ${lo} + losetup -o$((8192 * 512)) ${lo} ${OUT_NAME_NORM} + mkfs.${f} ${lo} + losetup -d ${lo} + elif [ $f = ${FS_NTFS} ]; then + mk${f} -f -F ${OUT_NAME} + else + mkfs.${f} -F ${OUT_NAME} + fi +done + diff --git a/tests/run.exp b/tests/run.exp new file mode 100755 index 0000000..3886832 --- /dev/null +++ b/tests/run.exp @@ -0,0 +1,20 @@ +#!/usr/bin/expect -f + +set timeout -1 + +spawn qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb \ + -watchdog i6300esb -watchdog-action poweroff \ + -serial stdio -append "root=/dev/sdc2 panic=1 rootfstype=ext4 ro console=ttyAMA0 console=ttyS0" \ + -drive file=[lindex $argv 1],index=0,media=disk \ + -drive file=[lindex $argv 2],index=1,media=disk \ + -drive file=[lindex $argv 0],index=2,media=disk \ + -vnc 0.0.0.0:1 \ + -serial stdio \ + -soundhw all \ + -chardev stdio,id=mon0 -mon chardev=mon0,mode=readline \ + -chardev socket,id=mon1,host=localhost,port=4444,server,nowait \ + -mon chardev=mon1,mode=control,pretty=on + +expect "System halted." + +send "quit\n" diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..abb102c --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/ + +IMAGE='../2014-01-07-wheezy-raspbian.img' +OFFSET_ROOTFS=$((122880 * 512)) + +IMAGE_VFAT_NORM="testcase.vfat" +OFFSET_VFAT_NORM=$((8192 * 512)) + +IMAGE_VFAT_PART="testcase.part.vfat" +OFFSET_VFAT_PART1=$((8192 * 512)) +OFFSET_VFAT_PART2=$((122880 * 512)) + +IMAGE_DEST="testcase_dest.vfat" + +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +set -e +set -x + +SETUP_DIR="setup" + +clean(){ + mount -o loop,offset=${OFFSET_ROOTFS} ${IMAGE} ${SETUP_DIR} + mv ${SETUP_DIR}/etc/ld.so.preload_bkp ${SETUP_DIR}/etc/ld.so.preload + umount ${SETUP_DIR} + rm -rf ${SETUP_DIR} +} + +trap clean EXIT TERM INT + +mkdir -p ${SETUP_DIR} + +# make the CIRCLean image compatible with qemu +mount -o loop,offset=${OFFSET_ROOTFS} ${IMAGE} ${SETUP_DIR} +mv ${SETUP_DIR}/etc/ld.so.preload ${SETUP_DIR}/etc/ld.so.preload_bkp +umount ${SETUP_DIR} + +# Prepare the test source key +mount -o loop,offset=${OFFSET_VFAT_NORM} ${IMAGE_VFAT_NORM} ${SETUP_DIR} +cp content_img_vfat_norm/* ${SETUP_DIR} +umount ${SETUP_DIR} +# Prepare the test source key (with partitions) +mount -o loop,offset=${OFFSET_VFAT_PART1} ${IMAGE_VFAT_PART} ${SETUP_DIR} +cp content_img_vfat_part1/* ${SETUP_DIR} +umount ${SETUP_DIR} +mount -o loop,offset=${OFFSET_VFAT_PART2} ${IMAGE_VFAT_PART} ${SETUP_DIR} +cp content_img_vfat_part2/* ${SETUP_DIR} +umount ${SETUP_DIR} + +./run.exp ${IMAGE} ${IMAGE_VFAT_NORM} ${IMAGE_DEST} +#./run.exp ${IMAGE} ${IMAGE_VFAT_PART} ${IMAGE_DEST} +