From nobody Fri Apr 19 07:04:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1600196543; cv=none; d=zohomail.com; s=zohoarc; b=ay7epYUTqwSZrgjYy6wzNgNTYk0BC3t4zY6vaF5vBiaPTKdhr5ne+aUbWXw+2Ws4lVEF0fbCndfXVAOBhvEGoOwCpVFavmZvgCOrhyGh24b3RqZzfqGSKq9CUtTgMVah4SDLoV+hyw3/y291UVeK66rsXp+9mKUpdBFFqQ33U0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600196543; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=VRTDEU0Zz0tX0OWHbDYWv6AVf0U0XGWfUMysep2ru1c=; b=Jq2/vmWRD3VvrZKltsAN5Y1jkIaktC0W8zmhBIWG2lyggxthXU1JMZ3kIrEgqABczsVte2IAKXCMxzTeYUVp2va+7xNLF8No8+gCAkyJuyahS/D+Z80OV/1JQ4QWC2hYmyaUniS6juiF9nbSiK18wht/MYrH94RA3ntmq3fR/ek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600196543599647.2675460936392; Tue, 15 Sep 2020 12:02:23 -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-228-f5MBYktpMZm5fhZrT320hg-1; Tue, 15 Sep 2020 15:02:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 076B5186842A; Tue, 15 Sep 2020 19:02:09 +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 D2A0F610AF; Tue, 15 Sep 2020 19:02:07 +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 492EF183D021; Tue, 15 Sep 2020 19:02:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08FJ211f015142 for ; Tue, 15 Sep 2020 15:02:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 222111000320; Tue, 15 Sep 2020 19:02:01 +0000 (UTC) Received: from localhost.localdomain (ovpn-114-110.ams2.redhat.com [10.36.114.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id D00A41002D53; Tue, 15 Sep 2020 19:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600196542; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VRTDEU0Zz0tX0OWHbDYWv6AVf0U0XGWfUMysep2ru1c=; b=QJbq0DXjKKGpiEl8GogodjDWU9Ztf6x0BD0gf27hUpdKFerAkjmFvFFE4I2aC1lVBp7Ir2 tCSnrtK4pczfRFgnPbKWGL7z0Ce83Dp/glGSBP4lDPo98FIardpDTK5TJjnrhv/6hQoH67 fmYY7hTXDc6YBgqORsEhJN+X522PFOo= X-MC-Unique: f5MBYktpMZm5fhZrT320hg-1 From: Sebastian Mitterle To: libvir-list@redhat.com Subject: [PATCH] Add unit tests for timer validation Date: Tue, 15 Sep 2020 19:01:36 +0000 Message-Id: <20200915190136.32868-1-smitterl@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: thuth@redhat.com, Sebastian Mitterle 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.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add minimal coverage for non-x86_64 timer validation from commit 2f5d8ffebe5d3d00e16a051ed62ce8a703f18e7c Signed-off-by: Sebastian Mitterle --- tests/meson.build | 1 + tests/qemuvalidatetest.c | 107 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 tests/qemuvalidatetest.c diff --git a/tests/meson.build b/tests/meson.build index 0a204c46e4..dfdc1e8b93 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -460,6 +460,7 @@ if conf.has('WITH_QEMU') { 'name': 'qemumigparamstest', 'link_with': [ test_qemu_driver_lib, te= st_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] }, { 'name': 'qemumonitorjsontest', 'link_with': [ test_qemu_driver_lib, = test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] }, { 'name': 'qemusecuritytest', 'sources': [ 'qemusecuritytest.c', 'qemu= securitymock.c' ], 'link_with': [ test_qemu_driver_lib ], 'link_whole': [ t= est_utils_qemu_lib ] }, + { 'name': 'qemuvalidatetest', 'link_with': [ test_qemu_driver_lib ], '= link_whole': [ test_file_wrapper_lib ] }, { 'name': 'qemuvhostusertest', 'link_with': [ test_qemu_driver_lib ], = 'link_whole': [ test_file_wrapper_lib ] }, { 'name': 'qemuxml2argvtest', 'link_with': [ test_qemu_driver_lib, tes= t_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib, test_file_= wrapper_lib ] }, { 'name': 'qemuxml2xmltest', 'link_with': [ test_qemu_driver_lib ], 'l= ink_whole': [ test_utils_qemu_lib, test_file_wrapper_lib ] }, diff --git a/tests/qemuvalidatetest.c b/tests/qemuvalidatetest.c new file mode 100644 index 0000000000..617669dae0 --- /dev/null +++ b/tests/qemuvalidatetest.c @@ -0,0 +1,107 @@ +/* + * qemuvalidatetest.c: Test the qemu domain validation + * + * Copyright (C) 2010-2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "qemu/qemu_validate.c" +#include "testutils.h" +#include "internal.h" +#include "src/conf/virconftypes.h" +#include "src/conf/domain_conf.h" +#include "src/qemu/qemu_capabilities.h" +#include "src/util/virarch.h" + +static virDomainDefPtr +getDefWithUnsupportedTimerPresent(void) +{ + virDomainTimerDefPtr timer; + virDomainDefPtr def; + + if (VIR_ALLOC(timer) < 0) + return NULL; + + timer->present =3D 1; + timer->name =3D VIR_DOMAIN_TIMER_NAME_TSC; + + def =3D virDomainDefNew(); + def->virtType =3D VIR_DOMAIN_VIRT_QEMU; + def->os =3D (virDomainOSDef) { + .arch =3D VIR_ARCH_S390X, + .machine =3D (char *)"m" + }; + def->emulator =3D (char *)"e"; + def->clock =3D (virDomainClockDef) { + .ntimers =3D 1, + }; + if (VIR_ALLOC_N(def->clock.timers, 1) < 0) + return NULL; + def->clock.timers[0] =3D timer; + + return def; +} + +static int +errorTimersNotOnX86(const void *unused G_GNUC_UNUSED) +{ + int ret =3D 0; + char *log; + char expectedError[75] =3D "'tsc' timer is not supported for virtType= =3Dqemu arch=3Ds390x machine=3Dm guests"; + virDomainDefPtr def =3D getDefWithUnsupportedTimerPresent(); + if (qemuValidateDomainDefClockTimers(def, NULL) !=3D -1) { + ret =3D -1; + } + log =3D virTestLogContentAndReset(); + if (!strstr(log, expectedError)) { + printf("expected : %s", expectedError); + printf("but got : %s", virTestLogContentAndReset()); + ret =3D -1; + } + return ret; +} + +static int +onlyErrorTimersNotOnX86IfPresent(const void *unused G_GNUC_UNUSED) +{ + int ret =3D 0; + virDomainDefPtr def =3D getDefWithUnsupportedTimerPresent(); + def->clock.timers[0]->present =3D 0; + if (qemuValidateDomainDefClockTimers(def, NULL) =3D=3D -1) { + ret =3D -1; + } + return ret; +} + +static int +testsuite(void) +{ + int ret =3D 0; + +#define DO_TEST(NAME) \ + if (virTestRun("Command Exec " #NAME " test", \ + NAME, NULL) < 0) \ + ret =3D -1 + + DO_TEST(errorTimersNotOnX86); + DO_TEST(onlyErrorTimersNotOnX86IfPresent); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(testsuite); --=20 2.26.2