summaryrefslogtreecommitdiffstats
path: root/test/parser
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-10-30 15:26:04 +1100
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-11-16 13:55:13 +1100
commit646d77d8156ad72da1c24f734a029a525ba4bed9 (patch)
tree8eaa5db080f5c2b733b506fd82eec773ac2afdb3 /test/parser
parent638f16c7683db165154bbe53772c4b864f9dc90d (diff)
downloadtalos-petitboot-646d77d8156ad72da1c24f734a029a525ba4bed9.tar.gz
talos-petitboot-646d77d8156ad72da1c24f734a029a525ba4bed9.zip
discover: Reimplement native-parser as a Bison parser
Occasionally you look at some code and realise that a) this never gets built, and b) even if it did it would never compile. Today's example is native-parser.c which we must have just assumed worked for quite a while. The native parser has bitrotted entirely and needs to be brought up to date. While we're here, lets take the chance to implement a proper grammar for it. This helps us reason more effectively about the parser, lets us extend it easily in the future, and.. I wanted to write a Bison parser too. This implements most of the old functionality, but drops off some smaller details like settings icons which needs some separate attention to bring up to date. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'test/parser')
-rw-r--r--test/parser/Makefile.am14
-rw-r--r--test/parser/data/native-short.conf4
-rw-r--r--test/parser/test-native-globals.c45
-rw-r--r--test/parser/test-native-short.c24
-rw-r--r--test/parser/test-native-simple.c31
-rw-r--r--test/parser/test-native-strings.c35
6 files changed, 150 insertions, 3 deletions
diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am
index 363933e..483add9 100644
--- a/test/parser/Makefile.am
+++ b/test/parser/Makefile.am
@@ -87,7 +87,11 @@ parser_TESTS = \
test/parser/test-syslinux-single-yocto \
test/parser/test-syslinux-global-append \
test/parser/test-syslinux-explicit \
- test/parser/test-syslinux-nested-config
+ test/parser/test-syslinux-nested-config \
+ test/parser/test-native-globals \
+ test/parser/test-native-short \
+ test/parser/test-native-simple \
+ test/parser/test-native-strings
TESTS += $(parser_TESTS)
@@ -100,7 +104,8 @@ check_DATA += \
test/parser/data/yaboot-rh8-ppc64.conf \
test/parser/data/syslinux-include-root.cfg \
test/parser/data/syslinux-include-nest-1.cfg \
- test/parser/data/syslinux-include-nest-2.cfg
+ test/parser/data/syslinux-include-nest-2.cfg \
+ test/parser/data/native-short.conf
$(parser_TESTS): AM_CPPFLAGS += \
-I$(top_srcdir)/discover \
@@ -133,13 +138,16 @@ test_parser_libtest_ro_SOURCES = \
discover/parser-conf.c \
discover/user-event.c \
discover/event.c \
- $(discover_grub2_grub2_parser_ro_SOURCES)
+ $(discover_grub2_grub2_parser_ro_SOURCES) \
+ $(discover_native_native_parser_ro_SOURCES)
test_parser_libtest_ro_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(top_srcdir)/discover \
-I$(top_srcdir)/discover/grub2 \
-I$(top_builddir)/discover/grub2 \
+ -I$(top_srcdir)/discover/native \
+ -I$(top_builddir)/discover/native \
-DPETITBOOT_TEST \
-DLOCAL_STATE_DIR='"$(localstatedir)"' \
-DTEST_CONF_BASE='"$(top_srcdir)/test/parser/data"'
diff --git a/test/parser/data/native-short.conf b/test/parser/data/native-short.conf
new file mode 100644
index 0000000..a814e9d
--- /dev/null
+++ b/test/parser/data/native-short.conf
@@ -0,0 +1,4 @@
+name Ubuntu
+image /boot/vmlinux-4.15.0-22-generic
+initrd /boot/initrd.img-4.15.0-22-generic
+args root=UUID=09d1034f-3cff-413a-af22-68be1fa5e3d8 ro
diff --git a/test/parser/test-native-globals.c b/test/parser/test-native-globals.c
new file mode 100644
index 0000000..0361e03
--- /dev/null
+++ b/test/parser/test-native-globals.c
@@ -0,0 +1,45 @@
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+
+default first
+
+name first
+image /vmlinuz
+args console=hvc0
+initrd /initrd
+
+name second
+image /boot/vmlinuz
+args console=tty0
+initrd /boot/initrd
+
+#endif
+
+void run_test(struct parser_test *test)
+{
+ struct discover_boot_option *opt;
+ struct discover_context *ctx;
+
+ test_read_conf_embedded(test, "/boot/petitboot.conf");
+
+ test_run_parser(test, "native");
+
+ ctx = test->ctx;
+
+ check_boot_option_count(ctx, 2);
+
+ opt = get_boot_option(ctx, 0);
+
+ check_name(opt, "first");
+ check_resolved_local_resource(opt->boot_image, ctx->device, "/vmlinuz");
+ check_args(opt, "console=hvc0");
+ check_resolved_local_resource(opt->initrd, ctx->device, "/initrd");
+ check_is_default(opt);
+
+ opt = get_boot_option(ctx, 1);
+ check_name(opt, "second");
+ check_resolved_local_resource(opt->boot_image, ctx->device, "/boot/vmlinuz");
+ check_args(opt, "console=tty0");
+ check_resolved_local_resource(opt->initrd, ctx->device, "/boot/initrd");
+}
diff --git a/test/parser/test-native-short.c b/test/parser/test-native-short.c
new file mode 100644
index 0000000..178d080
--- /dev/null
+++ b/test/parser/test-native-short.c
@@ -0,0 +1,24 @@
+#include "parser-test.h"
+
+void run_test(struct parser_test *test)
+{
+ struct discover_boot_option *opt;
+ struct discover_context *ctx;
+
+ test_read_conf_file(test, "native-short.conf", "/boot/petitboot.conf");
+
+ test_run_parser(test, "native");
+
+ ctx = test->ctx;
+
+ check_boot_option_count(ctx, 1);
+
+ opt = get_boot_option(ctx, 0);
+
+ check_name(opt, "Ubuntu");
+ check_resolved_local_resource(opt->boot_image, ctx->device,
+ "/boot/vmlinux-4.15.0-22-generic");
+ check_args(opt, "root=UUID=09d1034f-3cff-413a-af22-68be1fa5e3d8 ro");
+ check_resolved_local_resource(opt->initrd, ctx->device,
+ "/boot/initrd.img-4.15.0-22-generic");
+}
diff --git a/test/parser/test-native-simple.c b/test/parser/test-native-simple.c
new file mode 100644
index 0000000..f817228
--- /dev/null
+++ b/test/parser/test-native-simple.c
@@ -0,0 +1,31 @@
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+
+name native-option
+image /vmlinuz
+args console=hvc0
+initrd /initrd
+
+#endif
+
+void run_test(struct parser_test *test)
+{
+ struct discover_boot_option *opt;
+ struct discover_context *ctx;
+
+ test_read_conf_embedded(test, "/boot/petitboot.conf");
+
+ test_run_parser(test, "native");
+
+ ctx = test->ctx;
+
+ check_boot_option_count(ctx, 1);
+
+ opt = get_boot_option(ctx, 0);
+
+ check_name(opt, "native-option");
+ check_resolved_local_resource(opt->boot_image, ctx->device, "/vmlinuz");
+ check_args(opt, "console=hvc0");
+ check_resolved_local_resource(opt->initrd, ctx->device, "/initrd");
+}
diff --git a/test/parser/test-native-strings.c b/test/parser/test-native-strings.c
new file mode 100644
index 0000000..33d242a
--- /dev/null
+++ b/test/parser/test-native-strings.c
@@ -0,0 +1,35 @@
+#include "parser-test.h"
+
+#if 0 /* PARSER_EMBEDDED_CONFIG */
+
+name A longer name
+
+image /some/kernel
+initrd /some/other/initrd
+args console=tty0 console=hvc0 debug
+dtb /a/dtb
+description Contains a number of words
+
+#endif
+
+void run_test(struct parser_test *test)
+{
+ struct discover_boot_option *opt;
+ struct discover_context *ctx;
+
+ test_read_conf_embedded(test, "/boot/petitboot.conf");
+
+ test_run_parser(test, "native");
+
+ ctx = test->ctx;
+
+ check_boot_option_count(ctx, 1);
+
+ opt = get_boot_option(ctx, 0);
+
+ check_name(opt, "A longer name");
+ check_resolved_local_resource(opt->boot_image, ctx->device, "/some/kernel");
+ check_args(opt, "console=tty0 console=hvc0 debug ");
+ check_resolved_local_resource(opt->initrd, ctx->device, "/some/other/initrd");
+ check_resolved_local_resource(opt->dtb, ctx->device, "/a/dtb");
+}
OpenPOWER on IntegriCloud