]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Add a very simple test harness
authorVictor Lowther <victor.lowther@gmail.com>
Sun, 8 Mar 2009 14:23:11 +0000 (09:23 -0500)
committerVictor Lowther <victor.lowther@gmail.com>
Sun, 8 Mar 2009 16:39:55 +0000 (11:39 -0500)
This creates a basic root filesystem, creates an initramfs, and tries
to boot to the basic filesystem.

The init code on the test filesystem prints how much memory is used vs. free
and then drops to a shell.  Exiting the shell will power off the VM.

test/dracut.conf.test [new file with mode: 0644]
test/test-init [new file with mode: 0755]
test/test-initramfs [new file with mode: 0755]

diff --git a/test/dracut.conf.test b/test/dracut.conf.test
new file mode 100644 (file)
index 0000000..7273df7
--- /dev/null
@@ -0,0 +1,2 @@
+dracutmodules="kernel-modules udev-rules base"
+modules="ata_piix ext2 sd_mod"
diff --git a/test/test-init b/test/test-init
new file mode 100755 (executable)
index 0000000..63fde1e
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+exec >/dev/console 2>&1
+export TERM=linux
+ln -s /proc/mounts /etc/mtab
+export PS1='initramfs-test:\w\$'
+stty sane
+echo "made it to the rootfs!"
+echo 3 >/proc/sys/vm/drop_caches
+free
+sh -i
+mount -o remount,ro /
+poweroff -f
\ No newline at end of file
diff --git a/test/test-initramfs b/test/test-initramfs
new file mode 100755 (executable)
index 0000000..f27f9db
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+. ./dracut-functions
+kernel=$(uname -r)
+[[ -f root.ext2 ]] || {
+    readonly initdir=$(mktemp -d -t initramfs-test-XXXXXXXX)
+    readonly mnttarget=$(mktemp -d -t initramfs-test-target-XXXXXXXX)
+    trap 'rm -rf "$initdir"' 0
+    dracut_install sh df free ls shutdown poweroff stty cat ps ln \
+       /lib/terminfo/l/linux mount dmesg
+    inst test-init /sbin/init
+    dd if=/dev/zero of=root.ext2 bs=1M count=10
+    mke2fs -F root.ext2
+    mount -o loop -t ext2 root.ext2 "$mnttarget"
+    cp -a -t "$mnttarget" "$initdir"/*
+    (cd "$mnttarget"; mkdir -p dev sys proc etc)
+    umount -l "$mnttarget"
+    rm -rf "$mnttarget" "$initdir"
+}
+./dracut -c dracut.conf.test -l -f initramfs.testing
+
+exec qemu-kvm -hda root.ext2 -nographic -net none \
+    -kernel /boot/vmlinuz-$kernel \
+    -append "root=/dev/sda rw rootfstype=ext2 console=ttyS0,115200n81 quiet" \
+    -initrd initramfs.testing
\ No newline at end of file