]> git.ozlabs.org Git - petitboot/commitdiff
Add parser tests, clean up test system
authorJeremy Kerr <jk@ozlabs.org>
Thu, 23 Aug 2007 08:23:21 +0000 (16:23 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 23 Aug 2007 08:27:34 +0000 (16:27 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
devices/parser-test.c
devices/parser-test.sh [new file with mode: 0755]
devices/parser-tests/001/etc/kboot.conf [new file with mode: 0644]
devices/parser-tests/001/expected-output [new file with mode: 0644]
devices/parser-tests/002/etc/yaboot.conf [new file with mode: 0644]
devices/parser-tests/002/expected-output [new file with mode: 0644]

index 9622d4d31463e0268207483507f1b990fddaa42c..12348b8991f680bb3c0683f257ff58c823a9165b 100644 (file)
@@ -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 (executable)
index 0000000..351dc75
--- /dev/null
@@ -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 (file)
index 0000000..591c51b
--- /dev/null
@@ -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 (file)
index 0000000..6e68671
--- /dev/null
@@ -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 (file)
index 0000000..f13b1b3
--- /dev/null
@@ -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 (file)
index 0000000..d0dde25
--- /dev/null
@@ -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