All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "wangyanan (Y)" <wangyanan55@huawei.com>, qemu-devel@nongnu.org
Cc: Andrew Jones <drjones@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>
Subject: Re: [PATCH v4 2/2] tests/unit: Add an unit test for smp parsing
Date: Thu, 11 Nov 2021 10:37:45 +0100	[thread overview]
Message-ID: <440cee74-13e0-ba38-070f-49f939f33319@redhat.com> (raw)
In-Reply-To: <14250bbd-c3fb-9afc-f08d-587326f0382c@huawei.com>

On 11/11/21 10:31, wangyanan (Y) wrote:
> 
> On 2021/11/11 17:14, Philippe Mathieu-Daudé wrote:
>> On 10/28/21 17:09, Philippe Mathieu-Daudé wrote:
>>> From: Yanan Wang <wangyanan55@huawei.com>
>>>
>>> Now that we have a generic parser smp_parse(), let's add an unit
>>> test for the code. All possible valid/invalid SMP configurations
>>> that the user can specify are covered.
>>>
>>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
>>> Reviewed-by: Andrew Jones <drjones@redhat.com>
>>> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>> Message-Id: <20211026034659.22040-3-wangyanan55@huawei.com>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>> ---
>>>   tests/unit/test-smp-parse.c | 594 ++++++++++++++++++++++++++++++++++++
>>>   MAINTAINERS                 |   1 +
>>>   tests/unit/meson.build      |   1 +
>>>   3 files changed, 596 insertions(+)
>>>   create mode 100644 tests/unit/test-smp-parse.c
>>> +static struct SMPTestData data_generic_valid[] = {
>>> +    {
>>> +        /* config: no configuration provided
>>> +         * expect: cpus=1,sockets=1,cores=1,threads=1,maxcpus=1 */
>> [1]
>>
>>> +        .config = SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, F, 0, F, 0),
>>> +        .expect_prefer_sockets = CPU_TOPOLOGY_GENERIC(1, 1, 1, 1, 1),
>>> +        .expect_prefer_cores   = CPU_TOPOLOGY_GENERIC(1, 1, 1, 1, 1),
>>> +    }, {
>>> +static void test_generic(void)
>>> +{
>>> +    Object *obj = object_new(TYPE_MACHINE);
>>> +    MachineState *ms = MACHINE(obj);
>>> +    MachineClass *mc = MACHINE_GET_CLASS(obj);
>> Watch out, while you create a machine instance in each
>> test, there is only one machine class registered (see
>> type_register_static(&smp_machine_info) below in [2]),
>> ...
> Yes, I noticed this. So on the top of each sub-test function, the
> properties
> of the single machine class is re-initialized by
> smp_machine_class_init(mc).
> See [*] below.
>>> +    SMPTestData *data = &(SMPTestData){0};
>>> +    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);
>>> +
>>> +        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);
>>> +    }
>>> +
>>> +    /* Reset the supported min CPUs and max CPUs */
>>> +    mc->min_cpus = 2;
>>> +    mc->max_cpus = 511;
>> ... and here you are modifying the single machine class state, ...
>>
>>> +
>>> +    for (i = 0; i < ARRAY_SIZE(data_generic_invalid); i++) {
>>> +        *data = data_generic_invalid[i];
>>> +        unsupported_params_init(mc, data);
>>> +
>>> +        smp_parse_test(ms, data, false);
>>> +    }
>>> +
>>> +    object_unref(obj);
>>> +}
>>> +
>>> +static void test_with_dies(void)
>>> +{
>>> +    Object *obj = object_new(TYPE_MACHINE);
>>> +    MachineState *ms = MACHINE(obj);
>>> +    MachineClass *mc = MACHINE_GET_CLASS(obj);
>> ... so here the machine class state is inconsistent, ...
>>
>>> +    SMPTestData *data = &(SMPTestData){0};
>>> +    unsigned int num_dies = 2;
>>> +    int i;
>>> +
>>> +    smp_machine_class_init(mc);
> And here [*].
>>> +    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);
>>> +
>>> +        /* when dies parameter is omitted, it will be set as 1 */
>>> +        data->expect_prefer_sockets.dies = 1;
>>> +        data->expect_prefer_cores.dies = 1;
>>> +
>>> +        smp_parse_test(ms, data, true);
>> ... in particular the first test [1] is tested with mc->min_cpus = 2.
>>
>> I wonder why you are not getting:
>>
>> Output error report: Invalid SMP CPUs 1. The min CPUs supported by
>> machine '(null)' is 2
>>
>> for [1].
> So as I have explained above, we won't get an output error report like
> this here. :)

I see. IMHO this is bad practice example, so I'll send a cleanup patch.



  reply	other threads:[~2021-11-11  9:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28 15:09 [PATCH v4 0/2] hw/core/machine: Add an unit test for smp_parse Philippe Mathieu-Daudé
2021-10-28 15:09 ` [PATCH v4 1/2] hw/core/machine: Split out the smp parsing code Philippe Mathieu-Daudé
2021-10-28 15:09 ` [PATCH v4 2/2] tests/unit: Add an unit test for smp parsing Philippe Mathieu-Daudé
2021-10-31 12:02   ` wangyanan (Y)
2021-11-01 10:43     ` Philippe Mathieu-Daudé
2021-11-09  9:36   ` Philippe Mathieu-Daudé
2021-11-09 12:10     ` wangyanan (Y)
2021-11-09 12:18     ` wangyanan (Y)
2021-11-10  8:10       ` Thomas Huth
2021-11-11  9:14   ` Philippe Mathieu-Daudé
2021-11-11  9:31     ` wangyanan (Y)
2021-11-11  9:37       ` Philippe Mathieu-Daudé [this message]
2021-11-11 13:00         ` wangyanan (Y)
2021-10-29 17:10 ` [PATCH v4 0/2] hw/core/machine: Add an unit test for smp_parse Eduardo Habkost
2021-11-01 18:28 ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=440cee74-13e0-ba38-070f-49f939f33319@redhat.com \
    --to=philmd@redhat.com \
    --cc=drjones@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wangyanan55@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.