From nobody Mon May 6 10:48:01 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504605444595951.9659877650344; Tue, 5 Sep 2017 02:57:24 -0700 (PDT) Received: from localhost ([::1]:57836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpAbj-0004yU-AU for importer@patchew.org; Tue, 05 Sep 2017 05:57:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpAYT-0002Gf-4G for qemu-devel@nongnu.org; Tue, 05 Sep 2017 05:54:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpAYO-0001DV-F1 for qemu-devel@nongnu.org; Tue, 05 Sep 2017 05:54:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpAYO-0001DD-7D; Tue, 05 Sep 2017 05:53:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D8304E334; Tue, 5 Sep 2017 09:53:55 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-114.ams2.redhat.com [10.36.116.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 191DA90D63; Tue, 5 Sep 2017 09:53:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2D8304E334 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=thuth@redhat.com From: Thomas Huth To: "Dr. David Alan Gilbert" , qemu-devel@nongnu.org Date: Tue, 5 Sep 2017 11:53:47 +0200 Message-Id: <1504605227-5124-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 05 Sep 2017 09:53:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH] tests: Add a device_add/del HMP test 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexander Graf , qemu-ppc@nongnu.org, Igor Mammedov , John Snow , =?UTF-8?q?Andreas=20F=C3=A4rber?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" People tend to forget to mark internal devices with "user_creatable =3D fal= se or hotpluggable =3D false, and these devices can crash QEMU if added via the HMP monitor. So let's add a test to run through all devices and that tries to add them blindly (without arguments) to see whether this could crash the QEMU instance. Signed-off-by: Thomas Huth --- I've marked the patch as RFC since not all of the required device bug fixes have been merged yet (so this patch can not be included yet without breaking "make check"). It's also sad that "macio-oldworld" currently has to be blacklisted - I tried to find a fix for that device, but I was not able to spot the exact problem so far. So help for fixing that device is very very welcome! The crash can be reproduced like this: $ qemu-system-ppc64 -nographic -S -monitor stdio -serial none QEMU 2.10.50 monitor - type 'help' for more information (qemu) device_add macio-oldworld,id=3Dx (qemu) device_del x (qemu) ** ERROR:qom/object.c:1611:object_get_canonical_path_component: assertion failed: (obj->parent !=3D NULL) Aborted (core dumped) tests/test-hmp.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/tests/test-hmp.c b/tests/test-hmp.c index 7a38cdc..e8a25c4 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -28,7 +28,6 @@ static const char *hmp_cmds[] =3D { "commit all", "cpu-add 1", "cpu 0", - "device_add ?", "device_add usb-mouse,id=3Dmouse1", "mouse_button 7", "mouse_move 10 10", @@ -116,6 +115,64 @@ static void test_info_commands(void) g_free(info_buf); } =20 +/* + * People tend to forget to mark internal devices with "user_creatable =3D= false + * and these devices can crash QEMU if added via the HMP monitor. So let's= run + * through all devices and try to add them blindly (without arguments) to = see + * whether this could crash the QEMU instance. + */ +static void test_device_add_commands(void) +{ + char *resp, *devices, *devices_buf, *endp; + + devices =3D devices_buf =3D hmp("device_add help"); + + while (*devices) { + /* Ignore header lines etc. */ + if (strncmp(devices, "name \"", 6)) { + devices =3D strchr(devices, '\n'); + if (!devices) { + break; + } + devices +=3D 1; + continue; + } + /* Extract the device name, ignore parameters and description */ + devices +=3D 6; + endp =3D strchr(devices, '"'); + g_assert(endp !=3D NULL); + *endp =3D '\0'; + /* Check whether it is blacklisted... */ + if (g_str_equal("macio-oldworld", devices)) { + devices =3D strchr(endp + 1, '\n'); + if (!devices) { + break; + } + devices +=3D 1; + continue; + } + /* Now run the device_add + device_del commands */ + if (verbose) { + fprintf(stderr, "\tdevice_add %s,id=3D%s\n", devices, devices); + } + resp =3D hmp("device_add %s,id=3D%s", devices, devices); + g_free(resp); + if (verbose) { + fprintf(stderr, "\tdevice_del %s\n", devices); + } + resp =3D hmp("device_del %s", devices); + g_free(resp); + /* And move forward to the next line */ + devices =3D strchr(endp + 1, '\n'); + if (!devices) { + break; + } + devices +=3D 1; + } + + g_free(devices_buf); +} + static void test_machine(gconstpointer data) { const char *machine =3D data; @@ -125,6 +182,7 @@ static void test_machine(gconstpointer data) qtest_start(args); =20 test_info_commands(); + test_device_add_commands(); test_commands(); =20 qtest_end(); --=20 1.8.3.1