Stack independent BT HAL test tool
v2 cover Stack independent BT HAL test tool
v2:
- license changed to apache
- source folder changed to hal-client (underscore to dash)
v1:
This tool is for testing Android HAL interfaces from command line. Due to lack of readline on Android simple equivalent is hand coded. This tool can be used with bluedroid stack so no glib dependency.
Tool source code is in folder hal_client, please comment if it should be somewhere else.
Comments welcome.
Best regards
Jerzy Kasenberg
Jerzy Kasenberg (5):
android: Add haltest skeleton
android: Add line editing to haltest
android: Add history to line editor in haltest
android: Add text conversion helpers to haltest
android: Add calls to adapter methods in haltest
android/Android.mk | 21 ++ android/hal-client/haltest.c | 161 ++++++++++ android/hal-client/history.c | 98 ++++++ android/hal-client/history.h | 21 ++ android/hal-client/if_bt.c | 631 ++++++++++++++++++++++++++++++++++++++ android/hal-client/if_main.h | 99 ++++++ android/hal-client/pollhandler.c | 123 ++++++++ android/hal-client/pollhandler.h | 26 ++ android/hal-client/terminal.c | 534 ++++++++++++++++++++++++++++++++ android/hal-client/terminal.h | 59 ++++ android/hal-client/textconv.c | 205 +++++++++++++ android/hal-client/textconv.h | 113 +++++++ 12 files changed, 2091 insertions(+) create mode 100644 android/hal-client/haltest.c create mode 100644 android/hal-client/history.c create mode 100644 android/hal-client/history.h create mode 100644 android/hal-client/if_bt.c create mode 100644 android/hal-client/if_main.h create mode 100644 android/hal-client/pollhandler.c create mode 100644 android/hal-client/pollhandler.h create mode 100644 android/hal-client/terminal.c create mode 100644 android/hal-client/terminal.h create mode 100644 android/hal-client/textconv.c create mode 100644 android/hal-client/textconv.h
Signature · 1 line
1.7.9.5
PATCH v2 1/5 android: Add haltest skeleton
This tool will be used to test Android Bluetooth HAL implementation.
--- android/Android.mk | 17 ++++++ android/hal-client/haltest.c | 51 ++++++++++++++++ android/hal-client/pollhandler.c | 123 ++++++++++++++++++++++++++++++++++++++ android/hal-client/pollhandler.h | 26 ++++++++ 4 files changed, 217 insertions(+) create mode 100644 android/hal-client/haltest.c create mode 100644 android/hal-client/pollhandler.c create mode 100644 android/hal-client/pollhandler.h
android/Android.mk +17 -0
@@ -49,3 +49,20 @@ LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := SHARED_LIBRARIES include $(BUILD_SHARED_LIBRARY) + +# +# haltest +# + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + hal-client/haltest.c \ + hal-client/pollhandler.c \ + +LOCAL_SHARED_LIBRARIES := libhardware + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := haltest + +include $(BUILD_EXECUTABLE)
android/hal-client/haltest.c new file +51 -0
51 lines not on this page · raw message
android/hal-client/pollhandler.c new file +123 -0
123 lines not on this page · raw message
android/hal-client/pollhandler.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 2013 Intel Corporation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +#include <poll.h> + +/* Function to be called when there are event for some descriptor */ +typedef void (*poll_handler )(struct pollfd *pollfd); + +int poll_register_fd (int fd,short events,poll_handler ph); +int poll_unregister_fd (int fd,poll_handler ph); + +void poll_dispatch_loop (void );
Signature · 1 line
1.7.9.5
PATCH v2 2/5 android: Add line editing to haltest
In reply to Jerzy KasenbergAndroid does not have readline.
This patch allows to edit command line.
--- android/Android.mk | 1 + android/hal-client/haltest.c | 39 +++- android/hal-client/terminal.c | 428 +++++++++++++++++++++++++++++++++++++++++ android/hal-client/terminal.h | 59 ++++++ 4 files changed, 524 insertions(+), 3 deletions(-) create mode 100644 android/hal-client/terminal.c create mode 100644 android/hal-client/terminal.h
android/Android.mk +1 -0
@@ -59,6 +59,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := \ hal-client/haltest.c \ hal-client/pollhandler.c \ + hal-client/terminal.c \ LOCAL_SHARED_LIBRARIES := libhardware
android/hal-client/haltest.c +36 -3
@@ -19,8 +19,40 @@#include <poll.h> #include <unistd.h> +#include "terminal.h" #include "pollhandler.h" +/* +* This function changes input parameter line_buffer so it has +* null termination after each token (due to strtok) +* Output argv is filled with pointers to arguments +* returns number of tokens parsed - argc +*/ +static int command_line_to_argv (char *line_buffer, +char *argv[],int argv_size) +{ +static const char *token_breaks ="\r\n\t " ; +char *token; +int argc =0 ; + + token =strtok (line_buffer, token_breaks); +while (token !=NULL && argc < (int )argv_size) { + argv[argc++] = token; + token =strtok (NULL , token_breaks); + } + +return argc; +} + +static void process_line (char *line_buffer) +{ +char *argv[10 ]; +int argc; + + argc =command_line_to_argv (line_buffer, argv,10 ); + +/* TODO: process command line */ +}/* called when there is something on stdin */ static void stdin_handler (struct pollfd *pollfd)
@@ -33,15 +65,16 @@ static void stdin_handler(struct pollfd *pollfd)if (count >0 ) {int i; -for (i =0 ; i < count; ++i) { -/* TODO: process input */ - } +for (i =0 ; i < count; ++i) +terminal_process_char (buf[i], process_line); } } }int main (int argc,char **argv) { +terminal_setup (); +/* Register command line handler */ poll_register_fd (0 ,POLLIN , stdin_handler);
android/hal-client/terminal.c new file +428 -0
428 lines not on this page · raw message
android/hal-client/terminal.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 3/5 android: Add history to line editor in haltest
In reply to Jerzy KasenbergAdded simple history to editor to save time.
--- android/Android.mk | 1 + android/hal-client/history.c | 98 +++++++++++++++++++++++++++++++++++++ android/hal-client/history.h | 21 ++++++++ android/hal-client/terminal.c | 106 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 android/hal-client/history.c create mode 100644 android/hal-client/history.h
android/Android.mk +1 -0
@@ -60,6 +60,7 @@ LOCAL_SRC_FILES := \ hal-client/haltest.c \ hal-client/pollhandler.c \ hal-client/terminal.c \ + hal-client/history.c \ LOCAL_SHARED_LIBRARIES := libhardware
android/hal-client/history.c new file +98 -0
98 lines not on this page · raw message
android/hal-client/history.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Copyright (C) 2013 Intel Corporation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ + +void history_store (const char *filename); +void history_restore (const char *filename); +void history_add_line (const char *line); +int history_get_line (int n,char *buf,int buf_size);
android/hal-client/terminal.c +106 -0
143 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 4/5 android: Add text conversion helpers to haltest
In reply to Jerzy KasenbergApplication uses a lot of text in the form of defines found in header files to represent arguments and output.
Conversion helpers keep functionality of converting string as bt_status_t or uuid in one place.
--- android/Android.mk | 1 + android/hal-client/textconv.c | 205 +++++++++++++++++++++++++++++++++++++++++ android/hal-client/textconv.h | 113 +++++++++++++++++++++++ 3 files changed, 319 insertions(+) create mode 100644 android/hal-client/textconv.c create mode 100644 android/hal-client/textconv.h
android/Android.mk +1 -0
@@ -61,6 +61,7 @@ LOCAL_SRC_FILES := \ hal-client/pollhandler.c \ hal-client/terminal.c \ hal-client/history.c \ + hal-client/textconv.c \ LOCAL_SHARED_LIBRARIES := libhardware
android/hal-client/textconv.c new file +205 -0
205 lines not on this page · raw message
android/hal-client/textconv.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 5/5 android: Add calls to adapter methods in haltest
In reply to Jerzy KasenbergThis is first code that actually calls HAL functions. Functions defined in bt_interface_t can be executed.
--- android/Android.mk | 1 + android/hal-client/haltest.c | 79 +++++- android/hal-client/if_bt.c | 631 ++++++++++++++++++++++++++++++++++++++++++ android/hal-client/if_main.h | 99 +++++++ 4 files changed, 809 insertions(+), 1 deletion(-) create mode 100644 android/hal-client/if_bt.c create mode 100644 android/hal-client/if_main.h
android/Android.mk +1 -0
@@ -62,6 +62,7 @@ LOCAL_SRC_FILES := \ hal-client/terminal.c \ hal-client/history.c \ hal-client/textconv.c \ + hal-client/if_bt.c \ LOCAL_SHARED_LIBRARIES := libhardware
android/hal-client/haltest.c +78 -1
105 lines not on this page · raw message
android/hal-client/if_bt.c new file +631 -0
631 lines not on this page · raw message
android/hal-client/if_main.h new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH v2 5/5] android: Add calls to adapter methods in haltest
Hi Jerzy,
Quoted 5 lines · Jerzy Kasenberg
android/hal-client/if_bt.c new file +5
-0+static bt_callbacks_t bt_callbacks = { +sizeof (bt_callbacks), + adapter_state_changed_cb, + adapter_properties_cb, + remote_device_properties_cb,
android/hal-client/if_bt.c line 281
Quoted 10 lines
android/hal-client/if_bt.c new file +10
-0+ device_found_cb, + discovery_state_changed_cb, + pin_request_cb, + ssp_request_cb, + bond_state_changed_cb, + acl_state_changed_cb, + thread_evt_cb, + dut_mode_recv_cb, + le_test_mode_cb +};
Could we get structure initializations like this to use follow the coding style, i.e.:
static bt_callbacks_t bt_callbacks = {
.member1 = sizeof(),
.member2 = adapter_state_changed_cb,
...
};This way you can directly see that the right members are initialized to the right values and there's no risk that e.g. two members with the same type are swapped (something the compiler wouldn't warn about).
As a general point to others working on the android code: if there are any other similar places elsewhere in the code please fix those too.
Quoted 10 lines
android/hal-client/if_bt.c new file +10
-0+static void init_p (int argc,const char **argv) +{ +int err; +const hw_module_t *module; +hw_device_t *device; + + err =hw_get_module (BT_HARDWARE_MODULE_ID , &module); +if (err) { +haltest_error ("he_get_module returned %d\n" , err); +return ;
android/hal-client/if_bt.c line 302
Quoted 10 lines
android/hal-client/if_bt.c new file +10
-0+ } + + err = module->methods->open (module,BT_HARDWARE_MODULE_ID , &device); +if (err) { +haltest_error ("module->methods->open returned %d\n" , err); +return ; + } + + if_bluetooth = + ((bluetooth_device_t *)device)->get_bluetooth_interface ();
The user space coding style convention is to have a space between the type cast and the variable. In this case you might make the code more readable by adding an extra variable, something like:
bluetooth_device_t *btdev; ... btdev = (bluetooth_device_t *) device; if_bluetooth = btdev->get_bluetooth_interface(); ...
Johan