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