From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 5/5] test: self: add bootloader spec files test
Date: Mon, 9 Feb 2026 10:08:55 +0100 [thread overview]
Message-ID: <20260209090911.3561875-6-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260209090911.3561875-1-a.fatoum@barebox.org>
With spec-conformant sorting added for bootloader specification entries,
add a simple self test that verifies that the sort order is as one would
expect.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
include/bselftest.h | 20 ++++++++
test/self/Kconfig | 5 ++
test/self/Makefile | 2 +
test/self/blspec.c | 46 +++++++++++++++++++
.../data/test/boot/boot.sh | 3 ++
.../data/test/loader/entries/boarda.conf | 6 +++
.../data/test/loader/entries/boardb.conf | 6 +++
.../data/test/loader/entries/boardc.conf | 6 +++
.../data/test/loader/entries/boardd.conf | 5 ++
9 files changed, 99 insertions(+)
create mode 100644 test/self/blspec.c
create mode 100755 test/self/defaultenv-blspec-test/data/test/boot/boot.sh
create mode 100644 test/self/defaultenv-blspec-test/data/test/loader/entries/boarda.conf
create mode 100644 test/self/defaultenv-blspec-test/data/test/loader/entries/boardb.conf
create mode 100644 test/self/defaultenv-blspec-test/data/test/loader/entries/boardc.conf
create mode 100644 test/self/defaultenv-blspec-test/data/test/loader/entries/boardd.conf
diff --git a/include/bselftest.h b/include/bselftest.h
index c3f323864358..fc698d7c5c0c 100644
--- a/include/bselftest.h
+++ b/include/bselftest.h
@@ -78,4 +78,24 @@ static inline void selftests_run(void)
int selftest_run(struct selftest *test);
bool selftest_is_running(struct selftest *test);
+#define __assert_cond(cond) ({ total_tests++; cond || (failed_tests++, false); })
+
+#define assert_cond(cond) ({ \
+ bool __cond = __assert_cond(cond); \
+ if (!__cond) \
+ pr_warn("%s:%d: condition %s unexpectedly false\n", \
+ __func__, __LINE__, #cond); \
+ __cond; \
+})
+
+#define assert_inteq(a, b) assert_cond(a == b)
+
+#define assert_streq(a, b) ({ \
+ bool __cond = __assert_cond(strcmp(a, b) == 0); \
+ if (!__cond) \
+ pr_warn("%s:%d: %s and %s unexpectedly unequal\n", \
+ __func__, __LINE__, a, b); \
+ __cond; \
+})
+
#endif
diff --git a/test/self/Kconfig b/test/self/Kconfig
index 2ccdfe621821..85a3ef790116 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -51,6 +51,7 @@ config SELFTEST_ENABLE_ALL
select SELFTEST_TLV
select SELFTEST_DM
select SELFTEST_TALLOC
+ select SELFTEST_BLSPEC if BLSPEC && DEFAULT_ENVIRONMENT
help
Selects all self-tests compatible with current configuration
@@ -127,6 +128,10 @@ config SELFTEST_SETJMP
bool "setjmp/longjmp library selftest"
depends on ARCH_HAS_SJLJ
+config SELFTEST_BLSPEC
+ bool "bootloader spec selftest"
+ depends on BLSPEC && DEFAULT_ENVIRONMENT
+
config SELFTEST_REGULATOR
bool "Regulator selftest"
depends on REGULATOR_FIXED
diff --git a/test/self/Makefile b/test/self/Makefile
index 9f839fc0d07a..2bfdbb9949df 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -25,6 +25,8 @@ obj-$(CONFIG_SELFTEST_TEST_COMMAND) += test_command.o
obj-$(CONFIG_SELFTEST_IDR) += idr.o
obj-$(CONFIG_SELFTEST_TLV) += tlv.o tlv.dtb.o
obj-$(CONFIG_SELFTEST_DM) += dm.o
+obj-$(CONFIG_SELFTEST_BLSPEC) += blspec.o
+bbenv-$(CONFIG_SELFTEST_BLSPEC) += defaultenv-blspec-test
ifdef REGENERATE_KEYTOC
diff --git a/test/self/blspec.c b/test/self/blspec.c
new file mode 100644
index 000000000000..0e9eca4d06e9
--- /dev/null
+++ b/test/self/blspec.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <common.h>
+#include <bselftest.h>
+#include <boot.h>
+#include <envfs.h>
+#include <init.h>
+
+BSELFTEST_GLOBALS();
+
+static void test_blspec(void)
+{
+ struct bootentries *entries;
+ struct bootentry *entry;
+ int ret, i = 0;
+ const char *expected[] = {
+ "/env/data/test/loader/entries/boardb.conf",
+ "/env/data/test/loader/entries/boardc.conf",
+ "/env/data/test/loader/entries/boarda.conf",
+ "/env/data/test/loader/entries/boardd.conf",
+ };
+
+ entries = bootentries_alloc();
+
+ ret = bootentry_create_from_name(entries, "/env/data/test");
+ if (!assert_inteq(ret, 4))
+ return;
+
+ if (!assert_cond(!list_empty(&entries->entries)))
+ return;
+
+ bootentries_for_each_entry(entries, entry) {
+ assert_streq(expected[i], entry->path);
+ i++;
+ }
+}
+bselftest(parser, test_blspec);
+
+static int test_blspec_env_init(void)
+{
+ defaultenv_append_directory(defaultenv_blspec_test);
+ return 0;
+}
+late_initcall(test_blspec_env_init);
diff --git a/test/self/defaultenv-blspec-test/data/test/boot/boot.sh b/test/self/defaultenv-blspec-test/data/test/boot/boot.sh
new file mode 100755
index 000000000000..19ba0024098b
--- /dev/null
+++ b/test/self/defaultenv-blspec-test/data/test/boot/boot.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo boot test
diff --git a/test/self/defaultenv-blspec-test/data/test/loader/entries/boarda.conf b/test/self/defaultenv-blspec-test/data/test/loader/entries/boarda.conf
new file mode 100644
index 000000000000..a0b8356476be
--- /dev/null
+++ b/test/self/defaultenv-blspec-test/data/test/loader/entries/boarda.conf
@@ -0,0 +1,6 @@
+title barebox - Test Image - v6.1-rc2 A
+version Dummy v6.1-rc2
+options rootwait
+linux /boot/boot.sh
+sort-key blspec-test
+linux-appendroot true
diff --git a/test/self/defaultenv-blspec-test/data/test/loader/entries/boardb.conf b/test/self/defaultenv-blspec-test/data/test/loader/entries/boardb.conf
new file mode 100644
index 000000000000..93d5ab5f0fac
--- /dev/null
+++ b/test/self/defaultenv-blspec-test/data/test/loader/entries/boardb.conf
@@ -0,0 +1,6 @@
+title barebox - Test Image - v6.19 B
+version Dummy v6.19
+options rootwait
+linux /boot/boot.sh
+sort-key blspec-test
+linux-appendroot true
diff --git a/test/self/defaultenv-blspec-test/data/test/loader/entries/boardc.conf b/test/self/defaultenv-blspec-test/data/test/loader/entries/boardc.conf
new file mode 100644
index 000000000000..8df597d4f251
--- /dev/null
+++ b/test/self/defaultenv-blspec-test/data/test/loader/entries/boardc.conf
@@ -0,0 +1,6 @@
+title barebox - Test Image - v6.9 C
+version Dummy v6.9
+options rootwait
+linux /boot/boot.sh
+sort-key blspec-test
+linux-appendroot true
diff --git a/test/self/defaultenv-blspec-test/data/test/loader/entries/boardd.conf b/test/self/defaultenv-blspec-test/data/test/loader/entries/boardd.conf
new file mode 100644
index 000000000000..b2581147c3d7
--- /dev/null
+++ b/test/self/defaultenv-blspec-test/data/test/loader/entries/boardd.conf
@@ -0,0 +1,5 @@
+title barebox - Test Image - v9999 (no sort-key) D
+version v9999
+options rootwait
+linux /boot/boot.sh
+linux-appendroot true
--
2.47.3
prev parent reply other threads:[~2026-02-09 9:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-09 9:08 [PATCH 0/5] blspec: sort entries according to specification Ahmad Fatoum
2026-02-09 9:08 ` [PATCH 1/5] boot: aggregate bootentry provider entries one by one Ahmad Fatoum
2026-02-09 9:08 ` [PATCH 2/5] blspec: sort entries according to specification Ahmad Fatoum
2026-02-09 9:08 ` [PATCH 3/5] boot: give struct bootentry a path member Ahmad Fatoum
2026-02-09 9:08 ` [PATCH 4/5] commands: boot: support file path in boot -M for default entry Ahmad Fatoum
2026-02-09 9:08 ` Ahmad Fatoum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260209090911.3561875-6-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox