summaryrefslogtreecommitdiff
path: root/android/test-ipc.c
diff options
context:
space:
mode:
authorJakub Tyszkowski <jakub.tyszkowski@tieto.com>2014-02-04 15:39:01 +0100
committerSzymon Janc <szymon.janc@gmail.com>2014-02-04 21:35:10 +0100
commite7a054a8b2e3ad1417497b79415d38ac974abc7c (patch)
tree787aa3e83e617f4bc526e8dbd65054e76e4cb76e /android/test-ipc.c
parentcca001f942f26b47e28d9ed7c5d3f40c6ca03251 (diff)
downloadbluez-e7a054a8b2e3ad1417497b79415d38ac974abc7c.tar.gz
android/unit: Add test cases for proper handler calls
This patch adds tests for calling proper opcode handler. Two handlers are registered, but one always results in failure. No failure means that proper opcode <-> handler maching is done by the ipc mechanism.
Diffstat (limited to 'android/test-ipc.c')
-rw-r--r--android/test-ipc.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/android/test-ipc.c b/android/test-ipc.c
index 8e3150781..1e027fa72 100644
--- a/android/test-ipc.c
+++ b/android/test-ipc.c
@@ -368,6 +368,16 @@ static void test_cmd_handler_1(const void *buf, uint16_t len)
ipc_send_rsp(0, 1, 0);
}
+static void test_cmd_handler_2(const void *buf, uint16_t len)
+{
+ ipc_send_rsp(0, 2, 0);
+}
+
+static void test_cmd_handler_invalid(const void *buf, uint16_t len)
+{
+ raise(SIGTERM);
+}
+
static const struct test_data test_init_1 = {};
static const struct hal_hdr test_cmd_1_hdr = {
@@ -376,6 +386,12 @@ static const struct hal_hdr test_cmd_1_hdr = {
.len = 0
};
+static const struct hal_hdr test_cmd_2_hdr = {
+ .service_id = 0,
+ .opcode = 2,
+ .len = 0
+};
+
static const struct test_data test_cmd_service_invalid_1 = {
.cmd = &test_cmd_1_hdr,
.cmd_size = sizeof(test_cmd_1_hdr),
@@ -403,6 +419,32 @@ static const struct test_data test_cmd_service_invalid_2 = {
.expected_signal = SIGTERM
};
+static const struct ipc_handler cmd_handlers_invalid_2[] = {
+ { test_cmd_handler_1, false, 0 },
+ { test_cmd_handler_invalid, false, 0 }
+};
+
+static const struct ipc_handler cmd_handlers_invalid_1[] = {
+ { test_cmd_handler_invalid, false, 0 },
+ { test_cmd_handler_2, false, 0 },
+};
+
+static const struct test_data test_cmd_opcode_valid_1 = {
+ .cmd = &test_cmd_1_hdr,
+ .cmd_size = sizeof(test_cmd_1_hdr),
+ .service = 0,
+ .handlers = cmd_handlers_invalid_2,
+ .handlers_size = 2,
+};
+
+static const struct test_data test_cmd_opcode_valid_2 = {
+ .cmd = &test_cmd_2_hdr,
+ .cmd_size = sizeof(test_cmd_2_hdr),
+ .service = 0,
+ .handlers = cmd_handlers_invalid_1,
+ .handlers_size = 2,
+};
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -417,6 +459,10 @@ int main(int argc, char *argv[])
&test_cmd_service_valid_1, test_cmd_reg);
g_test_add_data_func("/android_ipc/test_cmd_service_invalid_2",
&test_cmd_service_invalid_2, test_cmd_reg_1);
+ g_test_add_data_func("/android_ipc/test_cmd_opcode_valid_1",
+ &test_cmd_opcode_valid_1, test_cmd_reg);
+ g_test_add_data_func("/android_ipc/test_cmd_opcode_valid_2",
+ &test_cmd_opcode_valid_2, test_cmd_reg);
return g_test_run();
}