From 7ba4515fb643cb6ee7ec6740f1dd43abeca686f8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 12 Jan 2014 16:00:47 -0800 Subject: [PATCH] tools: Add skeleton for HCI controller testing --- .gitignore | 1 + Makefile.tools | 10 +++- doc/test-coverage.txt | 3 +- tools/hci-tester.c | 115 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 tools/hci-tester.c diff --git a/.gitignore b/.gitignore index 175828583..077b1c95a 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,7 @@ tools/mpris-player tools/bluetooth-player tools/l2cap-tester tools/sco-tester +tools/hci-tester tools/btproxy tools/btinfo tools/3dsp diff --git a/Makefile.tools b/Makefile.tools index 6d767d552..4b07bab35 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -39,7 +39,7 @@ if EXPERIMENTAL noinst_PROGRAMS += emulator/btvirt emulator/b1ee tools/3dsp \ tools/mgmt-tester tools/gap-tester \ tools/l2cap-tester tools/sco-tester \ - tools/smp-tester + tools/smp-tester tools/hci-tester emulator_btvirt_SOURCES = emulator/main.c monitor/bt.h \ monitor/mainloop.h monitor/mainloop.c \ @@ -111,6 +111,14 @@ tools_sco_tester_SOURCES = tools/sco-tester.c monitor/bt.h \ src/shared/hciemu.h src/shared/hciemu.c \ src/shared/tester.h src/shared/tester.c tools_sco_tester_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@ + +tools_hci_tester_SOURCES = tools/hci-tester.c monitor/bt.h \ + src/shared/io.h src/shared/io-glib.c \ + src/shared/hci.h src/shared/hci.c \ + src/shared/util.h src/shared/util.c \ + src/shared/queue.h src/shared/queue.c \ + src/shared/tester.h src/shared/tester.c +tools_hci_tester_LDADD = @GLIB_LIBS@ endif if TOOLS diff --git a/doc/test-coverage.txt b/doc/test-coverage.txt index 1cfe7fb89..61461c392 100644 --- a/doc/test-coverage.txt +++ b/doc/test-coverage.txt @@ -35,8 +35,9 @@ l2cap-tester 15 Kernel L2CAP implementation testing smp-tester 4 Kernel SMP implementation testing sco-tester 8 Kernel SCO implementation testing gap-tester 1 Daemon D-Bus API testing +hci-tester 1 Controller hardware testing ----- - 190 + 191 Android end-to-end testing diff --git a/tools/hci-tester.c b/tools/hci-tester.c new file mode 100644 index 000000000..29d261a1d --- /dev/null +++ b/tools/hci-tester.c @@ -0,0 +1,115 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2013 Intel Corporation. All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "monitor/bt.h" +#include "src/shared/hci.h" +#include "src/shared/tester.h" + +struct test_data { + const void *test_data; + uint16_t index; + struct bt_hci *hci; +}; + +static void test_pre_setup_reset_complete(const void *data, uint8_t size, + void *user_data) +{ + uint8_t status = *((uint8_t *) data); + + if (status) { + tester_warn("HCI Reset command failed (0x%02x)", status); + tester_pre_setup_failed(); + return; + } + + tester_pre_setup_complete(); +} + +static void test_pre_setup(const void *test_data) +{ + struct test_data *data = tester_get_data(); + + data->hci = bt_hci_new_user_channel(data->index); + if (!data->hci) { + tester_warn("Failed to setup HCI user channel"); + tester_pre_setup_failed(); + return; + } + + if (!bt_hci_send(data->hci, BT_HCI_CMD_RESET, NULL, 0, + test_pre_setup_reset_complete, NULL, NULL)) { + tester_warn("Failed to send HCI Reset command"); + tester_pre_setup_failed(); + return; + } +} + +static void test_post_teardown(const void *test_data) +{ + struct test_data *data = tester_get_data(); + + bt_hci_unref(data->hci); + data->hci = NULL; + + tester_post_teardown_complete(); +} + +static void test_data_free(void *test_data) +{ + struct test_data *data = test_data; + + free(data); +} + +#define test_hci(name, data, setup, func) \ + do { \ + struct test_data *user; \ + user = calloc(1, sizeof(struct test_data)); \ + if (!user) \ + break; \ + user->test_data = data; \ + user->index = 0; \ + tester_add_full(name, data, \ + test_pre_setup, setup, func, NULL, \ + test_post_teardown, 2, user, test_data_free); \ + } while (0) + +static void dummy_test(const void *test_data) +{ + tester_test_passed(); +} + +int main(int argc, char *argv[]) +{ + tester_init(&argc, &argv); + + test_hci("User channel setup", NULL, NULL, dummy_test); + + return tester_run(); +} -- 2.47.3