From patchwork Fri Oct 28 04:57:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 13023074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00D45ECAAA1 for ; Fri, 28 Oct 2022 05:07:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooHRs-0003mI-97; Fri, 28 Oct 2022 00:58:28 -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 1ooHRo-0003ld-GF for qemu-devel@nongnu.org; Fri, 28 Oct 2022 00:58:24 -0400 Received: from mx0a-0064b401.pphosted.com ([205.220.166.238]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooHRm-00027T-P2 for qemu-devel@nongnu.org; Fri, 28 Oct 2022 00:58:24 -0400 Received: from pps.filterd (m0250809.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 29S4wLMp017954; Thu, 27 Oct 2022 21:58:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=PPS06212021; bh=RU0NaIOfqT5nuKq/A7791gRn6np2jXF6/QYbNcHmKmI=; b=OOqIaqpWh7pnh78OqE36xSCR/rLIxpQ0dzKHniXzjfwMAqb7NUZXDd4virV4ffeS29YW fmf4COwQlf9zds3PBwUX9XTH+VIYhjz/XSIBAWB8bzVhz7mbBAYczxOX0TQuFYGqwrZQ XQqqYLtyzcvC/b7vKNJuSu+Ofj1T/hz/bTfgONztKd6DeXfXPJRQfxJYIKp3HDw9fs+f 3qjko7b9sgEDu0UKMkyoTXt1k8I63z6Gha5UjVo/XIe+roIXL7ZJFC2dVwsJ+fIfg98c YVYmKGaREV2jcs5dif2qeD7YyB4MszogStRU7OjuEKuMaFURZrgKzrSrmrCe9/mcHbOe 2w== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 3kfg3gs4tx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Oct 2022 21:58:21 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eqNk52HwNVYVerLNQk7gdVbeHnYnR/CJmBVyk2ICkvW8vvK6YFe2vNIopVpspztf1FYKFyMOnBfY+PKFS5nfY8Mz0d15KFdLnHAr+kNVgs9hn8U3jLGAV4IXVdA4yQZ8rxoIfTkO81jxnfAKG6Z+A6SGlNK4eqvnpFcfLztA7MiHLRz65L7OBnqyAi6eGRQu5GjfMaJ/g0Xsz2FBR5kizWlQVrFz6R/Lxac0atay3KzFb30LhFp5jYf6KlmJGDg4MY1X6XhgFIrLhGqM1zRC09Iw1ddOEuaWqFrQnaUSLFuMwJ+sk6n6o7FVnTFok7UwXd+fWc2NMa6B7xbpZebKIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RU0NaIOfqT5nuKq/A7791gRn6np2jXF6/QYbNcHmKmI=; b=UMs81Zwrq6McVbPl7VKaQWAz9oimdguvSPYil3uVC3fuMyr+LPiWVvN3YkFZFGkKhhSttBHH+cPNcVhCH9PY6rfhBSl+9lAtTHvCWtZxpgi3dXuaRxKvFo0T1sNBFDovdHkVMIbf0gtI22nLK27FHiTvWjfCgB8k74Iv+lWgjz8PXyWtDV4TVaxlneQwKm9Jbc2lhM3PLRLLBw861ixze044VG4EIgza+TH9aJa8ztFbaU8HqsMtHm72A7lMSu4F+5bUUb0yCoqJ7h8nxl/GW+4Tz3x6JvLeudqkbLuKMXaBcbGmIv2gPK3O5+mxh0UkD0pvcFHnIb8Szu6bC5n3Ug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from BL1PR11MB5351.namprd11.prod.outlook.com (2603:10b6:208:318::5) by MN2PR11MB4632.namprd11.prod.outlook.com (2603:10b6:208:24f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.21; Fri, 28 Oct 2022 04:58:19 +0000 Received: from BL1PR11MB5351.namprd11.prod.outlook.com ([fe80::9a11:fa81:cdd8:b201]) by BL1PR11MB5351.namprd11.prod.outlook.com ([fe80::9a11:fa81:cdd8:b201%9]) with mapi id 15.20.5746.026; Fri, 28 Oct 2022 04:58:19 +0000 From: Bin Meng To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Laurent Vivier , Paolo Bonzini , Thomas Huth Subject: [PATCH v6 06/11] tests/qtest: libqtest: Introduce qtest_wait_qemu() Date: Fri, 28 Oct 2022 12:57:31 +0800 Message-Id: <20221028045736.679903-7-bin.meng@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221028045736.679903-1-bin.meng@windriver.com> References: <20221028045736.679903-1-bin.meng@windriver.com> X-ClientProxiedBy: SL2PR04CA0009.apcprd04.prod.outlook.com (2603:1096:100:2d::21) To BL1PR11MB5351.namprd11.prod.outlook.com (2603:10b6:208:318::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL1PR11MB5351:EE_|MN2PR11MB4632:EE_ X-MS-Office365-Filtering-Correlation-Id: f46d4ae7-1ab3-4e0b-547f-08dab8a107f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z3XzQhSMVLU0PxNqbwCHSwap7Cj7RPZf0+DVAZSquKGI29fuo+QZIGwKXPDyRXkxWkFGui4JbY/mu9RdSl0VdprBjE8gl86RJdD1ebrFy3ggHOs/Jkf5SWTMk+F4sD6gRSxYd+JZhOwGHp9m6IoLfJjTktnTbd66jUIi5eY5dDb50pmf557nYfrkIN9Cmvty26zyI8wvwAfRz63a23eQ6q7yusDwDoHsKjyETSxIHMlLYkkIadi67ql/o+63BvLkHs4NAlHXFG+sxE2v+ftlxgcPArB/TrMjunaKdpr6hBbD0p5d+ALX1fAnRLzsoJEFZsjD3ATnNm/EAtYJOe4JYHEHFMXKTL7HOM0jjh/0pKq4Xvp0a82aRvidV8oh94qpOQ36fRA3n123YUU4VWOYc4gMseVuG1tdIuqHFU0jB5GnYWKsGZcBjiPIpV01/qQ6Xu15MmR5TaJ9QajatOIoO6ESxBJc6svSRir4TrohALY6LebZGp1AKOXPRr40E5iEf+BBKXycqd8H033W4QY5yGp5wGG9KG648BI/pDzR5VraFz/tntfznXufE79okSCC1LXXRV8bSXvxoz6XpQoZQm6kdS3x5GrB6QedowR6Lapx1al4PP8LAsWBt15ct0oMLuwtuDH1gdHIAaAiX0FEK6BOCex4TlhSExA3q+4b7BeWq7u02BnxWZtLFl+mzHwIN2kygGoExWlhdwGHz5jOAZ59p8rHAH9lSSElNU4CgUwoo+NCUuDxoRoIxXNur2NHbsWoR1WOFT8qu5Sp1CToXg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL1PR11MB5351.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(136003)(376002)(39850400004)(346002)(366004)(396003)(451199015)(478600001)(26005)(6486002)(6506007)(36756003)(2906002)(83380400001)(52116002)(6666004)(86362001)(5660300002)(38100700002)(38350700002)(2616005)(316002)(186003)(1076003)(6512007)(66476007)(8676002)(54906003)(4326008)(6916009)(41300700001)(66946007)(66556008)(44832011)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?KjRxoMtJi871VGBijafAslafXuOT?= =?utf-8?q?HTUxyxow5cOn3e9MR4vmrLdOR1/glyvzL09aZ8BNkmqV38U4rN6lM9rWpHUZ6CD5p?= =?utf-8?q?QU/NG8MJcVRxT47ghKPz1s7xog5ipV1xIQS3CrQcyNu9WJDFdh3nx9lFirBb8nKAE?= =?utf-8?q?n9uoK2PkiginrKa4I1PlKBUzcc1koFz2AHol5kuOrrZ+wpHySVBqWScRtr4nbeG8M?= =?utf-8?q?CA5bDGdor9CJev7+q0VnSD73nHRqkwK+hgylURjxrUDkTHuHS4xsv+bNxl7V9o2W+?= =?utf-8?q?aZv2D+3vr0PfTrIomGg0nSs1sgYHKbz5uifw9AF0we3yY0RAfeiuchDWisfIpzGyE?= =?utf-8?q?cVHyl71rES7zYuHdzrKLESkjhzvFEjowjrxGHn3pxwsMTGHdhKlknSxw1KxyZAb0O?= =?utf-8?q?Zd9ACOJ4dQUGEDX9bUh7nvmSs+fnJBslVZ/yBhPh+s2osYQfy4/qL/laPpq3jnzar?= =?utf-8?q?sGAJNLgSopFL+cypnthDO9WHygf1V5AiENWrWaqEtjOraBxHI02560nUpaMD01p4s?= =?utf-8?q?LRF8j7N7Acj+wBIgyUFS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vgM1vpftsLlCWzuPpzUNesHqwG47K61juGO40+CV?= =?utf-8?q?i1YnvXOCb2usDGn4nT7oCLQOHCZ5uV+COGCIKQu1b3zOJD19B/Pj9E6tBZPvMGUNt?= =?utf-8?q?ke/t0uTdMTUz?= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: f46d4ae7-1ab3-4e0b-547f-08dab8a107f0 X-MS-Exchange-CrossTenant-AuthSource: BL1PR11MB5351.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2022 04:58:19.2687 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ajbS8ZFDmxziMHwW/ct3T008TmxOEk+DfoNZEew3d9nzKXlTGjj+Y0fAB1GlueffRWOfmhJO0wTAvQnKNgP/Pg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4632 X-Proofpoint-GUID: O_5-D2W8swr_sfmHHF0oB0Re9rN_RNM8 X-Proofpoint-ORIG-GUID: O_5-D2W8swr_sfmHHF0oB0Re9rN_RNM8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-28_02,2022-10-27_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=933 mlxscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210280030 Received-SPF: pass client-ip=205.220.166.238; envelope-from=prvs=7300ee25fa=bin.meng@windriver.com; helo=mx0a-0064b401.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce an API for qtest to wait for the QEMU process to terminate. Suggested-by: Marc-André Lureau Signed-off-by: Bin Meng --- Changes in v6: - new patch: "tests/qtest: libqtest: Introduce qtest_wait_qemu()" tests/qtest/libqtest.h | 9 ++++++ tests/qtest/libqtest.c | 63 +++++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index 65c040e504..91a5f7edd9 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -75,6 +75,15 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args); */ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd); +/** + * qtest_wait_qemu: + * @s: #QTestState instance to operate on. + * + * Wait for the QEMU process to terminate. It is safe to call this function + * multiple times. + */ +void qtest_wait_qemu(QTestState *s); + /** * qtest_kill_qemu: * @s: #QTestState instance to operate on. diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index d12a604d78..e1e2d39a6e 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -156,37 +156,14 @@ void qtest_set_expected_status(QTestState *s, int status) s->expected_status = status; } -void qtest_kill_qemu(QTestState *s) +static void qtest_check_status(QTestState *s) { - pid_t pid = s->qemu_pid; -#ifndef _WIN32 - int wstatus; -#else - DWORD ret; -#endif - - /* Skip wait if qtest_probe_child already reaped. */ - if (pid != -1) { -#ifndef _WIN32 - kill(pid, SIGTERM); - TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0)); - assert(pid == s->qemu_pid); -#else - TerminateProcess((HANDLE)pid, s->expected_status); - ret = WaitForSingleObject((HANDLE)pid, INFINITE); - assert(ret == WAIT_OBJECT_0); - GetExitCodeProcess((HANDLE)pid, &s->exit_code); - CloseHandle((HANDLE)pid); -#endif - s->qemu_pid = -1; - } - /* * Check whether qemu exited with expected exit status; anything else is * fishy and should be logged with as much detail as possible. */ #ifndef _WIN32 - wstatus = s->wstatus; + int wstatus = s->wstatus; if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status) { fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU " "process but encountered exit status %d (expected %d)\n", @@ -212,6 +189,42 @@ void qtest_kill_qemu(QTestState *s) #endif } +void qtest_wait_qemu(QTestState *s) +{ +#ifndef _WIN32 + pid_t pid; + + TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0)); + assert(pid == s->qemu_pid); +#else + DWORD ret; + + ret = WaitForSingleObject((HANDLE)s->qemu_pid, INFINITE); + assert(ret == WAIT_OBJECT_0); + GetExitCodeProcess((HANDLE)s->qemu_pid, &s->exit_code); + CloseHandle((HANDLE)s->qemu_pid); +#endif + + qtest_check_status(s); +} + +void qtest_kill_qemu(QTestState *s) +{ + /* Skip wait if qtest_probe_child() already reaped */ + if (s->qemu_pid != -1) { +#ifndef _WIN32 + kill(s->qemu_pid, SIGTERM); +#else + TerminateProcess((HANDLE)s->qemu_pid, s->expected_status); +#endif + qtest_wait_qemu(s); + s->qemu_pid = -1; + return; + } + + qtest_check_status(s); +} + static void kill_qemu_hook_func(void *s) { qtest_kill_qemu(s);