aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2014-02-21 23:24:02 +0100
committerPaul Kocialkowski <contact@paulk.fr>2014-02-21 23:24:02 +0100
commit420519cbbaf40fb2af8295f8eb7a80d281b0933d (patch)
tree28681d2d264bcc913b16ccadd08801b6a6796d47
parent33246c77f3d28e9e7a47e089e8230528151125b1 (diff)
downloadexternal_libsamsung-ipc-420519cbbaf40fb2af8295f8eb7a80d281b0933d.zip
external_libsamsung-ipc-420519cbbaf40fb2af8295f8eb7a80d281b0933d.tar.gz
external_libsamsung-ipc-420519cbbaf40fb2af8295f8eb7a80d281b0933d.tar.bz2
tools: ipc-test test program, for various purposes
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--Android.mk14
-rw-r--r--tools/Makefile.am5
-rw-r--r--tools/ipc-test.c137
3 files changed, 156 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
index 6de4d33..f762eef 100644
--- a/Android.mk
+++ b/Android.mk
@@ -104,3 +104,17 @@ LOCAL_MODULE := ipc-modem
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := tools/ipc-test.c
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+
+LOCAL_STATIC_LIBRARIES := libsamsung-ipc
+LOCAL_SHARED_LIBRARIES := libutils
+
+LOCAL_MODULE := ipc-test
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 188b64a..4a0a821 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -6,8 +6,13 @@ AM_CFLAGS = \
bin_PROGRAMS = \
ipc-modem \
+ ipc-test \
$(NULL)
ipc_modem_SOURCES = ipc-modem.c
ipc_modem_LDADD = $(top_builddir)/samsung-ipc/libsamsung-ipc.la
ipc_modem_LDFLAGS =
+
+ipc_test_SOURCES = ipc-test.c
+ipc_test_LDADD = $(top_builddir)/samsung-ipc/libsamsung-ipc.la
+ipc_test_LDFLAGS =
diff --git a/tools/ipc-test.c b/tools/ipc-test.c
new file mode 100644
index 0000000..2965f05
--- /dev/null
+++ b/tools/ipc-test.c
@@ -0,0 +1,137 @@
+/*
+ * This file is part of libsamsung-ipc.
+ *
+ * Copyright (C) 2014 Paul Kocialkowsk <contact@paulk.fr>
+ *
+ * libsamsung-ipc 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.
+ *
+ * libsamsung-ipc 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 libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <samsung-ipc.h>
+
+void log_callback(void *data, const char *message)
+{
+ char *buffer;
+ size_t length;
+ int i;
+
+ if (message == NULL)
+ return;
+
+ buffer = strdup(message);
+ length = strlen(message);
+
+ for (i = length; i > 0; i--) {
+ if (buffer[i] == '\n')
+ buffer[i] = '\0';
+ else if (buffer[i] != '\0')
+ break;
+ }
+
+ printf("[ipc] %s\n", buffer);
+
+ free(buffer);
+}
+
+int main(int args, char *argv[])
+{
+ struct ipc_client *client = NULL;
+ struct ipc_message message;
+ int rc;
+ int i;
+
+ client = ipc_client_create(IPC_CLIENT_TYPE_FMT);
+ if (client == NULL) {
+ printf("Creating client failed\n");
+ goto error;
+ }
+
+ rc = ipc_client_log_callback_register(client, log_callback, NULL);
+ if (rc < 0) {
+ printf("Registering log callback failed\n");
+ goto error;
+ }
+
+ rc = ipc_client_data_create(client);
+ if (rc < 0) {
+ printf("Creating data failed\n");
+ goto error;
+ }
+
+ rc = ipc_client_boot(client);
+ if (rc < 0) {
+ printf("Booting failed\n");
+ goto error;
+ }
+
+ rc = ipc_client_power_on(client);
+ if (rc < 0) {
+ printf("Powering on failed\n");
+ goto error;
+ }
+
+ rc = ipc_client_open(client);
+ if (rc < 0) {
+ printf("Opening failed\n");
+ goto error;
+ }
+
+ for (i = 0; i < 5; i++) {
+ rc = ipc_client_poll(client, NULL);
+ if (rc < 0) {
+ printf("Polling failed\n");
+ break;
+ }
+
+ rc = ipc_client_recv(client, &message);
+ if (rc < 0) {
+ printf("Receiving failed\n");
+ break;
+ }
+
+ if (message.data != NULL && message.size > 0) {
+ free(message.data);
+ message.data = NULL;
+ }
+ }
+
+ rc = ipc_client_close(client);
+ if (rc < 0) {
+ printf("Closing failed\n");
+ goto error;
+ }
+
+ rc = ipc_client_power_off(client);
+ if (rc < 0) {
+ printf("Powering on failed\n");
+ goto error;
+ }
+
+ rc = 0;
+ goto complete;
+
+error:
+ rc = 1;
+
+complete:
+ if (client != NULL)
+ ipc_client_destroy(client);
+
+ return rc;
+}
+
+// vim:ts=4:sw=4:expandtab