Skip to content

Commit

Permalink
Merge tag 'machine-core-20211115' of https://github.com/philmd/qemu i…
Browse files Browse the repository at this point in the history
…nto staging

Machine core patches

- Rework SMP parsing unit test to work on WinGW:

  https://github.com/qemu/qemu/runs/4078386652

  This fixes:

    Test smp_parse failed!
    Expected error report: Invalid SMP CPUs 1. The min CPUs supported by machine '(null)' is 2
      Output error report: Invalid SMP CPUs 1. The min CPUs supported by machine '(NULL)' is 2

# gpg: Signature made Mon 15 Nov 2021 11:46:36 PM CET
# gpg:                using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE
# gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [full]

* tag 'machine-core-20211115' of https://github.com/philmd/qemu:
  tests/unit/test-smp-parse: Explicit MachineClass name
  tests/unit/test-smp-parse: QOM'ify smp_machine_class_init()
  tests/unit/test-smp-parse: Restore MachineClass fields after modifying

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Nov 16, 2021
2 parents 3e59553 + 7b6d1bc commit 9f0f846
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions tests/unit/test-smp-parse.c
Expand Up @@ -23,6 +23,8 @@
#define MIN_CPUS 1 /* set the min CPUs supported by the machine as 1 */
#define MAX_CPUS 512 /* set the max CPUs supported by the machine as 512 */

#define SMP_MACHINE_NAME "TEST-SMP"

/*
* Used to define the generic 3-level CPU topology hierarchy
* -sockets/cores/threads
Expand Down Expand Up @@ -75,14 +77,6 @@ typedef struct SMPTestData {
const char *expect_error;
} SMPTestData;

/* Type info of the tested machine */
static const TypeInfo smp_machine_info = {
.name = TYPE_MACHINE,
.parent = TYPE_OBJECT,
.class_size = sizeof(MachineClass),
.instance_size = sizeof(MachineState),
};

/*
* List all the possible valid sub-collections of the generic 5
* topology parameters (i.e. cpus/maxcpus/sockets/cores/threads),
Expand Down Expand Up @@ -315,13 +309,13 @@ static struct SMPTestData data_generic_invalid[] = {
* should tweak the supported min CPUs to 2 for testing */
.config = SMP_CONFIG_GENERIC(T, 1, F, 0, F, 0, F, 0, F, 0),
.expect_error = "Invalid SMP CPUs 1. The min CPUs supported "
"by machine '(null)' is 2",
"by machine '" SMP_MACHINE_NAME "' is 2",
}, {
/* config: -smp 512
* should tweak the supported max CPUs to 511 for testing */
.config = SMP_CONFIG_GENERIC(T, 512, F, 0, F, 0, F, 0, F, 0),
.expect_error = "Invalid SMP CPUs 512. The max CPUs supported "
"by machine '(null)' is 511",
"by machine '" SMP_MACHINE_NAME "' is 511",
},
};

Expand Down Expand Up @@ -480,14 +474,17 @@ static void unsupported_params_init(MachineClass *mc, SMPTestData *data)
}
}

/* Reset the related machine properties before each sub-test */
static void smp_machine_class_init(MachineClass *mc)
static void machine_base_class_init(ObjectClass *oc, void *data)
{
MachineClass *mc = MACHINE_CLASS(oc);

mc->min_cpus = MIN_CPUS;
mc->max_cpus = MAX_CPUS;

mc->smp_props.prefer_sockets = true;
mc->smp_props.dies_supported = false;

mc->name = g_strdup(SMP_MACHINE_NAME);
}

static void test_generic(void)
Expand All @@ -498,8 +495,6 @@ static void test_generic(void)
SMPTestData *data = &(SMPTestData){{ }};
int i;

smp_machine_class_init(mc);

for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) {
*data = data_generic_valid[i];
unsupported_params_init(mc, data);
Expand All @@ -512,7 +507,7 @@ static void test_generic(void)
smp_parse_test(ms, data, true);
}

/* Reset the supported min CPUs and max CPUs */
/* Force invalid min CPUs and max CPUs */
mc->min_cpus = 2;
mc->max_cpus = 511;

Expand All @@ -523,6 +518,10 @@ static void test_generic(void)
smp_parse_test(ms, data, false);
}

/* Reset the supported min CPUs and max CPUs */
mc->min_cpus = MIN_CPUS;
mc->max_cpus = MAX_CPUS;

object_unref(obj);
}

Expand All @@ -535,7 +534,7 @@ static void test_with_dies(void)
unsigned int num_dies = 2;
int i;

smp_machine_class_init(mc);
/* Force the SMP compat properties */
mc->smp_props.dies_supported = true;

for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) {
Expand Down Expand Up @@ -575,15 +574,30 @@ static void test_with_dies(void)
smp_parse_test(ms, data, false);
}

/* Restore the SMP compat properties */
mc->smp_props.dies_supported = false;

object_unref(obj);
}

/* Type info of the tested machine */
static const TypeInfo smp_machine_types[] = {
{
.name = TYPE_MACHINE,
.parent = TYPE_OBJECT,
.class_init = machine_base_class_init,
.class_size = sizeof(MachineClass),
.instance_size = sizeof(MachineState),
}
};

DEFINE_TYPES(smp_machine_types)

int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);

module_call_init(MODULE_INIT_QOM);
type_register_static(&smp_machine_info);

g_test_init(&argc, &argv, NULL);

g_test_add_func("/test-smp-parse/generic", test_generic);
g_test_add_func("/test-smp-parse/with_dies", test_with_dies);
Expand Down

0 comments on commit 9f0f846

Please sign in to comment.