discover: Reimplement native-parser as a Bison parser
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 30 Oct 2018 04:26:04 +0000 (15:26 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Fri, 16 Nov 2018 02:55:13 +0000 (13:55 +1100)
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>
14 files changed:
Makefile.am
discover/Makefile.am
discover/native-parser.c [deleted file]
discover/native/Makefile.am [new file with mode: 0644]
discover/native/native-lexer.l [new file with mode: 0644]
discover/native/native-parser.y [new file with mode: 0644]
discover/native/native.c [new file with mode: 0644]
discover/native/native.h [new file with mode: 0644]
test/parser/Makefile.am
test/parser/data/native-short.conf [new file with mode: 0644]
test/parser/test-native-globals.c [new file with mode: 0644]
test/parser/test-native-short.c [new file with mode: 0644]
test/parser/test-native-simple.c [new file with mode: 0644]
test/parser/test-native-strings.c [new file with mode: 0644]

index c0ad8397371c783bc0e0a54d5099f2ba1e4c991b..63456ca4f453993fc535c1e97a781d206d1dfcae 100644 (file)
@@ -50,6 +50,7 @@ CLEANFILES =
 
 include lib/Makefile.am
 include discover/grub2/Makefile.am
+include discover/native/Makefile.am
 include discover/Makefile.am
 include test/Makefile.am
 include test/lib/Makefile.am
index d98ebec69129c9c9be42409d1ce7fe8a38685834..bfe33fad142db16e5a4592541601efff1b9522ca 100644 (file)
@@ -55,6 +55,7 @@ discover_pb_discover_SOURCES = \
 
 discover_pb_discover_LDADD = \
        discover/grub2/grub2-parser.ro \
+       discover/native/native-parser.ro \
        discover/platform.ro \
        $(core_lib) \
        $(UDEV_LIBS)
diff --git a/discover/native-parser.c b/discover/native-parser.c
deleted file mode 100644 (file)
index 08309d1..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; version 2 of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#include "parser.h"
-#include "params.h"
-#include "paths.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-static const char *conf_filename = "/boot/petitboot.conf";
-
-static struct boot_option *cur_opt;
-static struct device *dev;
-static const char *devpath;
-static int device_added;
-
-static int check_and_add_device(struct device *dev)
-{
-       if (!dev->icon_file)
-               dev->icon_file = strdup(generic_icon_file(guess_device_type()));
-
-       return !add_device(dev);
-}
-
-static int section(char *section_name)
-{
-       if (!device_added++ && !check_and_add_device(dev))
-               return 0;
-
-       if (cur_opt) {
-               add_boot_option(cur_opt);
-               free_boot_option(cur_opt);
-       }
-
-       cur_opt = malloc(sizeof(*cur_opt));
-       memset(cur_opt, 0, sizeof(*cur_opt));
-       return 1;
-}
-
-
-static void set_boot_option_parameter(struct boot_option *opt,
-               const char *name, const char *value)
-{
-       if (streq(name, "name"))
-               opt->name = strdup(value);
-
-       else if (streq(name, "description"))
-               opt->description = strdup(value);
-
-       else if (streq(name, "image"))
-               opt->boot_image_file = resolve_path(value, devpath);
-
-       else if (streq(name, "icon"))
-               opt->icon_file = resolve_path(value, devpath);
-
-       else if (streq(name, "initrd"))
-               opt->initrd_file =resolve_path(value, devpath);
-
-       else if (streq(name, "args"))
-               opt->boot_args = strdup(value);
-
-       else
-               fprintf(stderr, "Unknown parameter %s\n", name);
-}
-
-static void set_device_parameter(struct device *dev,
-               const char *name, const char *value)
-{
-       if (streq(name, "name"))
-               dev->name = strdup(value);
-
-       else if (streq(name, "description"))
-               dev->description = strdup(value);
-
-       else if (streq(name, "icon"))
-               dev->icon_file = resolve_path(value, devpath);
-}
-
-static int parameter(char *param_name, char *param_value)
-{
-       if (cur_opt)
-               set_boot_option_parameter(cur_opt, param_name, param_value);
-       else
-               set_device_parameter(dev, param_name, param_value);
-       return 1;
-}
-
-
-static int native_parse(const char *device)
-{
-       char *filepath;
-       int rc;
-
-       filepath = resolve_path(conf_filename, device);
-
-       cur_opt = NULL;
-       dev = malloc(sizeof(*dev));
-       memset(dev, 0, sizeof(*dev));
-       dev->id = strdup(device);
-
-       rc = pm_process(filepath, section, parameter);
-       if (!rc)
-               return 0;
-
-       if (cur_opt) {
-               add_boot_option(cur_opt);
-               free_boot_option(cur_opt);
-       }
-
-       cur_opt = NULL;
-
-       free(filepath);
-
-       return 1;
-}
-
-define_parser(native, native_parse);
diff --git a/discover/native/Makefile.am b/discover/native/Makefile.am
new file mode 100644 (file)
index 0000000..f120e70
--- /dev/null
@@ -0,0 +1,54 @@
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; version 2 of the License.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+noinst_PROGRAMS += discover/native/native-parser.ro
+
+discover_native_native_parser_ro_SOURCES = \
+       discover/native/native.h \
+       discover/native/native.c \
+       discover/native/native-lexer.l \
+       discover/native/native-parser.y
+
+BUILT_SOURCES += \
+       discover/native/native-parser.c \
+       discover/native/native-parser.h \
+       discover/native/native-lexer.h \
+       discover/native/native-lexer.c
+
+CLEANFILES += \
+       discover/native/native-parser.c \
+       discover/native/native-parser.h \
+       discover/native/native-lexer.c \
+       discover/native/native-lexer.h
+
+discover_native_native_parser_ro_CPPFLAGS = \
+       $(AM_CPPFLAGS) \
+       -I$(top_srcdir)/discover/native \
+       -I$(top_builddir)/discover/native
+
+discover_native_native_parser_ro_LINK = \
+       $(LD) -r -o $@
+
+# ylwrap doesn't handle flex header files well; use our own rule here.
+discover/native/native-lexer.h discover/native/native-lexer.c: \
+               $(top_srcdir)/discover/native/native-lexer.l
+       $(AM_V_LEX)$(LEXCOMPILE) --header-file=discover/native/native-lexer.h \
+                                      -o discover/native/native-lexer.c $^
+
+# We need to loosen our warnings for the generated lexer code.
+discover/native/%native-lexer.o discover/native/native-lexer.o: \
+               AM_CFLAGS += -Wno-unused-parameter -Wno-missing-prototypes \
+                              -Wno-missing-declarations -Wno-sign-compare
+
+$(discover_native_native_parser_ro_OBJECTS): discover/native/native-parser.h
diff --git a/discover/native/native-lexer.l b/discover/native/native-lexer.l
new file mode 100644 (file)
index 0000000..bf1408a
--- /dev/null
@@ -0,0 +1,65 @@
+%{
+#include "native.h"
+#include "native-parser.h"
+#include <talloc/talloc.h>
+
+#define YYSTYPE NSTYPE
+
+void yyerror(struct native_parser *parser, const char *fmt, ...);
+%}
+
+%option nounput noinput
+%option batch never-interactive
+%option warn
+%option noyywrap
+%option reentrant
+%option bison-bridge
+%option yylineno
+%option noyyalloc noyyfree noyyrealloc
+%option extra-type="struct native_parser *"
+%option prefix="n"
+
+%x label
+%x args
+
+DELIM  [ \t]+
+NUMBER 0|[1-9][0-9]*
+WORDS  [^\n]+
+NEWLINE [\n]+
+
+%%
+
+name           { BEGIN(label); return TOKEN_NAME; }
+image          { BEGIN(label); return TOKEN_IMAGE; }
+initrd         { BEGIN(label); return TOKEN_INITRD; }
+args           { BEGIN(label); return TOKEN_ARGS; }
+dtb            { BEGIN(label); return TOKEN_DTB; }
+description    { BEGIN(label); return TOKEN_DESCRIPTION; }
+default                { BEGIN(label); return TOKEN_DEFAULT; }
+dev_description { BEGIN(label); return TOKEN_DEV_DESCRIPTION; }
+{DELIM}                { ; }
+{NEWLINE}      { ; }
+<label>{DELIM} { BEGIN(args); return TOKEN_DELIM; }
+<args>{WORDS}  { yylval->word = strdup(yytext); return TOKEN_WORD; }
+<args>{NEWLINE}        { BEGIN(INITIAL); ; }
+
+%%
+
+struct native_parser;
+
+void *yyalloc(size_t bytes, void *yyscanner)
+{
+       struct native_parser *parser = yyget_extra(yyscanner);
+       return talloc_size(parser, bytes);
+}
+
+void *yyrealloc(void *ptr, size_t bytes, void *yyscanner)
+{
+       struct native_parser *parser = yyget_extra(yyscanner);
+       return talloc_realloc_size(parser, ptr, bytes);
+}
+
+void yyfree(void *ptr, void *yyscanner __attribute__((unused)))
+{
+       talloc_free(ptr);
+}
diff --git a/discover/native/native-parser.y b/discover/native/native-parser.y
new file mode 100644 (file)
index 0000000..bafcf49
--- /dev/null
@@ -0,0 +1,200 @@
+
+%pure-parser
+%lex-param { nscan_t scanner }
+%parse-param { struct native_parser *parser }
+%parse-param { void *scanner }
+%error-verbose
+
+%define api.prefix {n}
+%{
+#include <talloc/talloc.h>
+#include <log/log.h>
+#include "discover/resource.h"
+#include "discover/parser-utils.h"
+
+#include "native.h"
+
+void yyerror(struct native_parser *parser, void *scanner, const char *fmt, ...);
+%}
+
+%union {
+       char    *word;
+       int     num;
+}
+
+%token <word>  TOKEN_WORD
+%token <num>   TOKEN_NUMBER
+%token <num>   TOKEN_DELIM
+
+%token TOKEN_DEFAULT
+%token TOKEN_DEV_DESCRIPTION
+
+%token TOKEN_NAME
+%token TOKEN_IMAGE
+%token TOKEN_INITRD
+%token TOKEN_ARGS
+%token TOKEN_DTB
+%token TOKEN_DESCRIPTION
+%token TOKEN_NEWLINE
+
+%{
+#include "native-lexer.h"
+%}
+
+%%
+
+native:
+      globals boot_options { native_parser_finish(parser); }
+      | boot_options { native_parser_finish(parser); }
+      ;
+
+globals: globals global
+       | global
+       ;
+
+global: TOKEN_DEFAULT delims TOKEN_WORD {
+               if (parser->default_name)
+                       pb_log_fn("Duplicate default option, ignoring\n");
+               else
+                       parser->default_name = talloc_strdup(parser, $3);
+       }
+       | TOKEN_DEV_DESCRIPTION delims TOKEN_WORD {
+               native_append_string(parser,
+                       &parser->ctx->device->device->description, $3);
+       }
+       ;
+
+boot_options:
+           boot_options option
+           | option
+           ;
+
+option: name params
+     ;
+
+name: TOKEN_NAME delims TOKEN_WORD {
+               native_parser_create_option(parser, $3);
+       }
+       ;
+
+params: params param
+      | param
+      ;
+
+param: TOKEN_IMAGE delims TOKEN_WORD {
+               native_set_resource(parser, &parser->opt->boot_image, $3);
+       }
+       | TOKEN_INITRD delims TOKEN_WORD {
+               native_set_resource(parser, &parser->opt->initrd, $3);
+       }
+       | TOKEN_DTB delims TOKEN_WORD  {
+               native_set_resource(parser, &parser->opt->dtb, $3);
+       }
+       | TOKEN_ARGS delims TOKEN_WORD {
+               native_append_string(parser, &parser->opt->option->boot_args, $3);
+       }
+       | TOKEN_DESCRIPTION delims TOKEN_WORD  {
+               native_append_string(parser, &parser->opt->option->description, $3);
+       }
+       ;
+
+delims: delims TOKEN_DELIM
+      | TOKEN_DELIM
+      ;
+
+%%
+
+void yyerror(struct native_parser *parser, void *scanner, const char *fmt, ...)
+{
+       const char *str;
+       va_list ap;
+
+       va_start(ap, fmt);
+       str = talloc_vasprintf(parser, fmt, ap);
+       va_end(ap);
+
+       pb_log("parse error: %d('%s'): %s\n", nget_lineno(scanner),
+                                       nget_text(scanner), str);
+}
+
+void native_parser_finish(struct native_parser *parser)
+{
+       if (parser->opt) {
+               discover_context_add_boot_option(parser->ctx, parser->opt);
+               parser->opt = NULL;
+       }
+}
+
+void native_set_resource(struct native_parser *parser,
+               struct resource ** resource, const char *path)
+{
+       if (*resource) {
+               pb_log_fn("Duplicate resource at line %d: %s\n",
+                       nget_lineno(parser->scanner), path);
+               return;
+       }
+
+       *resource = create_devpath_resource(parser->opt, parser->opt->device,
+                                       path);
+}
+
+void native_append_string(struct native_parser *parser,
+               char **str, const char *append)
+{
+       if (*str)
+               *str = talloc_asprintf_append(*str, "%s", append);
+       else
+               *str = talloc_strdup(parser->opt, append);
+}
+
+void native_parser_create_option(struct native_parser *parser, const char *name)
+{
+       struct discover_boot_option *opt = parser->opt;
+
+       if (opt)
+               native_parser_finish(parser);
+
+       opt = discover_boot_option_create(parser->ctx, parser->ctx->device);
+       opt->option->name = talloc_strdup(opt, name);
+       opt->option->id = talloc_asprintf(opt, "%s@%p",
+                       parser->ctx->device->device->id, opt);
+       opt->option->type = DISCOVER_BOOT_OPTION;
+       opt->option->is_default = parser->default_name &&
+                               streq(parser->default_name, name);
+       parser->opt = opt;
+       return;
+}
+
+struct native_parser *native_parser_create(struct discover_context *ctx)
+{
+       struct native_parser *parser;
+
+       parser = talloc_zero(ctx, struct native_parser);
+       parser->ctx = ctx;
+       nlex_init_extra(parser, &parser->scanner);
+
+       return parser;
+}
+
+void native_parser_parse(struct native_parser *parser, const char *filename,
+       char *buf, int len)
+{
+       YY_BUFFER_STATE bufstate;
+       int rc;
+
+       if (!len)
+               return;
+
+       parser->filename = filename;
+
+       bufstate = n_scan_bytes(buf, len - 1, parser->scanner);
+       nset_lineno(1, parser->scanner);
+
+       rc = nparse(parser, parser->scanner);
+
+       if (rc)
+               pb_log("Failed to parse %s\n", filename);
+
+       n_delete_buffer(bufstate, parser->scanner);
+}
+
diff --git a/discover/native/native.c b/discover/native/native.c
new file mode 100644 (file)
index 0000000..964ad1d
--- /dev/null
@@ -0,0 +1,55 @@
+#include <assert.h>
+#include <string.h>
+#include <i18n/i18n.h>
+
+#include <talloc/talloc.h>
+#include <url/url.h>
+
+#include <discover/resource.h>
+#include <discover/parser.h>
+#include <discover/parser-utils.h>
+
+#include "native.h"
+
+static const char *const native_conf_files[] = {
+       "/boot/petitboot.conf",
+       "/petitboot.conf",
+       NULL
+};
+
+static int native_parse(struct discover_context *dc)
+{
+       const char * const *filename;
+       struct native_parser *parser;
+       int len, rc;
+       char *buf;
+
+       /* Support block device boot only at present */
+       if (dc->event)
+               return -1;
+
+       for (filename = native_conf_files; *filename; filename++) {
+               rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
+               if (rc)
+                       continue;
+
+               parser = native_parser_create(dc);
+               native_parser_parse(parser, *filename, buf, len);
+               device_handler_status_dev_info(dc->handler, dc->device,
+                               _("Parsed native configuration from %s"),
+                               *filename);
+               talloc_free(buf);
+               talloc_free(parser);
+               break;
+       }
+
+       return 0;
+}
+
+static struct parser native_parser = {
+       .name                   = "native",
+       .parse                  = native_parse,
+       .resolve_resource       = resolve_devpath_resource,
+};
+
+register_parser(native_parser);
diff --git a/discover/native/native.h b/discover/native/native.h
new file mode 100644 (file)
index 0000000..1cf7d6a
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef NATIVE_H
+#define NATIVE_H
+
+#include <discover/device-handler.h>
+
+struct native_parser {
+       struct discover_context         *ctx;
+       struct discover_boot_option     *opt;
+       void                            *scanner;
+       const char                      *filename;
+       char                            *default_name;
+};
+
+void native_parser_finish(struct native_parser *parser);
+void native_set_resource(struct native_parser *parser, struct resource **,
+               const char *path);
+void native_append_string(struct native_parser *parser,
+               char **str, const char *append);
+void native_parser_create_option(struct native_parser *parser,
+               const char *name);
+
+/* external parser api */
+struct native_parser *native_parser_create(struct discover_context *ctx);
+void native_parser_parse(struct native_parser *parser, const char *filename,
+               char *buf, int len);
+#endif /* NATIVE_H */
+
index 363933e324efabba0168e9c93d923ab88706f555..483add90d2c9ae6702e36de1dea1e46e4a47acc7 100644 (file)
@@ -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 (file)
index 0000000..a814e9d
--- /dev/null
@@ -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 (file)
index 0000000..0361e03
--- /dev/null
@@ -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 (file)
index 0000000..178d080
--- /dev/null
@@ -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 (file)
index 0000000..f817228
--- /dev/null
@@ -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 (file)
index 0000000..33d242a
--- /dev/null
@@ -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");
+}