* [PATCH 3/3] Add tests for cmdline module
@ 2020-06-12 15:14 Vladimir 'phcoder' Serbinenko
2020-06-12 20:10 ` Konrad Rzeszutek Wilk
0 siblings, 1 reply; 2+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2020-06-12 15:14 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 42 bytes --]
--
Regards
Vladimir 'phcoder' Serbinenko
[-- Attachment #2: 0003-Add-tests-for-cmdline-module.patch --]
[-- Type: application/octet-stream, Size: 4037 bytes --]
From 69e11c5a68e75c9f48953e320cddbdf3e7f9eb46 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Fri, 12 Jun 2020 17:09:44 +0200
Subject: [PATCH 3/3] Add tests for cmdline module
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
grub-core/Makefile.core.def | 12 +++++
grub-core/tests/loader_cmdline_test.c | 69 +++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
create mode 100644 grub-core/tests/loader_cmdline_test.c
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 166b444c7..5038e03be 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1823,6 +1823,13 @@ module = {
enable = noemu;
};
+/* Special case for emu so we always have cmdline available for the tests. */
+module = {
+ name = cmdline_lib;
+ common = lib/cmdline.c;
+ enable = emu;
+};
+
module = {
name = fdt;
efi = loader/efi/fdt.c;
@@ -2119,6 +2126,11 @@ module = {
common = tests/strtoull_test.c;
};
+module = {
+ name = loader_cmdline_test;
+ common = tests/loader_cmdline_test.c;
+};
+
module = {
name = setjmp_test;
common = tests/setjmp_test.c;
diff --git a/grub-core/tests/loader_cmdline_test.c b/grub-core/tests/loader_cmdline_test.c
new file mode 100644
index 000000000..c3f6bcebe
--- /dev/null
+++ b/grub-core/tests/loader_cmdline_test.c
@@ -0,0 +1,69 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 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/misc.h>
+#include <grub/dl.h>
+#include <grub/command.h>
+#include <grub/env.h>
+#include <grub/test.h>
+#include <grub/mm.h>
+#include <grub/lib/cmdline.h>
+#include <grub/misc.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+struct cmdline_test {
+ int argc;
+ const char *const *argv;
+ const char *result;
+};
+
+static struct cmdline_test tests[] = {
+ {0, (const char *const[]) {"dummy"}, ""},
+ {1, (const char *const[]) {"bzimage"}, "bzimage"},
+ {2, (const char *const[]) {"bzimage", "root=/dev/sda1"}, "bzimage root=/dev/sda1"},
+ {3, (const char *const[]) {"bzimage", "root=/dev/sda1", "acpi_osi=Windows 2006"}, "bzimage root=/dev/sda1 acpi_osi=\"Windows 2006\""},
+ {3, (const char *const[]) {"bzimage", "root=/dev/sda1", "Hello World"}, "bzimage root=/dev/sda1 \"Hello World\""},
+ {3, (const char *const[]) {"bzimage", "root=/dev/sda1", "Hello World=Hi"}, "bzimage root=/dev/sda1 \"Hello World=Hi\""},
+};
+
+static void
+loader_cmdline_test (void)
+{
+ unsigned i;
+ for (i = 0; i < ARRAY_SIZE(tests); i++)
+ {
+ static char resbuf[512];
+ grub_err_t err;
+ int sz = grub_loader_cmdline_size (tests[i].argc, tests[i].argv);
+ grub_test_assert(sz == (int) grub_strlen(tests[i].result) + 1,
+ "Wrong computed size for %s: should be %d, got %d",
+ tests[i].result,
+ (int) grub_strlen(tests[i].result) + 1, sz);
+ err = grub_create_loader_cmdline (tests[i].argc, tests[i].argv, resbuf,
+ sz, GRUB_VERIFY_KERNEL_CMDLINE);
+ grub_test_assert(err == 0,
+ "grub_create_loader_cmdline returned error: %d: %s",
+ err, grub_errmsg);
+ grub_test_assert(grub_strcmp(resbuf, tests[i].result) == 0,
+ "grub_create_loader_cmdline made wrong string: expected %s, got %s",
+ tests[i].result, resbuf);
+ }
+}
+
+GRUB_FUNCTIONAL_TEST (loader_cmdline_test, loader_cmdline_test);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/3] Add tests for cmdline module
2020-06-12 15:14 [PATCH 3/3] Add tests for cmdline module Vladimir 'phcoder' Serbinenko
@ 2020-06-12 20:10 ` Konrad Rzeszutek Wilk
0 siblings, 0 replies; 2+ messages in thread
From: Konrad Rzeszutek Wilk @ 2020-06-12 20:10 UTC (permalink / raw)
To: The development of GNU GRUB
On Fri, Jun 12, 2020 at 05:14:23PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> --
> Regards
> Vladimir 'phcoder' Serbinenko
From 69e11c5a68e75c9f48953e320cddbdf3e7f9eb46 Mon Sep 17 00:00:00 2001
>From: Vladimir Serbinenko <phcoder@gmail.com>
>Date: Fri, 12 Jun 2020 17:09:44 +0200
>Subject: [PATCH 3/3] Add tests for cmdline module
>
>Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
>---
> grub-core/Makefile.core.def | 12 +++++
> grub-core/tests/loader_cmdline_test.c | 69 +++++++++++++++++++++++++++
> 2 files changed, 81 insertions(+)
> create mode 100644 grub-core/tests/loader_cmdline_test.c
>
>diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
>index 166b444c7..5038e03be 100644
>--- a/grub-core/Makefile.core.def
>+++ b/grub-core/Makefile.core.def
>@@ -1823,6 +1823,13 @@ module = {
> enable = noemu;
> };
>
>+/* Special case for emu so we always have cmdline available for the tests. */
>+module = {
>+ name = cmdline_lib;
>+ common = lib/cmdline.c;
>+ enable = emu;
>+};
>+
> module = {
> name = fdt;
> efi = loader/efi/fdt.c;
>@@ -2119,6 +2126,11 @@ module = {
> common = tests/strtoull_test.c;
> };
>
>+module = {
>+ name = loader_cmdline_test;
>+ common = tests/loader_cmdline_test.c;
>+};
>+
> module = {
> name = setjmp_test;
> common = tests/setjmp_test.c;
>diff --git a/grub-core/tests/loader_cmdline_test.c b/grub-core/tests/loader_cmdline_test.c
>new file mode 100644
>index 000000000..c3f6bcebe
>--- /dev/null
>+++ b/grub-core/tests/loader_cmdline_test.c
>@@ -0,0 +1,69 @@
>+/*
>+ * GRUB -- GRand Unified Bootloader
>+ * Copyright (C) 2013 Free Software Foundation, Inc.
2013?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-12 20:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-12 15:14 [PATCH 3/3] Add tests for cmdline module Vladimir 'phcoder' Serbinenko
2020-06-12 20:10 ` Konrad Rzeszutek Wilk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.