1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

test: add test that verifies correct order of boot entries

This commit is contained in:
Lennart Poettering 2022-03-07 18:00:55 +01:00
parent d23b3bfdd6
commit 1fe368e526
2 changed files with 98 additions and 0 deletions

View File

@ -513,6 +513,8 @@ tests += [
[files('test-strbuf.c')],
[files('test-bootspec.c')],
[files('test-strv.c')],
[files('test-path-util.c')],

96
src/test/test-bootspec.c Normal file
View File

@ -0,0 +1,96 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "bootspec.h"
#include "fileio.h"
#include "path-util.h"
#include "rm-rf.h"
#include "tests.h"
#include "tmpfile-util.h"
TEST_RET(bootspec_sort) {
static const struct {
const char *fname;
const char *contents;
} entries[] = {
{
.fname = "a-10.conf",
.contents =
"title A\n"
"version 10\n"
"machine-id dd235d00696545768f6f693bfd23b15f\n",
},
{
.fname = "a-5.conf",
.contents =
"title A\n"
"version 5\n"
"machine-id dd235d00696545768f6f693bfd23b15f\n",
},
{
.fname = "b.conf",
.contents =
"title B\n"
"version 3\n"
"machine-id b75451ad92f94feeab50b0b442768dbd\n",
},
{
.fname = "c.conf",
.contents =
"title C\n"
"sort-key xxxx\n"
"version 5\n"
"machine-id 309de666fd5044268a9a26541ac93176\n",
},
{
.fname = "cx.conf",
.contents =
"title C\n"
"sort-key xxxx\n"
"version 10\n"
"machine-id 309de666fd5044268a9a26541ac93176\n",
},
{
.fname = "d.conf",
.contents =
"title D\n"
"sort-key kkkk\n"
"version 100\n"
"machine-id 81c6e3147cf544c19006af023e22b292\n",
},
};
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
_cleanup_(boot_config_free) BootConfig config = {};
assert_se(mkdtemp_malloc("/tmp/bootspec-testXXXXXX", &d) >= 0);
for (size_t i = 0; i < ELEMENTSOF(entries); i++) {
_cleanup_free_ char *j = NULL;
j = path_join(d, "/loader/entries/", entries[i].fname);
assert_se(j);
assert_se(write_string_file(j, entries[i].contents, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MKDIR_0755) >= 0);
}
assert_se(boot_entries_load_config(d, NULL, &config) >= 0);
assert_se(config.n_entries == 6);
/* First, because has sort key, and its the lowest one */
assert_se(streq(config.entries[0].id, "d.conf"));
/* These two have a sort key, and newest must be first */
assert_se(streq(config.entries[1].id, "cx.conf"));
assert_se(streq(config.entries[2].id, "c.conf"));
/* The following ones have no sort key, hence order by version compared ids, lowest first */
assert_se(streq(config.entries[3].id, "a-5.conf"));
assert_se(streq(config.entries[4].id, "a-10.conf"));
assert_se(streq(config.entries[5].id, "b.conf"));
return 0;
}
DEFINE_TEST_MAIN(LOG_INFO);