mirror of git://git.sysmocom.de/ofono
Add simple unit test for CAIF sockets
This commit is contained in:
parent
392f092ee0
commit
648eded47e
|
@ -32,10 +32,11 @@ src/ofono.ver
|
|||
|
||||
unit/test-common
|
||||
unit/test-util
|
||||
unit/test-idmap
|
||||
unit/test-sms
|
||||
unit/test-simutil
|
||||
unit/test-mux
|
||||
unit/test-idmap
|
||||
unit/test-caif
|
||||
|
||||
plugins/*-ofono.rules
|
||||
gatchat/gsmdial
|
||||
|
|
25
Makefile.am
25
Makefile.am
|
@ -155,9 +155,9 @@ builtin_modules += stemodem
|
|||
builtin_sources += drivers/atmodem/atutil.h \
|
||||
drivers/stemodem/stemodem.h \
|
||||
drivers/stemodem/stemodem.c \
|
||||
drivers/stemodem/gprs-context.c \
|
||||
drivers/stemodem/caif_socket.h \
|
||||
drivers/stemodem/if_caif.h \
|
||||
drivers/stemodem/gprs-context.c
|
||||
drivers/stemodem/if_caif.h
|
||||
|
||||
builtin_modules += modemconf
|
||||
builtin_sources += plugins/modemconf.c
|
||||
|
@ -281,9 +281,9 @@ dist_man_MANS = doc/ofonod.8
|
|||
|
||||
unit_objects =
|
||||
|
||||
noinst_PROGRAMS = unit/test-common unit/test-util \
|
||||
unit/test-sms unit/test-simutil unit/test-mux \
|
||||
unit/test-idmap
|
||||
noinst_PROGRAMS = unit/test-common unit/test-util unit/test-idmap \
|
||||
unit/test-sms unit/test-simutil \
|
||||
unit/test-mux unit/test-caif
|
||||
|
||||
unit_test_common_SOURCES = unit/test-common.c src/common.c
|
||||
unit_test_common_LDADD = @GLIB_LIBS@
|
||||
|
@ -293,13 +293,16 @@ unit_test_util_SOURCES = unit/test-util.c src/util.c
|
|||
unit_test_util_LDADD = @GLIB_LIBS@
|
||||
unit_objects += $(unit_test_utils_OBJECTS)
|
||||
|
||||
unit_test_idmap_SOURCES = unit/test-idmap.c src/idmap.c
|
||||
unit_test_idmap_LDADD = @GLIB_LIBS@
|
||||
unit_objects += $(unit_test_idmap_OBJECTS)
|
||||
|
||||
unit_test_sms_SOURCES = unit/test-sms.c src/util.c src/smsutil.c src/storage.c
|
||||
unit_test_sms_LDADD = @GLIB_LIBS@
|
||||
unit_objects += $(unit_test_sms_OBJECTS)
|
||||
|
||||
unit_test_simutil_SOURCES = unit/test-simutil.c src/util.c \
|
||||
src/simutil.c src/smsutil.c \
|
||||
src/storage.c
|
||||
src/simutil.c src/smsutil.c src/storage.c
|
||||
unit_test_simutil_LDADD = @GLIB_LIBS@
|
||||
unit_objects += $(unit_test_simutil_OBJECTS)
|
||||
|
||||
|
@ -307,9 +310,11 @@ unit_test_mux_SOURCES = unit/test-mux.c $(gatchat_sources)
|
|||
unit_test_mux_LDADD = @GLIB_LIBS@
|
||||
unit_objects += $(unit_test_mux_OBJECTS)
|
||||
|
||||
unit_test_idmap_SOURCES = unit/test-idmap.c src/idmap.c
|
||||
unit_test_idmap_LDADD = @GLIB_LIBS@
|
||||
unit_objects += $(unit_test_idmap_OBJECTS)
|
||||
unit_test_caif_SOURCES = unit/test-caif.c $(gatchat_sources) \
|
||||
drivers/stemodem/caif_socket.h \
|
||||
drivers/stemodem/if_caif.h
|
||||
unit_test_caif_LDADD = @GLIB_LIBS@
|
||||
unit_objects += $(unit_test_caif_OBJECTS)
|
||||
|
||||
noinst_PROGRAMS += gatchat/gsmdial
|
||||
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
*
|
||||
* oFono - Open Source Telephony
|
||||
*
|
||||
* Copyright (C) 2008-2010 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 version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gprintf.h>
|
||||
|
||||
#include <gatchat.h>
|
||||
|
||||
#include <drivers/stemodem/caif_socket.h>
|
||||
#include <drivers/stemodem/if_caif.h>
|
||||
|
||||
static GMainLoop *mainloop;
|
||||
|
||||
static int do_connect(void)
|
||||
{
|
||||
struct sockaddr_caif addr;
|
||||
int sk, err;
|
||||
|
||||
/* Create a CAIF socket for AT Service */
|
||||
sk = socket(AF_CAIF, SOCK_SEQPACKET, CAIFPROTO_AT);
|
||||
if (sk < 0) {
|
||||
g_printerr("CAIF socket creation failed (%d)\n", errno);
|
||||
return -EIO;
|
||||
}
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.family = AF_CAIF;
|
||||
addr.u.at.type = CAIF_ATTYPE_PLAIN;
|
||||
|
||||
/* Connect to the AT Service at the modem */
|
||||
err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
|
||||
if (err < 0) {
|
||||
g_printerr("CAIF socket connect failed (%d)\n", errno);
|
||||
close(sk);
|
||||
return err;
|
||||
}
|
||||
|
||||
return sk;
|
||||
}
|
||||
|
||||
static void caif_debug(const char *str, void *data)
|
||||
{
|
||||
g_print("%s\n", str);
|
||||
}
|
||||
|
||||
static void caif_init(gboolean ok, GAtResult *result, gpointer data)
|
||||
{
|
||||
GAtChat *chat = data;
|
||||
|
||||
g_print("caif_init: %d\n", ok);
|
||||
|
||||
if (ok == FALSE) {
|
||||
g_at_chat_unref(chat);
|
||||
g_main_loop_quit(mainloop);
|
||||
return;
|
||||
}
|
||||
|
||||
g_at_chat_unref(chat);
|
||||
g_main_loop_quit(mainloop);
|
||||
}
|
||||
|
||||
static void test_connect(void)
|
||||
{
|
||||
GIOChannel *io;
|
||||
GAtChat *chat;
|
||||
GAtSyntax *syntax;
|
||||
int sk;
|
||||
|
||||
sk = do_connect();
|
||||
if (sk < 0)
|
||||
return;
|
||||
|
||||
io = g_io_channel_unix_new(sk);
|
||||
g_io_channel_set_close_on_unref(io, TRUE);
|
||||
|
||||
syntax = g_at_syntax_new_gsm_permissive();
|
||||
chat = g_at_chat_new(io, syntax);
|
||||
g_at_syntax_unref(syntax);
|
||||
|
||||
g_io_channel_unref(io);
|
||||
|
||||
if (!chat) {
|
||||
g_printerr("Chat creation failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
g_at_chat_set_debug(chat, caif_debug, NULL);
|
||||
g_at_chat_send(chat, "ATE0 +CMEE=1", NULL, caif_init, chat, NULL);
|
||||
|
||||
mainloop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
g_main_loop_run(mainloop);
|
||||
g_main_loop_unref(mainloop);
|
||||
}
|
||||
|
||||
static void test_basic(void)
|
||||
{
|
||||
if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) {
|
||||
test_connect();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
g_test_trap_assert_passed();
|
||||
//g_test_trap_assert_stderr("failed");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func("/testcaif/basic", test_basic);
|
||||
|
||||
return g_test_run();
|
||||
}
|
Loading…
Reference in New Issue