From nobody Thu May 2 09:25:19 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 1541793561362598.1187800509181; Fri, 9 Nov 2018 11:59:21 -0800 (PST) Received: from localhost ([::1]:35763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLCw4-00050S-9f for importer@patchew.org; Fri, 09 Nov 2018 14:59:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLCux-0004Vd-5t for qemu-devel@nongnu.org; Fri, 09 Nov 2018 14:58:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLCus-0001O0-0o for qemu-devel@nongnu.org; Fri, 09 Nov 2018 14:58:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56024) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLCur-0001NQ-Am for qemu-devel@nongnu.org; Fri, 09 Nov 2018 14:58:05 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AE0D30014D2 for ; Fri, 9 Nov 2018 19:58:04 +0000 (UTC) Received: from virtlab501.virt.lab.eng.bos.redhat.com (virtlab501.virt.lab.eng.bos.redhat.com [10.19.152.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 129BC6015E; Fri, 9 Nov 2018 19:58:00 +0000 (UTC) From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Date: Fri, 9 Nov 2018 14:58:00 -0500 Message-Id: <20181109195800.19071-1-wainersm@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 09 Nov 2018 19:58:04 +0000 (UTC) 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] [PATCH] Acceptance test: add coverage tests for -smp option 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: ccarrara@redhat.com, philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This adds tests for SMP option, by passing -smp with various combinations of cpus, cores, threads, and sockets values it checks that invalid topologies are not accepted as well as missing values are correctly calculated. Signed-off-by: Wainer dos Santos Moschetta --- tests/acceptance/smp_option_coverage.py | 218 ++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 tests/acceptance/smp_option_coverage.py diff --git a/tests/acceptance/smp_option_coverage.py b/tests/acceptance/smp= _option_coverage.py new file mode 100644 index 0000000000..ab68d1a67d --- /dev/null +++ b/tests/acceptance/smp_option_coverage.py @@ -0,0 +1,218 @@ +# QEMU -smp option coverage test. +# +# Copyright (c) 2018 Red Hat, Inc. +# +# Author: +# Wainer dos Santos Moschetta +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +from functools import reduce +from avocado.utils.process import run + +from avocado_qemu import Test + + +class SmpOption(Test): + """ + Launches QEMU with various cpus, cores, threads, sockets, and maxcpus + combination through -smp option, to check it does not accept invalid S= MP + topologies as well as it is able to calculate correctly any missing va= lues. + + :avocado: enable + :avocado: tags=3Dslow,coverage + """ + def setUp(self): + super().setUp() + self.cores =3D self.params.get('cores', default=3D2) + self.threads =3D self.params.get('threads', default=3D2) + self.sockets =3D self.params.get('sockets', default=3D2) + self.cpus =3D self.params.get('cpus', default=3D8) + + def get_smp_topology(self): + """ + Returns a dict with the id of cores, threads and sockets. + """ + res =3D self.vm.qmp('query-hotpluggable-cpus')['return'] + cpus =3D [x['props'] for x in res] + + return reduce(lambda x, y: {'core-id': x['core-id'].union([y['core= -id']]), + 'thread-id': x['thread-id'].union([y['= thread-id']]), + 'socket-id': x['socket-id'].union([y['= socket-id']])}, + cpus, {'core-id': set(), 'thread-id': set(), 'socket= -id': set()}) + + @staticmethod + def build_option(**kwargs): + """ + Builds string for the -smp option. + Use cpus, cores, threads, sockets, maxcpus keys. + """ + option_list =3D [] + if kwargs.get('cpus', None) is not None: + option_list.append(str(kwargs.get('cpus'))) + for key, val in kwargs.items(): + if key =3D=3D 'cpus': + continue + option_list.append('%s=3D%s' % (key, val)) + + return ",".join(option_list) + + def launch_and_check(self, expect_cores=3D1, expect_threads=3D1, + expect_sockets=3D1, **kwargs): + """ + Launches VM and check its SMP topology was correctly set. + Use cpus, cores, threads, sockets, and maxcpus keys to specify the + topology. + """ + option =3D self.build_option(**{key: val for key, val in kwargs.it= ems() + if key in ['cpus', 'cores', 'threads= ', + 'sockets', 'maxcpus']}) + self.vm.add_args('-smp', option) + self.vm.launch() + smp =3D self.get_smp_topology() + self.assertEqual(smp['core-id'], set(range(0, expect_cores))) + self.assertEqual(smp['thread-id'], set(range(0, expect_threads))) + self.assertEqual(smp['socket-id'], set(range(0, expect_sockets))) + + def launch_and_check_fail(self, **kwargs): + """ + Launches VM and check the process exits with expected error code, = for + cases where the topology is expected not valid. + """ + option =3D self.build_option(**kwargs) + res =3D run("%s -smp %s" % (self.qemu_bin, option), timeout=3D10, + ignore_status=3DTrue) + self.assertNotEqual(res.exit_status, 0) + + # Passing cpus and maxcpus only. + # + + def test_cpus_eq_maxcpus(self): + self.launch_and_check(cpus=3Dself.cpus, + maxcpus=3Dself.cpus, + expect_sockets=3Dself.cpus) + + def test_cpus_lt_maxcpus(self): + maxcpus =3D self.cpus * 2 + self.launch_and_check(cpus=3Dself.cpus, + maxcpus=3Dmaxcpus, + expect_sockets=3Dmaxcpus) + + def test_cpus_gt_maxcpus(self): + self.launch_and_check_fail(cpus=3Dself.cpus, + maxcpus=3Dself.cpus // 2) + + # Passing a combination of cores, threads and sockets only. + # + + def test_no_cores_no_threads_no_sockets(self): + self.launch_and_check(cpus=3Dself.cpus, + expect_sockets=3Dself.cpus) + + def test_no_cores_no_threads_sockets(self): + self.launch_and_check(sockets=3Dself.sockets, + expect_sockets=3Dself.sockets) + + def test_no_cores_threads_no_sockets(self): + self.launch_and_check(threads=3Dself.threads, + expect_threads=3Dself.threads) + + def test_no_cores_threads_sockets(self): + self.launch_and_check(threads=3Dself.threads, + sockets=3Dself.sockets, + expect_threads=3Dself.threads, + expect_sockets=3Dself.sockets) + + def test_cores_no_threads_no_sockets(self): + self.launch_and_check(cores=3Dself.cores, + expect_cores=3Dself.cores) + + def test_cores_no_threads_sockets(self): + self.launch_and_check(cores=3Dself.cores, + sockets=3Dself.sockets, + expect_cores=3Dself.cores, + expect_sockets=3Dself.sockets) + + def test_cores_threads_no_sockets(self): + self.launch_and_check(cores=3Dself.cores, + threads=3Dself.threads, + expect_cores=3Dself.cores, + expect_threads=3Dself.threads) + + def test_cores_threads_sockets(self): + self.launch_and_check(cores=3Dself.cores, + threads=3Dself.threads, + sockets=3Dself.sockets, + expect_cores=3Dself.cores, + expect_threads=3Dself.threads, + expect_sockets=3Dself.sockets) + + # Passing cpus always and a combination of cores, threads and sockets. + # + + def test_cpus_no_cores_no_threads_sockets(self): + self.launch_and_check(cpus=3Dself.cpus, + sockets=3Dself.sockets, + expect_cores=3Dself.cpus // self.sockets, + expect_sockets=3Dself.sockets) + + def test_cpus_no_cores_threads_no_sockets(self): + self.launch_and_check(cpus=3Dself.cpus, + threads=3Dself.threads, + expect_threads=3Dself.threads, + expect_sockets=3Dself.cpus // self.threads) + + def test_cpus_no_cores_threads_sockets(self): + self.launch_and_check(cpus=3Dself.cpus, + threads=3Dself.threads, + sockets=3Dself.sockets, + expect_threads=3Dself.threads, + expect_sockets=3Dself.sockets, + expect_cores=3Dself.cpus // (self.threads * = self.sockets)) + + def test_cpus_cores_no_threads_no_sockets(self): + self.launch_and_check(cpus=3Dself.cpus, + cores=3Dself.cores, + expect_cores=3Dself.cores, + expect_sockets=3Dself.cpus // self.cores) + + def test_cpus_cores_no_threads_sockets(self): + self.launch_and_check(cpus=3Dself.cpus, + cores=3Dself.cores, + sockets=3Dself.sockets, + expect_cores=3Dself.cores, + expect_sockets=3Dself.sockets, + expect_threads=3Dself.cpus // (self.cores * = self.sockets)) + + def test_cpus_cores_threads_no_sockets(self): + self.launch_and_check(cpus=3Dself.cpus, + cores=3Dself.cores, + threads=3Dself.threads, + expect_cores=3Dself.cores, + expect_threads=3Dself.threads, + expect_sockets=3Dself.cpus // (self.cores * = self.threads)) + + def test_cpus_cores_threads_sockets(self): + self.launch_and_check(cpus=3Dself.cores * self.threads * self.sock= ets, + cores=3Dself.cores, + threads=3Dself.threads, + sockets=3Dself.sockets, + expect_cores=3Dself.cores, + expect_threads=3Dself.threads, + expect_sockets=3Dself.sockets) + + # Passing cpus less (or greater) than cores, threads and sockets. + # + + def test_cpus_lt_cores_threads_sockets(self): + self.launch_and_check_fail(cpus=3D(self.cores * self.threads * sel= f.sockets) // 2, + cores=3Dself.cores, + threads=3Dself.threads, + sockets=3Dself.sockets,) + + def test_cpus_gt_cores_threads_sockets(self): + self.launch_and_check_fail(cpus=3Dself.cores * self.threads * self= .sockets * 2, + cores=3Dself.cores, + threads=3Dself.threads, + sockets=3Dself.sockets) --=20 2.17.2