From nobody Fri Apr 4 05:33:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1740652826; cv=none; d=zohomail.com; s=zohoarc; b=dSMQvhSTcNpOzqxkfLU+VQNjmxeGlyVDqhVRbEH6M8xjFyQyTHKbNY6sgdXNAbEamoRD+NfPbfS4G+46UGX9tf9ajqHApUah+iqf3tQxrTMT6KdpV8VxcGWhAHjE/RkL+3hq6tHzcXwHljgrlLk+HeKavGpw3c+2uIKLR8E2y4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1740652826; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GWBy97K/W0cA9vpV4/TYPcmJHBMA6YOQWarCsegSOPc=; b=CMAjw7ORSTV63CrpAePtQ7covBmnfBZxPLPtsoMeiFIrzlWrRG8uNuKPewhQSOOK4Vp5C8N+uUFDKfcIR5nbrnx7v3MdU/CJDmCUeSGrGX9L5JRrJdkKvW9nxXOld5c6AUR41Z7ExtV1chVYRyu0DlcI9/BLYvyYtI0W7Ew3PR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1740652826107986.1759920650603; Thu, 27 Feb 2025 02:40:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnbIo-0007Ux-6R; Thu, 27 Feb 2025 05:39:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnbIk-0007Tx-Kp for qemu-devel@nongnu.org; Thu, 27 Feb 2025 05:39:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tnbIi-0003BX-Mg for qemu-devel@nongnu.org; Thu, 27 Feb 2025 05:39:34 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-jQNcx4wJMrCyKIxRKon40A-1; Thu, 27 Feb 2025 05:39:28 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB1EB180087A; Thu, 27 Feb 2025 10:39:26 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.44.33.184]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F1CBB300018D; Thu, 27 Feb 2025 10:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740652772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GWBy97K/W0cA9vpV4/TYPcmJHBMA6YOQWarCsegSOPc=; b=ZXMZlKC9ODSjjBexbHHLc1007idOsDjcXemrHVFaIkP94J2Ul9Ymv5FHal7Q0pi8UAmtp5 /dn51HJAGZTcBcRCxGl6T9E2GSgpEL6ACuGmPFBRo5T2Ze0sT4mBG7R6dyZzZxHe3OQJS9 Tl5v9L7p0PNb/Mw2xXE32MNHte8u2KE= X-MC-Unique: jQNcx4wJMrCyKIxRKon40A-1 X-Mimecast-MFC-AGG-ID: jQNcx4wJMrCyKIxRKon40A_1740652767 From: Thomas Huth To: qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Aurelien Jarno , Jiaxun Yang Subject: [PATCH 1/6] tests/functional: Move the code for testing HTTP downloads to a common function Date: Thu, 27 Feb 2025 11:39:10 +0100 Message-ID: <20250227103915.19795-2-thuth@redhat.com> In-Reply-To: <20250227103915.19795-1-thuth@redhat.com> References: <20250227103915.19795-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.44, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1740652827471019100 Content-Type: text/plain; charset="utf-8" We are going to use this code in other tests, too, so let's move it to the qemu_test module to be able to re-use it more easily. Signed-off-by: Thomas Huth --- tests/functional/qemu_test/linuxkernel.py | 26 ++++++++++++++++++++++- tests/functional/test_intel_iommu.py | 22 +------------------ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/tests/functional/qemu_test/linuxkernel.py b/tests/functional/q= emu_test/linuxkernel.py index 2c9598102d0..2aca0ee3cd0 100644 --- a/tests/functional/qemu_test/linuxkernel.py +++ b/tests/functional/qemu_test/linuxkernel.py @@ -3,8 +3,12 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. =20 +import hashlib +import urllib.request + +from .cmd import wait_for_console_pattern, exec_command_and_wait_for_patte= rn from .testcase import QemuSystemTest -from .cmd import wait_for_console_pattern +from .utils import get_usernet_hostfwd_port =20 =20 class LinuxKernelTest(QemuSystemTest): @@ -26,3 +30,23 @@ def launch_kernel(self, kernel, initrd=3DNone, dtb=3DNon= e, console_index=3D0, self.vm.launch() if wait_for: self.wait_for_console_pattern(wait_for) + + def check_http_download(self, filename, hashsum, guestport=3D8080, + pythoncmd=3D'python3 -m http.server'): + exec_command_and_wait_for_pattern(self, + f'{pythoncmd} {guestport} & sleep 1', + f'Serving HTTP on 0.0.0.0 port {guestport}') + hl =3D hashlib.sha256() + hostport =3D get_usernet_hostfwd_port(self.vm) + url =3D f'http://localhost:{hostport}{filename}' + self.log.info(f'Downloading {url} ...') + with urllib.request.urlopen(url) as response: + while True: + chunk =3D response.read(1 << 20) + if not chunk: + break + hl.update(chunk) + + digest =3D hl.hexdigest() + self.log.info(f'sha256sum of download is {digest}.') + self.assertEqual(digest, hashsum) diff --git a/tests/functional/test_intel_iommu.py b/tests/functional/test_i= ntel_iommu.py index a9e8f82ab59..62268d6f278 100755 --- a/tests/functional/test_intel_iommu.py +++ b/tests/functional/test_intel_iommu.py @@ -10,11 +10,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. =20 -import hashlib -import urllib.request - from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pa= ttern -from qemu_test.utils import get_usernet_hostfwd_port =20 =20 class IntelIOMMU(LinuxKernelTest): @@ -125,23 +121,7 @@ def run_and_check(self): =20 # Check virtio-net via HTTP: exec_command_and_wait_for_pattern(self, 'dhclient eth0', prompt) - exec_command_and_wait_for_pattern(self, - f'python3 -m http.server {self.GUEST_PORT} & sleep= 1', - f'Serving HTTP on 0.0.0.0 port {self.GUEST_PORT}') - hl =3D hashlib.sha256() - hostport =3D get_usernet_hostfwd_port(self.vm) - url =3D f'http://localhost:{hostport}{filename}' - self.log.info(f'Downloading {url} ...') - with urllib.request.urlopen(url) as response: - while True: - chunk =3D response.read(1 << 20) - if not chunk: - break - hl.update(chunk) - - digest =3D hl.hexdigest() - self.log.info(f'sha256sum of download is {digest}.') - self.assertEqual(digest, hashsum) + self.check_http_download(filename, hashsum, self.GUEST_PORT) =20 def test_intel_iommu(self): self.common_vm_setup() --=20 2.48.1