1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26
27#include "hw/i386/topology.h"
28
29static void test_topo_bits(void)
30{
31
32 g_assert_cmpuint(apicid_smt_width(1, 1), ==, 0);
33 g_assert_cmpuint(apicid_core_width(1, 1), ==, 0);
34
35 g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 0), ==, 0);
36 g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 1), ==, 1);
37 g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 2), ==, 2);
38 g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 3), ==, 3);
39
40
41
42
43 g_assert_cmpuint(apicid_smt_width(1, 2), ==, 1);
44 g_assert_cmpuint(apicid_smt_width(1, 3), ==, 2);
45 g_assert_cmpuint(apicid_smt_width(1, 4), ==, 2);
46
47 g_assert_cmpuint(apicid_smt_width(1, 14), ==, 4);
48 g_assert_cmpuint(apicid_smt_width(1, 15), ==, 4);
49 g_assert_cmpuint(apicid_smt_width(1, 16), ==, 4);
50 g_assert_cmpuint(apicid_smt_width(1, 17), ==, 5);
51
52
53 g_assert_cmpuint(apicid_core_width(30, 2), ==, 5);
54 g_assert_cmpuint(apicid_core_width(31, 2), ==, 5);
55 g_assert_cmpuint(apicid_core_width(32, 2), ==, 5);
56 g_assert_cmpuint(apicid_core_width(33, 2), ==, 6);
57
58
59
60
61
62
63
64 g_assert_cmpuint(apicid_smt_width(6, 3), ==, 2);
65 g_assert_cmpuint(apicid_core_width(6, 3), ==, 3);
66 g_assert_cmpuint(apicid_pkg_offset(6, 3), ==, 5);
67
68 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 0), ==, 0);
69 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1), ==, 1);
70 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2), ==, 2);
71
72 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 3 + 0), ==,
73 (1 << 2) | 0);
74 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 3 + 1), ==,
75 (1 << 2) | 1);
76 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 3 + 2), ==,
77 (1 << 2) | 2);
78
79 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2 * 3 + 0), ==,
80 (2 << 2) | 0);
81 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2 * 3 + 1), ==,
82 (2 << 2) | 1);
83 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2 * 3 + 2), ==,
84 (2 << 2) | 2);
85
86 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 5 * 3 + 0), ==,
87 (5 << 2) | 0);
88 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 5 * 3 + 1), ==,
89 (5 << 2) | 1);
90 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 5 * 3 + 2), ==,
91 (5 << 2) | 2);
92
93 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 6 * 3 + 0 * 3 + 0), ==,
94 (1 << 5));
95 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 6 * 3 + 1 * 3 + 1), ==,
96 (1 << 5) | (1 << 2) | 1);
97 g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 3 * 6 * 3 + 5 * 3 + 2), ==,
98 (3 << 5) | (5 << 2) | 2);
99}
100
101int main(int argc, char **argv)
102{
103 g_test_init(&argc, &argv, NULL);
104
105 g_test_add_func("/cpuid/topology/basic", test_topo_bits);
106
107 g_test_run();
108
109 return 0;
110}
111