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
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEE+qvnXhKRciHc/Wuy4+MsLN6twN4FAmGS40wACgkQ4+MsLN6t
 wN4kTRAAxGW80BhZepvsr2zZOouFO7Bbnbqbx9lzsvCcAUC/pqi4x9oYhmOVeNdf
 YOuOB94yI1GWLaljrV2wiaWmanKCZL44PeDJbu6/mB5FtKhJb8z0rkP0joCA9YeF
 WAy2iGrKR1O1QaMrY2kOoK29O+w711xkrpwQTb3DoeHssvwHVau8xUeMMIUCUV8f
 6i1hC5mIeiZMFprQm0vU1ZSHHEnC0xdPdwnYRLfk53tWzIeT5DeAeJJXbBJ5ttG4
 ttevbkWWIMr/hwuAsA81jpITAgdt4qa3/qQqHBzzpcBXlScZGnHc61tfDR6Sz8IQ
 4wF6dyOvdDU34xE0kPEkif6ltMdnu0DjNXFkaRo2E+mGNlErFPuZ1N413ZGVNrGp
 IOp3pR2WQi8XYBjGHRvX1JciUuNS7CniCgn7Yqq7eBmQTBxYMyV0XVHc10MzY2QW
 vjtYnYo7Y7gaSp4klevrphk9Y8w7xzQ/CWWMKH3k9XPE63x+3k0F4XQpdv+Q8s3Q
 EhGPWA9r69cBPwBMXx+qhKbk72j98sioWkhD5avKCwJPnq2+Ade1jrSmZDGtCU5w
 Mfa9hZ+9d5BvL957IvtaoWX1LkovVfZWArbF/ohCMd0T8LurV0FhDI4L4PayMoWr
 X8bBwyl+PID2IPrjVF/tHdpmbbZ88vPuAEcMPRn6ody3qnecaCI=
 =JDca
 -----END PGP SIGNATURE-----

Merge tag 'machine-core-20211115' of https://github.com/philmd/qemu into 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>
This commit is contained in:
Richard Henderson 2021-11-16 12:50:27 +01:00
commit 9f0f846465

View File

@ -23,6 +23,8 @@
#define MIN_CPUS 1 /* set the min CPUs supported by the machine as 1 */ #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 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 * Used to define the generic 3-level CPU topology hierarchy
* -sockets/cores/threads * -sockets/cores/threads
@ -75,14 +77,6 @@ typedef struct SMPTestData {
const char *expect_error; const char *expect_error;
} SMPTestData; } 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 * List all the possible valid sub-collections of the generic 5
* topology parameters (i.e. cpus/maxcpus/sockets/cores/threads), * topology parameters (i.e. cpus/maxcpus/sockets/cores/threads),
@ -315,13 +309,13 @@ static struct SMPTestData data_generic_invalid[] = {
* should tweak the supported min CPUs to 2 for testing */ * should tweak the supported min CPUs to 2 for testing */
.config = SMP_CONFIG_GENERIC(T, 1, F, 0, F, 0, F, 0, F, 0), .config = SMP_CONFIG_GENERIC(T, 1, F, 0, F, 0, F, 0, F, 0),
.expect_error = "Invalid SMP CPUs 1. The min CPUs supported " .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 /* config: -smp 512
* should tweak the supported max CPUs to 511 for testing */ * should tweak the supported max CPUs to 511 for testing */
.config = SMP_CONFIG_GENERIC(T, 512, F, 0, F, 0, F, 0, F, 0), .config = SMP_CONFIG_GENERIC(T, 512, F, 0, F, 0, F, 0, F, 0),
.expect_error = "Invalid SMP CPUs 512. The max CPUs supported " .expect_error = "Invalid SMP CPUs 512. The max CPUs supported "
"by machine '(null)' is 511", "by machine '" SMP_MACHINE_NAME "' is 511",
}, },
}; };
@ -480,14 +474,17 @@ static void unsupported_params_init(MachineClass *mc, SMPTestData *data)
} }
} }
/* Reset the related machine properties before each sub-test */ static void machine_base_class_init(ObjectClass *oc, void *data)
static void smp_machine_class_init(MachineClass *mc)
{ {
MachineClass *mc = MACHINE_CLASS(oc);
mc->min_cpus = MIN_CPUS; mc->min_cpus = MIN_CPUS;
mc->max_cpus = MAX_CPUS; mc->max_cpus = MAX_CPUS;
mc->smp_props.prefer_sockets = true; mc->smp_props.prefer_sockets = true;
mc->smp_props.dies_supported = false; mc->smp_props.dies_supported = false;
mc->name = g_strdup(SMP_MACHINE_NAME);
} }
static void test_generic(void) static void test_generic(void)
@ -498,8 +495,6 @@ static void test_generic(void)
SMPTestData *data = &(SMPTestData){{ }}; SMPTestData *data = &(SMPTestData){{ }};
int i; int i;
smp_machine_class_init(mc);
for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) { for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) {
*data = data_generic_valid[i]; *data = data_generic_valid[i];
unsupported_params_init(mc, data); unsupported_params_init(mc, data);
@ -512,7 +507,7 @@ static void test_generic(void)
smp_parse_test(ms, data, true); 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->min_cpus = 2;
mc->max_cpus = 511; mc->max_cpus = 511;
@ -523,6 +518,10 @@ static void test_generic(void)
smp_parse_test(ms, data, false); 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); object_unref(obj);
} }
@ -535,7 +534,7 @@ static void test_with_dies(void)
unsigned int num_dies = 2; unsigned int num_dies = 2;
int i; int i;
smp_machine_class_init(mc); /* Force the SMP compat properties */
mc->smp_props.dies_supported = true; mc->smp_props.dies_supported = true;
for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) { for (i = 0; i < ARRAY_SIZE(data_generic_valid); i++) {
@ -575,15 +574,30 @@ static void test_with_dies(void)
smp_parse_test(ms, data, false); smp_parse_test(ms, data, false);
} }
/* Restore the SMP compat properties */
mc->smp_props.dies_supported = false;
object_unref(obj); 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[]) int main(int argc, char *argv[])
{ {
g_test_init(&argc, &argv, NULL);
module_call_init(MODULE_INIT_QOM); 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/generic", test_generic);
g_test_add_func("/test-smp-parse/with_dies", test_with_dies); g_test_add_func("/test-smp-parse/with_dies", test_with_dies);