Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp984764pxy; Wed, 5 May 2021 20:12:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLsxcacLYipiZlmaRfdoH64YK6z8c+wND9TsO83TxOTdW4rwsR8YVo7SjCcAphAobZt5YK X-Received: by 2002:a17:907:161e:: with SMTP id hb30mr1952670ejc.360.1620270750723; Wed, 05 May 2021 20:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620270750; cv=none; d=google.com; s=arc-20160816; b=sMzSE8OvRmNatRchPe0J0z27zG4k0SkWmC2xH8YESEQDCgnRAqdkIHmoOWBgskqkdJ X9SFsKMyYoVabWRWKYhWBO8YHyq8H/xla58mjr5DtiUYlO/WPuDkZpTEFiufLV64v6ek k4d8z6CSsJPiY+CwgE2O5Q+lJzqh0MEh7/GcJX37jeIsnWWPLm35msw6yLVHohODr1LP jjzDr4L+/eNK/dwelu753gsHwuudWsG1uLms+vRZ8TuVGbSqOtB49Fa2yMZ7E0rjpvXJ lNogI1PViXYuhO4OO3hfNWnWmheKhcW+k5rFCKF1EphOnGgHqh57BsT03ut1rg2Phq8S z7AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=LghOW4k4wx1m1Ed4anRER1DzEEAWiD6ZCNH/jmaooXc=; b=wx2pGnC87IgPXCAj7JupTBUJsb10l2BL3Fkh5wXh2+t+2NdhQHgqVww1qQH+2uXg2w /0C+/ScP0BZ7MAE5WxMt+XrysoVAa8YcdEnKBTtHXc6W3KmWElx0yo1Fha11B7YJ0L+l cmPWy2f+DEvzUUYaYCUcWDdYeWXbhHHr67zPZhTQT58fLnLUx27YX1xvEE7BZywtkiQZ XfnEB/9uiX8C40ywhrmNxthPOYfWDjGtx6G5EM9FRPB2BV4N94CR3EYqONhHBdoHJk7W Qa8T4+GmwjjbMoAQQM0n1VJ74f3fyEqoths9EQ0/LGsF+jJeT47jivBTm7orIc2Mcsm2 23VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc2si1397697ejc.593.2021.05.05.20.11.58; Wed, 05 May 2021 20:12:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbhEFCTc (ORCPT + 99 others); Wed, 5 May 2021 22:19:32 -0400 Received: from mga06.intel.com ([134.134.136.31]:27097 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231349AbhEFCTa (ORCPT ); Wed, 5 May 2021 22:19:30 -0400 IronPort-SDR: drTc5KnWW6puvEnvIwiYi8iiXHRO3H2K/jTN1Dw8Wj1u2mkfk1kKlHGyoR7hTJpW/7VUDe9aCJ 1HelJ4Gw6inA== X-IronPort-AV: E=McAfee;i="6200,9189,9975"; a="259631499" X-IronPort-AV: E=Sophos;i="5.82,276,1613462400"; d="scan'208";a="259631499" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2021 19:18:32 -0700 IronPort-SDR: yRJCGG+7Cua4cIuj5lA/iF+0pEYbaUNqHOWy5XrmlAGdooVfKh/7XG6XRCoR6y0isc5P4CQvjK 5AYPDkhFP7nw== X-IronPort-AV: E=Sophos;i="5.82,276,1613462400"; d="scan'208";a="469230424" Received: from zloh1-mobl.gar.corp.intel.com (HELO istotlan-desk.intel.com) ([10.254.6.126]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2021 19:18:31 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, Inga Stotland Subject: [PATCH BlueZ 03/11] tools/gap-tester: Convert to use ELL library Date: Wed, 5 May 2021 19:18:09 -0700 Message-Id: <20210506021817.289939-4-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210506021817.289939-1-inga.stotland@intel.com> References: <20210506021817.289939-1-inga.stotland@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This reworks the source code to use ELL primitives and removes dependencies on GLib. --- Makefile.tools | 6 +-- tools/gap-tester.c | 107 +++++++++++++++++++++++++-------------------- 2 files changed, 62 insertions(+), 51 deletions(-) diff --git a/Makefile.tools b/Makefile.tools index c836b5984..55674ca55 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -152,14 +152,12 @@ tools_smp_tester_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la $(GLIB_LIBS) tools_gap_tester_SOURCES = tools/gap-tester.c monitor/bt.h \ - emulator/hciemu.h emulator/hciemu.c \ + emulator/hciemu.h emulator/hciemu-ell.c \ emulator/btdev.h emulator/btdev.c \ emulator/bthost.h emulator/bthost.c \ emulator/smp.c tools_gap_tester_LDADD = lib/libbluetooth-internal.la \ - gdbus/libgdbus-internal.la \ - src/libshared-glib.la \ - $(GLIB_LIBS) $(DBUS_LIBS) + src/libshared-ell.la $(ell_ldadd) tools_sco_tester_SOURCES = tools/sco-tester.c monitor/bt.h \ emulator/hciemu.h emulator/hciemu.c \ diff --git a/tools/gap-tester.c b/tools/gap-tester.c index 942c37d27..c60cf9beb 100644 --- a/tools/gap-tester.c +++ b/tools/gap-tester.c @@ -12,102 +12,114 @@ #include #endif -#include "gdbus/gdbus.h" +#include -#include "src/shared/tester.h" #include "emulator/hciemu.h" +#include "src/shared/bttester.h" -static DBusConnection *dbus_conn = NULL; -static GDBusClient *dbus_client = NULL; -static GDBusProxy *adapter_proxy = NULL; +static struct l_dbus *dbus_conn; +struct l_dbus_client *dbus_client; +struct l_dbus_proxy *adapter_proxy; -static struct hciemu *hciemu_stack = NULL; +static struct hciemu *hciemu_stack; +static struct l_tester *tester; -static void connect_handler(DBusConnection *connection, void *user_data) +static void connect_handler(struct l_dbus *connection, void *user_data) { - tester_print("Connected to daemon"); + bttester_print("Connected to daemon"); hciemu_stack = hciemu_new(HCIEMU_TYPE_BREDRLE); } -static void disconnect_handler(DBusConnection *connection, void *user_data) +static void destroy_client(void *data) { - tester_print("Disconnected from daemon"); + l_dbus_client_destroy(dbus_client); + dbus_client = NULL; +} - dbus_connection_unref(dbus_conn); +static void destroy_conn(void *data) +{ + l_dbus_destroy(dbus_conn); dbus_conn = NULL; +} - tester_teardown_complete(); +static void service_disconnect_handler(struct l_dbus *connection, + void *user_data) +{ + bttester_print("Daemon disconnected"); } -static gboolean compare_string_property(GDBusProxy *proxy, const char *name, - const char *value) +static void client_destroy_handler(void *user_data) { - DBusMessageIter iter; - const char *str; + bttester_print("Disconnected from daemon"); - if (g_dbus_proxy_get_property(proxy, name, &iter) == FALSE) - return FALSE; + if (dbus_conn) + l_idle_oneshot(destroy_conn, NULL, NULL); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) - return FALSE; + l_tester_teardown_complete(tester); +} - dbus_message_iter_get_basic(&iter, &str); +static bool compare_string_property(struct l_dbus_proxy *proxy, + const char *name, const char *value) +{ + const char *str; + + if (!l_dbus_proxy_get_property(proxy, name, "s", &str)) + return false; - return g_str_equal(str, value); + return !strcmp(str, value); } -static void proxy_added(GDBusProxy *proxy, void *user_data) +static void proxy_added(struct l_dbus_proxy *proxy, void *user_data) { const char *interface; - interface = g_dbus_proxy_get_interface(proxy); + interface = l_dbus_proxy_get_interface(proxy); - if (g_str_equal(interface, "org.bluez.Adapter1") == TRUE) { + if (!strcmp(interface, "org.bluez.Adapter1")) { if (compare_string_property(proxy, "Address", - hciemu_get_address(hciemu_stack)) == TRUE) { + hciemu_get_address(hciemu_stack))) { adapter_proxy = proxy; - tester_print("Found adapter"); + bttester_print("Found adapter"); - tester_setup_complete(); + l_tester_setup_complete(tester); } } } -static void proxy_removed(GDBusProxy *proxy, void *user_data) +static void proxy_removed(struct l_dbus_proxy *proxy, void *user_data) { const char *interface; - interface = g_dbus_proxy_get_interface(proxy); + interface = l_dbus_proxy_get_interface(proxy); - if (g_str_equal(interface, "org.bluez.Adapter1") == TRUE) { + if (!strcmp(interface, "org.bluez.Adapter1")) { if (adapter_proxy == proxy) { adapter_proxy = NULL; - tester_print("Adapter removed"); - - g_dbus_client_unref(dbus_client); - dbus_client = NULL; + bttester_print("Adapter removed"); + l_idle_oneshot(destroy_client, NULL, NULL); } } } static void test_setup(const void *test_data) { - dbus_conn = g_dbus_setup_private(DBUS_BUS_SYSTEM, NULL, NULL); - - dbus_client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez"); + dbus_conn = l_dbus_new_default(L_DBUS_SYSTEM_BUS); - g_dbus_client_set_connect_watch(dbus_client, connect_handler, NULL); - g_dbus_client_set_disconnect_watch(dbus_client, - disconnect_handler, NULL); + dbus_client = l_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez"); + l_dbus_client_set_connect_handler(dbus_client, connect_handler, NULL, + NULL); + l_dbus_client_set_disconnect_handler(dbus_client, + service_disconnect_handler, + NULL, client_destroy_handler); - g_dbus_client_set_proxy_handlers(dbus_client, proxy_added, - proxy_removed, NULL, NULL); + l_dbus_client_set_proxy_handlers(dbus_client, proxy_added, + proxy_removed, NULL, NULL, NULL); } static void test_run(const void *test_data) { - tester_test_passed(); + l_tester_test_passed(tester); } static void test_teardown(const void *test_data) @@ -118,9 +130,10 @@ static void test_teardown(const void *test_data) int main(int argc, char *argv[]) { - tester_init(&argc, &argv); + tester = bttester_init(&argc, &argv); - tester_add("Adapter setup", NULL, test_setup, test_run, test_teardown); + l_tester_add(tester, "Adapter setup", NULL, test_setup, test_run, + test_teardown); - return tester_run(); + return bttester_run(); } -- 2.26.3