From nobody Thu May 2 06:42:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541801687532200.29076675877025; Fri, 9 Nov 2018 14:14:47 -0800 (PST) Received: from localhost ([::1]:36278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLF38-0000Og-7P for importer@patchew.org; Fri, 09 Nov 2018 17:14:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLF1L-0006xE-1k for qemu-devel@nongnu.org; Fri, 09 Nov 2018 17:12:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLF1F-00056s-5p for qemu-devel@nongnu.org; Fri, 09 Nov 2018 17:12:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLF0x-0004Sq-1W; Fri, 09 Nov 2018 17:12:33 -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 mx1.redhat.com (Postfix) with ESMTPS id 7040530820C0; Fri, 9 Nov 2018 22:12:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-124-135.rdu2.redhat.com [10.10.124.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EAE7C5D6B3; Fri, 9 Nov 2018 22:12:21 +0000 (UTC) From: Cleber Rosa To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 9 Nov 2018 17:12:12 -0500 Message-Id: <20181109221213.7310-2-crosa@redhat.com> In-Reply-To: <20181109221213.7310-1-crosa@redhat.com> References: <20181109221213.7310-1-crosa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 09 Nov 2018 22:12:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 1/2] Acceptance Tests: add QemuImgTest base class X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Eduardo Habkost , Cleber Rosa , Wainer dos Santos Moschetta , Max Reitz , Caio Carrara , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Testing other utilities such as qemu-img do not require the same infrastructure that testing QEMU itself does. Let's add a base class that just sets the suitable qemu-img binary to be used during test. Signed-off-by: Cleber Rosa --- tests/acceptance/avocado_qemu/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/a= vocado_qemu/__init__.py index 1e54fd5932..dfd147b7e2 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -40,6 +40,20 @@ def pick_default_qemu_bin(): return qemu_bin_from_src_dir_path =20 =20 +def pick_default_qemu_img_bin(): + """ + Picks the path of a QEMU binary, starting either in the current working + directory or in the source tree root directory. + """ + qemu_img_bin_local =3D os.path.abspath("qemu-img") + if is_readable_executable_file(qemu_img_bin_local): + return qemu_img_bin_local + + qemu_img_bin_from_src_dir_path =3D os.path.join(SRC_ROOT_DIR, "qemu-im= g") + if is_readable_executable_file(qemu_img_bin_from_src_dir_path): + return qemu_img_bin_from_src_dir_path + + class Test(avocado.Test): def setUp(self): self.vm =3D None @@ -52,3 +66,9 @@ class Test(avocado.Test): def tearDown(self): if self.vm is not None: self.vm.shutdown() + + +class QemuImgTest(avocado.Test): + def setUp(self): + self.qemu_img_bin =3D self.params.get('qemu_img_bin', + default=3Dpick_default_qemu_im= g_bin()) --=20 2.19.1 From nobody Thu May 2 06:42:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541801686760139.7880085935251; Fri, 9 Nov 2018 14:14:46 -0800 (PST) Received: from localhost ([::1]:36277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLF37-0000O9-G3 for importer@patchew.org; Fri, 09 Nov 2018 17:14:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLF1L-000704-JI for qemu-devel@nongnu.org; Fri, 09 Nov 2018 17:12:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLF1F-000578-8g for qemu-devel@nongnu.org; Fri, 09 Nov 2018 17:12:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLF13-0004U9-Rk; Fri, 09 Nov 2018 17:12:38 -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 mx1.redhat.com (Postfix) with ESMTPS id 24105307EABF; Fri, 9 Nov 2018 22:12:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-124-135.rdu2.redhat.com [10.10.124.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0F565D6B3; Fri, 9 Nov 2018 22:12:23 +0000 (UTC) From: Cleber Rosa To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 9 Nov 2018 17:12:13 -0500 Message-Id: <20181109221213.7310-3-crosa@redhat.com> In-Reply-To: <20181109221213.7310-1-crosa@redhat.com> References: <20181109221213.7310-1-crosa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 09 Nov 2018 22:12:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 2/2] qemu-img: consider a zero number of I/O requests an invalid count X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Eduardo Habkost , Cleber Rosa , Wainer dos Santos Moschetta , Max Reitz , Caio Carrara , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It's debatable whether it makes sense to consider the bench command successful when no I/O requests will be performed. This changes the behavior to consider a zero count of I/O requests an invalid value. While at it, avoid using signed types for number of I/O requests. The image file used, is a simple raw image with 1K size. There's a obvious trade off between creating and reusing those images. This is an experiment in sharing those among tests. It was created using: mkdir -p tests/data/images/empty cd tests/data/images/empty qemu-img create raw 1K This relies on the Test's "get_data()", which by default looks for data files on sources that map to various levels of specificity of a test: file, test and additionally with variant and a symlink. One other possibility with regards to in-tree images, is to extend the Test's "get_data()" API (which is extensible by design) and make the common images directory a "source". The resulting API usage would be similar to: self.get_data("empty/raw", source=3D"common_images") or simply: self.get_data("empty/raw") To look for "empty/raw" in any of the available sources. That would make the symlink unnecessary. Reference: https://avocado-framework.readthedocs.io/en/65.0/api/core/avocad= o.core.html#avocado.core.test.TestData Signed-off-by: Cleber Rosa --- qemu-img.c | 8 ++--- tests/acceptance/qemu_img_bench.py | 34 ++++++++++++++++++++ tests/acceptance/qemu_img_bench.py.data/img | 1 + tests/data/images/empty/raw | Bin 0 -> 1024 bytes 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/acceptance/qemu_img_bench.py create mode 120000 tests/acceptance/qemu_img_bench.py.data/img create mode 100644 tests/data/images/empty/raw diff --git a/qemu-img.c b/qemu-img.c index 4c96db7ba4..7ffcdd1589 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3960,7 +3960,7 @@ typedef struct BenchData { int bufsize; int step; int nrreq; - int n; + unsigned int n; int flush_interval; bool drain_on_flush; uint8_t *buf; @@ -4051,7 +4051,7 @@ static int img_bench(int argc, char **argv) bool quiet =3D false; bool image_opts =3D false; bool is_write =3D false; - int count =3D 75000; + unsigned int count =3D 75000; int depth =3D 64; int64_t offset =3D 0; size_t bufsize =3D 4096; @@ -4098,7 +4098,7 @@ static int img_bench(int argc, char **argv) { unsigned long res; =20 - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { + if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > UINT_MAX = || res <=3D 0) { error_report("Invalid request count specified"); return 1; } @@ -4248,7 +4248,7 @@ static int img_bench(int argc, char **argv) .flush_interval =3D flush_interval, .drain_on_flush =3D drain_on_flush, }; - printf("Sending %d %s requests, %d bytes each, %d in parallel " + printf("Sending %u %s requests, %d bytes each, %d in parallel " "(starting at offset %" PRId64 ", step size %d)\n", data.n, data.write ? "write" : "read", data.bufsize, data.nrreq, data.offset, data.step); diff --git a/tests/acceptance/qemu_img_bench.py b/tests/acceptance/qemu_img= _bench.py new file mode 100644 index 0000000000..327524ad8f --- /dev/null +++ b/tests/acceptance/qemu_img_bench.py @@ -0,0 +1,34 @@ +# Test for the basic qemu-img bench command +# +# Copyright (c) 2018 Red Hat, Inc. +# +# Author: +# Cleber Rosa +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import os + +from avocado_qemu import QemuImgTest +from avocado.utils import process + + +class Bench(QemuImgTest): + """ + Runs the qemu-img tool with the bench command and different + options and verifies the expected outcome. + + :avocado: enable + """ + def check_invalid_count(self, count): + cmd =3D "%s bench -c %d %s" % (self.qemu_img_bin, count, self.get_= data("img")) + result =3D process.run(cmd, ignore_status=3DTrue) + self.assertEqual(1, result.exit_status) + self.assertIn(b"Invalid request count", result.stderr) + + def test_zero_count(self): + self.check_invalid_count(0) + + def test_negative_count(self): + self.check_invalid_count(-1) diff --git a/tests/acceptance/qemu_img_bench.py.data/img b/tests/acceptance= /qemu_img_bench.py.data/img new file mode 120000 index 0000000000..6d01ef2e85 --- /dev/null +++ b/tests/acceptance/qemu_img_bench.py.data/img @@ -0,0 +1 @@ +../../data/images/empty/raw \ No newline at end of file diff --git a/tests/data/images/empty/raw b/tests/data/images/empty/raw new file mode 100644 index 0000000000000000000000000000000000000000..06d7405020018ddf3cacee90fd4= af10487da3d20 GIT binary patch literal 1024 ScmZQz7zLvtFd70QH3R?z00031 literal 0 HcmV?d00001 --=20 2.19.1