SVN: geninitrd/trunk/tests/initramfs_switchroot.sh
glen
glen at pld-linux.org
Fri Mar 30 16:11:09 CEST 2012
Author: glen
Date: Fri Mar 30 16:11:09 2012
New Revision: 12526
Added:
geninitrd/trunk/tests/initramfs_switchroot.sh (contents, props changed)
Log:
add test
Added: geninitrd/trunk/tests/initramfs_switchroot.sh
==============================================================================
--- (empty file)
+++ geninitrd/trunk/tests/initramfs_switchroot.sh Fri Mar 30 16:11:09 2012
@@ -0,0 +1,73 @@
+#!/bin/sh
+# test for initrd_gen_initramfs_switchroot parsing
+
+. ./setup-test.sh
+flags=$-
+
+mount() {
+ echo "mount $@"
+}
+
+
+ # parse 'root=xxx' kernel commandline
+ # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
+# add_linuxrc <<-'EOF'
+runtest_run() {
+ device=/dev/no_partition_found
+ eval "$(
+ busybox awk -v c="$ROOT" '
+ BEGIN {
+ num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
+ num_pattern = "[0-9a-f]" num_pattern_short;
+ dev_pattern = "[hms][a-z][a-z]([0-9])+";
+ partition = "no_partition_found";
+ min = -1; maj = -1;
+
+ sub("^0x", "", c);
+ if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
+ if (c ~ "^" num_pattern "$") {
+ maj = sprintf("%s",substr(c,1,2));
+ min = sprintf("%s",substr(c,3));
+ }
+ if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
+ if (c ~ "^" dev_pattern "$") partition = c;
+ }
+
+ $4 == partition { maj = $1; min = $2; }
+ $1 == maj && $2 == min { partition = $4; }
+
+ END {
+ if (maj >= 0 && min >= 0) {
+ printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
+ }
+ }
+ ' /proc/partitions
+ )"
+ if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
+ mknod $device b $maj $min
+ fi
+
+ if [ "$device" = '/dev/no_partition_found' ]; then
+ device=$ROOT
+ fi
+
+ [ -n "$ROOTFSFLAGS" ] && ROOTFSFLAGS="-o $ROOTFSFLAGS"
+
+ mount -t $ROOTFS -r $device $ROOTFSFLAGS /newroot || echo "Mount of rootfs failed."
+ init=$INIT
+ if [ -z "$init" -o ! -x "/newroot$init" ]; then
+ init=/sbin/init
+ fi
+# EOF
+# echo "init=$init"
+}
+
+#ROOT=/dev/sda2
+#runtest <<'EOF'
+#mount -t -r /dev/sda2 /newroot
+#EOF
+
+ROOT=302
+runtest <<'EOF'
+mount -t -r /dev/sda2 /newroot
+EOF
More information about the pld-cvs-commit
mailing list