functional_test_mod_CFLAGS = $(COMMON_CFLAGS)
functional_test_mod_LDFLAGS = $(COMMON_LDFLAGS)
+pkglib_MODULES += test_blockarg.mod
+test_blockarg_mod_SOURCES = tests/test_blockarg.c
+test_blockarg_mod_CFLAGS = $(COMMON_CFLAGS)
+test_blockarg_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
# Rules for unit tests
check_UTILITIES += example_unit_test
example_unit_test_SOURCES = tests/example_unit_test.c kern/list.c kern/misc.c tests/lib/test.c tests/lib/unit_test.c
check_SCRIPTS += grub_script_functions
grub_script_functions_SOURCES = tests/grub_script_functions.in
+check_SCRIPTS += grub_script_blockarg
+grub_script_blockarg_SOURCES = tests/grub_script_blockarg.in
+
# List of tests to execute on "make check"
# SCRIPTED_TESTS = example_scripted_test
# SCRIPTED_TESTS += example_grub_script_test
SCRIPTED_TESTS += grub_script_dollar
SCRIPTED_TESTS += grub_script_comments
SCRIPTED_TESTS += grub_script_functions
+SCRIPTED_TESTS += grub_script_blockarg
# dependencies between tests and testing-tools
$(SCRIPTED_TESTS): grub-shell grub-shell-tester
struct grub_script_mem *mem;
struct grub_script_cmd *cmd;
- /* Other grub_script's from block arguments. */
- struct grub_script *siblings;
+ /* grub_scripts from block arguments. */
+ struct grub_script *next_siblings;
struct grub_script *children;
};
\f
grub_normal_parse_line (char *line, grub_reader_getline_t getline);
static inline struct grub_script *
-grub_script_get (struct grub_script *script)
+grub_script_ref (struct grub_script *script)
{
if (script)
script->refcnt++;
}
static inline void
-grub_script_put (struct grub_script *script)
+grub_script_unref (struct grub_script *script)
{
if (! script)
return;
grub_script_argv_append (&result, arg->str) ||
grub_script_argv_append (&result, "}"))
goto fail;
- result.script = grub_script_get (arg->script);
+ result.script = arg->script;
break;
case GRUB_SCRIPT_ARG_TYPE_TEXT:
grub_script_execute (parsed_script);
/* The parsed script was executed, throw it away. */
- grub_script_put (parsed_script);
+ grub_script_unref (parsed_script);
}
return grub_errno;
/* restore old scripts; append $$->script to siblings. */
state->scripts = $<scripts>2 ?: $$->script;
if (s) {
- while (s->siblings)
- s = s->siblings;
- s->siblings = $$->script;
+ while (s->next_siblings)
+ s = s->next_siblings;
+ s->next_siblings = $$->script;
}
}
if ($3)
x = grub_script_add_arglist (state, $2, $3);
- if ($1 && x) {
- $1->next = x;
- $1->argcount += x->argcount;
- x->argcount = 0;
- }
+ if ($1 && x)
+ {
+ $1->next = x;
+ $1->argcount += x->argcount;
+ x->argcount = 0;
+ }
$$ = grub_script_create_cmdline (state, $1);
}
;
s = script->children;
while (s) {
- t = s->siblings;
- grub_script_put (s);
+ t = s->next_siblings;
+ grub_script_unref (s);
s = t;
}
grub_free (script);
parsed->mem = mem;
parsed->cmd = cmd;
parsed->refcnt = 0;
- parsed->siblings = 0;
parsed->children = 0;
+ parsed->next_siblings = 0;
return parsed;
}
--- /dev/null
+#! /bin/bash
+
+# Run GRUB script in a Qemu instance
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GRUB 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, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
+
+error_if_not () {
+ if test "$1" != "$2"; then
+ echo "[$1]" != "[$2]"
+ exit 1
+ fi
+}
+
+cmd='test_blockarg { true }'
+v=`echo "$cmd" | @builddir@/grub-shell`
+error_if_not "$v" '{ true }'
+
+tmp=`mktemp`
+cmd='test_blockarg { test_blockarg { true } }'
+echo "$cmd" | @builddir@/grub-shell >$tmp
+error_if_not "`head -n1 $tmp|tail -n1`" '{ test_blockarg { true } }'
+error_if_not "`head -n2 $tmp|tail -n1`" '{ true }'
+
+cmd='test_blockarg { test_blockarg { test_blockarg { true } }; test_blockarg { true } }'
+echo "$cmd" | @builddir@/grub-shell >$tmp
+error_if_not "`head -n1 $tmp|tail -n1`" '{ test_blockarg { test_blockarg { true } }; test_blockarg { true } }'
+error_if_not "`head -n2 $tmp|tail -n1`" '{ test_blockarg { true } }'
+error_if_not "`head -n3 $tmp|tail -n1`" '{ true }'
+error_if_not "`head -n4 $tmp|tail -n1`" '{ true }'
--- /dev/null
+/* test_blockarg.c - print and execute block argument */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2010 Free Software Foundation, Inc.
+ *
+ * GRUB 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/err.h>
+#include <grub/misc.h>
+#include <grub/i18n.h>
+#include <grub/extcmd.h>
+#include <grub/script_sh.h>
+
+static grub_err_t
+test_blockarg (grub_extcmd_context_t ctxt, int argc, char **args)
+{
+ if (! ctxt->script)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "no block parameter");
+
+ grub_printf ("%s\n", args[argc - 1]);
+ grub_script_execute (ctxt->script);
+ return GRUB_ERR_NONE;
+}
+
+static grub_extcmd_t cmd;
+
+GRUB_MOD_INIT(test_blockarg)
+{
+ cmd = grub_register_extcmd ("test_blockarg", test_blockarg,
+ GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_BLOCKS,
+ N_("BLOCK"),
+ N_("Print and execute block argument."), 0);
+}
+
+GRUB_MOD_FINI(test_blockarg)
+{
+ grub_unregister_extcmd (cmd);
+}