From 274f8c2024f6f0da1eb4bb3e5ec8c1beef185634 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 5 Oct 2018 11:50:46 +0300 Subject: [PATCH] unit: Make use of tester_monitor to print input/output PDUs tester_monitor will forward the data to btmon when -m/--monitor is enabled which will attempt to decode the PDUs: = test-gatt: /robustness/unkown-command - init 11:44:53.464325 = test-gatt: /robustness/unkown-command - setup = test-gatt: /robustness/unkown-command - setup complete = test-gatt: /robustness/unkown-command - run < test-gatt: User Data TX ATT: Exchange MTU Request (0x02) len 2 Client RX MTU: 23 > test-gatt: User Data RX ATT: Exchange MTU Response (0x03) len 2 Server RX MTU: 512 < test-gatt: User Data TX ATT: Unknown (0xff) len 1 00 . = test-gatt: /robustness/unkown-command - test passed = test-gatt: /robustness/unkown-command - teardown = test-gatt: /robustness/unkown-command - teardown complete = test-gatt: /robustness/unkown-command - done Change-Id: I44bd1f913f02a953301dc1e0a4b87a448219e7f0 Signed-off-by: himanshu --- unit/test-avctp.c | 11 ++--------- unit/test-avdtp.c | 11 ++--------- unit/test-avrcp.c | 21 +++++++-------------- unit/test-gatt.c | 6 +++--- unit/test-sdp.c | 11 ++--------- 5 files changed, 16 insertions(+), 44 deletions(-) diff --git a/unit/test-avctp.c b/unit/test-avctp.c index 3bc3569..60fd6ad 100755 --- a/unit/test-avctp.c +++ b/unit/test-avctp.c @@ -81,13 +81,6 @@ struct context { tester_add(name, &data, NULL, function, NULL); \ } while (0) -static void test_debug(const char *str, void *user_data) -{ - const char *prefix = user_data; - - tester_debug("%s%s", prefix, str); -} - static void test_free(gconstpointer user_data) { const struct test_data *data = user_data; @@ -131,7 +124,7 @@ static gboolean send_pdu(gpointer user_data) len = write(context->fd, pdu->data, pdu->size); - util_hexdump('<', pdu->data, len, test_debug, "AVCTP: "); + tester_monitor('<', 0x0000, 0x0017, pdu->data, len); g_assert_cmpint(len, ==, pdu->size); @@ -172,7 +165,7 @@ static gboolean test_handler(GIOChannel *channel, GIOCondition cond, g_assert(len > 0); - util_hexdump('>', buf, len, test_debug, "AVCTP: "); + tester_monitor('>', 0x0000, 0x0017, buf, len); g_assert_cmpint(len, ==, pdu->size); diff --git a/unit/test-avdtp.c b/unit/test-avdtp.c index dd8aed7..176852a 100755 --- a/unit/test-avdtp.c +++ b/unit/test-avdtp.c @@ -99,13 +99,6 @@ struct context { const struct test_data *data; }; -static void test_debug(const char *str, void *user_data) -{ - const char *prefix = user_data; - - tester_debug("%s%s", prefix, str); -} - static void test_free(gconstpointer user_data) { const struct test_data *data = user_data; @@ -158,7 +151,7 @@ static gboolean send_pdu(gpointer user_data) len = write(context->fd, pdu->data, pdu->size); - util_hexdump('<', pdu->data, len, test_debug, "AVDTP: "); + tester_monitor('<', 0x0000, 0x0019, pdu->data, len); g_assert_cmpint(len, ==, pdu->size); @@ -215,7 +208,7 @@ static gboolean test_handler(GIOChannel *channel, GIOCondition cond, g_assert(len > 0); - util_hexdump('>', buf, len, test_debug, "AVDTP: "); + tester_monitor('>', 0x0000, 0x0019, buf, len); g_assert_cmpint(len, ==, pdu->size); diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c index 01307e6..9ffd44c 100755 --- a/unit/test-avrcp.c +++ b/unit/test-avrcp.c @@ -113,13 +113,6 @@ struct context { tester_add(name, &data, NULL, function, NULL); \ } while (0) -static void test_debug(const char *str, void *user_data) -{ - const char *prefix = user_data; - - tester_debug("%s%s", prefix, str); -} - static void test_free(gconstpointer user_data) { const struct test_data *data = user_data; @@ -164,12 +157,13 @@ static gboolean send_pdu(gpointer user_data) pdu = &context->data->pdu_list[context->pdu_offset++]; - if (pdu->browse) + if (pdu->browse) { len = write(context->browse_fd, pdu->data, pdu->size); - else + tester_monitor('<', 0x0000, 0x001b, pdu->data, len); + } else { len = write(context->fd, pdu->data, pdu->size); - - util_hexdump('<', pdu->data, len, test_debug, "AVRCP: "); + tester_monitor('<', 0x0000, 0x0017, pdu->data, len); + } g_assert_cmpint(len, ==, pdu->size); @@ -215,8 +209,7 @@ static gboolean test_handler(GIOChannel *channel, GIOCondition cond, g_assert(len > 0); - if (g_test_verbose()) - util_hexdump('>', buf, len, test_debug, "AVRCP: "); + tester_monitor('>', 0x0000, 0x0017, buf, len); if (!pdu->continuing) g_assert_cmpint(len, ==, pdu->size); @@ -254,7 +247,7 @@ static gboolean browse_test_handler(GIOChannel *channel, GIOCondition cond, g_assert(len > 0); - util_hexdump('>', buf, len, test_debug, "AVRCP: "); + tester_monitor('>', 0x0000, 0x001b, buf, len); g_assert_cmpint(len, ==, pdu->size); diff --git a/unit/test-gatt.c b/unit/test-gatt.c index 5961b02..c888169 100755 --- a/unit/test-gatt.c +++ b/unit/test-gatt.c @@ -491,7 +491,7 @@ static gboolean send_pdu(gpointer user_data) len = write(context->fd, pdu->data, pdu->size); - util_hexdump('<', pdu->data, len, test_debug, "GATT: "); + tester_monitor('<', 0x0004, 0x0000, pdu->data, len); g_assert_cmpint(len, ==, pdu->size); @@ -557,7 +557,7 @@ static gboolean test_handler(GIOChannel *channel, GIOCondition cond, g_assert(len > 0); - util_hexdump('>', buf, len, test_debug, "GATT: "); + tester_monitor('>', 0x0004, 0x0000, buf, len); util_hexdump('=', pdu->data, pdu->size, test_debug, "PDU: "); @@ -2062,7 +2062,7 @@ static void test_server(gconstpointer data) g_assert_cmpint(len, ==, pdu.size); - util_hexdump('<', pdu.data, len, test_debug, "GATT: "); + tester_monitor('<', 0x0004, 0x0000, pdu.data, len); } static void test_search_primary(gconstpointer data) diff --git a/unit/test-sdp.c b/unit/test-sdp.c index ac921a9..b67a551 100755 --- a/unit/test-sdp.c +++ b/unit/test-sdp.c @@ -120,13 +120,6 @@ struct context { const struct test_data *data; }; -static void sdp_debug(const char *str, void *user_data) -{ - const char *prefix = user_data; - - tester_debug("%s%s\n", prefix, str); -} - static void destroy_context(struct context *context) { sdp_svcdb_collect_all(context->fd); @@ -186,7 +179,7 @@ static gboolean server_handler(GIOChannel *channel, GIOCondition cond, return FALSE; } - util_hexdump('<', buf, len, sdp_debug, "SDP: "); + tester_monitor('<', 0x0000, 0x0001, buf, len); handle_internal_request(fd, context->data->mtu, buf, len); @@ -254,7 +247,7 @@ static gboolean client_handler(GIOChannel *channel, GIOCondition cond, if (len < 0) return FALSE; - util_hexdump('>', buf, len, sdp_debug, "SDP: "); + tester_monitor('>', 0x0000, 0x0001, buf, len); g_assert(len > 0); g_assert((size_t) len == rsp_pdu->raw_size + rsp_pdu->cont_len); -- 2.7.4