From nobody Sun Feb 8 10:29:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1581212009915671.3887203404429; Sat, 8 Feb 2020 17:33:29 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-112-N230KZllPW-R9unLT0m5jA-1; Sat, 08 Feb 2020 20:33:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77C8EDB23; Sun, 9 Feb 2020 01:33:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 512BB8680D; Sun, 9 Feb 2020 01:33:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0CE0B866C1; Sun, 9 Feb 2020 01:33:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0191WvN0021204 for ; Sat, 8 Feb 2020 20:32:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4F2015C21B; Sun, 9 Feb 2020 01:32:57 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-20.brq.redhat.com [10.40.200.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 965635C28F for ; Sun, 9 Feb 2020 01:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581212008; 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=ZeFiky3ugkCpJ4TuWdQrECfEjh0XjG4dNg0zrE/foHw=; b=KR7Rd12CTlnfnnD0Y7mmnMt5VDNIlF/RSG8Zt6VJ5nUJ2jI/kL+32ELJb9BUzBgd7noLgk g8don0dgSdrIwwkkj+j98aiwFKWIb0jck5GUdVS8Z7PPw5oKzE36ughwNi13mXxwX94w1j 6aqmP3nFf6y7aX0MpU+xeCHvnxk4JUc= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 6/7] virshtest: use virCommand instead of custom impl Date: Sun, 9 Feb 2020 02:32:36 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: N230KZllPW-R9unLT0m5jA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Our virCommand helper API already has the ability to capture program output, there's no need to open-code it. Apart from simplifying the code, the test is marginally faster due to recent improvements in virCommandMassClose. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/virshtest.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 83675710ea..add33215b7 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -5,6 +5,7 @@ #include "internal.h" #include "virxml.h" #include "testutils.h" +#include "vircommand.h" #include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE @@ -61,10 +62,26 @@ testCompareOutputLit(const char *expectData, const char *filter, const char *const argv[]) { g_autofree char *actualData =3D NULL; + const char *empty =3D ""; + g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *errbuf =3D NULL; =20 - if (virTestCaptureProgramOutput(argv, &actualData, 4096) < 0) + if (!(cmd =3D virCommandNewArgs(argv))) return -1; =20 + virCommandAddEnvString(cmd, "LANG=3DC"); + virCommandSetInputBuffer(cmd, empty); + virCommandSetOutputBuffer(cmd, &actualData); + virCommandSetErrorBuffer(cmd, &errbuf); + + if (virCommandRun(cmd, NULL) < 0) + return -1; + + if (STRNEQ(errbuf, "")) { + fprintf(stderr, "Command reported error: %s", errbuf); + return -1; + } + if (filter && testFilterLine(actualData, filter) < 0) return -1; =20 --=20 2.21.1