From patchwork Wed Nov 13 22:50:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 1194498 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="nuzpxblt"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 47D0HL0tz6z9sNT for ; Thu, 14 Nov 2019 09:52:13 +1100 (AEDT) Received: from localhost ([::1]:52046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iV1Uh-0008A8-9U for incoming@patchwork.ozlabs.org; Wed, 13 Nov 2019 17:52:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33922) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iV1TP-000844-89 for qemu-devel@nongnu.org; Wed, 13 Nov 2019 17:50:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iV1TN-0007dN-Sv for qemu-devel@nongnu.org; Wed, 13 Nov 2019 17:50:51 -0500 Received: from mail-eopbgr820113.outbound.protection.outlook.com ([40.107.82.113]:22310 helo=NAM01-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iV1TN-0007aZ-Lx for qemu-devel@nongnu.org; Wed, 13 Nov 2019 17:50:49 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oF34da6vKD+mlY1Ia9l5iAICn8VFJcfgm0d2/vOjT6nthNmLxgfl/QHKMkcbp0lPkdt//l6RAi745R1eR1OjMTP+i0e9ng13c57QWVnon5Cd5hG6P51ZcLr3dkv7nqCFV+sFz+snB43xjaPG5rmRbJaYFn9lvQYEuEaSxOkY+KzP/rTT3BnaYsMiL9dAT0ZCuguRNBl1grsK+VW+0KzqFnUKCzgsunUHTm5Ee5tkpXz9yXOAGZbDiggJWPla7moxrOodYWMQiLSXYSLnFL/Ur1MjOCF9RTFccfG3Qd9v+wJCUhp9HTrD0y604Eei8owBFyAyxbOQ9A+80LvryhhgOw== 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-SenderADCheck; bh=6yK4EQTHiP96e3ckojDEgRnd8stUoJahr8uFLPEW7u8=; b=Xal+hYR0SajJXP4KzMuLQmkQR0s72UpWgaHAl5OiCM+p5V3SRsagotCQLrCvUxa5AxDcWNeJfUcR6Y/YfsCm+eYItlqZ3qQ7LNo/FYDY0qBnYqT8943ZY4m8L5tZknqXkCU+9kunLVdd6kjnWLPSxIV+lnQNW0YJkb73EaFgbllUC/eMOM/XGc25/5B+Oihd/1FzeHwrgOFs0ayhD47jXsdOlZw6O2wVUpWO4k1U8KuE3SE1jfojWFgjuPcF1hQZfZCX9KzU8QHr9iccwU0RuyrlGByJbpaz7AZngIGA0taucmpd2z7JqqAcDzoXy6UWNNDFkvxNlJp86YKxtS6COg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6yK4EQTHiP96e3ckojDEgRnd8stUoJahr8uFLPEW7u8=; b=nuzpxbltgPmu0+j8cd3/TuN9n3ji+l+2ML8PvdNxpVESTr1HkgXMArhN6/Oxw1Y5rIRNlPbYYXrYs5n9u9lyvPzzUlr5Ch3iLRgojCuwCl9ui5WAffR+nmZeRauez594OP+Fz+ZBPCYbhfRoSqWDIdWheYyX+doqvSpQNwlAT3Y= Received: from MN2PR03MB4800.namprd03.prod.outlook.com (20.179.82.78) by MN2PR03MB5024.namprd03.prod.outlook.com (52.132.169.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.20; Wed, 13 Nov 2019 22:50:44 +0000 Received: from MN2PR03MB4800.namprd03.prod.outlook.com ([fe80::344f:b88:26f0:9f66]) by MN2PR03MB4800.namprd03.prod.outlook.com ([fe80::344f:b88:26f0:9f66%7]) with mapi id 15.20.2451.023; Wed, 13 Nov 2019 22:50:44 +0000 From: "Oleinik, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v5 04/20] qtest: add qtest_server_send abstraction Thread-Topic: [PATCH v5 04/20] qtest: add qtest_server_send abstraction Thread-Index: AQHVmnTIX/obYBmBy0uZ1SClVEboIA== Date: Wed, 13 Nov 2019 22:50:44 +0000 Message-ID: <20191113225030.17023-5-alxndr@bu.edu> References: <20191113225030.17023-1-alxndr@bu.edu> In-Reply-To: <20191113225030.17023-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR15CA0028.namprd15.prod.outlook.com (2603:10b6:208:1b4::41) To MN2PR03MB4800.namprd03.prod.outlook.com (2603:10b6:208:101::14) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 21d69397-d06a-4801-6277-08d7688beaa5 x-ms-traffictypediagnostic: MN2PR03MB5024: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 0220D4B98D x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(366004)(136003)(376002)(346002)(39860400002)(199004)(189003)(2501003)(88552002)(75432002)(54906003)(446003)(7736002)(99286004)(11346002)(6436002)(6486002)(5640700003)(476003)(305945005)(256004)(786003)(2906002)(2351001)(316002)(14454004)(6116002)(86362001)(2616005)(6512007)(6916009)(486006)(3846002)(71200400001)(71190400001)(4326008)(1076003)(36756003)(386003)(8676002)(478600001)(66066001)(76176011)(81166006)(186003)(66946007)(5660300002)(6506007)(81156014)(64756008)(52116002)(26005)(102836004)(50226002)(25786009)(8936002)(66476007)(66556008)(66446008); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR03MB5024; H:MN2PR03MB4800.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 66tcz/E52zl4LA2qlMqUp8Oy81H3PeDRrU8NCESgEoN6b58t9LLcMgCeluRhz5bPS249dP3vFCWcfNAgoX5tw67sBxmAFpgocxcUqGGCp4WYhy6G/DuA+UcTvvb3rNyT3J7qpG+E6A73T/lgfwVnik4x+gsAmk3TvJQN8oJalHl5vTBNnnCTPUicd8ny5N8EYAYBaI3xuLtmZpbssbNoWegSS+KpMcs6SAs1VS5IuyoaTT5u4Z9w9j7cq4TNgZHp09+MGJUmGRPnAr0de0ezOovoZG+TdS8uWR+h1jv8e8dM3e1BQ7SFe35He9fRt8QtjnjpTwW2BiHC80nIvb21AlLc65LlCYTUx9YJ2ZsC99FZCihutMIdnEM/cjQidRjoBnWROWqJbElDbTGOEgqiZxg0IpRmg64ccEMYoyqy8TRqRR2dPzuHoAbr+SzUJjo4 MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 21d69397-d06a-4801-6277-08d7688beaa5 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2019 22:50:44.4513 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: l4L0gs6xnPFvSm8xIY6xVySgepaAtVXDxXTd69l9w3Dv1ERUdKsA5hvUf5nFM+TC X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB5024 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.82.113 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Oleinik, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" qtest_server_send is a function pointer specifying the handler used to transmit data to the qtest client. In the standard configuration, this calls the CharBackend handler, but now it is possible for other types of handlers, e.g direct-function calls if the qtest client and server exist within the same process (inproc) Signed-off-by: Alexander Bulekov --- include/sysemu/qtest.h | 3 +++ qtest.c | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index 5ed09c80b1..e2f1047fd7 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -26,4 +26,7 @@ bool qtest_driver(void); void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **errp); +void qtest_server_set_send_handler(void (*send)(void *, const char *), + void *opaque); + #endif diff --git a/qtest.c b/qtest.c index 8b50e2783e..58d7e2a6fb 100644 --- a/qtest.c +++ b/qtest.c @@ -42,6 +42,8 @@ static GString *inbuf; static int irq_levels[MAX_IRQ]; static qemu_timeval start_time; static bool qtest_opened; +static void (*qtest_server_send)(void*, const char*); +static void *qtest_server_send_opaque; #define FMT_timeval "%ld.%06ld" @@ -228,8 +230,10 @@ static void GCC_FMT_ATTR(1, 2) qtest_log_send(const char *fmt, ...) va_end(ap); } -static void do_qtest_send(CharBackend *chr, const char *str, size_t len) +static void qtest_server_char_be_send(void *opaque, const char *str) { + size_t len = strlen(str); + CharBackend* chr = (CharBackend *)opaque; qemu_chr_fe_write_all(chr, (uint8_t *)str, len); if (qtest_log_fp && qtest_opened) { fprintf(qtest_log_fp, "%s", str); @@ -238,7 +242,7 @@ static void do_qtest_send(CharBackend *chr, const char *str, size_t len) static void qtest_send(CharBackend *chr, const char *str) { - do_qtest_send(chr, str, strlen(str)); + qtest_server_send(qtest_server_send_opaque, str); } static void GCC_FMT_ATTR(2, 3) qtest_sendf(CharBackend *chr, @@ -783,6 +787,16 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** qemu_chr_fe_set_echo(&qtest_chr, true); inbuf = g_string_new(""); + + if (!qtest_server_send) { + qtest_server_set_send_handler(qtest_server_char_be_send, &qtest_chr); + } +} + +void qtest_server_set_send_handler(void (*send)(void*, const char*), void *opaque) +{ + qtest_server_send = send; + qtest_server_send_opaque = opaque; } bool qtest_driver(void)