From nobody Mon Nov 25 04:40:04 2024 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=1717528190; cv=none; d=zohomail.com; s=zohoarc; b=VbMQprmr25Ai2+BGP/24YxvCQFBfUfyM4ErZcBisU99Z+pCd2eaSovxLKiJJtt3NtCy86lFy7AbkjdNlF+wJ0bT3XOENlJvUC5ENN+wMMN8XHhUrnyNJb+34F9/3Uk/LEah0pl/0bZUcTruTQYu7RNUMvjaQOJ9jF4R+lU64s/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717528190; h=Content-Type: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=qGhmwqguo7pIYQaZC7WOHDuKcF1Cau7swIzTfVk8co4=; b=ZfSBOo/jcDGtIRYtgpdyqAx1n4h77XYXWdTXkQ1cay6TwiuHzGadTVfpar6XbbIK8IIAy3ewe9K5MWaPjtnfYVaz0EleQqQpxsxXqxPSpJJbnWls8ijoOtrSYdxNG5eOVMz+lTB/AYkTtxjjhzuyVmz2RiHZP+bDTgFRnzjCWUs= 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 1717528190082326.82911378785343; Tue, 4 Jun 2024 12:09:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEZWa-00012I-3g; Tue, 04 Jun 2024 15:08:48 -0400 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 1sEZWX-0000uV-O5 for qemu-devel@nongnu.org; Tue, 04 Jun 2024 15:08:45 -0400 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 1sEZWV-00013T-DW for qemu-devel@nongnu.org; Tue, 04 Jun 2024 15:08:45 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-XPZrGImMOpS4tPe_hapZlA-1; Tue, 04 Jun 2024 15:08:41 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-35e7cce4c32so1055719f8f.3 for ; Tue, 04 Jun 2024 12:08:41 -0700 (PDT) Received: from redhat.com ([2a0d:6fc7:552:cf5c:2b13:215c:b9df:f231]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd066b47asm12322567f8f.112.2024.06.04.12.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 12:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717528122; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=qGhmwqguo7pIYQaZC7WOHDuKcF1Cau7swIzTfVk8co4=; b=GlKo5WE5eKkUHJRvWBvZVtjatfq8dsg6nc4jDJMXtpAwjnHaS4PiQvgRJVa3+ZBOt/j1gY ZcDKWkoZ2bC0U/5ufc85Gx64g/lvgvIUVKkQRiKsOsfV41K+/jM7TewgvHYQp9KbHLvJon ux5185U4apNi+ubOyxJeKf+aufxrKAc= X-MC-Unique: XPZrGImMOpS4tPe_hapZlA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717528120; x=1718132920; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qGhmwqguo7pIYQaZC7WOHDuKcF1Cau7swIzTfVk8co4=; b=pYTP+ThjSUhHk2gJ16Ksf1b0DPUbmRed3ppHA3oFHmJqx4C53mGk9jr4LlhnRd0Tom s/XxONXDRgNPMCu6ujsfq8hO3BJfteQWka3nGCuNMEg3UqGMUORFGCe13LVYrlQmHEOZ 10lKy2lDhiU+xmSURNd7KGKPdbKlN5uhRi2hMMm7jZOmszveNLqsXe2wx6TxACLEcnhC qVmLHlKm9uWcMpf4HQNW3w7sMX6IEPNkrR40tWGLeoATdHWT5PvAOsN2MEdP2oQ4LG8t Y4lbGA9zOpDrMcXrcizZZNdeMznPvklqmKFu1gSsmFGuhiAIg4tR8X24xQpb6iXaFNmz j4vA== X-Gm-Message-State: AOJu0Yy/rCXTKriE12qMvvOe6L4v94DDEXjUGXBX8yKWDXnVw/J34LGq os8vrle/UQRepCC7mBixQdc4L3PKxWPA2fBtFN1/MTcdoCH4z0b39HGeczbOBo+WasLd7UDH4Ej puY5mAXVwLK+YZzMTmX91/UgqjpRwf/Hpb61OXxDfpaR4FMiOuj4c84v5zFWf/B94PLAG/VZvVJ FGJ/2CdWkniAzOVhA5qa4auGttdNs57w== X-Received: by 2002:a5d:4b02:0:b0:355:6e4:60e5 with SMTP id ffacd0b85a97d-35e8ef0879emr224310f8f.35.1717528119728; Tue, 04 Jun 2024 12:08:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENQYangbr476tDOUC1skzJUTv+DIBKAUfSQr/E+j3xZpGWb86F92aNTG71pnGt8Ja5Cjqb/A== X-Received: by 2002:a5d:4b02:0:b0:355:6e4:60e5 with SMTP id ffacd0b85a97d-35e8ef0879emr224289f8f.35.1717528119230; Tue, 04 Jun 2024 12:08:39 -0700 (PDT) Date: Tue, 4 Jun 2024 15:08:35 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Thomas =?utf-8?Q?Wei=C3=9Fschuh?= , Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [PULL 43/46] tests/qtest/pvpanic: add tests for pvshutdown event Message-ID: <982077b6957eab867d48feff46be615f217ebb9d.1717527933.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1717528190422100001 From: Thomas Wei=C3=9Fschuh Validate that a shutdown via the pvpanic device emits the correct QMP events. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Thomas Huth Message-Id: <20240527-pvpanic-shutdown-v8-7-5a28ec02558b@t-8ch.de> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/pvpanic-pci-test.c | 39 ++++++++++++++++++++++++++++++++++ tests/qtest/pvpanic-test.c | 29 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/tests/qtest/pvpanic-pci-test.c b/tests/qtest/pvpanic-pci-test.c index b372caf41d..dc021c2fdf 100644 --- a/tests/qtest/pvpanic-pci-test.c +++ b/tests/qtest/pvpanic-pci-test.c @@ -85,11 +85,50 @@ static void test_panic(void) qtest_quit(qts); } =20 +static void test_pvshutdown(void) +{ + uint8_t val; + QDict *response, *data; + QTestState *qts; + QPCIBus *pcibus; + QPCIDevice *dev; + QPCIBar bar; + + qts =3D qtest_init("-device pvpanic-pci,addr=3D04.0"); + pcibus =3D qpci_new_pc(qts, NULL); + dev =3D qpci_device_find(pcibus, QPCI_DEVFN(0x4, 0x0)); + qpci_device_enable(dev); + bar =3D qpci_iomap(dev, 0, NULL); + + qpci_memread(dev, bar, 0, &val, sizeof(val)); + g_assert_cmpuint(val, =3D=3D, PVPANIC_EVENTS); + + val =3D PVPANIC_SHUTDOWN; + qpci_memwrite(dev, bar, 0, &val, sizeof(val)); + + response =3D qtest_qmp_eventwait_ref(qts, "GUEST_PVSHUTDOWN"); + qobject_unref(response); + + response =3D qtest_qmp_eventwait_ref(qts, "SHUTDOWN"); + g_assert(qdict_haskey(response, "data")); + data =3D qdict_get_qdict(response, "data"); + g_assert(qdict_haskey(data, "guest")); + g_assert(qdict_get_bool(data, "guest")); + g_assert(qdict_haskey(data, "reason")); + g_assert_cmpstr(qdict_get_str(data, "reason"), =3D=3D, "guest-shutdown= "); + qobject_unref(response); + + g_free(dev); + qpci_free_pc(pcibus); + qtest_quit(qts); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); qtest_add_func("/pvpanic-pci/panic", test_panic); qtest_add_func("/pvpanic-pci/panic-nopause", test_panic_nopause); + qtest_add_func("/pvpanic-pci/pvshutdown", test_pvshutdown); =20 return g_test_run(); } diff --git a/tests/qtest/pvpanic-test.c b/tests/qtest/pvpanic-test.c index ccc603472f..d49d2ba931 100644 --- a/tests/qtest/pvpanic-test.c +++ b/tests/qtest/pvpanic-test.c @@ -58,11 +58,40 @@ static void test_panic(void) qtest_quit(qts); } =20 +static void test_pvshutdown(void) +{ + uint8_t val; + QDict *response, *data; + QTestState *qts; + + qts =3D qtest_init("-device pvpanic"); + + val =3D qtest_inb(qts, 0x505); + g_assert_cmpuint(val, =3D=3D, PVPANIC_EVENTS); + + qtest_outb(qts, 0x505, PVPANIC_SHUTDOWN); + + response =3D qtest_qmp_eventwait_ref(qts, "GUEST_PVSHUTDOWN"); + qobject_unref(response); + + response =3D qtest_qmp_eventwait_ref(qts, "SHUTDOWN"); + g_assert(qdict_haskey(response, "data")); + data =3D qdict_get_qdict(response, "data"); + g_assert(qdict_haskey(data, "guest")); + g_assert(qdict_get_bool(data, "guest")); + g_assert(qdict_haskey(data, "reason")); + g_assert_cmpstr(qdict_get_str(data, "reason"), =3D=3D, "guest-shutdown= "); + qobject_unref(response); + + qtest_quit(qts); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); qtest_add_func("/pvpanic/panic", test_panic); qtest_add_func("/pvpanic/panic-nopause", test_panic_nopause); + qtest_add_func("/pvpanic/pvshutdown", test_pvshutdown); =20 return g_test_run(); } --=20 MST