@@ -32,11 +32,36 @@ static void test_topo_bits(void)
g_assert_cmpuint(apicid_smt_width(1, 1), ==, 0);
g_assert_cmpuint(apicid_core_width(1, 1), ==, 0);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 0), ==, 0);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 1), ==, 1);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 2), ==, 2);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 3), ==, 3);
-
+ X86CPUTopoInfo topo = {0};
+
+ x86_topo_ids_from_idx(1, 1, 0, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, 0);
+ x86_topo_ids_from_idx(1, 1, 1, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, 1);
+ x86_topo_ids_from_idx(1, 1, 2, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, 2);
+ x86_topo_ids_from_idx(1, 1, 3, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, 3);
+
+ x86_topo_ids_from_apic_id(1, 1, 0, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+
+ x86_topo_ids_from_apic_id(1, 1, 1, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 1);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+
+ x86_topo_ids_from_apic_id(1, 1, 2, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 2);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+
+ x86_topo_ids_from_apic_id(1, 1, 3, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 3);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
/* Test field width calculation for multiple values
*/
@@ -65,37 +90,105 @@ static void test_topo_bits(void)
g_assert_cmpuint(apicid_core_width(6, 3), ==, 3);
g_assert_cmpuint(apicid_pkg_offset(6, 3), ==, 5);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 0), ==, 0);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1), ==, 1);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2), ==, 2);
-
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 3 + 0), ==,
- (1 << 2) | 0);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 3 + 1), ==,
- (1 << 2) | 1);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 3 + 2), ==,
- (1 << 2) | 2);
-
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2 * 3 + 0), ==,
- (2 << 2) | 0);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2 * 3 + 1), ==,
- (2 << 2) | 1);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 2 * 3 + 2), ==,
- (2 << 2) | 2);
-
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 5 * 3 + 0), ==,
- (5 << 2) | 0);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 5 * 3 + 1), ==,
- (5 << 2) | 1);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 5 * 3 + 2), ==,
- (5 << 2) | 2);
-
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 6 * 3 + 0 * 3 + 0), ==,
- (1 << 5));
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 1 * 6 * 3 + 1 * 3 + 1), ==,
- (1 << 5) | (1 << 2) | 1);
- g_assert_cmpuint(x86_apicid_from_cpu_idx(6, 3, 3 * 6 * 3 + 5 * 3 + 2), ==,
- (3 << 5) | (5 << 2) | 2);
+ x86_topo_ids_from_idx(6, 3, 0, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, 0);
+ x86_topo_ids_from_idx(6, 3, 1, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, 1);
+ x86_topo_ids_from_idx(6, 3, 2, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, 2);
+
+ x86_topo_ids_from_idx(6, 3, 1 * 3 + 0, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (1 << 2) | 0);
+ x86_topo_ids_from_idx(6, 3, 1 * 3 + 1, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (1 << 2) | 1);
+ x86_topo_ids_from_idx(6, 3, 1 * 3 + 2, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (1 << 2) | 2);
+
+ x86_topo_ids_from_idx(6, 3, 2 * 3 + 0, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (2 << 2) | 0);
+ x86_topo_ids_from_idx(6, 3, 2 * 3 + 1, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (2 << 2) | 1);
+ x86_topo_ids_from_idx(6, 3, 2 * 3 + 2, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (2 << 2) | 2);
+
+ x86_topo_ids_from_idx(6, 3, 5 * 3 + 0, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (5 << 2) | 0);
+ x86_topo_ids_from_idx(6, 3, 5 * 3 + 1, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (5 << 2) | 1);
+ x86_topo_ids_from_idx(6, 3, 5 * 3 + 2, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (5 << 2) | 2);
+
+ x86_topo_ids_from_idx(6, 3, 1 * 6 * 3 + 0 * 3 + 0, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (1 << 5) | 0);
+ x86_topo_ids_from_idx(6, 3, 1 * 6 * 3 + 1 * 3 + 1, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (1 << 5) | (1 << 2) | 1);
+ x86_topo_ids_from_idx(6, 3, 3 * 6 * 3 + 5 * 3 + 2, &topo);
+ g_assert_cmpuint(topo.apic_id, ==, (3 << 5) | (5 << 2) | 2);
+
+ x86_topo_ids_from_apic_id(6, 3, 0, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+ x86_topo_ids_from_apic_id(6, 3, 1, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 1);
+ x86_topo_ids_from_apic_id(6, 3, 2, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 2);
+
+ x86_topo_ids_from_apic_id(6, 3, (1 << 2) | 0, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 1);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+ x86_topo_ids_from_apic_id(6, 3, (1 << 2) | 1, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 1);
+ g_assert_cmpuint(topo.smt_id, ==, 1);
+ x86_topo_ids_from_apic_id(6, 3, (1 << 2) | 2, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 1);
+ g_assert_cmpuint(topo.smt_id, ==, 2);
+
+ x86_topo_ids_from_apic_id(6, 3, (2 << 2) | 0, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 2);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+ x86_topo_ids_from_apic_id(6, 3, (2 << 2) | 1, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 2);
+ g_assert_cmpuint(topo.smt_id, ==, 1);
+ x86_topo_ids_from_apic_id(6, 3, (2 << 2) | 2, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 2);
+ g_assert_cmpuint(topo.smt_id, ==, 2);
+
+ x86_topo_ids_from_apic_id(6, 3, (5 << 2) | 0, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 5);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+ x86_topo_ids_from_apic_id(6, 3, (5 << 2) | 1, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 5);
+ g_assert_cmpuint(topo.smt_id, ==, 1);
+ x86_topo_ids_from_apic_id(6, 3, (5 << 2) | 2, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 0);
+ g_assert_cmpuint(topo.core_id, ==, 5);
+ g_assert_cmpuint(topo.smt_id, ==, 2);
+
+ x86_topo_ids_from_apic_id(6, 3, (1 << 5) | 0, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 1);
+ g_assert_cmpuint(topo.core_id, ==, 0);
+ g_assert_cmpuint(topo.smt_id, ==, 0);
+ x86_topo_ids_from_apic_id(6, 3, (1 << 5) | (1 << 2) | 1, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 1);
+ g_assert_cmpuint(topo.core_id, ==, 1);
+ g_assert_cmpuint(topo.smt_id, ==, 1);
+ x86_topo_ids_from_apic_id(6, 3, (1 << 5) | (1 << 2) | 2, &topo);
+ g_assert_cmpuint(topo.pkg_id, ==, 1);
+ g_assert_cmpuint(topo.core_id, ==, 1);
+ g_assert_cmpuint(topo.smt_id, ==, 2);
}
int main(int argc, char **argv)
remove redundant x86_apicid_from_cpu_idx() tests. add tests to check x86_topo_ids_from_apic_id() and x86_topo_ids_from_apic_id() output. Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com> --- tests/test-x86-cpuid.c | 165 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 129 insertions(+), 36 deletions(-)