From nobody Mon Feb 9 01:16:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1629463595327626.5788381131919; Fri, 20 Aug 2021 05:46:35 -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-192-9R5l9y-bO5ix3f6n9_o7lA-1; Fri, 20 Aug 2021 08:46:32 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2989802929; Fri, 20 Aug 2021 12:46:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD5F51036D20; Fri, 20 Aug 2021 12:46:26 +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 9AFC74A7C9; Fri, 20 Aug 2021 12:46:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KCjNCx013730 for ; Fri, 20 Aug 2021 08:45:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4FCF520BEAB7; Fri, 20 Aug 2021 12:45:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B06C20B665E for ; Fri, 20 Aug 2021 12:45:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3467C856D20 for ; Fri, 20 Aug 2021 12:45:23 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-88-mVfm2WqRPJ64W2AyarKegw-1; Fri, 20 Aug 2021 08:45:20 -0400 Received: by mail-pg1-f171.google.com with SMTP id y23so9035447pgi.7 for ; Fri, 20 Aug 2021 05:45:20 -0700 (PDT) Received: from localhost ([38.94.109.214]) by smtp.gmail.com with ESMTPSA id b13sm7135949pfr.72.2021.08.20.05.45.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 05:45:19 -0700 (PDT) X-MC-Unique: 9R5l9y-bO5ix3f6n9_o7lA-1 X-MC-Unique: mVfm2WqRPJ64W2AyarKegw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L9MZJOaNvw9s1TTEE4CvU/t+U0+i4UwWYnaL92IFZQI=; b=kArxOXMaOgOLyBMoQWOhjQNYetbGgpQam+KaLh4vwoAfaJU5m3VF3VWov41sE9Vk5B sYTVWYkU95w8lwKjgAdIK3Y0B3/7xgDx2/m9LyqT1j+Ob1Y24UM/65xNz0QbuAH6jA8C 4LVYaEUAsgiWefJt6Yh2HjxrB6oCb8gj5I98abyFACGb6tFMNHJxER5ebQVtZvp6uYJr qIENo3bddR6thTEK08m1gB0ayxY2YXPtLRVOkVzmSn/sdGCovAVaPaCIppOKs/eDbkg+ Ii1MD1kTbdpug2olVj+rH9gi/uInrx6//xb5WU6YHtVrdjzdhIXWJltwE9ydTElOQYqu AQUw== X-Gm-Message-State: AOAM531EaY4BkPd68iGi/CzQa0lqT8IUA6uDlf1qCKC4CZZFSHoiAS9b enqBmMqQEbJBdVO+bLReNIVidc+5wfLndm0Gcvc= X-Google-Smtp-Source: ABdhPJxaQUblrwJOuS0wCMDLuxsaRllek4MVjjijbstYtIdBn2A0PW9c8sX9U3R+xog2QedkkatvVA== X-Received: by 2002:a63:1259:: with SMTP id 25mr9064683pgs.48.1629463519550; Fri, 20 Aug 2021 05:45:19 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v2 12/12] tests: Test detach-device and detach-device-alias for test driver Date: Fri, 20 Aug 2021 20:44:39 +0800 Message-Id: <20210820124439.535276-13-lukedyue@gmail.com> In-Reply-To: <20210820124439.535276-1-lukedyue@gmail.com> References: <20210820124439.535276-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1629463596550100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Luke Yue --- tests/virshtest.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/virshtest.c b/tests/virshtest.c index 0d2ffd960a..c37d24e900 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -159,6 +159,8 @@ static char *custom_uri; "--connect", \ custom_uri =20 +# define TEST_XML_PATH abs_top_builddir "/../examples/xml/test" + static int testCompareListDefault(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_DEFAULT, "list", NULL }; @@ -343,6 +345,74 @@ static int testCompareSetBlkioParameters(const void *d= ata G_GNUC_UNUSED) return testCompareOutputLit(exp, "", NULL, argv); } =20 +static int testCompareDetachDevice(const void *data G_GNUC_UNUSED) +{ + const char *const argv[] =3D { VIRSH_CUSTOM, "detach-device fc5\ + " TEST_XML_PATH "/testdevif.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevdiskcdrom.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevsound.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevhostdev.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevlease.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevcontroller.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevfs.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevrng.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevmem.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevshmem.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevwatchdog.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevinput.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevvsock.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevtpm.xml;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevtpm.xml", + NULL }; + const char *exp =3D +"Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\ +Device detached successfully\n\n\n"; + const char *error_msg =3D +"error: Failed to detach device from " TEST_XML_PATH "/testdevtpm.xml\n\ +error: device not found: matching tpm device not found\n"; + return testCompareOutputLit(exp, error_msg, NULL, argv); +} + +static int testCompareDetachDeviceAlias(const void *data G_GNUC_UNUSED) +{ + const char *const argv[] =3D { VIRSH_CUSTOM, + "detach-device-alias fc5 ua-testCD;\ + detach-device fc5\ + " TEST_XML_PATH "/testdevdiskcdrom.xml", + NULL }; + const char *exp =3D "Device detach request sent successfully\n\n\n"; + const char *error_msg =3D +"error: Failed to detach device from " TEST_XML_PATH "/testdevdiskcdrom.xm= l\n\ +error: device not found: no target device hdb\n"; + return testCompareOutputLit(exp, error_msg, NULL, argv); +} + struct testInfo { const char *const *argv; const char *result; @@ -443,6 +513,14 @@ mymain(void) testCompareSetBlkioParameters, NULL) !=3D 0) ret =3D -1; =20 + if (virTestRun("virsh detach-device", + testCompareDetachDevice, NULL) !=3D 0) + ret =3D -1; + + if (virTestRun("virsh detach-device-alias", + testCompareDetachDeviceAlias, NULL) !=3D 0) + ret =3D -1; + /* It's a bit awkward listing result before argument, but that's a * limitation of C99 vararg macros. */ # define DO_TEST(i, result, ...) \ --=20 2.33.0