From nobody Tue Sep 9 03:38:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1749732724; cv=none; d=zohomail.com; s=zohoarc; b=dZMeM41wy4cl89XazardrxY+UwslxeasNsa7a6YA/wz+8ClzjiiWSGAkhMuP9Er6oBTHdWekrj3yMBs8X1VZC+Qj8DHu2VNF0uy4bqbCwDQTJ44dIVOZZfmCiAeAIYvF4Esc7bVklOieIriNPO9M5bmkFl3Cd4cDtCTKCEnLLU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732724; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=ZMe+F/BV6SUKQdhvlYzbOQHu3L4U0JtErSEQNnb36QA=; b=bkxy3kAayp25YflmmG4y+vuh8aqn5VlDwY0PT7clzm1hy128FEpvYS6SKbEnFmmEicUHINpYbYwzdUJiYnBOfPVrryvWPLITNwCA7QZF9nZA73L2P+ZODcjnQK9Cq5Gq8ILj4AOgf/sBhYjboOP/+cglnkFYWC6Tu0oy6K1CxjA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1749732724640529.7283004057454; Thu, 12 Jun 2025 05:52:04 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9C4CC121D; Thu, 12 Jun 2025 08:52:03 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AE1DA1185; Thu, 12 Jun 2025 08:49:21 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4B56810F3; Thu, 12 Jun 2025 08:49:16 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4503AE1E for ; Thu, 12 Jun 2025 08:49:03 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-696-sEmZMX_7NfqeNR5VNRmGcQ-1; Thu, 12 Jun 2025 08:49:01 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7D3F519560AD for ; Thu, 12 Jun 2025 12:49:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A58E3195609D for ; Thu, 12 Jun 2025 12:48:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749732542; h=from:from: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; bh=W4c41mZ7tww4G5yJbl0NM9qleikxb9HkODXLzkgw5xQ=; b=UtTEMiFP+0wS8wHkyT8oXe5Xab9lgdioXsjCvkkYHf2C46K1CbSfSsT/TJvEEI2/d02L7/ rplOkiBuu11bUBAcA0Ag2LzKDl5ktCiwq8yZIXqNcb0jPoeqa2H44uTu3yP0uBT7WZkOkS /2uijlSyf1qYrKrPS5m4+oGbXW53NGE= X-MC-Unique: sEmZMX_7NfqeNR5VNRmGcQ-1 X-Mimecast-MFC-AGG-ID: sEmZMX_7NfqeNR5VNRmGcQ_1749732540 To: devel@lists.libvirt.org Subject: [PATCH 08/15] virt-aa-helper-test: Test hostdevs unconditionally Date: Thu, 12 Jun 2025 14:48:40 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JaPLs1dzlAjxYDCibPRmEWFiPM05-9QWYi_EO7s1xTY_1749732540 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: L5QBPMFGNYD67SJQPJHY7353RGU5NW7H X-Message-ID-Hash: L5QBPMFGNYD67SJQPJHY7353RGU5NW7H X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732726478116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Our test suite is very feature rich. In particular, it has two mocks that implement sysfs close enough to create host-independent environment to work with PCI and USB devices. These mocks are called virpcimock and virusbmock, respectively. Inside of virt-aa-helper-test there is an attempt to test whether virt-aa-helper generates profiles for , once for USB and the other time for PCI. Use this mocks to run virt-aa-helper in an environment where certain PCI/USB devices always exist. There are two problem though: 1) those two test cases use hardcoded PCI/USB addresses, which makes them host environment dependant, 2) neither of the test cases checks whether corresponding rule was added into the profile. Using mocks we can get away with problem 1), and by passing the fifth argument to testme() we can list an expected rule in the profile. Signed-off-by: Michal Privoznik --- tests/virt-aa-helper-test | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test index e462e46570..c0b8c1bafe 100755 --- a/tests/virt-aa-helper-test +++ b/tests/virt-aa-helper-test @@ -7,15 +7,9 @@ =20 set -e =20 -test_hostdev=3D"no" -if [ "$1" =3D "test_hostdev" ]; then - test_hostdev=3D"yes" - shift -fi - output=3D"/dev/null" use_valgrind=3D"" -ld_library_path=3D"$abs_top_builddir/src/" +ld_library_path=3D"$abs_top_builddir/tests/:$abs_top_builddir/src/" if [ ! -z "$1" ] && [ "$1" =3D "-d" ]; then output=3D"/dev/stdout" shift @@ -128,11 +122,12 @@ testme() { printf %s " < $input" >$output fi echo "': " >$output + ld_preload=3D"libvirusbmock.so:libvirpcimock.so" set +e if [ -n "$input" ]; then - LD_LIBRARY_PATH=3D"$ld_library_path" "${exe}" $extra_args $args < = $input >"$tmpout" 2>&1 + LD_PRELOAD=3D"$ld_preload" LD_LIBRARY_PATH=3D"$ld_library_path" ${= exe} $extra_args $args < $input >"$tmpout" 2>&1 else - LD_LIBRARY_PATH=3D"$ld_library_path" "${exe}" $extra_args $args >"= $tmpout" 2>&1 + LD_PRELOAD=3D"$ld_preload" LD_LIBRARY_PATH=3D"$ld_library_path" ${= exe} $extra_args $args >"$tmpout" 2>&1 fi rc=3D"$?" cat "$tmpout" >"$output" @@ -262,13 +257,11 @@ testme "0" "create multiple disks" "-c -u $valid_uuid= " "$test_xml" "$disk1.*rwk, sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###',${disk1}'/> "$test_xml" testme "0" "create (readonly)" "-c -u $valid_uuid" "$test_xml" "$disk1.*rk= ,$" =20 -if [ "$test_hostdev" =3D "yes" ]; then - sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,= ,
,g" "$template_xml" > "$test_xml" - testme "0" "create hostdev (USB)" "-c -u $valid_uuid" "$test_xml" +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,,
,g" "$template_xml" > "$test_xml" +testme "0" "create hostdev (USB)" "-c -u $valid_uuid" "$test_xml" "/dev/bu= s/usb/001/020" =20 - sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,= ,
,g" "$template_xml" = > "$test_xml" - testme "0" "create hostdev (PCI)" "-c -u $valid_uuid" "$test_xml" -fi +sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$disk1,g" -e "s,,
,g" "$template_xml" > "$t= est_xml" +testme "0" "create hostdev (PCI)" "-c -u $valid_uuid" "$test_xml" "/sys/de= vices/pci0000:00/0000:00:03.0/config" =20 sed -e "s,###UUID###,$uuid,g" -e "s,###DISK###,$nonexistent,g" "$template_= xml" > "$test_xml" testme "0" "create (non-existent disk)" "-c -u $valid_uuid" "$test_xml" "$= nonexistent.*rwk,$" --=20 2.49.0