]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-architecture.c
tests: add helper to unify skipping a test and exiting
[thirdparty/systemd.git] / src / test / test-architecture.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "architecture.h"
4 #include "log.h"
5 #include "tests.h"
6 #include "util.h"
7 #include "virt.h"
8
9 int main(int argc, char *argv[]) {
10 int a, v;
11 const char *p;
12
13 assert_se(architecture_from_string("") < 0);
14 assert_se(architecture_from_string(NULL) < 0);
15 assert_se(architecture_from_string("hoge") < 0);
16 assert_se(architecture_to_string(-1) == NULL);
17 assert_se(architecture_from_string(architecture_to_string(0)) == 0);
18 assert_se(architecture_from_string(architecture_to_string(1)) == 1);
19
20 v = detect_virtualization();
21 if (IN_SET(v, -EPERM, -EACCES))
22 return log_tests_skipped("Cannot detect virtualization");
23
24 assert_se(v >= 0);
25
26 log_info("virtualization=%s id=%s",
27 VIRTUALIZATION_IS_CONTAINER(v) ? "container" :
28 VIRTUALIZATION_IS_VM(v) ? "vm" : "n/a",
29 virtualization_to_string(v));
30
31 a = uname_architecture();
32 assert_se(a >= 0);
33
34 p = architecture_to_string(a);
35 assert_se(p);
36 log_info("uname architecture=%s", p);
37 assert_se(architecture_from_string(p) == a);
38
39 a = native_architecture();
40 assert_se(a >= 0);
41
42 p = architecture_to_string(a);
43 assert_se(p);
44 log_info("native architecture=%s", p);
45 assert_se(architecture_from_string(p) == a);
46
47 log_info("primary library architecture=" LIB_ARCH_TUPLE);
48
49 return 0;
50 }