On Thu, Oct 25, 2012 at 01:52:20PM +0100, Sam Thursfield wrote:
This makes it easier to identify what version of a system we are
running.
diff --git a/tests.as-root/disk-builds-rootfs-and-kernel.script
b/tests.as-root/disk-builds-rootfs-and-kernel.script
index f9748ca..b8f7cc9 100755
--- a/tests.as-root/disk-builds-rootfs-and-kernel.script
+++ b/tests.as-root/disk-builds-rootfs-and-kernel.script
@@ -83,8 +85,11 @@ git add linux.morph
git commit --quiet -m 'Make the kernel create a dummy zImage'
-"$SRCDIR/scripts/test-morph" \
- build-morphology test:morphs-repo custom system > /dev/null
+rootfs=$("$SRCDIR/morph" \
+ --no-default-config --config="$DATADIR/morph.conf" --verbose \
+ build-morphology test:morphs-repo custom system 2>&1 |
+ grep "system system-rootfs is cached at" |
+ sed -nre "s/^.*system system-rootfs is cached at (\S+)$/\1/p")
for suffix in kernel rootfs
do
I can see us needing to do this grep to find the rootfs a lot, it may be
more convenient to have it as a shell function, or helper script.
@@ -96,3 +101,9 @@ do
fi
done
+rootfs_mount_dir=$(loopback_mount_rootfs $rootfs)
$rootfs should be quoted, I think if TMPDIR is set to a path with
spaces, then this would fail.
+cd "$rootfs_mount_dir"
+find | sort
The find generates more output than is strictly needed for the test, I
would instead limit it to one of the subvolumes as that contains all the
required files.
sort should be run as LC_ALL=C sort, so that locale settings don't cause
it to fail.
+cd "$DATADIR"
+umount $rootfs_mount_dir
$rootfs_mount_dir should be quoted
diff --git a/tests.as-root/lib b/tests.as-root/lib
new file mode 100644
index 0000000..c5b7142
--- /dev/null
+++ b/tests.as-root/lib
@@ -0,0 +1,37 @@
snip
+loopback_mount_rootfs() {
+ # Find offset partition offset in a rootfs and mount it
+ ROOTFS=$1
$1 should be quoted
+
+ mv $ROOTFS $ROOTFS.gz
+ gunzip $ROOTFS.gz
+ OFFSET=$(sfdisk -d $ROOTFS | \
+ grep -m 1 -o 'start=\s\+\([0-9]\+\)' | \
+ awk '{ print $2 }')
+ OFFSET=$(expr $OFFSET \* 512)
I would use $(("$OFFSET" * 512)), since we're already requiring bash
elsewhere. The assumption that block sizes are 512 is becoming less
true, but I think it's still ok for virtual disks.
+
+ DEVICE=$(losetup --show -o $OFFSET -f $ROOTFS)
$ROOTFS and $OFFSET should be quoted
+
+ mkdir -p "$DATADIR/mnt"
+ mount $DEVICE "$DATADIR/mnt"
$DEVICE should be quoted
+ echo "$DATADIR/mnt"
+}
Some other tests need to do loopback_mount_rootfs, using different
implementations, it may be worth consolidating these.
syslinux-disk-builds-rootfs-and-kernel also needs quoting.