Skip to contentSkip to conversation

Stack independent BT HAL test tool

PATCH In review Jerzy Kasenberg 2 participants 7 messages Oct 16, 2013 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

v3 cover Stack independent BT HAL test tool

v3:
- underscores changed to dash in file names.
- corrected cast style (space after cast).
- structure initialization with explicit filed names.
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/client/haltest.c     |  161 +++++++++++
 android/client/history.c     |   98 +++++++
 android/client/history.h     |   21 ++
 android/client/if-bt.c       |  631 ++++++++++++++++++++++++++++++++++++++++++
 android/client/if-main.h     |   99 +++++++
 android/client/pollhandler.c |  123 ++++++++
 android/client/pollhandler.h |   26 ++
 android/client/terminal.c    |  538 +++++++++++++++++++++++++++++++++++
 android/client/terminal.h    |   59 ++++
 android/client/textconv.c    |  205 ++++++++++++++
 android/client/textconv.h    |  113 ++++++++
 12 files changed, 2095 insertions(+)
 create mode 100644 android/client/haltest.c
 create mode 100644 android/client/history.c
 create mode 100644 android/client/history.h
 create mode 100644 android/client/if-bt.c
 create mode 100644 android/client/if-main.h
 create mode 100644 android/client/pollhandler.c
 create mode 100644 android/client/pollhandler.h
 create mode 100644 android/client/terminal.c
 create mode 100644 android/client/terminal.h
 create mode 100644 android/client/textconv.c
 create mode 100644 android/client/textconv.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v3 1/5 android: Add haltest skeleton

This tool will be used to test Android Bluetooth HAL implementation.

---
 android/Android.mk           |   17 ++++++
 android/client/haltest.c     |   51 ++++++++++++++++++
 android/client/pollhandler.c |  123 ++++++++++++++++++++++++++++++++++++++++++
 android/client/pollhandler.h |   26 +++++++++
 4 files changed, 217 insertions(+)
 create mode 100644 android/client/haltest.c
 create mode 100644 android/client/pollhandler.c
 create mode 100644 android/client/pollhandler.h
android/Android.mk +17 -0
index 0e025ac..c2a0797 100644
@@ -49,3 +49,20 @@ LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 
 include $(BUILD_SHARED_LIBRARY)
+
+#
+# haltest
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+	client/haltest.c \
+	client/pollhandler.c \
+
+LOCAL_SHARED_LIBRARIES := libhardware
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := haltest
+
+include $(BUILD_EXECUTABLE)
android/client/haltest.c new file +51 -0

51 lines not on this page · raw message

android/client/pollhandler.c new file +123 -0

123 lines not on this page · raw message

android/client/pollhandler.h new file +26 -0
new file mode 100644
index 0000000..e2f22df
@@ -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
#2 lore raw

PATCH v3 2/5 android: Add line editing to haltest

In reply to Jerzy Kasenberg

Android does not have readline.
This patch allows to edit command line.

---
 android/Android.mk        |    1 +
 android/client/haltest.c  |   39 +++-
 android/client/terminal.c |  431 +++++++++++++++++++++++++++++++++++++++++++++
 android/client/terminal.h |   59 +++++++
 4 files changed, 527 insertions(+), 3 deletions(-)
 create mode 100644 android/client/terminal.c
 create mode 100644 android/client/terminal.h
android/Android.mk +1 -0
index c2a0797..2eac3ec 100644
@@ -59,6 +59,7 @@ include $(CLEAR_VARS)
 LOCAL_SRC_FILES := \
 	client/haltest.c \
 	client/pollhandler.c \
+	client/terminal.c \
 
 LOCAL_SHARED_LIBRARIES := libhardware
 
android/client/haltest.c +36 -3
index 11cdd97..de98079 100644
@@ -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/client/terminal.c new file +431 -0

431 lines not on this page · raw message

android/client/terminal.h new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v3 3/5 android: Add history to line editor in haltest

In reply to Jerzy Kasenberg

Added simple history to editor to save time.

---
 android/Android.mk        |    1 +
 android/client/history.c  |   98 +++++++++++++++++++++++++++++++++++++++++
 android/client/history.h  |   21 +++++++++
 android/client/terminal.c |  107 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 227 insertions(+)
 create mode 100644 android/client/history.c
 create mode 100644 android/client/history.h
android/Android.mk +1 -0
index 2eac3ec..d49056c 100644
@@ -60,6 +60,7 @@ LOCAL_SRC_FILES := \
 	client/haltest.c \
 	client/pollhandler.c \
 	client/terminal.c \
+	client/history.c \
 
 LOCAL_SHARED_LIBRARIES := libhardware
 
android/client/history.c new file +98 -0

98 lines not on this page · raw message

android/client/history.h new file +21 -0
new file mode 100644
index 0000000..26085b5
@@ -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/client/terminal.c +107 -0

145 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v3 4/5 android: Add text conversion helpers to haltest

In reply to Jerzy Kasenberg

Application 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/client/textconv.c |  205 +++++++++++++++++++++++++++++++++++++++++++++
 android/client/textconv.h |  113 +++++++++++++++++++++++++
 3 files changed, 319 insertions(+)
 create mode 100644 android/client/textconv.c
 create mode 100644 android/client/textconv.h
android/Android.mk +1 -0
index d49056c..6931c9c 100644
@@ -61,6 +61,7 @@ LOCAL_SRC_FILES := \
 	client/pollhandler.c \
 	client/terminal.c \
 	client/history.c \
+	client/textconv.c \
 
 LOCAL_SHARED_LIBRARIES := libhardware
 
android/client/textconv.c new file +205 -0

205 lines not on this page · raw message

android/client/textconv.h new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v3 5/5 android: Add calls to adapter methods in haltest

In reply to Jerzy Kasenberg

This is first code that actually calls HAL functions. Functions defined in bt_interface_t can be executed.

---
 android/Android.mk       |    1 +
 android/client/haltest.c |   79 +++++-
 android/client/if-bt.c   |  631 ++++++++++++++++++++++++++++++++++++++++++++++
 android/client/if-main.h |   99 ++++++++
 4 files changed, 809 insertions(+), 1 deletion(-)
 create mode 100644 android/client/if-bt.c
 create mode 100644 android/client/if-main.h
android/Android.mk +1 -0
index 6931c9c..88cb960 100644
@@ -62,6 +62,7 @@ LOCAL_SRC_FILES := \
 	client/terminal.c \
 	client/history.c \
 	client/textconv.c \
+	client/if-bt.c \
 
 LOCAL_SHARED_LIBRARIES := libhardware
 
android/client/haltest.c +78 -1

105 lines not on this page · raw message

android/client/if-bt.c new file +631 -0

631 lines not on this page · raw message

android/client/if-main.h new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#6 lore raw
In reply to Jerzy Kasenberg

Hi Jerzy,

Quoted 43 lines · Jerzy Kasenberg

v3:
- underscores changed to dash in file names.
- corrected cast style (space after cast).
- structure initialization with explicit filed names.
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/client/haltest.c     |  161 +++++++++++
 android/client/history.c     |   98 +++++++
 android/client/history.h     |   21 ++
 android/client/if-bt.c       |  631 ++++++++++++++++++++++++++++++++++++++++++
 android/client/if-main.h     |   99 +++++++
 android/client/pollhandler.c |  123 ++++++++
 android/client/pollhandler.h |   26 ++
 android/client/terminal.c    |  538 +++++++++++++++++++++++++++++++++++
 android/client/terminal.h    |   59 ++++
 android/client/textconv.c    |  205 ++++++++++++++
 android/client/textconv.h    |  113 ++++++++
 12 files changed, 2095 insertions(+)
 create mode 100644 android/client/haltest.c
 create mode 100644 android/client/history.c
 create mode 100644 android/client/history.h
Quoted 8 lines
 create mode 100644 android/client/if-bt.c
 create mode 100644 android/client/if-main.h
 create mode 100644 android/client/pollhandler.c
 create mode 100644 android/client/pollhandler.h
 create mode 100644 android/client/terminal.c
 create mode 100644 android/client/terminal.h
 create mode 100644 android/client/textconv.c
 create mode 100644 android/client/textconv.h

All five patches have been pushed upstream. I did have to fix "empty line before EOL" errors for each of the first three patches though, so please avoid that in the future.

Johan