From: Zhao Liu <zhao1....@intel.com> MachineState.smp is being replaced by MachineState.topo.smp, so test MachineState.topo.smp fields parsing for smp command.
Signed-off-by: Zhao Liu <zhao1....@intel.com> --- tests/unit/test-smp-parse.c | 62 ++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c index fdc39a846ca6..d6816f109084 100644 --- a/tests/unit/test-smp-parse.c +++ b/tests/unit/test-smp-parse.c @@ -41,10 +41,13 @@ #define CPU_TOPOLOGY_GENERIC(a, b, c, d, e) \ { \ .cpus = a, \ - .sockets = b, \ - .cores = c, \ - .threads = d, \ .max_cpus = e, \ + .topo_type = CPU_TOPO_TYPE_SMP, \ + .smp = { \ + .sockets = b, \ + .cores = c, \ + .threads = d, \ + } \ } /* @@ -406,8 +409,8 @@ static char *cpu_topology_to_string(const CpuTopology *topo) " .threads = %u,\n" " .max_cpus = %u,\n" "}", - topo->cpus, topo->sockets, topo->dies, topo->clusters, - topo->cores, topo->threads, topo->max_cpus); + topo->cpus, topo->smp.sockets, topo->smp.dies, topo->smp.clusters, + topo->smp.cores, topo->smp.threads, topo->max_cpus); } static void check_parse(MachineState *ms, const SMPConfiguration *config, @@ -422,18 +425,19 @@ static void check_parse(MachineState *ms, const SMPConfiguration *config, /* call the generic parser */ machine_parse_smp_config(ms, config, &err); - output_topo_str = cpu_topology_to_string(&ms->smp); + output_topo_str = cpu_topology_to_string(&ms->topo); /* when the configuration is supposed to be valid */ if (is_valid) { if ((err == NULL) && - (ms->smp.cpus == expect_topo->cpus) && - (ms->smp.sockets == expect_topo->sockets) && - (ms->smp.dies == expect_topo->dies) && - (ms->smp.clusters == expect_topo->clusters) && - (ms->smp.cores == expect_topo->cores) && - (ms->smp.threads == expect_topo->threads) && - (ms->smp.max_cpus == expect_topo->max_cpus)) { + (machine_topo_is_smp(ms) == true) && + (machine_topo_get_cpus(ms) == expect_topo->cpus) && + (machine_topo_get_sockets(ms) == expect_topo->smp.sockets) && + (machine_topo_get_dies(ms) == expect_topo->smp.dies) && + (machine_topo_get_clusters(ms) == expect_topo->smp.clusters) && + (machine_topo_get_smp_cores(ms) == expect_topo->smp.cores) && + (machine_topo_get_smp_threads(ms) == expect_topo->smp.threads) && + (machine_topo_get_max_cpus(ms) == expect_topo->max_cpus)) { return; } @@ -509,13 +513,13 @@ static void smp_parse_test(MachineState *ms, SMPTestData *data, bool is_valid) static void unsupported_params_init(const MachineClass *mc, SMPTestData *data) { if (!mc->smp_props.dies_supported) { - data->expect_prefer_sockets.dies = 1; - data->expect_prefer_cores.dies = 1; + data->expect_prefer_sockets.smp.dies = 1; + data->expect_prefer_cores.smp.dies = 1; } if (!mc->smp_props.clusters_supported) { - data->expect_prefer_sockets.clusters = 1; - data->expect_prefer_cores.clusters = 1; + data->expect_prefer_sockets.smp.clusters = 1; + data->expect_prefer_cores.smp.clusters = 1; } } @@ -529,6 +533,13 @@ static void machine_base_class_init(ObjectClass *oc, void *data) mc->name = g_strdup(SMP_MACHINE_NAME); } +static void machine_smp_topo_initfn(Object *obj) +{ + MachineState *ms = MACHINE(obj); + + ms->topo.topo_type = CPU_TOPO_TYPE_SMP; +} + static void machine_generic_invalid_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -610,8 +621,8 @@ static void test_with_dies(const void *opaque) unsupported_params_init(mc, &data); /* when dies parameter is omitted, it will be set as 1 */ - data.expect_prefer_sockets.dies = 1; - data.expect_prefer_cores.dies = 1; + data.expect_prefer_sockets.smp.dies = 1; + data.expect_prefer_cores.smp.dies = 1; smp_parse_test(ms, &data, true); @@ -625,10 +636,10 @@ static void test_with_dies(const void *opaque) data.config.maxcpus *= num_dies; } - data.expect_prefer_sockets.dies = num_dies; + data.expect_prefer_sockets.smp.dies = num_dies; data.expect_prefer_sockets.cpus *= num_dies; data.expect_prefer_sockets.max_cpus *= num_dies; - data.expect_prefer_cores.dies = num_dies; + data.expect_prefer_cores.smp.dies = num_dies; data.expect_prefer_cores.cpus *= num_dies; data.expect_prefer_cores.max_cpus *= num_dies; @@ -660,8 +671,8 @@ static void test_with_clusters(const void *opaque) unsupported_params_init(mc, &data); /* when clusters parameter is omitted, it will be set as 1 */ - data.expect_prefer_sockets.clusters = 1; - data.expect_prefer_cores.clusters = 1; + data.expect_prefer_sockets.smp.clusters = 1; + data.expect_prefer_cores.smp.clusters = 1; smp_parse_test(ms, &data, true); @@ -675,10 +686,10 @@ static void test_with_clusters(const void *opaque) data.config.maxcpus *= num_clusters; } - data.expect_prefer_sockets.clusters = num_clusters; + data.expect_prefer_sockets.smp.clusters = num_clusters; data.expect_prefer_sockets.cpus *= num_clusters; data.expect_prefer_sockets.max_cpus *= num_clusters; - data.expect_prefer_cores.clusters = num_clusters; + data.expect_prefer_cores.smp.clusters = num_clusters; data.expect_prefer_cores.cpus *= num_clusters; data.expect_prefer_cores.max_cpus *= num_clusters; @@ -704,6 +715,7 @@ static const TypeInfo smp_machine_types[] = { .class_init = machine_base_class_init, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState), + .instance_init = machine_smp_topo_initfn, }, { .name = MACHINE_TYPE_NAME("smp-generic-valid"), .parent = TYPE_MACHINE, -- 2.34.1