* [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix
@ 2014-03-04 12:28 Marcin Kraglak
0 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-04 12:28 UTC (permalink / raw)
To: linux-bluetooth
It should be freed while destroy.
---
src/shared/hfp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index b10316e..41973b7 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -82,6 +82,8 @@ static void destroy_cmd_handler(void *data)
if (handler->destroy)
handler->destroy(handler->user_data);
+ free(handler->prefix);
+
free(handler);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix
@ 2014-03-05 19:22 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 02/11] unit: Initial version of test-hfp Marcin Kraglak
` (10 more replies)
0 siblings, 11 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
It should be freed while destroy.
---
src/shared/hfp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 08393d8..9523243 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -82,6 +82,8 @@ static void destroy_cmd_handler(void *data)
if (handler->destroy)
handler->destroy(handler->user_data);
+ free(handler->prefix);
+
free(handler);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 02/11] unit: Initial version of test-hfp
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 03/11] unit/test-hfp: Add /hfp/test_cmd_handler_1 Marcin Kraglak
` (9 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
This is skeleton of hfp unit tests with basic init test
for hfp_gw_new().
Basic test with hfp_gw_new() and hfp_gw_unref.
---
.gitignore | 1 +
Makefile.am | 12 ++++
unit/test-hfp.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 186 insertions(+)
create mode 100644 unit/test-hfp.c
diff --git a/.gitignore b/.gitignore
index 94c0c78..6719be8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -84,6 +84,7 @@ unit/test-gdbus-client
unit/test-sdp
unit/test-lib
unit/test-mgmt
+unit/test-hfp
tools/mgmt-tester
tools/smp-tester
tools/gap-tester
diff --git a/Makefile.am b/Makefile.am
index 0c79e58..0107cef 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -293,6 +293,18 @@ unit_test_avrcp_SOURCES = unit/test-avrcp.c \
android/avrcp-lib.c android/avrcp-lib.h
unit_test_avrcp_LDADD = @GLIB_LIBS@ lib/libbluetooth-internal.la
+unit_tests += unit/test-hfp
+
+unit_test_hfp_SOURCES = unit/test-hfp.c \
+ src/shared/io.h src/shared/io-glib.c \
+ src/shared/queue.h src/shared/queue.c \
+ src/shared/util.h src/shared/util.c \
+ src/shared/mgmt.h src/shared/mgmt.c \
+ src/shared/ringbuf.h src/shared/ringbuf.c \
+ src/shared/hfp.h src/shared/hfp.c
+
+unit_test_hfp_LDADD = @GLIB_LIBS@
+
unit_tests += unit/test-gdbus-client
unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
new file mode 100644
index 0000000..f220569
--- /dev/null
+++ b/unit/test-hfp.c
@@ -0,0 +1,173 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2014 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
+ *
+ */
+
+#include <sys/socket.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+#include "src/shared/hfp.h"
+
+struct context {
+ GMainLoop *main_loop;
+ guint watch_id;
+ int fd_server;
+ int fd_client;
+ struct hfp_gw *hfp;
+ const struct test_data *data;
+ unsigned int pdu_offset;
+};
+
+struct test_pdu {
+ bool valid;
+ const uint8_t *data;
+ size_t size;
+};
+
+struct test_data {
+ char *test_name;
+ struct test_pdu *pdu_list;
+};
+
+#define data(args...) ((const unsigned char[]) { args })
+
+#define raw_pdu(args...) \
+ { \
+ .valid = true, \
+ .data = data(args), \
+ .size = sizeof(data(args)), \
+ }
+
+#define data_end() \
+ { \
+ .valid = false, \
+ }
+
+#define define_test(name, function, args...) \
+ do { \
+ const struct test_pdu pdus[] = { \
+ args, { } \
+ }; \
+ static struct test_data data; \
+ data.test_name = g_strdup(name); \
+ data.pdu_list = g_malloc(sizeof(pdus)); \
+ memcpy(data.pdu_list, pdus, sizeof(pdus)); \
+ g_test_add_data_func(name, &data, function); \
+ } while (0)
+
+static void context_quit(struct context *context)
+{
+ g_main_loop_quit(context->main_loop);
+}
+
+static void test_free(gconstpointer user_data)
+{
+ const struct test_data *data = user_data;
+
+ g_free(data->test_name);
+ g_free(data->pdu_list);
+}
+
+static gboolean test_handler(GIOChannel *channel, GIOCondition cond,
+ gpointer user_data)
+{
+ struct context *context = user_data;
+ const struct test_pdu *pdu;
+
+ pdu = &context->data->pdu_list[context->pdu_offset++];
+
+ g_assert(!pdu->valid);
+ context_quit(context);
+
+ return FALSE;
+}
+
+static struct context *create_context(gconstpointer data)
+{
+ struct context *context = g_new0(struct context, 1);
+ GIOChannel *channel;
+ int err, sv[2];
+
+ context->main_loop = g_main_loop_new(NULL, FALSE);
+ g_assert(context->main_loop);
+
+ err = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv);
+ g_assert(err == 0);
+
+ channel = g_io_channel_unix_new(sv[1]);
+
+ g_io_channel_set_close_on_unref(channel, TRUE);
+ g_io_channel_set_encoding(channel, NULL, NULL);
+ g_io_channel_set_buffered(channel, FALSE);
+
+ context->watch_id = g_io_add_watch(channel,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ test_handler, context);
+ g_assert(context->watch_id > 0);
+
+ g_io_channel_unref(channel);
+
+ context->fd_server = sv[1];
+ context->fd_client = sv[0];
+ context->data = data;
+
+ return context;
+}
+
+static void execute_context(struct context *context)
+{
+ g_main_loop_run(context->main_loop);
+
+ g_source_remove(context->watch_id);
+
+ g_main_loop_unref(context->main_loop);
+
+ test_free(context->data);
+
+ g_free(context);
+}
+
+static void test_init(gconstpointer data)
+{
+ struct context *context = create_context(data);
+
+ context->hfp = hfp_gw_new(context->fd_client);
+
+ g_assert(context->hfp);
+ g_assert(hfp_gw_set_close_on_unref(context->hfp, true));
+
+ hfp_gw_unref(context->hfp);
+
+ execute_context(context);
+}
+
+int main(int argc, char *argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+
+ define_test("/hfp/test_init", test_init, data_end());
+
+ return g_test_run();
+}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 03/11] unit/test-hfp: Add /hfp/test_cmd_handler_1
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 02/11] unit: Initial version of test-hfp Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 04/11] unit/test-hfp: Add /hfp/test_cmd_handler_2 Marcin Kraglak
` (8 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index f220569..5e16378 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -104,6 +104,20 @@ static gboolean test_handler(GIOChannel *channel, GIOCondition cond,
return FALSE;
}
+static void cmd_handler(const char *command, void *user_data)
+{
+ struct context *context = user_data;
+ const struct test_pdu *pdu;
+ unsigned int cmd_len = strlen(command);
+
+ pdu = &context->data->pdu_list[context->pdu_offset++];
+
+ g_assert(cmd_len == pdu->size);
+ g_assert(!memcmp(command, pdu->data, cmd_len));
+
+ hfp_gw_send_result(context->hfp, HFP_RESULT_ERROR);
+}
+
static struct context *create_context(gconstpointer data)
{
struct context *context = g_new0(struct context, 1);
@@ -146,6 +160,9 @@ static void execute_context(struct context *context)
test_free(context->data);
+ if (context->hfp)
+ hfp_gw_unref(context->hfp);
+
g_free(context);
}
@@ -159,6 +176,32 @@ static void test_init(gconstpointer data)
g_assert(hfp_gw_set_close_on_unref(context->hfp, true));
hfp_gw_unref(context->hfp);
+ context->hfp = NULL;
+
+ execute_context(context);
+}
+
+static void test_command_handler(gconstpointer data)
+{
+ struct context *context = create_context(data);
+ const struct test_pdu *pdu;
+ ssize_t len;
+ bool ret;
+
+ context->hfp = hfp_gw_new(context->fd_client);
+ g_assert(context->hfp);
+
+ pdu = &context->data->pdu_list[context->pdu_offset++];
+
+ ret = hfp_gw_set_close_on_unref(context->hfp, true);
+ g_assert(ret);
+
+ ret = hfp_gw_set_command_handler(context->hfp, cmd_handler,
+ context, NULL);
+ g_assert(ret);
+
+ len = write(context->fd_server, pdu->data, pdu->size);
+ g_assert_cmpint(len, ==, pdu->size);
execute_context(context);
}
@@ -168,6 +211,10 @@ int main(int argc, char *argv[])
g_test_init(&argc, &argv, NULL);
define_test("/hfp/test_init", test_init, data_end());
+ define_test("/hfp/test_cmd_handler_1", test_command_handler,
+ raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '\r'),
+ raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F'),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 04/11] unit/test-hfp: Add /hfp/test_cmd_handler_2
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 02/11] unit: Initial version of test-hfp Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 03/11] unit/test-hfp: Add /hfp/test_cmd_handler_1 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 05/11] unit/test-hfp: Add /hfp/test_register_1 Marcin Kraglak
` (7 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index 5e16378..1a22298 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -215,6 +215,10 @@ int main(int argc, char *argv[])
raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '\r'),
raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F'),
data_end());
+ define_test("/hfp/test_cmd_handler_2", test_command_handler,
+ raw_pdu('A', 'T', 'D', '1', '2', '3', '4', '\r'),
+ raw_pdu('A', 'T', 'D', '1', '2', '3', '4'),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 05/11] unit/test-hfp: Add /hfp/test_register_1
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (2 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 04/11] unit/test-hfp: Add /hfp/test_cmd_handler_2 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 06/11] unit/test-hfp: Add /hfp/test_register_2 Marcin Kraglak
` (6 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index 1a22298..f202f91 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -44,6 +44,7 @@ struct test_pdu {
bool valid;
const uint8_t *data;
size_t size;
+ enum hfp_gw_cmd_type type;
};
struct test_data {
@@ -65,6 +66,14 @@ struct test_data {
.valid = false, \
}
+#define type_pdu(cmd_type, args...) \
+ { \
+ .valid = true, \
+ .data = data(args), \
+ .size = sizeof(data(args)), \
+ .type = cmd_type, \
+ }
+
#define define_test(name, function, args...) \
do { \
const struct test_pdu pdus[] = { \
@@ -118,6 +127,19 @@ static void cmd_handler(const char *command, void *user_data)
hfp_gw_send_result(context->hfp, HFP_RESULT_ERROR);
}
+static void prefix_handler(struct hfp_gw_result *result,
+ enum hfp_gw_cmd_type type, void *user_data)
+{
+ struct context *context = user_data;
+ const struct test_pdu *pdu;
+
+ pdu = &context->data->pdu_list[context->pdu_offset++];
+
+ g_assert(type == pdu->type);
+
+ hfp_gw_send_result(context->hfp, HFP_RESULT_ERROR);
+}
+
static struct context *create_context(gconstpointer data)
{
struct context *context = g_new0(struct context, 1);
@@ -206,6 +228,33 @@ static void test_command_handler(gconstpointer data)
execute_context(context);
}
+static void test_register(gconstpointer data)
+{
+ struct context *context = create_context(data);
+ const struct test_pdu *pdu;
+ ssize_t len;
+ bool ret;
+
+ context->hfp = hfp_gw_new(context->fd_client);
+ g_assert(context->hfp);
+
+ pdu = &context->data->pdu_list[context->pdu_offset++];
+
+ ret = hfp_gw_set_close_on_unref(context->hfp, true);
+ g_assert(ret);
+
+ ret = hfp_gw_register(context->hfp, prefix_handler, (char *)pdu->data,
+ context, NULL);
+ g_assert(ret);
+
+ pdu = &context->data->pdu_list[context->pdu_offset++];
+
+ len = write(context->fd_server, pdu->data, pdu->size);
+ g_assert_cmpint(len, ==, pdu->size);
+
+ execute_context(context);
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -219,6 +268,11 @@ int main(int argc, char *argv[])
raw_pdu('A', 'T', 'D', '1', '2', '3', '4', '\r'),
raw_pdu('A', 'T', 'D', '1', '2', '3', '4'),
data_end());
+ define_test("/hfp/test_register_1", test_register,
+ raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
+ raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '\r'),
+ type_pdu(HFP_GW_CMD_TYPE_COMMAND, 0),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 06/11] unit/test-hfp: Add /hfp/test_register_2
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (3 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 05/11] unit/test-hfp: Add /hfp/test_register_1 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 07/11] unit/test-hfp: Add /hfp/test_register_3 Marcin Kraglak
` (5 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index f202f91..cb422d4 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -273,6 +273,11 @@ int main(int argc, char *argv[])
raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '\r'),
type_pdu(HFP_GW_CMD_TYPE_COMMAND, 0),
data_end());
+ define_test("/hfp/test_register_2", test_register,
+ raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
+ raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '=', '\r'),
+ type_pdu(HFP_GW_CMD_TYPE_SET, 0),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 07/11] unit/test-hfp: Add /hfp/test_register_3
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (4 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 06/11] unit/test-hfp: Add /hfp/test_register_2 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 08/11] unit/test-hfp: Add /hfp/test_register_4 Marcin Kraglak
` (4 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index cb422d4..a5fe436 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -278,6 +278,11 @@ int main(int argc, char *argv[])
raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '=', '\r'),
type_pdu(HFP_GW_CMD_TYPE_SET, 0),
data_end());
+ define_test("/hfp/test_register_3", test_register,
+ raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
+ raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '?', '\r'),
+ type_pdu(HFP_GW_CMD_TYPE_READ, 0),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 08/11] unit/test-hfp: Add /hfp/test_register_4
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (5 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 07/11] unit/test-hfp: Add /hfp/test_register_3 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 09/11] unit/test-hfp: Add /hfp/test_register_5 Marcin Kraglak
` (3 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index a5fe436..85d3a60 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -283,6 +283,12 @@ int main(int argc, char *argv[])
raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '?', '\r'),
type_pdu(HFP_GW_CMD_TYPE_READ, 0),
data_end());
+ define_test("/hfp/test_register_4", test_register,
+ raw_pdu('+', 'B', 'R', 'S', 'F', '\0'),
+ raw_pdu('A', 'T', '+', 'B', 'R', 'S', 'F', '=', '?',
+ '\r'),
+ type_pdu(HFP_GW_CMD_TYPE_TEST, 0),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 09/11] unit/test-hfp: Add /hfp/test_register_5
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (6 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 08/11] unit/test-hfp: Add /hfp/test_register_4 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 10/11] unit/test-hfp: Add /hfp/test_fragmented_1 Marcin Kraglak
` (2 subsequent siblings)
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index 85d3a60..546a239 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -289,6 +289,11 @@ int main(int argc, char *argv[])
'\r'),
type_pdu(HFP_GW_CMD_TYPE_TEST, 0),
data_end());
+ define_test("/hfp/test_register_5", test_register,
+ raw_pdu('D', '\0'),
+ raw_pdu('A', 'T', 'D', '1', '2', '3', '4', '5', '\r'),
+ type_pdu(HFP_GW_CMD_TYPE_SET, 0),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 10/11] unit/test-hfp: Add /hfp/test_fragmented_1
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (7 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 09/11] unit/test-hfp: Add /hfp/test_register_5 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 11/11] shared/hfp: Don't try read uninitialized data in ringbuffer Marcin Kraglak
2014-03-06 9:21 ` [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Szymon Janc
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
---
unit/test-hfp.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index 546a239..5218a2b 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -45,6 +45,7 @@ struct test_pdu {
const uint8_t *data;
size_t size;
enum hfp_gw_cmd_type type;
+ bool fragmented;
};
struct test_data {
@@ -74,6 +75,14 @@ struct test_data {
.type = cmd_type, \
}
+#define frg_pdu(args...) \
+ { \
+ .valid = true, \
+ .data = data(args), \
+ .size = sizeof(data(args)), \
+ .fragmented = true, \
+ }
+
#define define_test(name, function, args...) \
do { \
const struct test_pdu pdus[] = { \
@@ -255,6 +264,40 @@ static void test_register(gconstpointer data)
execute_context(context);
}
+static gboolean send_pdu(gpointer user_data)
+{
+ struct context *context = user_data;
+ const struct test_pdu *pdu;
+ ssize_t len;
+
+ pdu = &context->data->pdu_list[context->pdu_offset++];
+
+ len = write(context->fd_server, pdu->data, pdu->size);
+ g_assert_cmpint(len, ==, pdu->size);
+
+ pdu = &context->data->pdu_list[context->pdu_offset];
+ if (pdu->fragmented)
+ g_idle_add(send_pdu, context);
+
+ return FALSE;
+}
+
+static void test_fragmented(gconstpointer data)
+{
+ struct context *context = create_context(data);
+ bool ret;
+
+ context->hfp = hfp_gw_new(context->fd_client);
+ g_assert(context->hfp);
+
+ ret = hfp_gw_set_close_on_unref(context->hfp, true);
+ g_assert(ret);
+
+ g_idle_add(send_pdu, context);
+
+ execute_context(context);
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -294,6 +337,10 @@ int main(int argc, char *argv[])
raw_pdu('A', 'T', 'D', '1', '2', '3', '4', '5', '\r'),
type_pdu(HFP_GW_CMD_TYPE_SET, 0),
data_end());
+ define_test("/hfp/test_fragmented_1", test_fragmented,
+ frg_pdu('A'), frg_pdu('T'), frg_pdu('+'), frg_pdu('B'),
+ frg_pdu('R'), frg_pdu('S'), frg_pdu('F'), frg_pdu('\r'),
+ data_end());
return g_test_run();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCHv2 11/11] shared/hfp: Don't try read uninitialized data in ringbuffer
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (8 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 10/11] unit/test-hfp: Add /hfp/test_fragmented_1 Marcin Kraglak
@ 2014-03-05 19:22 ` Marcin Kraglak
2014-03-06 9:21 ` [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Szymon Janc
10 siblings, 0 replies; 13+ messages in thread
From: Marcin Kraglak @ 2014-03-05 19:22 UTC (permalink / raw)
To: linux-bluetooth
Don't try to read uninitialized value if '\r' was not found.
This is call stack from test-hfp run with valgrind:
/hfp/test_fragmented_1: ==24869== Conditional jump or move depends on uninitialised value(s)
==24869== at 0x400A5E4: memchr (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==24869== by 0x804D24D: can_read_data (hfp.c:359)
==24869== by 0x804A6E2: read_callback (io-glib.c:168)
==24869== by 0x4108BFD5: ??? (in /usr/lib/libglib-2.0.so.0.3600.4)
==24869== by 0x410470E5: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.3600.4)
==24869== by 0x41047497: ??? (in /usr/lib/libglib-2.0.so.0.3600.4)
==24869== by 0x41047912: g_main_loop_run (in /usr/lib/libglib-2.0.so.0.3600.4)
==24869== by 0x8049EE0: execute_context (test-hfp.c:186)
==24869== by 0x4106CBC1: ??? (in /usr/lib/libglib-2.0.so.0.3600.4)
==24869== by 0x4106CD5B: ??? (in /usr/lib/libglib-2.0.so.0.3600.4)
==24869== by 0x4106D0E0: g_test_run_suite (in /usr/lib/libglib-2.0.so.0.3600.4)
==24869== by 0x4106D13C: g_test_run (in /usr/lib/libglib-2.0.so.0.3600.4)
---
src/shared/hfp.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 9523243..1be53fb 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -374,6 +374,12 @@ static void process_input(struct hfp_gw *hfp)
char *str2;
size_t len2;
+ /* If there is no more data in ringbuffer,
+ * it's just an incomplete command.
+ */
+ if (len == ringbuf_len(hfp->read_buf))
+ return;
+
str2 = ringbuf_peek(hfp->read_buf, len, &len2);
if (!str2)
return;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
` (9 preceding siblings ...)
2014-03-05 19:22 ` [PATCHv2 11/11] shared/hfp: Don't try read uninitialized data in ringbuffer Marcin Kraglak
@ 2014-03-06 9:21 ` Szymon Janc
10 siblings, 0 replies; 13+ messages in thread
From: Szymon Janc @ 2014-03-06 9:21 UTC (permalink / raw)
To: Marcin Kraglak; +Cc: linux-bluetooth
Hi Marcin,
On Wednesday 05 of March 2014 20:22:46 Marcin Kraglak wrote:
> It should be freed while destroy.
> ---
> src/shared/hfp.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index 08393d8..9523243 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -82,6 +82,8 @@ static void destroy_cmd_handler(void *data)
> if (handler->destroy)
> handler->destroy(handler->user_data);
>
> + free(handler->prefix);
> +
> free(handler);
> }
>
All patches applied, thanks.
--
Best regards,
Szymon Janc
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2014-03-06 9:21 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-05 19:22 [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 02/11] unit: Initial version of test-hfp Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 03/11] unit/test-hfp: Add /hfp/test_cmd_handler_1 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 04/11] unit/test-hfp: Add /hfp/test_cmd_handler_2 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 05/11] unit/test-hfp: Add /hfp/test_register_1 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 06/11] unit/test-hfp: Add /hfp/test_register_2 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 07/11] unit/test-hfp: Add /hfp/test_register_3 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 08/11] unit/test-hfp: Add /hfp/test_register_4 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 09/11] unit/test-hfp: Add /hfp/test_register_5 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 10/11] unit/test-hfp: Add /hfp/test_fragmented_1 Marcin Kraglak
2014-03-05 19:22 ` [PATCHv2 11/11] shared/hfp: Don't try read uninitialized data in ringbuffer Marcin Kraglak
2014-03-06 9:21 ` [PATCHv2 01/11] shared/hfp: Fix not freeing cmd_handler prefix Szymon Janc
-- strict thread matches above, loose matches on Subject: below --
2014-03-04 12:28 Marcin Kraglak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox