From patchwork Thu Nov 1 03:46:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 991803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42lrjT5zNWz9sPj for ; Thu, 1 Nov 2018 14:46:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="wDndoxf8"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TIuuVadW"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42lrjT49RlzF3L3 for ; Thu, 1 Nov 2018 14:46:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="wDndoxf8"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TIuuVadW"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mendozajonas.com (client-ip=66.111.4.27; helo=out3-smtp.messagingengine.com; envelope-from=sam@mendozajonas.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="wDndoxf8"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TIuuVadW"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42lrjB1YSBzF3Jy for ; Thu, 1 Nov 2018 14:46:22 +1100 (AEDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 0802D224CF; Wed, 31 Oct 2018 23:46:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 31 Oct 2018 23:46:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= mendozajonas.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=fm1; bh=PVL6Xls0K8Eqj6GQ3my5/1X8+V1KyY64XQv0KQ6BdRQ=; b=wDndo xf8oRcy2sv+aHjErDPNgt5pvJvLDNlIIeaN6ILCFQNJSjtbLJ81Y10tIwemy8GLR wRA5fPP0+1k2B4av0jaFWLNpCDvcia+Rmwo+hug8B1oCdl1/GkVFmmBCkNvAPeC+ VfCBpfWq8xf+QmvAka/RN48P+T5EpoUg6aNrTMKqT6i6mWUevC6KqOgIG/0x4cBS Nn4bwxo5JbGCR8k2J3yxNbr7Oec0lc4Td5Z8FibNVE1bT1wm5pKC/zSJgntBdZwn ToJDOIy+FdoiRbX8d1xa5nJJtOUFIrxZpebMYRi4B6Dde2ljQNm1/+gl8su6DCbt U8aKbTU6iFEZf881w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=PVL6Xls0K8Eqj6GQ3my5/1X8+V1KyY64XQv0KQ6BdRQ=; b=TIuuVadW Yl/PEhFMiwuy5hfeeevPXCMx7nL9WkbwUSGmnSSuUpCT6hNKqpcv4AlzLZ45vfvr k1cnRfSgAWNykuBDOei43GIyA4IVOyxKQjXMUHCpl+5Y6GkhdovhUX+4hNffS1UG /X97v0LP6GqInTnEdhWNwGWJNrKR8LLUUlfF8UR2l6e76SiglI3KNbBwOGd8BHqI Ht9ekWoqzkGIPBFe0+F3OqydRA625V8r+15t/UhCjUgfIk6nm79vuHhLoq6ej33+ feVFuekNLs8G3zkbZASfpmWxXMZ6JVWFS3Dh1Fq+ZPPHGRxitSxIul67bm+x8yhl auz1rbBKAC+z9g== X-ME-Sender: X-ME-Proxy: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 1B896E467A; Wed, 31 Oct 2018 23:46:17 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 2/2] discover: Reimplement native-parser as a Bison parser Date: Thu, 1 Nov 2018 14:46:10 +1100 Message-Id: <20181101034610.10297-2-sam@mendozajonas.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181101034610.10297-1-sam@mendozajonas.com> References: <20181101034610.10297-1-sam@mendozajonas.com> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" 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 change 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 --- Makefile.am | 1 + discover/Makefile.am | 1 + discover/native-parser.c | 131 -------------------- discover/native/Makefile.am | 54 +++++++++ discover/native/native-lexer.l | 61 ++++++++++ discover/native/native-parser.y | 194 ++++++++++++++++++++++++++++++ discover/native/native.c | 55 +++++++++ discover/native/native.h | 27 +++++ test/parser/Makefile.am | 9 +- test/parser/test-native-globals.c | 45 +++++++ test/parser/test-native-simple.c | 31 +++++ 11 files changed, 476 insertions(+), 133 deletions(-) delete mode 100644 discover/native-parser.c create mode 100644 discover/native/Makefile.am create mode 100644 discover/native/native-lexer.l create mode 100644 discover/native/native-parser.y create mode 100644 discover/native/native.c create mode 100644 discover/native/native.h create mode 100644 test/parser/test-native-globals.c create mode 100644 test/parser/test-native-simple.c diff --git a/Makefile.am b/Makefile.am index c0ad8397..63456ca4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/discover/Makefile.am b/discover/Makefile.am index d98ebec6..bfe33fad 100644 --- a/discover/Makefile.am +++ b/discover/Makefile.am @@ -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 index 08309d1b..00000000 --- a/discover/native-parser.c +++ /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 -#include -#include - -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 index 00000000..f120e704 --- /dev/null +++ b/discover/native/Makefile.am @@ -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 index 00000000..50ad94cb --- /dev/null +++ b/discover/native/native-lexer.l @@ -0,0 +1,61 @@ +%{ +#include "native.h" +#include "native-parser.h" +#include + +#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" + +DELIM [ \t]+ +NUMBER 0|[1-9][0-9]* +WORD [^{}|&$;<> \t\n'"#]+ +NEWLINE [\n]+ + +%% + +name { return TOKEN_NAME; } +image { return TOKEN_IMAGE; } +initrd { return TOKEN_INITRD; } +args { return TOKEN_ARGS; } +dtb { return TOKEN_DTB; } +description { return TOKEN_DESCRIPTION; } +default { return TOKEN_DEFAULT; } +dev_description { return TOKEN_DEV_DESCRIPTION; } +{DELIM} { ; } +{NUMBER} { yylval->num = atoi(yytext); return TOKEN_NUMBER; } +{WORD} { yylval->word = strdup(yytext); return TOKEN_WORD; } +{NEWLINE} { return TOKEN_NEWLINE; } + +%% + +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 index 00000000..f0a547b8 --- /dev/null +++ b/discover/native/native-parser.y @@ -0,0 +1,194 @@ + +%pure-parser +%lex-param { nscan_t scanner } +%parse-param { struct native_parser *parser } +%parse-param { void *scanner } +%error-verbose + +%define api.prefix {n} +%{ +#include +#include +#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 TOKEN_WORD +%token TOKEN_NUMBER + +%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 TOKEN_WORD { + if (parser->default_name) + pb_log_fn("Duplicate default option, ignoring\n"); + else + parser->default_name = talloc_strdup(parser, $2); + } + | TOKEN_DEV_DESCRIPTION TOKEN_WORD { + native_append_string(parser, + &parser->ctx->device->device->description, $2); + } + | TOKEN_NEWLINE + ; + +boot_options: + boot_options option + | option + ; +option: + label params + ; +label: + TOKEN_NAME TOKEN_WORD {native_parser_create_option(parser, $2);} + ; +params: + params line + | line + ; +line: + TOKEN_IMAGE TOKEN_WORD { + native_set_resource(parser, &parser->opt->boot_image, $2); + } + | TOKEN_INITRD TOKEN_WORD { + native_set_resource(parser, &parser->opt->initrd, $2); + } + | TOKEN_DTB TOKEN_WORD { + native_set_resource(parser, &parser->opt->dtb, $2); + } + | TOKEN_ARGS TOKEN_WORD { + native_append_string(parser, &parser->opt->option->boot_args, $2); + } + | TOKEN_DESCRIPTION TOKEN_WORD { + native_append_string(parser, &parser->opt->option->description, $2); + } + | TOKEN_NEWLINE + ; +%% + +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, 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 index 00000000..964ad1d4 --- /dev/null +++ b/discover/native/native.c @@ -0,0 +1,55 @@ +#include +#include +#include + +#include +#include + +#include +#include +#include + +#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 index 00000000..1cf7d6aa --- /dev/null +++ b/discover/native/native.h @@ -0,0 +1,27 @@ +#ifndef NATIVE_H +#define NATIVE_H + +#include + +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 */ + diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 363933e3..6e0da38c 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -87,7 +87,9 @@ 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-simple \ + test/parser/test-native-globals TESTS += $(parser_TESTS) @@ -133,13 +135,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/test-native-globals.c b/test/parser/test-native-globals.c new file mode 100644 index 00000000..0361e03b --- /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-simple.c b/test/parser/test-native-simple.c new file mode 100644 index 00000000..f817228e --- /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"); +}