From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0698DC433F5 for ; Thu, 11 Nov 2021 09:15:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 52C046124C for ; Thu, 11 Nov 2021 09:15:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 52C046124C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:42768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml6B2-0003rn-5k for qemu-devel@archiver.kernel.org; Thu, 11 Nov 2021 04:15:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml69r-00039h-Tw for qemu-devel@nongnu.org; Thu, 11 Nov 2021 04:14:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:59628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml69n-000311-UA for qemu-devel@nongnu.org; Thu, 11 Nov 2021 04:14:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636622045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XwIjkVZjRCDBs+z1W2ncNPi85WKKXgVUn3KRHbfoRj4=; b=ZI3vEC4zZ595Lff1ctyj9A3SRHJY8Deg5YUeUZgIDyTTg1Br1YjYr4TOj8TGO/PKn5LRcr mKel7mqxO7RDy2tjBQGlM4cI1jRQ2X8ODx4X0reHtb+cJpIlkcqS2WnCZGaqTu3wB9iMkh SUlJiAqy6pLyIMdC035pNUST08JQ2Qs= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-mDj9V22sMMG1i_qi3fx8sw-1; Thu, 11 Nov 2021 04:14:04 -0500 X-MC-Unique: mDj9V22sMMG1i_qi3fx8sw-1 Received: by mail-wr1-f71.google.com with SMTP id w14-20020adfbace000000b001884bf6e902so897933wrg.3 for ; Thu, 11 Nov 2021 01:14:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=XwIjkVZjRCDBs+z1W2ncNPi85WKKXgVUn3KRHbfoRj4=; b=qq71jSamOYLCaTmMQOuwLCRy2MiE+S5xylGGFORKraDgmjmgWrbMq/o1SaqGYt9cQE e2gZxuSaZO+lZBtMPrP7jCd1MRPMPveemMjbBLfOt4j2+NbEjf3tjKBN7v8/LMSAsG8h ykB7jgpQpqOkxNF4LVvs5GSQl4meRBhLnFkkSgthL2r1vPre+lssTKTqTUssYSrmRCVK sswgXfn0wWoYq7mX208fTuDAHy8STcx5ExY12/0VRG+j71YGTVo0aSFXT+mJw7n0Sa51 APdBYQ8LXuMA8LJ2UYtKrhQcqGiba3PFw4q5Gl7/x4ck1buAM0koed2JBD47EmR9InG8 IUjw== X-Gm-Message-State: AOAM533Kc7jLNFEC7WqRMF4d8TxWGkwVBT18GvebQWWs0Ok+RypK1Daz SXKtOds7HdR6z90bnBxNM2p9kmKRdjv5PcJC+dzgSUuuCRACdoIkIgxGuUGsG8f6iy7HxliXRXe NgH/FiVw9+mwuGx1jbM8tLIa2W0GsrmoKlfzoWgyoLFm3Lvher5/Uq1CAi0qeq2gx X-Received: by 2002:adf:eb4b:: with SMTP id u11mr6993662wrn.49.1636622042865; Thu, 11 Nov 2021 01:14:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGVcZPLxtkxlNKQHkeioAVAATJHPKEGFKuv3fkJ2bPMnKaVUEYkGo9oMlBDP6KMBg0h9MBGw== X-Received: by 2002:adf:eb4b:: with SMTP id u11mr6993630wrn.49.1636622042534; Thu, 11 Nov 2021 01:14:02 -0800 (PST) Received: from [192.168.1.36] (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id h16sm2648545wrm.27.2021.11.11.01.14.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Nov 2021 01:14:02 -0800 (PST) Message-ID: Date: Thu, 11 Nov 2021 10:14:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v4 2/2] tests/unit: Add an unit test for smp parsing To: qemu-devel@nongnu.org References: <20211028150913.1975305-1-philmd@redhat.com> <20211028150913.1975305-3-philmd@redhat.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= In-Reply-To: <20211028150913.1975305-3-philmd@redhat.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -74 X-Spam_score: -7.5 X-Spam_bar: ------- X-Spam_report: (-7.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-3.999, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yanan Wang , Andrew Jones , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 10/28/21 17:09, Philippe Mathieu-Daudé wrote: > From: Yanan Wang > > 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 > Reviewed-by: Andrew Jones > Tested-by: Philippe Mathieu-Daudé > Message-Id: <20211026034659.22040-3-wangyanan55@huawei.com> > Signed-off-by: Philippe Mathieu-Daudé > --- > 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]), ... > + 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); > + 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]. > + > + /* 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; > + } > + 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; > + > + 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); > + > + smp_parse_test(ms, data, false); > + } > + > + object_unref(obj); > +} > + > +int main(int argc, char *argv[]) > +{ > + g_test_init(&argc, &argv, NULL); > + > + module_call_init(MODULE_INIT_QOM); > + type_register_static(&smp_machine_info); [2]