From nobody Sun May 19 02:26:46 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1588769700; cv=none; d=zohomail.com; s=zohoarc; b=b7X4X7aLS8iDmXdp6AIHW6xKgzaBw+JpiJkJXb4OweTHhJLxNT9InbFjieiWAmym/D242F87DGuS8mj0Vj1sYsaNHZWnFzMEpoX4gR04tZTgacDN20md0QdkhWU9sNPMYHS93/Y8RQGNUmtRCzDo94njw5SkmbN/Z1D3JgaH218= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588769700; 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=6va4obbUuvReza+slv4bhHPSxmK25SueT/uMCz42r2A=; b=bl6WfC0IHKNIr754I/DyGzLkDNMBWpbsjQVXxqIac7vuhlvymtQPOS337SMP7Zfx3iOfsqx0Ll6WP3PCz1ebffiBh691D3EfAyCxpYfCqLUrT2wygFuIj3Zd2bfMJvLOz6lPdgj/g/VfAh0xHmebcH/zSjoWfX7dEHYUic1GugY= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= 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 1588769700404624.0850532587586; Wed, 6 May 2020 05:55:00 -0700 (PDT) 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-148-u6xcgBpjP_CcPlVR7qEKfw-1; Wed, 06 May 2020 08:54:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FBE7872FED; Wed, 6 May 2020 12:54:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61B7126552; Wed, 6 May 2020 12:54:23 +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 1C91F1809557; Wed, 6 May 2020 12:54:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 046CsEad000881 for ; Wed, 6 May 2020 08:54:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDA8626552; Wed, 6 May 2020 12:54:14 +0000 (UTC) Received: from kinshicho.usersys.redhat.com (unknown [10.40.194.206]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15E0B27C39 for ; Wed, 6 May 2020 12:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588769699; 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=6va4obbUuvReza+slv4bhHPSxmK25SueT/uMCz42r2A=; b=VNJhrmiVqA2getnRCmSj65nqTVNFCPUqG35BIhQWNoRop4eMa2NhuWVbB3aclIuvsXrRrj GePJYmKJb5zRO80K9UVyKOu7U1zigkfg7skEznYcWH791AUrw3bXI1/EiATvNccngm/eE5 DnvrraYJ1VH75umEfNLw8v3NgTvg6+Y= X-MC-Unique: u6xcgBpjP_CcPlVR7qEKfw-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/1] tests: Introduce virhostdevmock Date: Wed, 6 May 2020 14:54:06 +0200 Message-Id: <20200506125406.599106-2-abologna@redhat.com> In-Reply-To: <20200506125406.599106-1-abologna@redhat.com> References: <20200506125406.599106-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.84 on 10.5.11.23 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" We need this for all tests that use virHostdevManager, because during creation of this object for unprivileged connections like those used in the test suite we would end up writing inside the user's home directory. That's bad manners in general, but when running the test suite inside a purposefully constrained environment such as the one exposed by pbuilder, it turns into an outright test failure: Could not initialize HostdevManager - operation failed: Failed to create state dir '/nonexistent/.cache/libvirt/hostdevmgr' Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- tests/Makefile.am | 7 +++++++ tests/qemuhotplugtest.c | 1 + tests/virhostdevmock.c | 29 +++++++++++++++++++++++++++++ tests/virhostdevtest.c | 4 +++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/virhostdevmock.c diff --git a/tests/Makefile.am b/tests/Makefile.am index ada5b8fc57..fc516376b4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -212,6 +212,7 @@ test_libraries =3D libshunload.la \ libvirnetdaemonmock.la \ libvirnetserverclientmock.la \ libvircgroupmock.la \ + libvirhostdevmock.la \ libvirpcimock.la \ libvirnetdevmock.la \ libvirrandommock.la \ @@ -1226,6 +1227,12 @@ libvirfilecachemock_la_SOURCES =3D \ libvirfilecachemock_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) libvirfilecachemock_la_LIBADD =3D $(MOCKLIBS_LIBS) =20 +libvirhostdevmock_la_SOURCES =3D \ + virhostdevmock.c \ + $(NULL) +libvirhostdevmock_la_LDFLAGS =3D $(MOCKLIBS_LDFLAGS) +libvirhostdevmock_la_LIBADD =3D $(MOCKLIBS_LIBS) + if WITH_LINUX vircaps2xmltest_SOURCES =3D \ vircaps2xmltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper= .c diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 9a215ab303..cf87de187f 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -900,6 +900,7 @@ mymain(void) } =20 VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("virhostdev"), VIR_TEST_MOCK("virpci"), VIR_TEST_MOCK("domaincaps"), VIR_TEST_MOCK("virprocess"), diff --git a/tests/virhostdevmock.c b/tests/virhostdevmock.c new file mode 100644 index 0000000000..8658d9affd --- /dev/null +++ b/tests/virhostdevmock.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 Red Hat, Inc. + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include + +#include "virutil.h" +#include "virmock.h" + +static char *(*real_virGetUserRuntimeDirectory)(void); + +static void +init_syms(void) +{ + if (real_virGetUserRuntimeDirectory) + return; + + VIR_MOCK_REAL_INIT(virGetUserRuntimeDirectory); +} + +char * +virGetUserRuntimeDirectory(void) +{ + init_syms(); + + return g_build_filename(g_getenv("LIBVIRT_FAKE_ROOT_DIR"), + "user-runtime-directory", NULL); +} diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index b6260bd9c1..b0bad683a8 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -628,7 +628,9 @@ mymain(void) return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 -VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virpci")) +VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("virhostdev"), + VIR_TEST_MOCK("virpci")) #else int main(void) --=20 2.25.4