summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2007-08-23 16:23:21 +0800
committerJeremy Kerr <jk@ozlabs.org>2007-08-23 16:27:34 +0800
commit81aa8fc95444b14e427befa5b03f52388f64e21c (patch)
treef1aae9cb4616b38cebabc9259a3893b96f80869f
parent827e0b3bdfaf4a218e1d75cb9e6a52ec097a3a38 (diff)
downloadtalos-petitboot-81aa8fc95444b14e427befa5b03f52388f64e21c.tar.gz
talos-petitboot-81aa8fc95444b14e427befa5b03f52388f64e21c.zip
Add parser tests, clean up test system
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--devices/parser-test.c47
-rwxr-xr-xdevices/parser-test.sh20
-rw-r--r--devices/parser-tests/001/etc/kboot.conf9
-rw-r--r--devices/parser-tests/001/expected-output24
-rw-r--r--devices/parser-tests/002/etc/yaboot.conf8
-rw-r--r--devices/parser-tests/002/expected-output9
6 files changed, 98 insertions, 19 deletions
diff --git a/devices/parser-test.c b/devices/parser-test.c
index 9622d4d..12348b8 100644
--- a/devices/parser-test.c
+++ b/devices/parser-test.c
@@ -17,31 +17,44 @@ void pb_log(const char *fmt, ...)
va_end(ap);
}
-
int mount_device(const char *dev_path)
{
- pb_log("attempt to mount device (%s) not supported\n", dev_path);
+ printf("[mount] %s\n", dev_path);
return 0;
}
+static int device_idx;
+static int option_idx;
+
int add_device(const struct device *dev)
{
- printf("device added:\n");
- printf("\tid: %s\n", dev->id);
- printf("\tname: %s\n", dev->name);
- printf("\tdescription: %s\n", dev->description);
- printf("\tboot_image: %s\n", dev->icon_file);
+ printf("[dev %2d] id: %s\n", device_idx, dev->id);
+ printf("[dev %2d] name: %s\n", device_idx, dev->name);
+ printf("[dev %2d] description: %s\n", device_idx, dev->description);
+ printf("[dev %2d] boot_image: %s\n", device_idx, dev->icon_file);
+
+ device_idx++;
+ option_idx = 0;
return 0;
}
+
int add_boot_option(const struct boot_option *opt)
{
- printf("option added:\n");
- printf("\tname: %s\n", opt->name);
- printf("\tdescription: %s\n", opt->description);
- printf("\tboot_image: %s\n", opt->boot_image_file);
- printf("\tinitrd: %s\n", opt->initrd_file);
- printf("\tboot_args: %s\n", opt->boot_args);
+ if (!device_idx) {
+ fprintf(stderr, "Option (%s) added before device\n",
+ opt->name);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("[opt %2d] name: %s\n", option_idx, opt->name);
+ printf("[opt %2d] description: %s\n", option_idx, opt->description);
+ printf("[opt %2d] boot_image: %s\n", option_idx, opt->boot_image_file);
+ printf("[opt %2d] initrd: %s\n", option_idx, opt->initrd_file);
+ printf("[opt %2d] boot_args: %s\n", option_idx, opt->boot_args);
+
+ option_idx++;
+
return 0;
}
@@ -52,14 +65,10 @@ enum generic_icon_type guess_device_type(void)
static char *mountpoint;
+/* pretend that all devices are mounted at our original mountpoint */
const char *mountpoint_for_device(const char *dev_path)
{
- char *tmp, *dev;
- dev = strrchr(dev_path, '/');
- if (dev)
- dev_path = dev + 1;
- asprintf(&tmp, "%s/%s", mountpoint, dev_path);
- return tmp;
+ return mountpoint;
}
char *resolve_path(const char *path, const char *default_mountpoint)
diff --git a/devices/parser-test.sh b/devices/parser-test.sh
new file mode 100755
index 0000000..351dc75
--- /dev/null
+++ b/devices/parser-test.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+testdir=devices/parser-tests
+
+function test_dir()
+{
+ dir="$1"
+ ./parser-test "$dir" 2>/dev/null |
+ diff -u "$dir/expected-output" -
+}
+
+set -ex
+
+for test in $testdir/*
+do
+ echo $test
+ test_dir "$test"
+done
+
+echo "All tests passed"
diff --git a/devices/parser-tests/001/etc/kboot.conf b/devices/parser-tests/001/etc/kboot.conf
new file mode 100644
index 0000000..591c51b
--- /dev/null
+++ b/devices/parser-tests/001/etc/kboot.conf
@@ -0,0 +1,9 @@
+# Ubuntu feisty kboot.conf
+message=/etc/kboot.msg
+timeout=300
+default=live
+live='/casper/vmlinux initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --'
+live_nosplash='/casper/vmlinux initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper quiet --'
+driverupdates='/casper/vmlinux initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper debian-installer/driver-update=true quiet splash --'
+check='/casper/vmlinux initrd=/casper/initrd.gz boot=casper integrity-check quiet splash --'
+
diff --git a/devices/parser-tests/001/expected-output b/devices/parser-tests/001/expected-output
new file mode 100644
index 0000000..6e68671
--- /dev/null
+++ b/devices/parser-tests/001/expected-output
@@ -0,0 +1,24 @@
+[dev 0] id: sda1
+[dev 0] name: (null)
+[dev 0] description: (null)
+[dev 0] boot_image: /usr/share/petitboot/artwork/hdd.png
+[opt 0] name: live
+[opt 0] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --
+[opt 0] boot_image: devices/parser-tests/001//casper/vmlinux
+[opt 0] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt 0] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --
+[opt 1] name: live_nosplash
+[opt 1] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper quiet --
+[opt 1] boot_image: devices/parser-tests/001//casper/vmlinux
+[opt 1] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt 1] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper quiet --
+[opt 2] name: driverupdates
+[opt 2] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper debian-installer/driver-update=true quiet splash --
+[opt 2] boot_image: devices/parser-tests/001//casper/vmlinux
+[opt 2] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt 2] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz file=/cdrom/preseed/ubuntu.seed boot=casper debian-installer/driver-update=true quiet splash --
+[opt 3] name: check
+[opt 3] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz boot=casper integrity-check quiet splash --
+[opt 3] boot_image: devices/parser-tests/001//casper/vmlinux
+[opt 3] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt 3] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz boot=casper integrity-check quiet splash --
diff --git a/devices/parser-tests/002/etc/yaboot.conf b/devices/parser-tests/002/etc/yaboot.conf
new file mode 100644
index 0000000..f13b1b3
--- /dev/null
+++ b/devices/parser-tests/002/etc/yaboot.conf
@@ -0,0 +1,8 @@
+init-message = "\nWelcome to the 64-bit Yellow Dog Linux 5.0 installer!\nHit <TAB> for boot options.\n\n"
+timeout=6000
+default=linux
+
+image=/ppc/ppc64/vmlinux
+ label=linux
+ initrd=/ppc/ppc64/ramdisk.image.gz
+ read-only
diff --git a/devices/parser-tests/002/expected-output b/devices/parser-tests/002/expected-output
new file mode 100644
index 0000000..d0dde25
--- /dev/null
+++ b/devices/parser-tests/002/expected-output
@@ -0,0 +1,9 @@
+[dev 0] id: sda1
+[dev 0] name: (null)
+[dev 0] description:
+[dev 0] boot_image: /usr/share/petitboot/artwork/hdd.png
+[opt 0] name: linux
+[opt 0] description: (null)
+[opt 0] boot_image: devices/parser-tests/002//ppc/ppc64/vmlinux
+[opt 0] initrd: devices/parser-tests/002//ppc/ppc64/ramdisk.image.gz
+[opt 0] boot_args: ro
OpenPOWER on IntegriCloud