From nobody Sun Feb 8 17:22:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666620996; cv=none; d=zohomail.com; s=zohoarc; b=gzVAMt4/SNpEF4h5Al0Ei3+bTafN2G+uUV/fOEchlHPqoJggMBUhIAD+YK4pWu0p6buT0AfQ4qM/vX5VuMI9tvdpLBGE4AiAZpKusftxPQTNjpaLWvZByyQ7ttO7zBfugUH2n8XGDxBikeXTmzFqHNy7tHRgAA2/y7bytJ9G138= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666620996; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=roE4X0BB486r+S2hLsIiPmap8HvgVyTI/Stei411OfY=; b=nxT4KmEU/+ieH6LJ4HOybK1WW9c2HX6bXfY/7TKr+JC40jrmMeTcBXsDRqjQtu2/g1Jbn7aRWM565yS0VlMFaDCfvBXPyqKK12s6bziINzBDsnhMJDLJjVx4xQS+5mVzkf/Q6xO07AcWRGynr9AABO/VGoSE9pZ8kjSCs2L3uFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1666620996050286.6136316275042; Mon, 24 Oct 2022 07:16:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-333-WAWGEfuDO2SLw8CXDkhDYw-1; Mon, 24 Oct 2022 10:16:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3543486C175; Mon, 24 Oct 2022 14:15:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 211D4200C0CD; Mon, 24 Oct 2022 14:15:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1365F19465A0; Mon, 24 Oct 2022 14:15:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8955A1946594 for ; Mon, 24 Oct 2022 14:15:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7AB5F40C2064; Mon, 24 Oct 2022 14:15:26 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5769240C2088 for ; Mon, 24 Oct 2022 14:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666620995; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=roE4X0BB486r+S2hLsIiPmap8HvgVyTI/Stei411OfY=; b=U4owWaJEpPDTp244cLHIeB4d4To+dqaCue27WcIaoiJH3mMVapTAC3GRdMME2NSI7EKUgx RCZ+l/iumKGANTEitLANcQj7nARxzR++GwVerNyt3ptVFR58geEJK1bFLXe+SnihXfCVA+ UikvJysuIgGCkbsceZbQC9r3tUJt2O8= X-MC-Unique: WAWGEfuDO2SLw8CXDkhDYw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 22/43] testParseNodeInfo: Rewrite to virXPathU(Int|LongLong) Date: Mon, 24 Oct 2022 16:14:27 +0200 Message-Id: <05bd4691e5d0d7e6f86cbef003396e83a3de5fc5.1666619795.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666620996526100001 Content-Type: text/plain; charset="utf-8" Use the function for appropriate types and simplify the error logic. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/test/test_driver.c | 51 +++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 67c70de11d..5a988fbcbd 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -874,41 +874,30 @@ testParseXMLDocFromFile(xmlNodePtr node, static int testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathContextPtr ctxt) { - long l; - int ret; g_autofree char *str =3D NULL; + unsigned int activeCpus; + unsigned long long memory =3D 0; + int rc; - ret =3D virXPathLong("string(/node/cpu/nodes[1])", ctxt, &l); - if (ret =3D=3D 0) { - nodeInfo->nodes =3D l; - } else if (ret =3D=3D -2) { + if (virXPathUInt("string(/node/cpu/nodes[1])", ctxt, &nodeInfo->nodes)= =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node cpu nodes value")); return -1; } - ret =3D virXPathLong("string(/node/cpu/sockets[1])", ctxt, &l); - if (ret =3D=3D 0) { - nodeInfo->sockets =3D l; - } else if (ret =3D=3D -2) { + if (virXPathUInt("string(/node/cpu/sockets[1])", ctxt, &nodeInfo->sock= ets) =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node cpu sockets value")); return -1; } - ret =3D virXPathLong("string(/node/cpu/cores[1])", ctxt, &l); - if (ret =3D=3D 0) { - nodeInfo->cores =3D l; - } else if (ret =3D=3D -2) { + if (virXPathUInt("string(/node/cpu/cores[1])", ctxt, &nodeInfo->cores)= =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node cpu cores value")); return -1; } - ret =3D virXPathLong("string(/node/cpu/threads[1])", ctxt, &l); - if (ret =3D=3D 0) { - nodeInfo->threads =3D l; - } else if (ret =3D=3D -2) { + if (virXPathUInt("string(/node/cpu/threads[1])", ctxt, &nodeInfo->thre= ads) =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node cpu threads value")); return -1; @@ -916,19 +905,19 @@ testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathCo= ntextPtr ctxt) nodeInfo->cpus =3D (nodeInfo->cores * nodeInfo->threads * nodeInfo->sockets * nodeInfo->nodes); - ret =3D virXPathLong("string(/node/cpu/active[1])", ctxt, &l); - if (ret =3D=3D 0) { - if (l < nodeInfo->cpus) - nodeInfo->cpus =3D l; - } else if (ret =3D=3D -2) { + + if ((rc =3D virXPathUInt("string(/node/cpu/active[1])", ctxt, &activeC= pus)) =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node cpu active value")); return -1; } - ret =3D virXPathLong("string(/node/cpu/mhz[1])", ctxt, &l); - if (ret =3D=3D 0) { - nodeInfo->mhz =3D l; - } else if (ret =3D=3D -2) { + + if (rc =3D=3D 0) { + if (activeCpus < nodeInfo->cpus) + nodeInfo->cpus =3D activeCpus; + } + + if (virXPathUInt("string(/node/cpu/mhz[1])", ctxt, &nodeInfo->mhz) =3D= =3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node cpu mhz value")); return -1; @@ -943,15 +932,15 @@ testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathCo= ntextPtr ctxt) } } - ret =3D virXPathLong("string(/node/memory[1])", ctxt, &l); - if (ret =3D=3D 0) { - nodeInfo->memory =3D l; - } else if (ret =3D=3D -2) { + if ((rc =3D virXPathULongLong("string(/node/memory[1])", ctxt, &memory= )) =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node memory value")); return -1; } + if (rc =3D=3D 0) + nodeInfo->memory =3D memory; + return 0; } --=20 2.37.3