tests/unit: Rework test-smp-parse tests
v5 cover tests/unit: Rework test-smp-parse tests
Since v4:
- Rebase (skipping merged patches)
- Renamed tests (Yanan Wang)
Since v2:
- Restore 'dies_supported' field in test_with_dies (Yanan)
- Add R-b tags
- QOM-ify the TYPE_MACHINE classes
Supersedes: <[email protected]>
Philippe Mathieu-Daudé (8):
tests/unit/test-smp-parse: Pass machine type as argument to tests tests/unit/test-smp-parse: Split the 'generic' test in valid / invalid tests/unit/test-smp-parse: Add 'smp-with-dies' machine type tests/unit/test-smp-parse: Add 'smp-generic-invalid' machine type tests/unit/test-smp-parse: Add 'smp-generic-valid' machine type tests/unit/test-smp-parse: Simplify pointer to compound literal use tests/unit/test-smp-parse: Constify some pointer/struct hw/core: Rename smp_parse() -> machine_parse_smp_config()
include/hw/boards.h | 3 +- hw/core/machine-smp.c | 6 +- hw/core/machine.c | 2 +- tests/unit/test-smp-parse.c | 181 +++++++++++++++++++++++------------- 4 files changed, 121 insertions(+), 71 deletions(-)
Signature · 1 line
2.33.1
PATCH v5 1/8 tests/unit/test-smp-parse: Pass machine type as argument to tests
Use g_test_add_data_func() instead of g_test_add_func() so we can pass the machine type to the tests (we will soon have different machine types).
--- tests/unit/test-smp-parse.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
tests/unit/test-smp-parse.c +12 -6
@@ -487,9 +487,10 @@ static void machine_base_class_init(ObjectClass *oc, void *data) mc->name =g_strdup (SMP_MACHINE_NAME ); } -static void test_generic (void ) +static void test_generic (const void *opaque) { -Object *obj =object_new (TYPE_MACHINE ); +const char *machine_type = opaque; +Object *obj =object_new (machine_type);MachineState *ms =MACHINE (obj);MachineClass *mc =MACHINE_GET_CLASS (obj);SMPTestData *data = &(SMPTestData ){{ }};
@@ -525,9 +526,10 @@ static void test_generic(void)object_unref (obj); } -static void test_with_dies (void ) +static void test_with_dies (const void *opaque) { -Object *obj =object_new (TYPE_MACHINE ); +const char *machine_type = opaque; +Object *obj =object_new (machine_type);MachineState *ms =MACHINE (obj);MachineClass *mc =MACHINE_GET_CLASS (obj);SMPTestData *data = &(SMPTestData ){{ }};
@@ -599,8 +601,12 @@ int main(int argc, char *argv[])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); +g_test_add_data_func ("/test-smp-parse/generic" , +TYPE_MACHINE , + test_generic); +g_test_add_data_func ("/test-smp-parse/with_dies" , +TYPE_MACHINE , + test_with_dies);g_test_run ();
Signature · 1 line
2.33.1
PATCH v5 2/8 tests/unit/test-smp-parse: Split the 'generic' test in valid / invalid
In reply to Philippe Mathieu-DaudéSplit the 'generic' test in two tests: 'valid' and 'invalid'. This will allow us to remove the hack which modifies the MachineClass internal state.
--- tests/unit/test-smp-parse.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
tests/unit/test-smp-parse.c +18 -3
@@ -487,7 +487,7 @@ static void machine_base_class_init(ObjectClass *oc, void *data) mc->name =g_strdup (SMP_MACHINE_NAME ); } -static void test_generic (const void *opaque) +static void test_generic_valid (const void *opaque) {const char *machine_type = opaque;Object *obj =object_new (machine_type);
@@ -508,6 +508,18 @@ static void test_generic(const void *opaque)smp_parse_test (ms, data, true); } +object_unref (obj); +} + +static void test_generic_invalid (const void *opaque) +{ +const char *machine_type = opaque; +Object *obj =object_new (machine_type); +MachineState *ms =MACHINE (obj); +MachineClass *mc =MACHINE_GET_CLASS (obj); +SMPTestData *data = &(SMPTestData ){}; +int i; +/* Force invalid min CPUs and max CPUs */ mc->min_cpus =2 ; mc->max_cpus =511 ;
@@ -601,9 +613,12 @@ int main(int argc, char *argv[])g_test_init (&argc, &argv,NULL ); -g_test_add_data_func ("/test-smp-parse/generic" , +g_test_add_data_func ("/test-smp-parse/generic/valid" ,TYPE_MACHINE , - test_generic); + test_generic_valid); +g_test_add_data_func ("/test-smp-parse/generic/invalid" , +TYPE_MACHINE , + test_generic_invalid);g_test_add_data_func ("/test-smp-parse/with_dies" ,TYPE_MACHINE , test_with_dies);
Signature · 1 line
2.33.1
PATCH v5 3/8 tests/unit/test-smp-parse: Add 'smp-with-dies' machine type
In reply to Philippe Mathieu-DaudéAvoid modifying the MachineClass internals by adding the 'smp-with-dies' machine, which inherits from TYPE_MACHINE.
--- tests/unit/test-smp-parse.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
tests/unit/test-smp-parse.c +15 -7
@@ -487,6 +487,16 @@ static void machine_base_class_init(ObjectClass *oc, void *data) mc->name =g_strdup (SMP_MACHINE_NAME ); } +static void machine_with_dies_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->min_cpus =MIN_CPUS ; + mc->max_cpus =MAX_CPUS ; + + mc->smp_props.dies_supported = true; +} +static void test_generic_valid (const void *opaque) {const char *machine_type = opaque;
@@ -548,9 +558,6 @@ static void test_with_dies(const void *opaque)unsigned int num_dies =2 ;int i; -/* Force the SMP compat properties */ - mc->smp_props.dies_supported = true; -for (i =0 ; i <ARRAY_SIZE (data_generic_valid); i++) { *data = data_generic_valid[i];unsupported_params_init (mc, data);
@@ -588,9 +595,6 @@ static void test_with_dies(const void *opaque)smp_parse_test (ms, data, false); } -/* Restore the SMP compat properties */ - mc->smp_props.dies_supported = false; -object_unref (obj); }
@@ -602,6 +606,10 @@ static const TypeInfo smp_machine_types[] = { .class_init = machine_base_class_init, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState), + }, { + .name = MACHINE_TYPE_NAME("smp-with-dies"), + .parent = TYPE_MACHINE, + .class_init = machine_with_dies_class_init, } };
@@ -620,7 +628,7 @@ int main(int argc, char *argv[])TYPE_MACHINE , test_generic_invalid);g_test_add_data_func ("/test-smp-parse/with_dies" , -TYPE_MACHINE , +MACHINE_TYPE_NAME ("smp-with-dies" ), test_with_dies);g_test_run ();
Signature · 1 line
2.33.1
PATCH v5 4/8 tests/unit/test-smp-parse: Add 'smp-generic-invalid' machine type
In reply to Philippe Mathieu-DaudéAvoid modifying the MachineClass internals by adding the 'smp-generic-invalid' machine, which inherits from TYPE_MACHINE.
--- tests/unit/test-smp-parse.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
tests/unit/test-smp-parse.c +16 -9
@@ -487,6 +487,17 @@ static void machine_base_class_init(ObjectClass *oc, void *data) mc->name =g_strdup (SMP_MACHINE_NAME ); } +static void machine_without_dies_invalid_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + +/* Force invalid min CPUs and max CPUs */ + mc->min_cpus =2 ; + mc->max_cpus =511 ; + + mc->smp_props.dies_supported = false; +} +static void machine_with_dies_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -530,10 +541,6 @@ static void test_generic_invalid(const void *opaque)SMPTestData *data = &(SMPTestData ){};int i; -/* Force invalid min CPUs and max CPUs */ - mc->min_cpus =2 ; - mc->max_cpus =511 ; -for (i =0 ; i <ARRAY_SIZE (data_generic_invalid); i++) { *data = data_generic_invalid[i];unsupported_params_init (mc, data);
@@ -541,10 +548,6 @@ static void test_generic_invalid(const void *opaque)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); }
@@ -606,6 +609,10 @@ static const TypeInfo smp_machine_types[] = { .class_init = machine_base_class_init, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState), + }, { + .name = MACHINE_TYPE_NAME("smp-generic-invalid"), + .parent = TYPE_MACHINE, + .class_init = machine_without_dies_invalid_class_init, }, { .name = MACHINE_TYPE_NAME("smp-with-dies"), .parent = TYPE_MACHINE,
@@ -625,7 +632,7 @@ int main(int argc, char *argv[])TYPE_MACHINE , test_generic_valid);g_test_add_data_func ("/test-smp-parse/generic/invalid" , -TYPE_MACHINE , +MACHINE_TYPE_NAME ("smp-generic-invalid" ), test_generic_invalid); g_test_add_data_func("/test-smp-parse/with_dies", MACHINE_TYPE_NAME("smp-with-dies"),
Signature · 1 line
2.33.1
Re: [PATCH v5 4/8] tests/unit/test-smp-parse: Add 'smp-generic-invalid' machine type
Hi Philippe,
Quoted 54 lines · Philippe Mathieu-Daudé
Avoid modifying the MachineClass internals by adding the 'smp-generic-invalid' machine, which inherits from
TYPE_MACHINE.Reviewed-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/unit/test-smp-parse.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)tests/unit/test-smp-parse.c +11
-8@@ -487,6 +487,17 @@ static void machine_base_class_init(ObjectClass *oc, void *data) mc->name =g_strdup (SMP_MACHINE_NAME ); } +static void machine_without_dies_invalid_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + +/* Force invalid min CPUs and max CPUs */ + mc->min_cpus =2 ; + mc->max_cpus =511 ; + + mc->smp_props.dies_supported = false; +} +static void machine_with_dies_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -530,10 +541,6 @@ static void test_generic_invalid(const void *opaque)SMPTestData *data = &(SMPTestData ){};int i; -/* Force invalid min CPUs and max CPUs */ - mc->min_cpus =2 ; - mc->max_cpus =511 ; -for (i =0 ; i <ARRAY_SIZE (data_generic_invalid); i++) { *data = data_generic_invalid[i];unsupported_params_init (mc, data);@@ -541,10 +548,6 @@ static void test_generic_invalid(const void *opaque)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); }
tests/unit/test-smp-parse.c static const TypeInfo smp_machine_types[] = { · line 615
Quoted 7 lines
tests/unit/test-smp-parse.c +4
-0@@ -606,6 +609,10 @@ static const TypeInfo smp_machine_types[] = { .class_init = machine_base_class_init, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState), + }, { + .name = MACHINE_TYPE_NAME("smp-generic-invalid"), + .parent = TYPE_MACHINE, + .class_init = machine_without_dies_invalid_class_init,
Maybe it's better to rename "machine_without_dies_invalid_class_init" to "machine_generic_invalid_class_init" to be consistent with the .name field.
Thanks,
Yanan
Quoted 12 lines
tests/unit/test-smp-parse.c +1
-1}, { .name = MACHINE_TYPE_NAME("smp-with-dies"), .parent = TYPE_MACHINE,@@ -625,7 +632,7 @@ int main(int argc, char *argv[])TYPE_MACHINE , test_generic_valid);g_test_add_data_func ("/test-smp-parse/generic/invalid" , -TYPE_MACHINE , +MACHINE_TYPE_NAME ("smp-generic-invalid" ), test_generic_invalid); g_test_add_data_func("/test-smp-parse/with_dies", MACHINE_TYPE_NAME("smp-with-dies"),
Re: [PATCH v5 4/8] tests/unit/test-smp-parse: Add 'smp-generic-invalid' machine type
Quoted 20 lines · wangyanan (Y)
Hi Philippe,
Quoted 9 lines · Philippe Mathieu-Daudé
Avoid modifying the MachineClass internals by adding the 'smp-generic-invalid' machine, which inherits from
TYPE_MACHINE.Reviewed-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
tests/unit/test-smp-parse.c| 25 ++++++++++++++++---------1 file changed, 16 insertions(+), 9 deletions(-)Quoted 8 lines
@@ -606,6 +609,10 @@ static const TypeInfo smp_machine_types[] = { .class_init =
machine_base_class_init, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState),
+ }, {
+ .name =MACHINE_TYPE_NAME("smp-generic-invalid"), + .parent =TYPE_MACHINE,
+ .class_init =machine_without_dies_invalid_class_init,
Quoted 2 lines
Maybe it's better to rename "
machine_without_dies_invalid_class_init" to "machine_generic_invalid_class_init" to be consistent with the .name field.
Indeed I missed that... Thanks.
PATCH v5 5/8 tests/unit/test-smp-parse: Add 'smp-generic-valid' machine type
In reply to Philippe Mathieu-DaudéKeep the common TYPE_MACHINE class initialization in machine_base_class_init(), make it abstract, and move the non-common code to a new class: "smp-generic-valid".
--- tests/unit/test-smp-parse.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
tests/unit/test-smp-parse.c +15 -4
@@ -478,13 +478,19 @@ static void machine_base_class_init(ObjectClass *oc, void *data) {MachineClass *mc =MACHINE_CLASS (oc); + mc->smp_props.prefer_sockets = true; + + mc->name =g_strdup (SMP_MACHINE_NAME ); +} + +static void machine_without_dies_valid_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 machine_without_dies_invalid_class_init (ObjectClass *oc,void *data)
@@ -606,9 +612,14 @@ static const TypeInfo smp_machine_types[] = { { .name = TYPE_MACHINE, .parent = TYPE_OBJECT, + .abstract = true, .class_init = machine_base_class_init, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState), + }, { + .name = MACHINE_TYPE_NAME("smp-generic-valid"), + .parent = TYPE_MACHINE, + .class_init = machine_without_dies_valid_class_init, }, { .name = MACHINE_TYPE_NAME("smp-generic-invalid"), .parent = TYPE_MACHINE,
@@ -629,7 +640,7 @@ int main(int argc, char *argv[])g_test_init (&argc, &argv,NULL );g_test_add_data_func ("/test-smp-parse/generic/valid" , -TYPE_MACHINE , +MACHINE_TYPE_NAME ("smp-generic-valid" ), test_generic_valid); g_test_add_data_func("/test-smp-parse/generic/invalid", MACHINE_TYPE_NAME("smp-generic-invalid"),
Signature · 1 line
2.33.1
Re: [PATCH v5 5/8] tests/unit/test-smp-parse: Add 'smp-generic-valid' machine type
Quoted 39 lines · Philippe Mathieu-Daudé
Keep the common
TYPE_MACHINEclass initialization inmachine_base_class_init(), make it abstract, and move the non-common code to a new class: "smp-generic-valid".Reviewed-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/unit/test-smp-parse.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)tests/unit/test-smp-parse.c +9
-3@@ -478,13 +478,19 @@ static void machine_base_class_init(ObjectClass *oc, void *data) {MachineClass *mc =MACHINE_CLASS (oc); + mc->smp_props.prefer_sockets = true; + + mc->name =g_strdup (SMP_MACHINE_NAME ); +} + +static void machine_without_dies_valid_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 machine_without_dies_invalid_class_init (ObjectClass *oc,void *data)@@ -606,9 +612,14 @@ static const TypeInfo smp_machine_types[] = { {
tests/unit/test-smp-parse.c static const TypeInfo smp_machine_types[] = { · line 622
Quoted 10 lines
tests/unit/test-smp-parse.c +5
-0.name = TYPE_MACHINE, .parent = TYPE_OBJECT, + .abstract = true, .class_init = machine_base_class_init, .class_size = sizeof(MachineClass), .instance_size = sizeof(MachineState), + }, { + .name = MACHINE_TYPE_NAME("smp-generic-valid"), + .parent = TYPE_MACHINE, + .class_init = machine_without_dies_valid_class_init,
Similar to patch #4, can we also rename "machine_without_dies_valid_class_init" to "machine_generic_valid_class_init" ?
Thanks,
Yanan
Quoted 12 lines
tests/unit/test-smp-parse.c +1
-1}, { .name = MACHINE_TYPE_NAME("smp-generic-invalid"), .parent = TYPE_MACHINE,@@ -629,7 +640,7 @@ int main(int argc, char *argv[])g_test_init (&argc, &argv,NULL );g_test_add_data_func ("/test-smp-parse/generic/valid" , -TYPE_MACHINE , +MACHINE_TYPE_NAME ("smp-generic-valid" ), test_generic_valid); g_test_add_data_func("/test-smp-parse/generic/invalid", MACHINE_TYPE_NAME("smp-generic-invalid"),
PATCH v5 6/8 tests/unit/test-smp-parse: Simplify pointer to compound literal use
In reply to Philippe Mathieu-DaudéWe can simply use a local variable (and pass its pointer) instead of a pointer to a compound literal.
--- tests/unit/test-smp-parse.c | 66 ++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-)
tests/unit/test-smp-parse.c +33 -33
@@ -520,19 +520,19 @@ static void test_generic_valid(const void *opaque)Object *obj =object_new (machine_type);MachineState *ms =MACHINE (obj);MachineClass *mc =MACHINE_GET_CLASS (obj); -SMPTestData *data = &(SMPTestData ){{ }}; +SMPTestData data = {};int i;for (i =0 ; i <ARRAY_SIZE (data_generic_valid); i++) { - *data = data_generic_valid[i]; -unsupported_params_init (mc, data); + data = data_generic_valid[i]; +unsupported_params_init (mc, &data); -smp_parse_test (ms, data, true); +smp_parse_test (ms, &data, true);/* Unsupported parameters can be provided with their values as 1 */ - data->config.has_dies = true; - data->config.dies =1 ; -smp_parse_test (ms, data, true); + data.config.has_dies = true; + data.config.dies =1 ; +smp_parse_test (ms, &data, true); }object_unref (obj);
@@ -544,14 +544,14 @@ static void test_generic_invalid(const void *opaque)Object *obj =object_new (machine_type);MachineState *ms =MACHINE (obj);MachineClass *mc =MACHINE_GET_CLASS (obj); -SMPTestData *data = &(SMPTestData ){}; +SMPTestData data = {};int i;for (i =0 ; i <ARRAY_SIZE (data_generic_invalid); i++) { - *data = data_generic_invalid[i]; -unsupported_params_init (mc, data); + data = data_generic_invalid[i]; +unsupported_params_init (mc, &data); -smp_parse_test (ms, data, false); +smp_parse_test (ms, &data, false); }object_unref (obj);
@@ -563,45 +563,45 @@ static void test_with_dies(const void *opaque)Object *obj =object_new (machine_type);MachineState *ms =MACHINE (obj);MachineClass *mc =MACHINE_GET_CLASS (obj); -SMPTestData *data = &(SMPTestData ){{ }}; +SMPTestData data = {};unsigned int num_dies =2 ;int i;for (i =0 ; i <ARRAY_SIZE (data_generic_valid); i++) { - *data = data_generic_valid[i]; -unsupported_params_init (mc, data); + data = data_generic_valid[i]; +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.dies =1 ; + data.expect_prefer_cores.dies =1 ; -smp_parse_test (ms, data, true); +smp_parse_test (ms, &data, true);/* when dies parameter is specified */ - data->config.has_dies = true; - data->config.dies = num_dies; -if (data->config.has_cpus) { - data->config.cpus *= num_dies; + data.config.has_dies = true; + data.config.dies = num_dies; +if (data.config.has_cpus) { + data.config.cpus *= num_dies; } -if (data->config.has_maxcpus) { - data->config.maxcpus *= num_dies; +if (data.config.has_maxcpus) { + data.config.maxcpus *= num_dies; } - data->expect_prefer_sockets.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.cpus *= num_dies; - data->expect_prefer_cores.max_cpus *= num_dies; + data.expect_prefer_sockets.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.cpus *= num_dies; + data.expect_prefer_cores.max_cpus *= num_dies; -smp_parse_test (ms, data, true); +smp_parse_test (ms, &data, true); }for (i =0 ; i <ARRAY_SIZE (data_with_dies_invalid); i++) { - *data = data_with_dies_invalid[i]; -unsupported_params_init (mc, data); + data = data_with_dies_invalid[i]; +unsupported_params_init (mc, &data); -smp_parse_test (ms, data, false); +smp_parse_test (ms, &data, false); }object_unref (obj);
Signature · 1 line
2.33.1
PATCH v5 7/8 tests/unit/test-smp-parse: Constify some pointer/struct
In reply to Philippe Mathieu-DaudéDeclare structures const when we don't need to modify them at runtime.
--- tests/unit/test-smp-parse.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tests/unit/test-smp-parse.c +6 -6
@@ -83,7 +83,7 @@ typedef struct SMPTestData {* then test the automatic calculation algorithm of the missing * values in the parser. */ -static struct SMPTestData data_generic_valid[] = { +static const struct SMPTestData data_generic_valid[] = { {/* config: no configuration provided * expect: cpus=1,sockets=1,cores=1,threads=1,maxcpus=1 */
@@ -285,7 +285,7 @@ static struct SMPTestData data_generic_valid[] = { }, }; -static struct SMPTestData data_generic_invalid[] = { +static const struct SMPTestData data_generic_invalid[] = { {/* config: -smp 2,dies=2 */ .config =SMP_CONFIG_WITH_DIES (T ,2 ,F ,0 ,T ,2 ,F ,0 ,F ,0 ,F ,0 ),
@@ -319,7 +319,7 @@ static struct SMPTestData data_generic_invalid[] = { }, }; -static struct SMPTestData data_with_dies_invalid[] = { +static const struct SMPTestData data_with_dies_invalid[] = { {/* config: -smp 16,sockets=2,dies=2,cores=4,threads=2,maxcpus=16 */ .config =SMP_CONFIG_WITH_DIES (T ,16 ,T ,2 ,T ,2 ,T ,4 ,T ,2 ,T ,16 ),
@@ -356,7 +356,7 @@ static char *smp_config_to_string(SMPConfiguration *config) config->has_maxcpus ? "true" : "false", config->maxcpus); } -static char *cpu_topology_to_string (CpuTopology *topo) +static char *cpu_topology_to_string (const CpuTopology *topo) {return g_strdup_printf ( "(CpuTopology) {\n"
@@ -372,7 +372,7 @@ static char *cpu_topology_to_string(CpuTopology *topo) }static void check_parse (MachineState *ms,SMPConfiguration *config, -CpuTopology *expect_topo,const char *expect_err, +const CpuTopology *expect_topo,const char *expect_err,bool is_valid) { g_autofree char *config_str = smp_config_to_string(config);
@@ -466,7 +466,7 @@ static void smp_parse_test(MachineState *ms, SMPTestData *data, bool is_valid) }/* The parsed results of the unsupported parameters should be 1 */ -static void unsupported_params_init (MachineClass *mc,SMPTestData *data) +static void unsupported_params_init (const MachineClass *mc,SMPTestData *data) {if (!mc->smp_props.dies_supported) { data->expect_prefer_sockets.dies =1 ;
Signature · 1 line
2.33.1
PATCH v5 8/8 hw/core: Rename smp_parse() -> machine_parse_smp_config()
In reply to Philippe Mathieu-DaudéAll methods related to MachineState are prefixed with "machine_". smp_parse() does not need to be an exception. Rename it and const'ify the SMPConfiguration argument, since it doesn't need to be modified.
--- include/hw/boards.h | 3 ++- hw/core/machine-smp.c | 6 ++++-- hw/core/machine.c | 2 +- tests/unit/test-smp-parse.c | 8 ++++---- 4 files changed, 11 insertions(+), 8 deletions(-)
include/hw/boards.h +2 -1
@@ -34,7 +34,8 @@ HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);void machine_set_cpu_numa_node (MachineState *machine,const CpuInstanceProperties *props,Error **errp); -void smp_parse (MachineState *ms,SMPConfiguration *config,Error **errp); +void machine_parse_smp_config (MachineState *ms, +const SMPConfiguration *config,Error **errp);/** * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
hw/core/machine-smp.c +4 -2
@@ -44,7 +44,8 @@ static char *cpu_hierarchy_to_string(MachineState *ms) }/* -* smp_parse - Generic function used to parse the given SMP configuration +* machine_parse_smp_config: Generic function used to parse the given +* SMP configuration * * Any missing parameter in "cpus/maxcpus/sockets/cores/threads" will be * automatically computed based on the provided ones.
@@ -63,7 +64,8 @@ static char *cpu_hierarchy_to_string(MachineState *ms)* introduced topology members which are likely to be target specific should * be directly set as 1 if they are omitted (e.g. dies for PC since 4.1). */ -void smp_parse (MachineState *ms,SMPConfiguration *config,Error **errp) +void machine_parse_smp_config (MachineState *ms, +const SMPConfiguration *config,Error **errp) {MachineClass *mc =MACHINE_GET_CLASS (ms);unsigned cpus = config->has_cpus ? config->cpus :0 ;
hw/core/machine.c +1 -1
@@ -761,7 +761,7 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name,return ; } -smp_parse (ms, config, errp); +machine_parse_smp_config (ms, config, errp); }static void machine_class_init (ObjectClass *oc,void *data)
tests/unit/test-smp-parse.c +4 -4
@@ -337,7 +337,7 @@ static const struct SMPTestData data_with_dies_invalid[] = { }, }; -static char *smp_config_to_string (SMPConfiguration *config) +static char *smp_config_to_string (const SMPConfiguration *config) {return g_strdup_printf ( "(SMPConfiguration) {\n"
@@ -371,7 +371,7 @@ static char *cpu_topology_to_string(const CpuTopology *topo) topo->cores, topo->threads, topo->max_cpus); } -static void check_parse (MachineState *ms,SMPConfiguration *config, +static void check_parse (MachineState *ms,const SMPConfiguration *config,const CpuTopology *expect_topo,const char *expect_err,bool is_valid) {
@@ -380,8 +380,8 @@ static void check_parse(MachineState *ms, SMPConfiguration *config, g_autofree char *output_topo_str = NULL;Error *err =NULL ; -/* call the generic parser smp_parse() */ -smp_parse (ms, config, &err); +/* call the generic parser */ +machine_parse_smp_config (ms, config, &err); output_topo_str =cpu_topology_to_string (&ms->smp);
Signature · 1 line
2.33.1