]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add a "test" that prints the SBAT table
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 12 May 2022 17:06:29 +0000 (19:06 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 17 May 2022 14:45:15 +0000 (16:45 +0200)
The SBAT section was included in a special section in the EFI code, but
the contents weren't directly visible in any way. Let's add a "test" that
prints them for visual inspection.

If there's some external linter for this format, we could hook it up in the
future.

src/boot/efi/meson.build
src/boot/efi/secure-boot.c
src/fundamental/sbat.h [new file with mode: 0644]
src/test/meson.build
src/test/test-sbat.c [new file with mode: 0644]

index d7dae94ef2da324b8714b2858d05d92c4ae79ce0..e0edbf18a226e7a90d02487b47d62ab449b55638 100644 (file)
@@ -3,6 +3,8 @@
 conf.set10('ENABLE_EFI', get_option('efi'))
 conf.set10('HAVE_GNU_EFI', false)
 
+efi_config_h_dir = meson.current_build_dir()
+
 if not get_option('efi') or get_option('gnu-efi') == 'false'
         if get_option('gnu-efi') == 'true'
                 error('gnu-efi support requested, but general efi support is disabled')
index ab2d256031af78712b87bfdde84a2441e8b16811..23505d5ae80fedda3abef79b36fa3213583c0d16 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "sbat.h"
 #include "secure-boot.h"
 #include "util.h"
 
@@ -30,8 +31,5 @@ SecureBootMode secure_boot_mode(void) {
 }
 
 #ifdef SBAT_DISTRO
-static const char sbat[] _used_ _section_(".sbat") =
-        "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md\n"
-        SBAT_PROJECT ",1,The systemd Developers," SBAT_PROJECT "," PROJECT_VERSION "," PROJECT_URL "\n"
-        SBAT_PROJECT "." SBAT_DISTRO "," STRINGIFY(SBAT_DISTRO_GENERATION) "," SBAT_DISTRO_SUMMARY "," SBAT_DISTRO_PKGNAME "," SBAT_DISTRO_VERSION "," SBAT_DISTRO_URL "\n";
+static const char sbat[] _used_ _section_(".sbat") = SBAT_SECTION_TEXT;
 #endif
diff --git a/src/fundamental/sbat.h b/src/fundamental/sbat.h
new file mode 100644 (file)
index 0000000..b3c09dc
--- /dev/null
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#ifdef SBAT_DISTRO
+#  define SBAT_SECTION_TEXT \
+        "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md\n" \
+        SBAT_PROJECT ",1,The systemd Developers," SBAT_PROJECT "," PROJECT_VERSION "," PROJECT_URL "\n" \
+        SBAT_PROJECT "." SBAT_DISTRO "," STRINGIFY(SBAT_DISTRO_GENERATION) "," SBAT_DISTRO_SUMMARY "," SBAT_DISTRO_PKGNAME "," SBAT_DISTRO_VERSION "," SBAT_DISTRO_URL "\n"
+#endif
index eb24988bea23cff462c3371ccb26b93c1456f4ee..74da544a46eb7ce993b6565b84f5f534e19c488b 100644 (file)
@@ -478,6 +478,10 @@ tests += [
 
         [files('test-date.c')],
 
+        [files('test-sbat.c'),
+         [], [], [], 'HAVE_GNU_EFI', '',
+         ['-I@0@'.format(efi_config_h_dir)]],
+
         [files('test-sleep.c')],
 
         [files('test-tpm2.c')],
diff --git a/src/test/test-sbat.c b/src/test/test-sbat.c
new file mode 100644 (file)
index 0000000..1a90541
--- /dev/null
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+/* We include efi_config.h after undefining PROJECT_VERSION which is also defined in config.h. */
+#undef PROJECT_VERSION
+#include "efi_config.h"
+
+#include "build.h"
+#include "sbat.h"
+#include "tests.h"
+
+TEST(sbat_section_text) {
+        log_info("---SBAT-----------&<----------------------------------------\n"
+                 "%s"
+                 "------------------>&-----------------------------------------",
+#ifdef SBAT_DISTRO
+                 SBAT_SECTION_TEXT
+#else
+                 "(not defined)"
+#endif
+        );
+}
+
+DEFINE_TEST_MAIN(LOG_INFO);