| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "architecture.h" |
| 4 |
#include "errno-util.h" |
| 5 |
#include "log.h" |
| 6 |
#include "path-util.h" |
| 7 |
#include "tests.h" |
| 8 |
#include "virt.h" |
| 9 |
|
| 10 |
int main(int argc, char *argv[]) { |
| 11 |
Virtualization v; |
| 12 |
Architecture a; |
| 13 |
const char *p; |
| 14 |
|
| 15 |
test_setup_logging(LOG_INFO); |
| 16 |
|
| 17 |
ASSERT_LT(architecture_from_string(""), 0); |
| 18 |
ASSERT_LT(architecture_from_string(NULL), 0); |
| 19 |
ASSERT_LT(architecture_from_string("hoge"), 0); |
| 20 |
ASSERT_NULL(architecture_to_string(-1)); |
| 21 |
ASSERT_EQ(architecture_from_string(architecture_to_string(0)), 0); |
| 22 |
ASSERT_EQ(architecture_from_string(architecture_to_string(1)), 1); |
| 23 |
|
| 24 |
v = detect_virtualization(); |
| 25 |
if (ERRNO_IS_NEG_PRIVILEGE(v)) |
| 26 |
return log_tests_skipped("Cannot detect virtualization"); |
| 27 |
|
| 28 |
ASSERT_OK(v); |
| 29 |
|
| 30 |
log_info("virtualization=%s id=%s", |
| 31 |
VIRTUALIZATION_IS_CONTAINER(v) ? "container" : |
| 32 |
VIRTUALIZATION_IS_VM(v) ? "vm" : "n/a", |
| 33 |
virtualization_to_string(v)); |
| 34 |
|
| 35 |
a = uname_architecture(); |
| 36 |
ASSERT_OK(a); |
| 37 |
|
| 38 |
p = architecture_to_string(a); |
| 39 |
assert_se(p); |
| 40 |
log_info("uname architecture=%s", p); |
| 41 |
ASSERT_EQ(architecture_from_string(p), a); |
| 42 |
|
| 43 |
a = native_architecture(); |
| 44 |
ASSERT_OK(a); |
| 45 |
|
| 46 |
p = architecture_to_string(a); |
| 47 |
assert_se(p); |
| 48 |
log_info("native architecture=%s", p); |
| 49 |
ASSERT_EQ(architecture_from_string(p), a); |
| 50 |
|
| 51 |
log_info("primary library architecture=" LIB_ARCH_TUPLE); |
| 52 |
|
| 53 |
for (Architecture i = 0; i < _ARCHITECTURE_MAX; i++) { |
| 54 |
const char *n = ASSERT_PTR(architecture_to_string(i)); |
| 55 |
|
| 56 |
/* Let's validate that all architecture names we define are good for inclusion in .v/ |
| 57 |
* filename patterns which use "." and "_" as field separators in the filenames. */ |
| 58 |
assert(filename_part_is_valid(n)); |
| 59 |
assert(!strchr(n, '_')); |
| 60 |
assert(!strchr(n, '.')); |
| 61 |
|
| 62 |
log_info("Good for inclusion in .v/ filenames: %s", n); |
| 63 |
} |
| 64 |
|
| 65 |
return 0; |
| 66 |
} |