From 1854341db894fd9efc8aa5eabe32b3a101ec605c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 13 Dec 2008 19:15:04 +0100 Subject: [PATCH] Add small self testing framework --- src/Makefile.am | 6 +++--- src/connman.h | 2 ++ src/main.c | 11 +++++++++++ src/selftest.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/selftest.c diff --git a/src/Makefile.am b/src/Makefile.am index c3a811c..c2553b0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,9 +11,9 @@ DISTCLEANFILES = $(service_DATA) sbin_PROGRAMS = connmand -connmand_SOURCES = main.c connman.h log.c error.c plugin.c profile.c \ - element.c device.c network.c security.c resolver.c \ - storage.c manager.c agent.c rtnl.c dbus.c +connmand_SOURCES = main.c connman.h log.c selftest.c error.c plugin.c \ + profile.c element.c device.c network.c security.c \ + resolver.c storage.c manager.c agent.c rtnl.c dbus.c if UDEV connmand_SOURCES += udev.c diff --git a/src/connman.h b/src/connman.h index 0275feb..9fbe9ec 100644 --- a/src/connman.h +++ b/src/connman.h @@ -31,6 +31,8 @@ DBusMessage *__connman_error_failed(DBusMessage *msg); DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg); DBusMessage *__connman_error_permission_denied(DBusMessage *msg); +int __connman_selftest(void); + int __connman_storage_init(void); void __connman_storage_cleanup(void); diff --git a/src/main.c b/src/main.c index 000847d..929d31a 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,7 @@ static void disconnect_callback(DBusConnection *conn, void *user_data) static gchar *option_device = NULL; static gboolean option_detach = TRUE; +static gboolean option_selftest = FALSE; static gboolean option_compat = FALSE; static gboolean option_debug = FALSE; @@ -61,6 +62,8 @@ static GOptionEntry options[] = { { "nodaemon", 'n', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &option_detach, "Don't fork daemon to background" }, + { "selftest", 't', 0, G_OPTION_ARG_NONE, &option_selftest, + "Run self testing routines" }, { "compat", 'c', 0, G_OPTION_ARG_NONE, &option_compat, "Enable Network Manager compatibility" }, { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug, @@ -140,6 +143,13 @@ int main(int argc, char *argv[]) __connman_log_init(option_detach, option_debug); + if (option_selftest == TRUE) { + if (__connman_selftest() < 0) { + connman_error("Self testing routines failed"); + goto selftest; + } + } + __connman_storage_init(); __connman_element_init(conn, option_device); @@ -177,6 +187,7 @@ int main(int argc, char *argv[]) __connman_storage_cleanup(); +selftest: __connman_log_cleanup(); dbus_connection_unref(conn); diff --git a/src/selftest.c b/src/selftest.c new file mode 100644 index 0000000..b3e0c23 --- /dev/null +++ b/src/selftest.c @@ -0,0 +1,39 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007-2008 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 +#endif + +#include "connman.h" + +int __connman_selftest(void) +{ + int err; + + connman_info("Start self testing"); + + err = 0; + + connman_info("Finished self testing"); + + return err; +} -- 1.7.9.5