3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
37 #include <gatchat/gatserver.h>
39 #include "unit/stk-test-data.h"
41 #define OFONO_SERVICE "org.ofono"
42 #define STKTEST_PATH "/stktest"
43 #define STKTEST_ERROR "org.ofono.stktest.Error"
44 #define OFONO_ERROR "org.ofono.Error"
45 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
46 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
47 #define OFONO_STK_INTERFACE OFONO_SERVICE ".SimToolkit"
48 #define OFONO_STKAGENT_INTERFACE OFONO_SERVICE ".SimToolkitAgent"
50 #define LISTEN_PORT 12765
53 TEST_STATE_POWERING_UP = 1,
54 TEST_STATE_REGISTERING_AGENT,
56 TEST_STATE_POWERING_DOWN,
60 TEST_RESULT_NOT_RUN = 0,
65 typedef DBusMessage *(*display_text_cb_t)(DBusMessage *msg, const char *text,
66 unsigned char icon_id,
68 typedef void (*terminal_response_func)(const unsigned char *pdu,
74 unsigned char *req_pdu;
76 unsigned char *rsp_pdu;
79 terminal_response_func tr_func;
80 enum test_result result;
83 static GMainLoop *main_loop = NULL;
84 static volatile sig_atomic_t __terminated = 0;
86 GList *cur_test = NULL;
89 static DBusConnection *conn;
90 static gboolean ofono_running = FALSE;
91 static guint modem_changed_watch;
92 enum test_state state;
95 static guint server_watch;
96 static GAtServer *emulator;
98 /* Emulated modem state variables */
99 static int modem_mode = 0;
101 void __stktest_test_next();
102 void __stktest_test_finish(gboolean successful);
103 static gboolean create_tcp(void);
105 #define STKTEST_AGENT_ASSERT(expr) \
108 g_printerr("Assertion Failed %s:%d %s\n", \
109 __FILE__, __LINE__, #expr); \
110 __stktest_test_finish(FALSE); \
111 return stktest_error_failed(msg); \
115 #define STKTEST_RESPONSE_ASSERT(expect_pdu, expect_pdu_len, \
116 got_pdu, got_pdu_len) \
118 if ((expect_pdu_len) != (got_pdu_len)) { \
119 g_printerr("Assertion Failed %s:%d" \
120 " Wrong response len" \
121 " want: %d, got: %d\n", \
122 __FILE__, __LINE__, \
123 expect_pdu_len, got_pdu_len); \
124 __stktest_test_finish(FALSE); \
128 if (memcmp(expect_pdu, got_pdu, expect_pdu_len) != 0) { \
129 g_printerr("Assertion Failed %s:%d" \
130 "Wrong response\n", \
131 __FILE__, __LINE__); \
132 __stktest_test_finish(FALSE); \
137 static const char *to_hex(const unsigned char *data, unsigned int len)
139 static char buf[512+1];
142 for (i = 0; i < len; i++)
143 sprintf(buf + i * 2, "%02hhX", data[i]);
150 static void send_proactive_command(const unsigned char *pdu, unsigned int len)
154 sprintf(buf, "+CUSATP: %s", to_hex(pdu, len));
155 g_at_server_send_unsolicited(emulator, buf);
158 static DBusMessage *stktest_error_invalid_args(DBusMessage *msg)
160 return g_dbus_create_error(msg, STKTEST_ERROR ".InvalidArguments",
161 "Invalid arguments provided");
164 static DBusMessage *stktest_error_failed(DBusMessage *msg)
166 return g_dbus_create_error(msg, STKTEST_ERROR ".Failed",
170 static DBusMessage *stktest_error_end_session(DBusMessage *msg)
172 return g_dbus_create_error(msg, OFONO_ERROR ".EndSession",
173 "End Session Request");
176 static DBusMessage *stktest_error_go_back(DBusMessage *msg)
178 return g_dbus_create_error(msg, OFONO_ERROR ".GoBack",
182 static DBusMessage *stktest_error_busy(DBusMessage *msg)
184 return g_dbus_create_error(msg, OFONO_ERROR ".Busy",
188 static DBusMessage *agent_release(DBusConnection *conn, DBusMessage *msg,
191 g_print("Got Release\n");
193 return dbus_message_new_method_return(msg);
196 static DBusMessage *agent_display_text(DBusConnection *conn, DBusMessage *msg,
200 unsigned char icon_id;
203 display_text_cb_t func;
205 if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &text,
206 DBUS_TYPE_BYTE, &icon_id,
207 DBUS_TYPE_BOOLEAN, &urgent,
208 DBUS_TYPE_INVALID) == FALSE)
209 return stktest_error_invalid_args(msg);
211 if (cur_test == NULL)
212 return stktest_error_failed(msg);
214 test = cur_test->data;
215 func = test->agent_func;
217 return func(msg, text, icon_id, urgent);
220 static void server_debug(const char *str, void *data)
222 g_print("%s: %s\n", (char *) data, str);
225 static void cgmi_cb(GAtServer *server, GAtServerRequestType type,
226 GAtResult *cmd, gpointer user)
229 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
230 g_at_server_send_info(server, "oFono", TRUE);
231 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
233 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
234 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
237 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
241 static void cgmm_cb(GAtServer *server, GAtServerRequestType type,
242 GAtResult *cmd, gpointer user)
245 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
246 g_at_server_send_info(server, "oFono pre-1.0", TRUE);
247 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
249 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
250 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
253 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
257 static void cgmr_cb(GAtServer *server, GAtServerRequestType type,
258 GAtResult *cmd, gpointer user)
263 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
264 sprintf(buf, "oFono pre-1.0 version: %s", VERSION);
265 g_at_server_send_info(server, buf, TRUE);
266 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
268 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
269 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
272 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
276 static void cgsn_cb(GAtServer *server, GAtServerRequestType type,
277 GAtResult *cmd, gpointer user)
280 case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY:
281 g_at_server_send_info(server, "123456789", TRUE);
282 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
284 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
285 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
288 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
292 static gboolean send_ok(gpointer user)
294 GAtServer *server = user;
296 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
301 static void cfun_cb(GAtServer *server, GAtServerRequestType type,
302 GAtResult *cmd, gpointer user)
307 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
308 g_at_server_send_info(server, "+CFUN: (0-1,4)", TRUE);
309 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
311 case G_AT_SERVER_REQUEST_TYPE_QUERY:
312 snprintf(buf, sizeof(buf), "+CFUN: %d", modem_mode);
313 g_at_server_send_info(server, buf, TRUE);
314 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
316 case G_AT_SERVER_REQUEST_TYPE_SET:
321 g_at_result_iter_init(&iter, cmd);
322 g_at_result_iter_next(&iter, "");
324 if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
327 if (mode != 0 && mode != 1)
330 if (modem_mode == mode) {
331 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
336 g_timeout_add_seconds(1, send_ok, server);
346 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
349 static void cusatt_cb(GAtServer *server, GAtServerRequestType type,
350 GAtResult *cmd, gpointer user)
353 case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
354 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
356 case G_AT_SERVER_REQUEST_TYPE_QUERY:
357 g_at_server_send_ext_final(server, "+CME ERROR: 4");
359 case G_AT_SERVER_REQUEST_TYPE_SET:
362 const unsigned char *pdu;
365 terminal_response_func func;
367 g_at_result_iter_init(&iter, cmd);
368 g_at_result_iter_next(&iter, "");
370 if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
373 if (cur_test == NULL)
376 g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
378 test = cur_test->data;
379 func = test->tr_func;
390 g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
393 static void listen_again(gpointer user_data)
395 g_at_server_unref(emulator);
398 if (create_tcp() == TRUE)
401 g_print("Error listening to socket\n");
402 g_main_loop_quit(main_loop);
405 static void setup_emulator(GAtServer *server)
407 g_at_server_set_debug(server, server_debug, "Server");
409 g_at_server_register(server, "+CGMI", cgmi_cb, NULL, NULL);
410 g_at_server_register(server, "+CGMM", cgmm_cb, NULL, NULL);
411 g_at_server_register(server, "+CGMR", cgmr_cb, NULL, NULL);
412 g_at_server_register(server, "+CGSN", cgsn_cb, NULL, NULL);
413 g_at_server_register(server, "+CFUN", cfun_cb, NULL, NULL);
414 g_at_server_register(server, "+CUSATT", cusatt_cb, NULL, NULL);
416 g_at_server_set_disconnect_function(server, listen_again, NULL);
419 static gboolean on_socket_connected(GIOChannel *chan, GIOCondition cond,
422 struct sockaddr saddr;
423 unsigned int len = sizeof(saddr);
425 GIOChannel *client_io = NULL;
430 fd = accept(g_io_channel_unix_get_fd(chan), &saddr, &len);
434 client_io = g_io_channel_unix_new(fd);
436 emulator = g_at_server_new(client_io);
437 g_at_server_set_echo(emulator, FALSE);
438 g_io_channel_unref(client_io);
440 if (emulator == NULL)
443 setup_emulator(emulator);
450 static gboolean create_tcp(void)
452 struct sockaddr_in addr;
455 GIOChannel *server_io;
457 sk = socket(PF_INET, SOCK_STREAM, 0);
459 g_print("Can't create tcp/ip socket: %s (%d)\n",
460 strerror(errno), errno);
464 memset(&addr, 0, sizeof(addr));
466 addr.sin_family = AF_INET;
467 addr.sin_addr.s_addr = INADDR_ANY;
468 addr.sin_port = htons(LISTEN_PORT);
470 setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));
471 if (bind(sk, (struct sockaddr *) &addr, sizeof(struct sockaddr)) < 0) {
472 g_print("Can't bind socket: %s (%d)", strerror(errno), errno);
477 if (listen(sk, 1) < 0) {
478 g_print("Can't listen on socket: %s (%d)",
479 strerror(errno), errno);
484 g_print("new tcp is created at tcp port %d\n", LISTEN_PORT);
486 server_io = g_io_channel_unix_new(sk);
487 g_io_channel_set_close_on_unref(server_io, TRUE);
489 server_watch = g_io_add_watch_full(server_io,
491 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
492 on_socket_connected, NULL, NULL);
494 g_io_channel_unref(server_io);
499 static gboolean has_stk_interface(DBusMessageIter *iter)
501 DBusMessageIter entry;
503 dbus_message_iter_recurse(iter, &entry);
505 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
506 const char *interface;
508 dbus_message_iter_get_basic(&entry, &interface);
510 if (g_str_equal(interface, OFONO_STK_INTERFACE) == TRUE)
513 dbus_message_iter_next(&entry);
519 static int send_with_reply(const char *path, const char *interface,
520 const char *method, DBusPendingCall **call,
521 DBusPendingCallNotifyFunction cb,
522 void *user_data, DBusFreeFunction free_func,
523 int timeout, int type, ...)
530 msg = dbus_message_new_method_call(OFONO_SERVICE, path,
533 g_printerr("Unable to allocate new D-Bus %s message\n", method);
538 va_start(args, type);
540 if (!dbus_message_append_args_valist(msg, type, args)) {
551 if (!dbus_connection_send_with_reply(conn, msg, &c, timeout)) {
552 g_printerr("Sending %s failed\n", method);
560 dbus_pending_call_set_notify(c, cb, user_data, free_func);
561 dbus_pending_call_unref(c);
563 dbus_message_unref(msg);
568 if (free_func && user_data)
569 free_func(user_data);
572 dbus_message_unref(msg);
577 static void set_property_reply(DBusPendingCall *call, void *user_data)
579 DBusMessage *reply = dbus_pending_call_steal_reply(call);
582 dbus_error_init(&err);
584 if (dbus_set_error_from_message(&err, reply) == TRUE) {
585 g_printerr("%s: %s\n", err.name, err.message);
586 dbus_error_free(&err);
589 dbus_message_unref(reply);
592 static int set_property(const char *path, const char *interface,
593 const char *key, int type, const void *val,
594 DBusPendingCallNotifyFunction notify,
596 DBusFreeFunction destroy)
599 DBusMessageIter iter, value;
600 DBusPendingCall *call;
601 const char *signature;
603 msg = dbus_message_new_method_call(OFONO_SERVICE, path, interface,
608 dbus_message_set_auto_start(msg, FALSE);
610 dbus_message_iter_init_append(msg, &iter);
612 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
615 case DBUS_TYPE_BOOLEAN:
616 signature = DBUS_TYPE_BOOLEAN_AS_STRING;
619 dbus_message_unref(msg);
623 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
625 dbus_message_iter_append_basic(&value, type, val);
626 dbus_message_iter_close_container(&iter, &value);
628 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
629 dbus_message_unref(msg);
633 dbus_message_unref(msg);
638 dbus_pending_call_set_notify(call, notify, user_data, destroy);
640 dbus_pending_call_unref(call);
645 static void register_agent_reply(DBusPendingCall *call, void *user_data)
647 DBusMessage *reply = dbus_pending_call_steal_reply(call);
651 dbus_error_init(&err);
653 if (dbus_set_error_from_message(&err, reply) == TRUE) {
654 g_printerr("%s: %s\n", err.name, err.message);
655 dbus_error_free(&err);
658 dbus_message_unref(reply);
660 state = TEST_STATE_RUNNING;
661 test = cur_test->data;
662 send_proactive_command(test->req_pdu, test->req_len);
665 static void register_agent()
667 const char *path = "/default";
670 g_print("Gained STK interface, registering agent...\n");
672 status = send_with_reply(STKTEST_PATH, OFONO_STK_INTERFACE,
673 "RegisterAgent", NULL,
674 register_agent_reply, NULL, NULL, 1,
675 DBUS_TYPE_OBJECT_PATH, &path,
679 g_printerr("Unable to register agent with oFono\n");
680 g_main_loop_quit(main_loop);
684 state = TEST_STATE_REGISTERING_AGENT;
687 static gboolean modem_changed(DBusConnection *conn,
688 DBusMessage *msg, void *user_data)
690 DBusMessageIter iter, value;
691 const char *path, *key;
694 if (dbus_message_iter_init(msg, &iter) == FALSE)
697 path = dbus_message_get_path(msg);
699 if (g_str_equal(STKTEST_PATH, path) == FALSE)
702 dbus_message_iter_get_basic(&iter, &key);
704 dbus_message_iter_next(&iter);
705 dbus_message_iter_recurse(&iter, &value);
707 if (g_str_equal(key, "Interfaces") == FALSE)
710 has_stk = has_stk_interface(&value);
713 case TEST_STATE_POWERING_UP:
717 case TEST_STATE_REGISTERING_AGENT:
718 case TEST_STATE_RUNNING:
719 if (has_stk == FALSE)
720 g_printerr("Unexpectedly lost STK interface\n");
722 case TEST_STATE_POWERING_DOWN:
729 static void powerup(void)
731 dbus_bool_t powered = TRUE;
733 state = TEST_STATE_POWERING_UP;
734 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
735 DBUS_TYPE_BOOLEAN, &powered,
736 set_property_reply, NULL, NULL);
739 static void get_modems_reply(DBusPendingCall *call, void *user_data)
741 DBusMessage *reply = dbus_pending_call_steal_reply(call);
742 DBusMessageIter iter, list;
744 gboolean found = FALSE;
746 dbus_error_init(&err);
748 if (dbus_set_error_from_message(&err, reply) == TRUE) {
749 g_printerr("%s: %s\n", err.name, err.message);
750 dbus_error_free(&err);
754 if (dbus_message_has_signature(reply, "a(oa{sv})") == FALSE)
757 if (dbus_message_iter_init(reply, &iter) == FALSE)
760 dbus_message_iter_recurse(&iter, &list);
762 while (dbus_message_iter_get_arg_type(&list) == DBUS_TYPE_STRUCT) {
763 DBusMessageIter entry;
766 dbus_message_iter_recurse(&list, &entry);
767 dbus_message_iter_get_basic(&entry, &path);
769 if (g_str_equal(path, STKTEST_PATH))
772 dbus_message_iter_next(&list);
776 dbus_message_unref(reply);
778 if (found == FALSE) {
779 g_printerr("STK Test modem not found\n");
780 g_main_loop_quit(main_loop);
784 g_print("Test modem found\n");
786 modem_changed_watch = g_dbus_add_signal_watch(conn, OFONO_SERVICE,
788 OFONO_MODEM_INTERFACE,
793 if (create_tcp() == FALSE) {
794 g_printerr("Unable to listen on modem emulator socket\n");
795 g_main_loop_quit(main_loop);
798 __stktest_test_next();
801 static int get_modems(DBusConnection *conn)
804 DBusPendingCall *call;
806 msg = dbus_message_new_method_call(OFONO_SERVICE, "/",
807 OFONO_MANAGER_INTERFACE, "GetModems");
811 dbus_message_set_auto_start(msg, FALSE);
813 g_print("getting modems\n");
815 if (dbus_connection_send_with_reply(conn, msg, &call, -1) == FALSE) {
816 dbus_message_unref(msg);
820 dbus_message_unref(msg);
825 dbus_pending_call_set_notify(call, get_modems_reply, conn, NULL);
827 dbus_pending_call_unref(call);
832 static const GDBusMethodTable agent_methods[] = {
833 { GDBUS_METHOD("Release", NULL, NULL, agent_release) },
834 { GDBUS_METHOD("DisplayText",
835 GDBUS_ARGS({ "text", "s" }, { "icon_id", "y" },
836 { "urgent", "b" }), NULL,
837 agent_display_text) },
841 static void ofono_connect(DBusConnection *conn, void *user_data)
843 g_print("starting telephony interface\n");
845 if (!g_dbus_register_interface(conn, "/default",
846 OFONO_STKAGENT_INTERFACE,
847 agent_methods, NULL, NULL,
849 g_printerr("Unable to register local agent");
850 g_main_loop_quit(main_loop);
853 ofono_running = TRUE;
857 static void ofono_disconnect(DBusConnection *conn, void *user_data)
859 g_print("stopping telephony interface\n");
861 g_dbus_unregister_interface(conn, "/default", OFONO_STKAGENT_INTERFACE);
863 ofono_running = FALSE;
865 g_dbus_remove_watch(conn, modem_changed_watch);
866 modem_changed_watch = 0;
869 g_source_remove(server_watch);
873 g_at_server_unref(emulator);
877 static void sig_term(int sig)
879 if (__terminated > 0)
884 g_print("Terminating\n");
886 g_main_loop_quit(main_loop);
889 static void disconnect_callback(DBusConnection *conn, void *user_data)
891 g_printerr("D-Bus disconnect\n");
893 g_main_loop_quit(main_loop);
896 static gboolean end_session_and_finish(gpointer user_data)
898 g_at_server_send_unsolicited(emulator, "+CUSATEND");
899 __stktest_test_finish(TRUE);
904 static void expect_response(const unsigned char *pdu, unsigned int len)
906 struct test *test = cur_test->data;
908 STKTEST_RESPONSE_ASSERT(test->rsp_pdu, test->rsp_len, pdu, len);
910 g_idle_add(end_session_and_finish, NULL);
913 static DBusMessage *test_display_text_11(DBusMessage *msg,
915 unsigned char icon_id,
918 STKTEST_AGENT_ASSERT(g_str_equal(text, "Toolkit Test 1"));
919 STKTEST_AGENT_ASSERT(icon_id == 0);
920 STKTEST_AGENT_ASSERT(urgent == FALSE);
922 return dbus_message_new_method_return(msg);
925 static void power_down_reply(DBusPendingCall *call, void *user_data)
927 __stktest_test_next();
930 void __stktest_test_finish(gboolean successful)
932 struct test *test = cur_test->data;
933 dbus_bool_t powered = FALSE;
935 test->result = successful ? TEST_RESULT_PASSED : TEST_RESULT_FAILED;
937 state = TEST_STATE_POWERING_DOWN;
938 set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
939 DBUS_TYPE_BOOLEAN, &powered,
940 power_down_reply, NULL, NULL);
943 void __stktest_test_next()
945 if (cur_test == NULL)
948 cur_test = cur_test->next;
950 if (cur_test == NULL)
951 g_main_loop_quit(main_loop);
956 static void stktest_add_test(const char *name, const char *method,
957 const unsigned char *req, unsigned int req_len,
958 const unsigned char *rsp, unsigned int rsp_len,
960 terminal_response_func tr_func)
962 struct test *test = g_new0(struct test, 1);
964 test->name = g_strdup(name);
965 test->method = g_strdup(method);
966 test->req_pdu = g_memdup(req, req_len);
967 test->req_len = req_len;
968 test->rsp_pdu = g_memdup(rsp, rsp_len);
969 test->rsp_len = rsp_len;
970 test->agent_func = agent_func;
971 test->tr_func = tr_func;
973 tests = g_list_append(tests, test);
976 static void __stktest_test_init(void)
978 stktest_add_test("Display Text 1.1", "DisplayText",
979 display_text_111, sizeof(display_text_111),
980 display_text_response_111,
981 sizeof(display_text_response_111),
982 test_display_text_11, expect_response);
985 static void test_destroy(gpointer user_data)
987 struct test *test = user_data;
990 g_free(test->method);
991 g_free(test->req_pdu);
992 g_free(test->rsp_pdu);
997 static void __stktest_test_summarize(void)
1001 g_print("\n\nTest Summary\n");
1002 g_print("============\n");
1004 for (l = tests; l; l = l->next) {
1005 struct test *test = l->data;
1007 g_print("%-60s", test->name);
1009 switch (test->result) {
1010 case TEST_RESULT_NOT_RUN:
1011 g_print("Not Run\n");
1013 case TEST_RESULT_PASSED:
1014 g_print("Passed\n");
1016 case TEST_RESULT_FAILED:
1017 g_print("Failed\n");
1023 static void __stktest_test_cleanup(void)
1025 g_list_free_full(tests, test_destroy);
1030 static gboolean option_version = FALSE;
1032 static GOptionEntry options[] = {
1033 { "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
1034 "Show version information and exit" },
1038 int main(int argc, char **argv)
1040 GOptionContext *context;
1041 GError *error = NULL;
1044 struct sigaction sa;
1046 context = g_option_context_new(NULL);
1047 g_option_context_add_main_entries(context, options, NULL);
1049 if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
1050 if (error != NULL) {
1051 g_printerr("%s\n", error->message);
1052 g_error_free(error);
1054 g_printerr("An unknown error occurred\n");
1058 g_option_context_free(context);
1060 if (option_version == TRUE) {
1061 printf("%s\n", VERSION);
1065 __stktest_test_init();
1067 main_loop = g_main_loop_new(NULL, FALSE);
1069 dbus_error_init(&err);
1071 conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
1073 if (dbus_error_is_set(&err) == TRUE) {
1074 fprintf(stderr, "%s\n", err.message);
1075 dbus_error_free(&err);
1077 fprintf(stderr, "Can't register with system bus\n");
1081 g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
1083 memset(&sa, 0, sizeof(sa));
1084 sa.sa_handler = sig_term;
1085 sigaction(SIGINT, &sa, NULL);
1086 sigaction(SIGTERM, &sa, NULL);
1088 watch = g_dbus_add_service_watch(conn, OFONO_SERVICE,
1089 ofono_connect, ofono_disconnect, NULL, NULL);
1091 g_main_loop_run(main_loop);
1093 g_dbus_remove_watch(conn, watch);
1095 if (ofono_running == TRUE)
1096 ofono_disconnect(conn, NULL);
1098 dbus_connection_unref(conn);
1100 g_main_loop_unref(main_loop);
1102 __stktest_test_summarize();
1103 __stktest_test_cleanup();