Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2368992pxj; Sat, 5 Jun 2021 23:40:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTbf++tIT95aTc3zydiomqj3121vTNX1OcRvNWQpfi7+iSuOzTe4aBgKX9sDkTRU53Iu3b X-Received: by 2002:aa7:cb19:: with SMTP id s25mr14008109edt.194.1622961599939; Sat, 05 Jun 2021 23:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622961599; cv=none; d=google.com; s=arc-20160816; b=XuoQecjmd2TKhZRnUyX3hnd/FRMuFgDF1pzVwGpI48iaMtjtIaBBMOUsTY3ZurOZWu uQeXuiXbvhKAcdv3P90pciku87euR94TU95z/3zxO3jxzupV53GngNOe4CdjOW3myd5+ e3oMuZzmgG48Xar3XmPyghF3yvVfK/9j4pKRqjOGJEb8uHsxjpcYvdf3ncHtw/j3taJi J92P4/uhXjipT8wMR41lBBaXiuYTYWko6+Mq51Jx5jnTUB89dPn5vmDRM7Defx4Xst33 bTYrM+djdRMxVbi5obeqcYfXcvPhZAcLAnL4SZAxCPUANncEbUKSnQU2Qu8RiGd0S6Jr uVfg== 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=1pST2OqSbD8I/RU9LARN9sCT2wSScQYSFKrdHwaxHx8=; b=0MK401k4D9LpR3LuB4mzZGLC1bEfIeb8sGAQVmZDur5djhlN/cGDgHzK0xftaK39AK +mBXkxOzvyhkZSpPxRCdzwrkQXb3Y5jIJaZ70DD6lvXF2K17AN3vEpX98uxeCaP76Lw6 ptX2eVfKWz2eFHOwhkzJS2RTutfIX4ZmExrlrSaTM7h1QMLbUTVQCp+MEVhqhl+NP3T/ wN/+HOKXiK6DSPbQgPFwi+Ofpc11OeOIbRcAw7X9DxVfR13PqC8bT2WfswmnM+Nbsrv5 SDVMVkck9YWbouDrrs9/J9EjowLmHYUIve0t5JLh5jGQscfZ8kb8RigBuAW1oIvJA1FK OqZg== 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 t12si9002462ejs.333.2021.06.05.23.39.37; Sat, 05 Jun 2021 23:39:59 -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 S230129AbhFFGjU (ORCPT + 99 others); Sun, 6 Jun 2021 02:39:20 -0400 Received: from mga18.intel.com ([134.134.136.126]:34607 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbhFFGjT (ORCPT ); Sun, 6 Jun 2021 02:39:19 -0400 IronPort-SDR: 4WvLtUahPUrcsyuAM39+a0L7YVPX4t+gtkJttTk7VOC8JZDMXZVKaI7ODPWkBWfHheNdXXPJP9 Ej+ukHVUEIRw== X-IronPort-AV: E=McAfee;i="6200,9189,10006"; a="191815315" X-IronPort-AV: E=Sophos;i="5.83,252,1616482800"; d="scan'208";a="191815315" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2021 23:37:30 -0700 IronPort-SDR: zBfvh1in6TTOmInWN5pBQ92QjsEYIlCvGeWrGwQiSXupT73IF4PcdmprkgpRBZVYWf3SU+Ghun tVAlS5TTV/yA== X-IronPort-AV: E=Sophos;i="5.83,252,1616482800"; d="scan'208";a="481160898" Received: from skambhat-mobl.amr.corp.intel.com (HELO istotlan-desk.intel.com) ([10.209.68.161]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2021 23:37:30 -0700 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, tedd.an@intel.com, Inga Stotland Subject: [PATCH BlueZ 05/11] tools/userchan-tester: Convert to use ELL library Date: Sat, 5 Jun 2021 23:37:13 -0700 Message-Id: <20210606063719.339794-6-inga.stotland@intel.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210606063719.339794-1-inga.stotland@intel.com> References: <20210606063719.339794-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 | 4 +- tools/userchan-tester.c | 151 ++++++++++++++++++---------------------- 2 files changed, 70 insertions(+), 85 deletions(-) diff --git a/Makefile.tools b/Makefile.tools index e86a138a7..9193beef8 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -171,12 +171,12 @@ tools_hci_tester_SOURCES = tools/hci-tester.c monitor/bt.h tools_hci_tester_LDADD = src/libshared-glib.la $(GLIB_LIBS) tools_userchan_tester_SOURCES = tools/userchan-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_userchan_tester_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la $(GLIB_LIBS) + src/libshared-ell.la $(ell_ldadd) endif if TOOLS diff --git a/tools/userchan-tester.c b/tools/userchan-tester.c index c17644fb8..abae52a36 100644 --- a/tools/userchan-tester.c +++ b/tools/userchan-tester.c @@ -12,26 +12,18 @@ #include #endif -#include -#include -#include -#include -#include - -#include +#include #include "lib/bluetooth.h" #include "lib/hci.h" #include "lib/mgmt.h" -#include "monitor/bt.h" #include "emulator/bthost.h" #include "emulator/hciemu.h" -#include "src/shared/tester.h" +#include "src/shared/bttester.h" #include "src/shared/mgmt.h" #include "src/shared/hci.h" -#include "src/shared/util.h" struct test_data { struct mgmt *mgmt; @@ -42,27 +34,29 @@ struct test_data { unsigned int remove_id; }; +static struct l_tester *tester; + static void mgmt_debug(const char *str, void *user_data) { const char *prefix = user_data; - tester_print("%s%s", prefix, str); + bttester_print("%s%s", prefix, str); } static void read_info_callback(uint8_t status, uint16_t length, const void *param, void *user_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); const struct mgmt_rp_read_info *rp = param; char addr[18]; uint16_t manufacturer; uint32_t supported_settings, current_settings; - tester_print("Read Info callback"); - tester_print(" Status: 0x%02x", status); + bttester_print("Read Info callback"); + bttester_print(" Status: 0x%02x", status); if (status || !param) { - tester_pre_setup_failed(); + l_tester_pre_setup_failed(tester); return; } @@ -71,31 +65,29 @@ static void read_info_callback(uint8_t status, uint16_t length, supported_settings = btohl(rp->supported_settings); current_settings = btohl(rp->current_settings); - tester_print(" Address: %s", addr); - tester_print(" Version: 0x%02x", rp->version); - tester_print(" Manufacturer: 0x%04x", manufacturer); - tester_print(" Supported settings: 0x%08x", supported_settings); - tester_print(" Current settings: 0x%08x", current_settings); - tester_print(" Class: 0x%02x%02x%02x", + bttester_print(" Address: %s", addr); + bttester_print(" Version: 0x%02x", rp->version); + bttester_print(" Manufacturer: 0x%04x", manufacturer); + bttester_print(" Supported settings: 0x%08x", supported_settings); + bttester_print(" Current settings: 0x%08x", current_settings); + bttester_print(" Class: 0x%02x%02x%02x", rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]); - tester_print(" Name: %s", rp->name); - tester_print(" Short name: %s", rp->short_name); - - if (strcmp(hciemu_get_address(data->hciemu), addr)) { - tester_pre_setup_failed(); - return; - } + bttester_print(" Name: %s", rp->name); + bttester_print(" Short name: %s", rp->short_name); - tester_pre_setup_complete(); + if (strcmp(hciemu_get_address(data->hciemu), addr)) + l_tester_pre_setup_failed(tester); + else + l_tester_pre_setup_complete(tester); } static void index_added_callback(uint16_t index, uint16_t length, const void *param, void *user_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); - tester_print("Index Added callback"); - tester_print(" Index: 0x%04x", index); + bttester_print("Index Added callback"); + bttester_print(" Index: 0x%04x", index); if (data->mgmt_index != MGMT_INDEX_NONE) return; @@ -109,10 +101,10 @@ static void index_added_callback(uint16_t index, uint16_t length, static void index_removed_callback(uint16_t index, uint16_t length, const void *param, void *user_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); - tester_print("Index Removed callback"); - tester_print(" Index: 0x%04x", index); + bttester_print("Index Removed callback"); + bttester_print(" Index: 0x%04x", index); if (index != data->mgmt_index) return; @@ -120,7 +112,7 @@ static void index_removed_callback(uint16_t index, uint16_t length, if (data->remove_id) { mgmt_unregister(data->mgmt, data->remove_id); data->remove_id = 0; - tester_test_passed(); + l_tester_test_passed(tester); return; } @@ -129,19 +121,19 @@ static void index_removed_callback(uint16_t index, uint16_t length, mgmt_unref(data->mgmt); data->mgmt = NULL; - tester_post_teardown_complete(); + l_tester_post_teardown_complete(tester); } static void read_index_list_callback(uint8_t status, uint16_t length, const void *param, void *user_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); - tester_print("Read Index List callback"); - tester_print(" Status: 0x%02x", status); + bttester_print("Read Index List callback"); + bttester_print(" Status: 0x%02x", status); if (status || !param) { - tester_pre_setup_failed(); + l_tester_pre_setup_failed(tester); return; } @@ -150,25 +142,25 @@ static void read_index_list_callback(uint8_t status, uint16_t length, data->hciemu = hciemu_new(data->hciemu_type); if (!data->hciemu) { - tester_warn("Failed to setup HCI emulation"); - tester_pre_setup_failed(); + bttester_warn("Failed to setup HCI emulation"); + l_tester_pre_setup_failed(tester); } - tester_print("New hciemu instance created"); + bttester_print("New hciemu instance created"); } static void test_pre_setup(const void *test_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); data->mgmt = mgmt_new_default(); if (!data->mgmt) { - tester_warn("Failed to setup management interface"); - tester_pre_setup_failed(); + bttester_warn("Failed to setup management interface"); + l_tester_pre_setup_failed(tester); return; } - if (tester_use_debug()) + if (bttester_use_debug()) mgmt_set_debug(data->mgmt, mgmt_debug, "mgmt: ", NULL); mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0, NULL, @@ -177,7 +169,7 @@ static void test_pre_setup(const void *test_data) static void test_post_teardown(const void *test_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, data->mgmt_index, index_removed_callback, @@ -187,32 +179,25 @@ static void test_post_teardown(const void *test_data) data->hciemu = NULL; } -static void test_data_free(void *test_data) -{ - struct test_data *data = test_data; - - free(data); -} - static void setup_powered_client_callback(uint8_t status, uint16_t length, const void *param, void *user_data) { if (status != MGMT_STATUS_SUCCESS) { - tester_setup_failed(); + l_tester_setup_failed(tester); return; } - tester_print("Controller powered on"); + bttester_print("Controller powered on"); - tester_setup_complete(); + l_tester_setup_complete(tester); } static void setup_powered(const void *test_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); unsigned char param[] = { 0x01 }; - tester_print("Powering on controller"); + bttester_print("Powering on controller"); mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index, sizeof(param), param, setup_powered_client_callback, @@ -224,39 +209,39 @@ static void toggle_powered(const void *test_data); static void toggle_powered_client_callback(uint8_t status, uint16_t length, const void *param, void *user_data) { - bool power = PTR_TO_INT(user_data); + uint32_t power = L_PTR_TO_UINT(user_data); if (status != MGMT_STATUS_SUCCESS) { - tester_setup_failed(); + l_tester_setup_failed(tester); return; } - tester_print("Controller powered %s", power ? "on" : "off"); + bttester_print("Controller powered %s", power ? "on" : "off"); if (power) toggle_powered(false); else - tester_setup_complete(); + l_tester_setup_complete(tester); } static void toggle_powered(const void *test_data) { - struct test_data *data = tester_get_data(); - bool power = PTR_TO_INT(test_data); + struct test_data *data = l_tester_get_data(tester); + uint32_t power = L_PTR_TO_UINT(test_data); unsigned char param[1]; - param[0] = power ? 0x01 : 0x00; + param[0] = power; - tester_print("Powering %s controller", power ? "on" : "off"); + bttester_print("Powering %s controller", power != 0 ? "on" : "off"); mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index, sizeof(param), param, toggle_powered_client_callback, - INT_TO_PTR(power), NULL); + L_UINT_TO_PTR(power), NULL); } static void test_open_success(const void *test_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); struct bt_hci *hci; data->remove_id = mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, @@ -273,49 +258,49 @@ static void test_open_success(const void *test_data) mgmt_unregister(data->mgmt, data->remove_id); data->remove_id = 0; - tester_test_failed(); + l_tester_test_failed(tester); } static void test_open_failed(const void *test_data) { - struct test_data *data = tester_get_data(); + struct test_data *data = l_tester_get_data(tester); struct bt_hci *hci; hci = bt_hci_new_user_channel(data->mgmt_index); if (!hci) { - tester_test_passed(); + l_tester_test_passed(tester); return; } bt_hci_unref(hci); - tester_test_failed(); + l_tester_test_failed(tester); } #define test_user(name, data, setup, func) \ do { \ struct test_data *user; \ - user = malloc(sizeof(struct test_data)); \ + user = l_malloc(sizeof(struct test_data)); \ if (!user) \ break; \ user->hciemu_type = HCIEMU_TYPE_BREDR; \ user->mgmt_index = MGMT_INDEX_NONE; \ user->test_data = data; \ user->remove_id = 0; \ - tester_add_full(name, data, \ - test_pre_setup, setup, func, NULL, \ - test_post_teardown, 2, user, test_data_free); \ + l_tester_add_full(tester, name, data, test_pre_setup, setup, \ + func, NULL, test_post_teardown, 2,\ + user, l_free); \ } while (0) int main(int argc, char *argv[]) { - tester_init(&argc, &argv); + tester = bttester_init(&argc, &argv); test_user("User channel open - Success", NULL, NULL, test_open_success); test_user("User channel open - Failed", NULL, setup_powered, test_open_failed); - test_user("User channel open - Power Toggle Success", INT_TO_PTR(true), - toggle_powered, test_open_success); + test_user("User channel open - Power Toggle Success", + L_UINT_TO_PTR(0x1), toggle_powered, test_open_success); - return tester_run(); + return bttester_run(); } -- 2.26.3