Merge pull request #21444 from poettering/gpt-test
tests: dump table of archs + wether gpt partition type exists
This commit is contained in:
+6
-3
@@ -206,10 +206,13 @@ void strv_print(char * const *l);
|
||||
_found; \
|
||||
})
|
||||
|
||||
#define FOREACH_STRING(x, y, ...) \
|
||||
for (char **_l = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \
|
||||
#define _FOREACH_STRING(uniq, x, y, ...) \
|
||||
for (char **UNIQ_T(l, uniq) = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \
|
||||
x; \
|
||||
x = *(++_l))
|
||||
x = *(++UNIQ_T(l, uniq)))
|
||||
|
||||
#define FOREACH_STRING(x, y, ...) \
|
||||
_FOREACH_STRING(UNIQ, x, y, ##__VA_ARGS__)
|
||||
|
||||
char **strv_reverse(char **l);
|
||||
char **strv_shell_escape(char **l, const char *bad);
|
||||
|
||||
+2
-2
@@ -120,11 +120,11 @@ const char *gpt_partition_type_uuid_to_string_harder(
|
||||
|
||||
int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) {
|
||||
assert(s);
|
||||
assert(ret);
|
||||
|
||||
for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++)
|
||||
if (streq(s, gpt_partition_type_table[i].name)) {
|
||||
*ret = gpt_partition_type_table[i].uuid;
|
||||
if (ret)
|
||||
*ret = gpt_partition_type_table[i].uuid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -435,6 +435,8 @@ tests += [
|
||||
|
||||
[['src/test/test-architecture.c']],
|
||||
|
||||
[['src/test/test-gpt.c']],
|
||||
|
||||
[['src/test/test-log.c']],
|
||||
|
||||
[['src/test/test-ipcrm.c'],
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "architecture.h"
|
||||
#include "glyph-util.h"
|
||||
#include "gpt.h"
|
||||
#include "log.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_gpt_types_against_architectures(void) {
|
||||
const char *prefix;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* Dumps a table indicating for which architectures we know we have matching GPT partition
|
||||
* types. Also validates whether we can properly categorize the entries. */
|
||||
|
||||
FOREACH_STRING(prefix, "root-", "usr-") {
|
||||
for (int a = 0; a < _ARCHITECTURE_MAX; a++) {
|
||||
const char *suffix;
|
||||
|
||||
FOREACH_STRING(suffix, "", "-verity", "-verity-sig") {
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
sd_id128_t id;
|
||||
|
||||
joined = strjoin(prefix, architecture_to_string(a), suffix);
|
||||
if (!joined)
|
||||
return (void) log_oom();
|
||||
|
||||
r = gpt_partition_type_uuid_from_string(joined, &id);
|
||||
if (r < 0) {
|
||||
printf("%s%s%s %s\n", ansi_highlight_red(), special_glyph(SPECIAL_GLYPH_CROSS_MARK), ansi_normal(), joined);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s%s%s %s\n", ansi_highlight_green(), special_glyph(SPECIAL_GLYPH_CHECK_MARK), ansi_normal(), joined);
|
||||
|
||||
if (streq(prefix, "root-") && streq(suffix, ""))
|
||||
assert_se(gpt_partition_type_is_root(id));
|
||||
if (streq(prefix, "root-") && streq(suffix, "-verity"))
|
||||
assert_se(gpt_partition_type_is_root_verity(id));
|
||||
if (streq(prefix, "usr-") && streq(suffix, ""))
|
||||
assert_se(gpt_partition_type_is_usr(id));
|
||||
if (streq(prefix, "usr-") && streq(suffix, "-verity"))
|
||||
assert_se(gpt_partition_type_is_usr_verity(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_gpt_types_against_architectures();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user