From b4bacff9ece76ba19bed1508a61e69bc65c9c5db Mon Sep 17 00:00:00 2001 From: Abhishek Sansanwal Date: Thu, 15 Feb 2018 14:45:39 +0530 Subject: [PATCH] Added initial code for gtest - Without Wi-Fi Mesh feature Overall coverage rate: lines......: 80.5% (1213 of 1506 lines) functions..: 84.0% (121 of 144 functions) - Without Wi-Fi Mesh feature but without Wi-Fi chip Overall coverage rate: lines......: 85.6% (1327 of 1551 lines) functions..: 91.1% (133 of 146 functions) - With Wi-Fi Mesh feature and without peer nodes Overall coverage rate: lines......: 94.9% (1472 of 1551 lines) functions..: 95.9% (140 of 146 functions) - With Wi-Fi Mesh feature and with 1 more peer nodes Overall coverage rate: lines......: 97.1% (1506 of 1551 lines) functions..: 98.6% (144 of 146 functions) Change-Id: I17efc29c1933a015b418b7cb47b5afd3ad3ba431 Signed-off-by: Abhishek Sansanwal Signed-off-by: saerome.kim Signed-off-by: Nishant Chaprana Signed-off-by: Kshitiz --- CMakeLists.txt | 16 +- files/wmesh.sh.in | 0 include/wmesh-util.h | 4 + introspection/gen.sh | 0 packaging/wifi-mesh-manager.spec | 20 +- src/wmesh-bridge.c | 14 +- src/wmesh-gdbus.c | 87 ++++-- src/wmesh-interface.c | 44 ++- src/wmesh-netlink.c | 144 ++++++++- src/wmesh-peer-monitor.c | 13 +- src/wmesh-request.c | 104 ++++++- src/wmesh-service-interface.c | 198 ++++++++---- src/wmesh-service.c | 2 + src/wmesh-softap.c | 59 +++- src/wmeshd.c | 22 +- unittest/CMakeLists.txt | 32 ++ unittest/gdbus.cpp | 185 ++++++++++++ unittest/gdbus.h | 83 +++++ unittest/manager.cpp | 83 +++++ unittest/manager.h | 34 +++ unittest/unittest.cpp | 293 ++++++++++++++++++ unittest/wmesh.cpp | 632 +++++++++++++++++++++++++++++++++++++++ unittest/wmesh.h | 56 ++++ unittest/wmeshmgr.h | 46 +++ 24 files changed, 2034 insertions(+), 137 deletions(-) mode change 100755 => 100644 files/wmesh.sh.in mode change 100755 => 100644 introspection/gen.sh mode change 100755 => 100644 src/wmesh-gdbus.c create mode 100644 unittest/CMakeLists.txt create mode 100644 unittest/gdbus.cpp create mode 100644 unittest/gdbus.h create mode 100644 unittest/manager.cpp create mode 100644 unittest/manager.h create mode 100644 unittest/unittest.cpp create mode 100644 unittest/wmesh.cpp create mode 100644 unittest/wmesh.h create mode 100644 unittest/wmeshmgr.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6819b6c..bc9748d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,13 @@ MESSAGE(" - Adding external C flags") FOREACH(flag ${daemon_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wall -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable") + +IF (BUILD_GTESTS) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wall -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -fvisibility=default -fprofile-arcs -ftest-coverage") +ELSE (BUILD_GTESTS) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Werror -Wextra -Wall -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable") +ENDIF (BUILD_GTESTS) ##Address-Space Layout Randomization MESSAGE(" - Address-Space Layout Randomizations") @@ -37,6 +43,10 @@ IF(TIZEN_FEATURE_MESH_ON_DEMAND) ADD_DEFINITIONS(-DTIZEN_FEATURE_MESH_ON_DEMAND) ENDIF(TIZEN_FEATURE_MESH_ON_DEMAND) +IF(BUILD_GCOV) + ADD_DEFINITIONS(-DBUILD_GCOV) +ENDIF(BUILD_GCOV) + MESSAGE(" - Generating... dbus interface") SET(INTROSPECTION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/introspection) ADD_CUSTOM_COMMAND( @@ -78,3 +88,7 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) MESSAGE(" - Copying...meshd") CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/wmesh.sh.in ${CMAKE_SOURCE_DIR}/files/wmesh.sh @ONLY) INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/wmesh.sh DESTINATION ${SBIN_DIR}) + +IF(BUILD_GTESTS) + ADD_SUBDIRECTORY(unittest) +ENDIF(BUILD_GTESTS) diff --git a/files/wmesh.sh.in b/files/wmesh.sh.in old mode 100755 new mode 100644 diff --git a/include/wmesh-util.h b/include/wmesh-util.h index 211c778..17ca905 100644 --- a/include/wmesh-util.h +++ b/include/wmesh-util.h @@ -24,17 +24,21 @@ #define NOTUSED(var) (var = var) #define wmeshd_check_null_ret_error(name, value, error) do { \ + /* LCOV_EXCL_START */ \ if (G_UNLIKELY(NULL == (value))) { \ WMESH_LOGE("%s is NULL", name); \ return error; \ } \ + /* LCOV_EXCL_STOP */ \ } while (FALSE) #define wmeshd_check_null_ret(name, value) do { \ + /* LCOV_EXCL_START */ \ if (G_UNLIKELY(NULL == (value))) { \ WMESH_LOGE("%s is NULL", name); \ return; \ } \ + /* LCOV_EXCL_STOP */ \ } while (FALSE) #endif /* __WMESH_UTIL_H__ */ diff --git a/introspection/gen.sh b/introspection/gen.sh old mode 100755 new mode 100644 diff --git a/packaging/wifi-mesh-manager.spec b/packaging/wifi-mesh-manager.spec index 305c1bf..a738bdd 100644 --- a/packaging/wifi-mesh-manager.spec +++ b/packaging/wifi-mesh-manager.spec @@ -1,4 +1,6 @@ %define CHECK_WMESH_PRIVILEGE False +%define gcov 1 +%define gtests 1 Name: wifi-mesh-manager Summary: Wi-Fi mesh network daemon @@ -20,6 +22,11 @@ BuildRequires: pkgconfig(libcrypto) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-network-wifi-manager) BuildRequires: cmake + +%if 0%{?gtests:1} +BuildRequires: pkgconfig(gmock) +%endif + # if wmeshd do dhcp instead of connman Requires: net-tools Requires: toybox-symlinks-dhcp @@ -45,11 +52,17 @@ cp -a %{SOURCE3} . CFLAGS=$(echo $CFLAGS | sed 's/-O2/-O0/' | sed 's/-O1/-O0/' | sed 's/-Wp,-D_FORTIFY_SOURCE=2//') CXXFLAGS=$(echo $CXXFLAGS | sed 's/-O2/-O0/' | sed 's/-O1/-O0/' | sed 's/-Wp,-D_FORTIFY_SOURCE=2//') +%if 0%{?gcov:1} +export LDFLAGS+=" -lgcov" +%endif + cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ -DTIZEN_FEATURE_MESH_ON_DEMAND=1 \ -DLIB_DIR=%{_libdir} \ -DBIN_DIR=%{_bindir} \ - -DSBIN_DIR=%{_sbindir} + -DSBIN_DIR=%{_sbindir} \ + -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \ + -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} make %{?_smp_mflags} @@ -81,3 +94,8 @@ chmod 755 %{_sbindir}/wmesh.sh %attr(644,root,root) %{_datadir}/dbus-1/system-services/* %attr(644,root,root) %{_unitdir}/wmeshd.service %attr(750,root,root) %{_sbindir}/wmesh.sh + +%if 0%{?gtests:1} + %{_bindir}/gtest* +%endif + diff --git a/src/wmesh-bridge.c b/src/wmesh-bridge.c index 7a57f12..8c61a08 100644 --- a/src/wmesh-bridge.c +++ b/src/wmesh-bridge.c @@ -41,6 +41,7 @@ extern unsigned int if_nametoindex(const char *__ifname); #define ERROR_MESSAGE_LENGTH 256 +/* LCOV_EXCL_START */ int wmesh_bridge_create(const char* bridge_name) { int ret = WMESHD_ERROR_NONE; @@ -207,7 +208,7 @@ int wmesh_bridge_del_interface(const char* bridge_name, const char* interface) br_fd = socket(AF_LOCAL, SOCK_STREAM, 0); if (br_fd < 0) { strerror_r(errno, str_error, ERROR_MESSAGE_LENGTH); - WMESH_LOGD("Failed to open socket [%s(%d)]", str_error, errno); + WMESH_LOGE("Failed to open socket [%s(%d)]", str_error, errno); return WMESHD_ERROR_IO_ERROR; } @@ -222,7 +223,7 @@ int wmesh_bridge_del_interface(const char* bridge_name, const char* interface) #endif if (val < 0) { strerror_r(errno, str_error, ERROR_MESSAGE_LENGTH); - WMESH_LOGD("Failed to delete interface [%s] from bridge [%s(%d)]", + WMESH_LOGE("Failed to delete interface [%s] from bridge [%s(%d)]", interface, str_error, errno); ret = WMESHD_ERROR_IO_ERROR; @@ -232,6 +233,7 @@ int wmesh_bridge_del_interface(const char* bridge_name, const char* interface) return ret; } +/* LCOV_EXCL_STOP */ int wmesh_bridge_set_stp(const char* bridge_name, bool state) { @@ -246,16 +248,20 @@ int wmesh_bridge_set_stp(const char* bridge_name, bool state) stp_state, 0, 0 }; if (NULL == bridge_name || strlen(bridge_name) > IFNAMSIZ - 1) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter [%p]", bridge_name); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } br_fd = socket(AF_LOCAL, SOCK_STREAM, 0); if (br_fd < 0) { + /* LCOV_EXCL_START */ strerror_r(errno, str_error, ERROR_MESSAGE_LENGTH); - WMESH_LOGD("Failed to open socket [%s(%d)]", str_error, errno); + WMESH_LOGE("Failed to open socket [%s(%d)]", str_error, errno); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } snprintf(ifr.ifr_name, IFNAMSIZ, "%s", bridge_name); @@ -263,11 +269,13 @@ int wmesh_bridge_set_stp(const char* bridge_name, bool state) val = ioctl(br_fd, SIOCDEVPRIVATE, &ifr); if (val < 0) { + /* LCOV_EXCL_START */ strerror_r(errno, str_error, ERROR_MESSAGE_LENGTH); WMESH_LOGE("Failed to set bridge[%s] stp state", bridge_name); WMESH_LOGE(" %s(%d)", str_error, errno); ret = WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } close(br_fd); diff --git a/src/wmesh-gdbus.c b/src/wmesh-gdbus.c old mode 100755 new mode 100644 index f7f306d..4f9d1ea --- a/src/wmesh-gdbus.c +++ b/src/wmesh-gdbus.c @@ -30,6 +30,7 @@ static int _wmeshd_close_gdbus_call(wmesh_service *service); static int _wmesh_gdbus_get_mesh_network_property(wmesh_service *service, const gchar* object_path, wmesh_network_info_s *result); +/* LCOV_EXCL_START */ static int __channel_to_frequency(int channel, enum nl80211_band band) { if (channel <= 0) @@ -71,7 +72,7 @@ static int __frequency_to_channel(int freq) else return 0; } - +/* LCOV_EXCL_STOP */ static GDBusProxy *_proxy_get_connman(wmesh_service *service) { GDBusProxy *proxy = NULL; @@ -85,7 +86,7 @@ static GDBusProxy *_proxy_get_connman(wmesh_service *service) CONNMAN_INTERFACE_MANAGER, NULL, NULL); } else - proxy = _gproxy_connman; + proxy = _gproxy_connman; //LCOV_EXCL_LINE return proxy; } @@ -103,7 +104,7 @@ static GDBusProxy *_proxy_get_connman_mesh(wmesh_service *service) CONNMAN_INTERFACE_MESH, NULL, NULL); } else - proxy = _gproxy_connman_mesh; + proxy = _gproxy_connman_mesh; //LCOV_EXCL_LINE return proxy; } @@ -121,7 +122,7 @@ static GDBusProxy *_proxy_get_connman_ethernet(wmesh_service *service) CONNMAN_INTERFACE_TECH, /* interface Name */ NULL, NULL); } else - proxy = _gproxy_connman_ethernet; + proxy = _gproxy_connman_ethernet; //LCOV_EXCL_LINE return proxy; } @@ -139,11 +140,12 @@ static GDBusProxy *_proxy_get_connman_technology(wmesh_service *service) CONNMAN_INTERFACE_TECH, NULL, NULL); } else - proxy = _gproxy_connman_technology; + proxy = _gproxy_connman_technology; //LCOV_EXCL_LINE return proxy; } +/* LCOV_EXCL_START */ static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec, gpointer *user_data) { @@ -160,6 +162,7 @@ static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec, g_free(name_owner); } +/* LCOV_EXCL_STOP */ static int _wmeshd_create_gdbus_call(wmesh_service *service) { @@ -167,27 +170,31 @@ static int _wmeshd_create_gdbus_call(wmesh_service *service) GError *error = NULL; if (NULL == service) - return WMESHD_ERROR_INVALID_PARAMETER; + return WMESHD_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE if (NULL != service->connection) - return WMESHD_ERROR_ALREADY_REGISTERED; + return WMESHD_ERROR_ALREADY_REGISTERED; //LCOV_EXCL_LINE service->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (service->connection == NULL) { + /* LCOV_EXCL_START */ if (error != NULL) { WMESH_LOGE("Failed to connect to the D-BUS daemon [%s]", error->message); g_error_free(error); } return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } id = g_signal_connect(service->connection, "notify::g-name-owner", G_CALLBACK(_dbus_name_owner_notify), service); if (0 == id) { + /* LCOV_EXCL_START */ WMESH_LOGE("g_signal_connect() Fail"); g_object_unref(service->connection); service->connection = NULL; return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -202,6 +209,7 @@ static int _wmeshd_close_gdbus_call(wmesh_service *service) return WMESHD_ERROR_NONE; } +/* LCOV_EXCL_START */ static void _wmeshd_signal_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) @@ -243,7 +251,7 @@ static void _wmeshd_signal_handler(GDBusConnection *connection, ret = _wmesh_gdbus_get_mesh_network_property(service, object_path, &network_info); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Cannot get valid network property !"); + WMESH_LOGE("Cannot get valid network property !"); //LCOV_EXCL_LINE if (g_strcmp0("association", var) == 0) { /* Joined mesh network */ @@ -270,6 +278,7 @@ static void _wmeshd_signal_handler(GDBusConnection *connection, g_free(network_info.bssid); } } +/* LCOV_EXCL_STOP */ static void _wmeshd_subscribe_event(wmesh_service *service) { @@ -283,8 +292,10 @@ static void _wmeshd_subscribe_event(wmesh_service *service) "ScanDone", "/", NULL, G_DBUS_CALL_FLAGS_NONE, _wmeshd_signal_handler, service, NULL); if (0 == id) { + /* LCOV_EXCL_START */ WMESH_LOGE("g_dbus_connection_signal_subscribe(ScanDone) Fail(%d)", errno); return; + /* LCOV_EXCL_STOP */ } service->dbus_sub_ids = g_list_append(service->dbus_sub_ids, GUINT_TO_POINTER(id)); WMESH_LOGD("[Signal subscribe] : ScanDone (%d)", id); @@ -299,8 +310,10 @@ static void _wmeshd_subscribe_event(wmesh_service *service) NULL, G_DBUS_CALL_FLAGS_NONE, _wmeshd_signal_handler, service, NULL); if (0 == id) { + /* LCOV_EXCL_START */ WMESH_LOGE("g_dbus_connection_signal_subscribe(ScanDone) Fail(%d)", errno); return; + /* LCOV_EXCL_STOP */ } service->dbus_sub_ids = g_list_append(service->dbus_sub_ids, GUINT_TO_POINTER(id)); WMESH_LOGD("[Signal subscribe] : PropertyChanged (%d)", id); @@ -334,7 +347,7 @@ int wmeshd_dbus_start(wmesh_service *service) rv = _wmeshd_create_gdbus_call(service); if (WMESHD_ERROR_NONE != rv) - return rv; + return rv; /* LCOV_EXCL_LINE */ service->ca = g_cancellable_new(); @@ -374,7 +387,7 @@ int wmeshd_dbus_stop(wmesh_service *service) int rv; if (NULL == service) - return WMESHD_ERROR_INVALID_PARAMETER; + return WMESHD_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */ /* Unsubscribe events */ _wmeshd_unsubscribe_event(service); @@ -430,6 +443,7 @@ int wmesh_gdbus_create_mesh_interface(wmesh_service *service) -1, NULL, &error); if (variant) { WMESH_LOGD("Successfully requested. [MeshInterfaceAdd]"); + /* LCOV_EXCL_START */ } else if (error) { ret = WMESHD_ERROR_IO_ERROR; WMESH_LOGE("Failed DBus call [%s]", error->message); @@ -439,7 +453,7 @@ int wmesh_gdbus_create_mesh_interface(wmesh_service *service) ret = WMESHD_ERROR_INVALID_PARAMETER; g_error_free(error); } - + /* LCOV_EXCL_STOP */ return ret; } @@ -470,6 +484,7 @@ int wmesh_gdbus_remove_mesh_interface(wmesh_service *service) -1, NULL, &error); if (variant) { WMESH_LOGD("Successfully requested. [MeshInterfaceRemove]"); + /* LCOV_EXCL_START */ } else if (error) { ret = WMESHD_ERROR_IO_ERROR; WMESH_LOGE("Failed DBus call [%s]", error->message); @@ -479,6 +494,7 @@ int wmesh_gdbus_remove_mesh_interface(wmesh_service *service) ret = WMESHD_ERROR_NONE; g_error_free(error); } + /* LCOV_EXCL_STOP */ return ret; } @@ -527,12 +543,14 @@ int wmesh_gdbus_mesh_specific_scan(wmesh_service *service, gchar *mesh_id, gint G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant) { - WMESH_LOGD("Successfully requested. [MeshSpecificScan]"); + WMESH_LOGD("Successfully requested. [MeshSpecificScan]"); /* LCOV_EXCL_LINE */ + /* LCOV_EXCL_START */ } else if (error) { WMESH_LOGE("Failed DBus call [%s]", error->message); g_error_free(error); return WMESHD_ERROR_IO_ERROR; } + /* LCOV_EXCL_STOP */ return WMESHD_ERROR_NONE; } @@ -559,7 +577,8 @@ int wmesh_gdbus_mesh_cancel_scan(wmesh_service *service) G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant) { - WMESH_LOGD("Successfully requested. [AbortScan]"); + WMESH_LOGD("Successfully requested. [AbortScan]"); /* LCOV_EXCL_LINE */ + /* LCOV_EXCL_START */ } else if (error) { ret = WMESHD_ERROR_IO_ERROR; WMESH_LOGE("Failed DBus call [%s]", error->message); @@ -570,10 +589,12 @@ int wmesh_gdbus_mesh_cancel_scan(wmesh_service *service) g_error_free(error); } + /* LCOV_EXCL_START */ return ret; } +/* LCOV_EXCL_START */ static void _on_scan_result_destroy(gpointer data) { wmesh_scan_result_s *scan_item = (wmesh_scan_result_s *)data; @@ -594,6 +615,7 @@ static void _on_peer_info_destroy(gpointer data) g_free(peer->address); g_free(peer); } +/* LCOV_EXCL_STOP */ static void _get_joined_network(wmesh_service *service, GVariant *variant) { @@ -610,6 +632,7 @@ static void _get_joined_network(wmesh_service *service, GVariant *variant) const gchar* buf = NULL; g_variant_get(variant, "(a(oa{sv}))", &peer); + /* LCOV_EXCL_START */ while ((child = g_variant_iter_next_value(peer))) { wmesh_network_info_s *joined_info = NULL; gboolean valid_state = TRUE; @@ -714,9 +737,11 @@ static void _get_joined_network(wmesh_service *service, GVariant *variant) /* If found, stop loop iteration */ break; } + /* LCOV_EXCL_STOP */ g_variant_iter_free(peer); } + static void _get_mesh_peers(wmesh_service *service, GVariant *variant) { GVariantIter *peer = NULL; @@ -728,6 +753,7 @@ static void _get_mesh_peers(wmesh_service *service, GVariant *variant) const gchar* obj_path = NULL; g_variant_get(variant, "(a(oa{sv}))", &peer); + /* LCOV_EXCL_START */ while ((child = g_variant_iter_next_value(peer))) { wmesh_scan_result_s *scan_info = NULL; @@ -798,6 +824,7 @@ static void _get_mesh_peers(wmesh_service *service, GVariant *variant) g_variant_iter_free(property); } + /* LCOV_EXCL_STOP */ g_variant_iter_free(peer); } @@ -811,6 +838,7 @@ static void _get_connected_mesh_peers(wmesh_service *service, GVariant *variant) g_variant_get(variant, "(a(a{sv}))", &peer); while ((child = g_variant_iter_next_value(peer))) { + /* LCOV_EXCL_START */ wmesh_peer_info_s *peer_info = NULL; peer_info = g_try_new0(wmesh_peer_info_s, 1); @@ -835,6 +863,7 @@ static void _get_connected_mesh_peers(wmesh_service *service, GVariant *variant) service->connected_mesh_peers = g_list_prepend(service->connected_mesh_peers, peer_info); + /* LCOV_EXCL_STOP */ } g_variant_iter_free(peer); } @@ -858,8 +887,10 @@ int wmesh_gdbus_get_mesh_networks(wmesh_service *service) WMESH_LOGD("Successfully requested. [GetMeshPeers]"); if (service->scanned_mesh_network) { + /* LCOV_EXCL_START */ g_list_free_full(service->scanned_mesh_network, _on_scan_result_destroy); service->scanned_mesh_network = NULL; + /* LCOV_EXCL_STOP */ } _get_mesh_peers(service, variant); @@ -867,11 +898,13 @@ int wmesh_gdbus_get_mesh_networks(wmesh_service *service) /* List item is saved with reversed order for efficiency. */ service->scanned_mesh_network = g_list_reverse(service->scanned_mesh_network); + /* LCOV_EXCL_START */ } else if (error) { WMESH_LOGE("Failed DBus call [%s]", error->message); g_error_free(error); return WMESHD_ERROR_IO_ERROR; } + /* LCOV_EXCL_STOP */ return WMESHD_ERROR_NONE; } @@ -895,24 +928,29 @@ int wmesh_gdbus_get_joined_mesh_network(wmesh_service *service) WMESH_LOGD("Successfully requested. [GetMeshPeers]"); if (service->joined_network) { + /* LCOV_EXCL_START */ g_free(service->joined_network->mesh_id); g_free(service->joined_network->bssid); g_free(service->joined_network->ipv4_address); g_free(service->joined_network->ipv4_netmask); g_free(service->joined_network); service->joined_network = NULL; + /* LCOV_EXCL_STOP */ } _get_joined_network(service, variant); + /* LCOV_EXCL_START */ } else if (error) { WMESH_LOGE("Failed DBus call [%s]", error->message); g_error_free(error); return WMESHD_ERROR_IO_ERROR; } + /* LCOV_EXCL_STOP */ return WMESHD_ERROR_NONE; } +/* LCOV_EXCL_START */ int wmesh_gdbus_get_connected_peers(wmesh_service *service) { GVariant *variant = NULL; @@ -1005,6 +1043,7 @@ static void _get_mesh_property(GVariant *variant, wmesh_network_info_s *result) } g_variant_iter_free(property); } +/* LCOV_EXCL_STOP */ static int _wmesh_gdbus_get_mesh_network_property(wmesh_service *service, const gchar* object_path, wmesh_network_info_s *result) @@ -1030,11 +1069,13 @@ static int _wmesh_gdbus_get_mesh_network_property(wmesh_service *service, /* Get properties */ _get_mesh_property(variant, result); + /* LCOV_EXCL_START */ } else if (error) { - WMESH_LOGE("Failed DBus call [%s]", error->message); + LOGE("Failed DBus call [%s]", error->message); g_error_free(error); return WMESHD_ERROR_IO_ERROR; } + /* LCOV_EXCL_STOP */ return WMESHD_ERROR_NONE; } @@ -1085,16 +1126,19 @@ int wmesh_gdbus_create_network(wmesh_service *service, gchar *mesh_id, -1, NULL, &error); g_variant_builder_unref(&builder); if (variant) { - WMESH_LOGD("Successfully requested. [MeshCreateNetwork]"); + WMESH_LOGD("Successfully requested. [MeshCreateNetwork]"); /* LCOV_EXCL_LINE */ + /* LCOV_EXCL_START */ } else if (error) { WMESH_LOGE("Failed DBus call [%s]", error->message); g_error_free(error); return WMESHD_ERROR_IO_ERROR; } + /* LCOV_EXCL_STOP */ return WMESHD_ERROR_NONE; } +/* LCOV_EXCL_START */ int wmesh_gdbus_set_passphrase(wmesh_service *service, wmesh_scan_result_s *info, gchar *passphrase) { int ret = WMESHD_ERROR_NONE; @@ -1118,7 +1162,7 @@ int wmesh_gdbus_set_passphrase(wmesh_service *service, wmesh_scan_result_s *info if (variant) { WMESH_LOGD("Successfully requested. [SetProperty]"); } else if (error) { - WMESH_LOGE("Failed DBus call [%s]", error->message); + LOGE("Failed DBus call [%s]", error->message); g_error_free(error); ret = WMESHD_ERROR_IO_ERROR; } @@ -1197,7 +1241,7 @@ int wmesh_gdbus_disconnect_network(wmesh_service *service, wmesh_scan_result_s * if (variant) { WMESH_LOGD("Successfully requested. [Disconnect]"); } else if (error) { - WMESH_LOGE("Failed DBus call [%s]", error->message); + LOGE("Failed DBus call [%s]", error->message); g_error_free(error); return WMESHD_ERROR_IO_ERROR; } @@ -1224,7 +1268,7 @@ int wmesh_gdbus_remove_network(wmesh_service *service, wmesh_scan_result_s *info if (variant) { WMESH_LOGD("Successfully requested. [Remove]"); } else if (error) { - WMESH_LOGE("Failed DBus call [%s]", error->message); + LOGE("Failed DBus call [%s]", error->message); g_error_free(error); return WMESHD_ERROR_IO_ERROR; } @@ -1270,6 +1314,7 @@ int wmesh_gdbus_enable_ethernet_interface(wmesh_service *service, bool state) return ret; } +/* LCOV_EXCL_STOP */ int wmesh_gdbus_set_mesh_gate(wmesh_service *service) { @@ -1299,7 +1344,8 @@ int wmesh_gdbus_set_mesh_gate(wmesh_service *service) G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (variant) { - WMESH_LOGD("Successfully requested. [SetMeshGate]"); + WMESH_LOGD("Successfully requested. [SetMeshGate]"); /* LCOV_EXCL_LINE */ + /* LCOV_EXCL_START */ } else if (error) { ret = WMESHD_ERROR_IO_ERROR; WMESH_LOGE("Failed DBus call [%s]", error->message); @@ -1309,10 +1355,12 @@ int wmesh_gdbus_set_mesh_gate(wmesh_service *service) ret = WMESHD_ERROR_INVALID_PARAMETER; g_error_free(error); } + /* LCOV_EXCL_STOP */ return ret; } +/* LCOV_EXCL_START */ int wmesh_gdbus_mesh_remove_peer(wmesh_service *service, char *peer) { GVariant *variant = NULL; @@ -1343,4 +1391,5 @@ int wmesh_gdbus_mesh_remove_peer(wmesh_service *service, char *peer) return ret; } +/* LCOV_EXCL_STOP */ diff --git a/src/wmesh-interface.c b/src/wmesh-interface.c index 58df328..b4a2e3d 100644 --- a/src/wmesh-interface.c +++ b/src/wmesh-interface.c @@ -50,6 +50,7 @@ typedef enum { ETHERNET_CABLE_ATTACHED } cable_state_e; +/* LCOV_EXCL_START */ int wmesh_interface_set(const char *interface, const char* ip_addr, wmesh_set_interface_type_e type) { @@ -181,6 +182,7 @@ static char* _get_interface_not_exists_in_seq(const char* prefix) return res; } #endif +/* LCOV_EXCL_STOP */ static bool _check_interface_exists(const char* if_name) { @@ -199,7 +201,7 @@ static bool _check_interface_exists(const char* if_name) } } - return false; + return false; //LCOV_EXCL_LINE } /* Check if interface is bridged */ @@ -216,13 +218,14 @@ static bool _check_bridge_interface_exists(const char* bridge, const char* if_na ret = access(buf, F_OK); if (ret >= 0) { /* This name is exists. */ - return true; + return true; //LCOV_EXCL_LINE } } - return false; + return false; //LCOV_EXCL_LINE } +/* LCOV_EXCL_START */ char* wmesh_interface_get_address(const char* if_name) { FILE *pf; @@ -243,30 +246,39 @@ char* wmesh_interface_get_address(const char* if_name) return result; } +/* LCOV_EXCL_STOP */ int wmesh_interface_initialize(wmesh_interface_s *info) { if (NULL == info) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } info->bridge_interface = g_strdup(MESH_DEFAULT_BRIDGE_INTERFACE); if (NULL == info->bridge_interface) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get bridge interface !"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } info->base_interface = g_strdup(MESH_DEFAULT_BASE_INTERFACE); if (NULL == info->bridge_interface) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get base interface !"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } info->mesh_interface = g_strdup(MESH_DEFAULT_MESH_INTERFACE); if (NULL == info->bridge_interface) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get mesh interface !"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } info->softap_interface = g_strdup(MESH_DEFAULT_SOFTAP_INTERFACE); @@ -296,26 +308,33 @@ static int _check_ethernet_cable_plugin_status(const char* interface, if (0 == access(file_path, F_OK)) { fd = fopen(file_path, "r"); if (fd == NULL) { + /* LCOV_EXCL_START */ WMESH_LOGE("Error! Could not open /sys/class/net/%s/carrier file", interface); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } } else { + /* LCOV_EXCL_START */ WMESH_LOGE("Error! Could not access /sys/class/net/%s/carrier file", interface); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } errno = 0; rv = fscanf(fd, "%d", &ret); if (rv < 0) { + /* LCOV_EXCL_START */ strerror_r(errno, error_buf, 256); WMESH_LOGE("Error! Failed to read from file, rv:[%d], error:[%s]", rv, error_buf); fclose(fd); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } + /* LCOV_EXCL_START */ if (ret == 1) { WMESH_LOGD("/sys/class/net/%s/carrier : [%d]", interface, ret); *status = ETHERNET_CABLE_ATTACHED; @@ -323,6 +342,7 @@ static int _check_ethernet_cable_plugin_status(const char* interface, WMESH_LOGD("/sys/class/net/%s/carrier : [%d]", interface, ret); *status = ETHERNET_CABLE_DETACHED; } + /* LCOV_EXCL_STOP */ fclose(fd); return WMESHD_ERROR_NONE; @@ -336,26 +356,30 @@ int wmesh_interface_check_external_exists(const char* external_interface, bool * cable_state_e cable_state = ETHERNET_CABLE_DETACHED; if (NULL == external_interface || NULL == state) - return WMESHD_ERROR_INVALID_PARAMETER; + return WMESHD_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE bool ex = _check_interface_exists(external_interface); if (FALSE == ex) { + /* LCOV_EXCL_START */ WMESH_LOGE("External interface[%s] was not found.", external_interface); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } /* If external interface seems Ethernet, check cable state */ if (g_str_has_prefix(external_interface, "eth")) { ret = _check_ethernet_cable_plugin_status(external_interface, &cable_state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get Ethernet cable state"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } } *state = FALSE; if (ETHERNET_CABLE_ATTACHED == cable_state) - *state = TRUE; + *state = TRUE; /* LCOV_EXCL_LINE */ return WMESHD_ERROR_NONE; } @@ -365,12 +389,14 @@ int wmesh_interface_check(const char* interface) bool ex = FALSE; if (NULL == interface || strlen(interface) == 0) - return WMESHD_ERROR_INVALID_PARAMETER; + return WMESHD_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE ex = _check_interface_exists(interface); if (FALSE == ex) { + /* LCOV_EXCL_START */ WMESH_LOGE("Interface[%s] was not found.", interface); return WMESHD_ERROR_NO_DATA; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -382,14 +408,16 @@ int wmesh_interface_check_bridge_interface_exists(const char* bridge, const char if (NULL == bridge || NULL == interface || strlen(bridge) == 0 || strlen(interface) == 0) - return WMESHD_ERROR_INVALID_PARAMETER; + return WMESHD_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE ex = _check_bridge_interface_exists(bridge, interface); if (FALSE == ex) { + /* LCOV_EXCL_START */ WMESH_LOGE("Interface[%s] was not found.", interface); return WMESHD_ERROR_NO_DATA; + /* LCOV_EXCL_STOP */ } - return WMESHD_ERROR_NONE; + return WMESHD_ERROR_NONE; /* LCOV_EXCL_LINE */ } diff --git a/src/wmesh-netlink.c b/src/wmesh-netlink.c index e69dad8..3e31be8 100644 --- a/src/wmesh-netlink.c +++ b/src/wmesh-netlink.c @@ -106,36 +106,44 @@ static int __initialize_nl80211(mesh_nl_state *state) state->nl_socket = nl_socket_alloc(); if (!state->nl_socket) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to allocate netlink socket."); return WMESHD_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ } if (genl_connect(state->nl_socket)) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to connect to generic netlink."); err = WMESHD_ERROR_OPERATION_FAILED; goto DESTROY; + /* LCOV_EXCL_STOP */ } nl_socket_set_buffer_size(state->nl_socket, 8192, 8192); state->nl80211_id = genl_ctrl_resolve(state->nl_socket, "nl80211"); if (state->nl80211_id < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("nl80211 not found."); err = WMESHD_ERROR_NO_DATA; goto DESTROY; + /* LCOV_EXCL_STOP */ } return 0; DESTROY: + /* LCOV_EXCL_START */ nl_socket_free(state->nl_socket); return err; + /* LCOV_EXCL_STOP */ } static void __clean_nl80211(mesh_nl_state *state) { if (!state) - return; + return; /* LCOV_EXCL_LINE */ if (state->nl_socket) { nl_socket_free(state->nl_socket); @@ -149,20 +157,25 @@ static int __get_device_index_from_string(const char* if_name, int *index) int device_index = 0; if (NULL == if_name) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } device_index = if_nametoindex(if_name); if (device_index == 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("No interface index found [%s]", if_name); return WMESHD_ERROR_NO_DATA; + /* LCOV_EXCL_STOP */ } - *index = device_index; + *index = device_index; /* LCOV_EXCL_LINE */ - return WMESHD_ERROR_NONE; + return WMESHD_ERROR_NONE; /* LCOV_EXCL_LINE */ } +/* LCOV_EXCL_START */ static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) { mesh_nl_state *state = (mesh_nl_state *)arg; @@ -203,6 +216,7 @@ static int ack_handler(struct nl_msg *msg, void *arg) return NL_STOP; } +/* LCOV_EXCL_STOP */ static int ack_simple_handler(struct nl_msg *msg, void *arg) { @@ -230,7 +244,7 @@ static int family_handler(struct nl_msg *msg, void *arg) genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (!tb[CTRL_ATTR_MCAST_GROUPS]) - return NL_SKIP; + return NL_SKIP; //LCOV_EXCL_LINE nla_for_each_nested(mcast_group, tb[CTRL_ATTR_MCAST_GROUPS], rem_mcast_group) { struct nlattr *tb_mcast_group[CTRL_ATTR_MCAST_GRP_MAX + 1]; @@ -240,12 +254,12 @@ static int family_handler(struct nl_msg *msg, void *arg) if (!tb_mcast_group[CTRL_ATTR_MCAST_GRP_NAME] || !tb_mcast_group[CTRL_ATTR_MCAST_GRP_ID]) - continue; + continue; //LCOV_EXCL_LINE if (strncmp(nla_data(tb_mcast_group[CTRL_ATTR_MCAST_GRP_NAME]), group->group, nla_len(tb_mcast_group[CTRL_ATTR_MCAST_GRP_NAME]))) - continue; + continue; //LCOV_EXCL_LINE group->id = nla_get_u32(tb_mcast_group[CTRL_ATTR_MCAST_GRP_ID]); WMESH_LOGD("mcast group id [%d]", group->id); @@ -267,12 +281,14 @@ static int __nl_get_multicast_id(struct nl_sock *sock, const char *family, const msg = nlmsg_alloc(); if (!msg) - return -ENOMEM; + return -ENOMEM; //LCOV_EXCL_LINE cb = nl_cb_alloc(NL_CB_DEFAULT); if (!cb) { + /* LCOV_EXCL_START */ ret = -ENOMEM; goto FAILURE; + /* LCOV_EXCL_STOP */ } ctrlid = genl_ctrl_resolve(sock, "nlctrl"); @@ -285,8 +301,10 @@ static int __nl_get_multicast_id(struct nl_sock *sock, const char *family, const ret = nl_send_auto(sock, msg); if (ret < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_send_auto"); goto out; + /* LCOV_EXCL_STOP */ } ret = 1; @@ -318,15 +336,19 @@ static int __prepare_listen_events(mesh_nl_state *state) /* Configuration multicast group */ mcid = __nl_get_multicast_id(state->nl_socket, "nl80211", "config"); if (mcid < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get nl80211 config"); return mcid; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Mesh multicast id (config): [%d]", mcid); ret = nl_socket_add_membership(state->nl_socket, mcid); if (ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_socket_add_membership"); return ret; + /* LCOV_EXCL_STOP */ } /* Scan multicast group */ @@ -334,8 +356,10 @@ static int __prepare_listen_events(mesh_nl_state *state) if (mcid >= 0) { ret = nl_socket_add_membership(state->nl_socket, mcid); if (ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_socket_add_membership"); return ret; + /* LCOV_EXCL_STOP */ } } WMESH_LOGD("Mesh multicast id (scan): [%d]", mcid); @@ -345,8 +369,10 @@ static int __prepare_listen_events(mesh_nl_state *state) if (mcid >= 0) { ret = nl_socket_add_membership(state->nl_socket, mcid); if (ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_socket_add_membership"); return ret; + /* LCOV_EXCL_STOP */ } } WMESH_LOGD("Mesh multicast id (regulatory): [%d]", mcid); @@ -356,8 +382,10 @@ static int __prepare_listen_events(mesh_nl_state *state) if (mcid >= 0) { ret = nl_socket_add_membership(state->nl_socket, mcid); if (ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_socket_add_membership"); return ret; + /* LCOV_EXCL_STOP */ } } WMESH_LOGD("Mesh multicast id (mlme): [%d]", mcid); @@ -366,8 +394,10 @@ static int __prepare_listen_events(mesh_nl_state *state) if (mcid >= 0) { ret = nl_socket_add_membership(state->nl_socket, mcid); if (ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_socket_add_membership"); return ret; + /* LCOV_EXCL_STOP */ } } WMESH_LOGD("Mesh multicast id (vendor): [%d]", mcid); @@ -389,12 +419,13 @@ static mesh_nl_state *_create_mesh_nl_state() static void _delete_mesh_nl_state(mesh_nl_state **state) { if (NULL == state || NULL == *state) - return; + return; //LCOV_EXCL_LINE g_free(*state); *state = NULL; } +/* LCOV_EXCL_START */ static int valid_handler(struct nl_msg *msg, void *arg) { struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); @@ -419,6 +450,7 @@ static int valid_handler(struct nl_msg *msg, void *arg) return NL_SKIP; } +/* LCOV_EXCL_STOP */ static int no_seq_check(struct nl_msg *msg, void *arg) { @@ -431,7 +463,7 @@ static int no_seq_check(struct nl_msg *msg, void *arg) static void __clean_netlink_message(mesh_nl_state *state) { if (!state) - return; + return; /* LCOV_EXCL_LINE */ if (state->cb) nl_cb_put(state->cb); @@ -452,24 +484,30 @@ static int __initialize_netlink_message(mesh_nl_state *state) int err = WMESHD_ERROR_NONE; if (NULL == state) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter !"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } /* Create netlink message */ state->msg = nlmsg_alloc(); if (NULL == state->msg) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to allocate netlink message"); return WMESHD_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ } /* NL_CB_DEFAULT */ state->cb = nl_cb_alloc(NL_CB_DEFAULT); state->s_cb = nl_cb_alloc(NL_CB_DEFAULT); if (!state->cb) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to allocate netlink callback"); err = WMESHD_ERROR_OUT_OF_MEMORY; goto DESTROY; + /* LCOV_EXCL_STOP */ } /* Set socket callback */ @@ -486,9 +524,11 @@ static int __initialize_netlink_message(mesh_nl_state *state) return WMESHD_ERROR_NONE; DESTROY: + /* LCOV_EXCL_START */ __clean_netlink_message(state); return err; + /* LCOV_EXCL_STOP */ } static gboolean _on_socket_event_io_received(GIOChannel *source, @@ -503,7 +543,7 @@ static gboolean _on_socket_event_io_received(GIOChannel *source, WMESH_LOGD("[Event] I/O received"); while (nl_recvmsgs_report(state->nl_socket, state->cb) > 0) - WMESH_LOGD(" count [%02d]", ++test); + WMESH_LOGD(" count [%02d]", ++test); //LCOV_EXCL_LINE /* Do not remove I/O source */ return TRUE; @@ -527,6 +567,8 @@ static void mac_addr_n2a(char *mac_addr, unsigned char *arg) "%02x:%02x:%02x:%02x:%02x:%02x", arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); } + +/* LCOV_EXCL_START */ #if defined(NL80211_STA_INFO_CHAIN_SIGNAL) || defined(NL80211_STA_INFO_CHAIN_SIGNAL_AVG) static char *get_chain_signal(struct nlattr *attr_list) { @@ -573,7 +615,7 @@ static int parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen) if (nla_parse_nested(rate_info, NL80211_RATE_INFO_MAX, bitrate_attr, rate_policy)) { if (buf) - snprintf(buf, buflen, "failed to parse nested rate attributes!"); + snprintf(buf, buflen, "failed to parse nested rate attributes!"); //LCOV_EXCL_LINE return 0; } @@ -1358,6 +1400,7 @@ static int _on_receive_mesh_event(struct nl_msg *msg, void *arg) return NL_SKIP; } +/* LCOV_EXCL_STOP */ static int _send_nl_set_mesh_parameter(const char* mesh_if_name, const char* param_name, unsigned int value) @@ -1381,14 +1424,18 @@ static int _send_nl_set_mesh_parameter(const char* mesh_if_name, ret = __initialize_nl80211(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize nl80211"); return ret; + /* LCOV_EXCL_STOP */ } ret = __initialize_netlink_message(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize netlink message"); goto DESTROY; + /* LCOV_EXCL_STOP */ } /* Set command into message */ @@ -1398,16 +1445,20 @@ static int _send_nl_set_mesh_parameter(const char* mesh_if_name, /* Add attributes into message */ ret = __get_device_index_from_string(mesh_if_name, &device_index); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get mesh device index"); err = ret; goto DESTROY; + /* LCOV_EXCL_STOP */ } NLA_PUT_U32(state.msg, NL80211_ATTR_IFINDEX, device_index); container = nla_nest_start(state.msg, NL80211_ATTR_MESH_PARAMS); if (!container) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize netlink message"); goto DESTROY; + /* LCOV_EXCL_STOP */ } /* Logic need to be changed if additional parameter is required */ @@ -1420,19 +1471,23 @@ static int _send_nl_set_mesh_parameter(const char* mesh_if_name, NLA_PUT_U8(state.msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, (uint8_t)value); } else { + /* LCOV_EXCL_START */ WMESH_LOGE("Parameter [%s] is not required !", param_name); nla_nest_end(state.msg, container); goto DESTROY; + /* LCOV_EXCL_STOP */ } nla_nest_end(state.msg, container); /* Send message into kernel */ ret = nl_send_auto(state.nl_socket, state.msg); if (ret < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_send_auto() [%s](%d)", nl_geterror(ret), ret); err = WMESHD_ERROR_OPERATION_FAILED; goto DESTROY; + /* LCOV_EXCL_STOP */ } /* sync response */ @@ -1449,11 +1504,13 @@ DESTROY: return err; nla_put_failure: + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to message build"); __clean_netlink_message(&state); __clean_nl80211(&state); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } static int _send_nl_get_station_info(const char* if_name, GList **station_list) @@ -1475,14 +1532,18 @@ static int _send_nl_get_station_info(const char* if_name, GList **station_list) ret = __initialize_nl80211(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize nl80211"); return ret; + /* LCOV_EXCL_STOP */ } ret = __initialize_netlink_message(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize netlink message"); goto DESTROY; + /* LCOV_EXCL_STOP */ } /* Set command into message */ @@ -1493,9 +1554,11 @@ static int _send_nl_get_station_info(const char* if_name, GList **station_list) WMESH_LOGD("Dump station list with interface [%s]", if_name); ret = __get_device_index_from_string(if_name, &device_index); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get mesh interface device index"); err = ret; goto DESTROY; + /* LCOV_EXCL_STOP */ } NLA_PUT_U32(state.msg, NL80211_ATTR_IFINDEX, device_index); @@ -1506,17 +1569,21 @@ static int _send_nl_get_station_info(const char* if_name, GList **station_list) /* Send message into kernel */ ret = nl_send_auto(state.nl_socket, state.msg); if (ret < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_send_auto() [%s](%d)", nl_geterror(ret), ret); err = WMESHD_ERROR_OPERATION_FAILED; goto DESTROY; + /* LCOV_EXCL_STOP */ } /* sync response */ state.callback_state = MESH_NL_CALLBACK_TRYING; while (state.callback_state == MESH_NL_CALLBACK_TRYING) { + /* LCOV_EXCL_START */ WMESH_LOGD(" count [%02d]", ++test); nl_recvmsgs(state.nl_socket, state.cb); + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Finished"); @@ -1527,11 +1594,13 @@ DESTROY: return err; nla_put_failure: + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to message build"); __clean_netlink_message(&state); __clean_nl80211(&state); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } static int _send_nl_get_mpath_info(const char* if_name, GList **mpath_list) @@ -1553,14 +1622,18 @@ static int _send_nl_get_mpath_info(const char* if_name, GList **mpath_list) ret = __initialize_nl80211(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize nl80211"); return ret; + /* LCOV_EXCL_STOP */ } ret = __initialize_netlink_message(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize netlink message"); goto DESTROY; + /* LCOV_EXCL_STOP */ } /* Set command into message */ @@ -1571,9 +1644,11 @@ static int _send_nl_get_mpath_info(const char* if_name, GList **mpath_list) WMESH_LOGD("Dump station list with interface [%s]", if_name); ret = __get_device_index_from_string(if_name, &device_index); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get mesh interface device index"); err = ret; goto DESTROY; + /* LCOV_EXCL_STOP */ } NLA_PUT_U32(state.msg, NL80211_ATTR_IFINDEX, device_index); @@ -1584,17 +1659,21 @@ static int _send_nl_get_mpath_info(const char* if_name, GList **mpath_list) /* Send message into kernel */ ret = nl_send_auto(state.nl_socket, state.msg); if (ret < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_send_auto() [%s](%d)", nl_geterror(ret), ret); err = WMESHD_ERROR_OPERATION_FAILED; goto DESTROY; + /* LCOV_EXCL_STOP */ } /* sync response */ state.callback_state = MESH_NL_CALLBACK_TRYING; while (state.callback_state == MESH_NL_CALLBACK_TRYING) { + /* LCOV_EXCL_START */ WMESH_LOGD(" count [%02d]", ++test); nl_recvmsgs(state.nl_socket, state.cb); + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Finished"); @@ -1605,11 +1684,13 @@ DESTROY: return err; nla_put_failure: + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to message build"); __clean_netlink_message(&state); __clean_nl80211(&state); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } static int _send_nl_get_meshconf_info(wmesh_service *service) @@ -1631,14 +1712,18 @@ static int _send_nl_get_meshconf_info(wmesh_service *service) ret = __initialize_nl80211(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize nl80211"); return ret; + /* LCOV_EXCL_STOP */ } ret = __initialize_netlink_message(&state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize netlink message"); goto DESTROY; + /* LCOV_EXCL_STOP */ } /* Set command into message */ @@ -1650,10 +1735,12 @@ static int _send_nl_get_meshconf_info(wmesh_service *service) service->interface_info->mesh_interface); ret = __get_device_index_from_string( service->interface_info->mesh_interface, &device_index); - if (WMESHD_ERROR_NONE != ret) { + if (WMESHD_ERROR_NONE != ret) + /* LCOV_EXCL_START */{ WMESH_LOGE("Failed to get mesh interface device index"); err = ret; goto DESTROY; + /* LCOV_EXCL_STOP */ } NLA_PUT_U32(state.msg, NL80211_ATTR_IFINDEX, device_index); @@ -1664,17 +1751,21 @@ static int _send_nl_get_meshconf_info(wmesh_service *service) /* Send message into kernel */ ret = nl_send_auto(state.nl_socket, state.msg); if (ret < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to nl_send_auto() [%s](%d)", nl_geterror(ret), ret); err = WMESHD_ERROR_OPERATION_FAILED; goto DESTROY; + /* LCOV_EXCL_STOP */ } /* sync response */ state.callback_state = MESH_NL_CALLBACK_TRYING; while (state.callback_state == MESH_NL_CALLBACK_TRYING) { + /* LCOV_EXCL_START */ WMESH_LOGD(" count [%02d]", ++test); nl_recvmsgs(state.nl_socket, state.cb); + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Finished"); @@ -1685,11 +1776,13 @@ DESTROY: return err; nla_put_failure: + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to message build"); __clean_netlink_message(&state); __clean_nl80211(&state); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } static int _send_nl_register_event_handler(wmesh_service *service) @@ -1699,29 +1792,37 @@ static int _send_nl_register_event_handler(wmesh_service *service) GIOChannel *recv_channel = NULL; if (event_state) { + /* LCOV_EXCL_START */ WMESH_LOGE("Already event handler registered !"); return WMESHD_ERROR_IN_PROGRESS; + /* LCOV_EXCL_STOP */ } event_state = _create_mesh_nl_state(""); ret = __initialize_nl80211(event_state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize nl80211"); return ret; + /* LCOV_EXCL_STOP */ } /* Subscribe multicast group should be proceed before scanning */ ret = __prepare_listen_events(event_state); if (ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("__prepare_listen_events : [%d]", ret); goto DESTROY; + /* LCOV_EXCL_STOP */ } ret = __initialize_netlink_message(event_state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to initialize netlink message"); goto DESTROY; + /* LCOV_EXCL_STOP */ } /* Set command into message */ @@ -1738,9 +1839,10 @@ static int _send_nl_register_event_handler(wmesh_service *service) /* Change socket type to non-blocking */ ret = nl_socket_set_nonblocking(event_state->nl_socket); if (ret < 0) - WMESH_LOGE("Failed to non-blocking socket [%s](%d)", nl_geterror(ret), ret); + WMESH_LOGE("Failed to non-blocking socket [%s](%d)", nl_geterror(ret), ret); /* LCOV_EXCL_LINE */ /* Register I/O callback to wait asynchronously */ + /* LCOV_EXCL_START */ if (FALSE == event_state->error_occured) { recv_channel = g_io_channel_unix_new(nl_socket_get_fd(event_state->nl_socket)); event_state->event_source = g_io_add_watch(recv_channel, @@ -1750,17 +1852,21 @@ static int _send_nl_register_event_handler(wmesh_service *service) WMESH_LOGE("Error responded. Failed to register event callback !!"); goto DESTROY; } + /* LCOV_EXCL_STOP */ /* Resource should be free on I/O callback */ return WMESHD_ERROR_NONE; DESTROY: + /* LCOV_EXCL_START */ __clean_netlink_message(event_state); __clean_nl80211(event_state); _delete_mesh_nl_state(&event_state); return err; + /* LCOV_EXCL_STOP */ } +/* LCOV_EXCL_STOP */ int wmesh_netlink_set_mesh_parameter(const char* mesh_if_name, const char* param_name, unsigned int value) @@ -1768,8 +1874,10 @@ int wmesh_netlink_set_mesh_parameter(const char* mesh_if_name, int ret = WMESHD_ERROR_NONE; if (NULL == mesh_if_name || strlen(mesh_if_name) > IFNAMSIZ) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter [%p]", mesh_if_name); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Set mesh[%s] param [%s] value [%d]", @@ -1784,12 +1892,16 @@ int wmesh_netlink_get_station_info(const char* mesh_if_name, GList **station_lis int ret = WMESHD_ERROR_NONE; if (NULL == mesh_if_name || strlen(mesh_if_name) > IFNAMSIZ) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter [%p]", mesh_if_name); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } if (NULL == station_list) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter [%p]", station_list); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Get connected stations"); @@ -1803,12 +1915,16 @@ int wmesh_netlink_get_mpath_info(const char* mesh_if_name, GList **mpath_list) int ret = WMESHD_ERROR_NONE; if (NULL == mesh_if_name || strlen(mesh_if_name) > IFNAMSIZ) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter [%p]", mesh_if_name); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } if (NULL == mpath_list) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter [%p]", mpath_list); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Get current mpath info"); @@ -1822,8 +1938,10 @@ int wmesh_netlink_get_meshconf_info(wmesh_service *service) int ret = WMESHD_ERROR_NONE; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter [%p]", service); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Get current Mesh Config info"); diff --git a/src/wmesh-peer-monitor.c b/src/wmesh-peer-monitor.c index 6949eb5..431ae16 100644 --- a/src/wmesh-peer-monitor.c +++ b/src/wmesh-peer-monitor.c @@ -30,6 +30,7 @@ #define MESH_MONITORING_TIME 5 #define MESH_MAXIMUM_BEACON_LOST_COUNT 10 +/* LCOV_EXCL_START */ static void _on_station_list_destroy(gpointer data) { wmesh_station_info_s *info = (wmesh_station_info_s*)data; @@ -127,6 +128,7 @@ static int _get_station_info(void *pdata) return ret; } + #if 0 static gboolean _get_mpath_info(void *pdata) { @@ -230,6 +232,7 @@ static gboolean _on_mesh_monitor_cb(gpointer pdata) return G_SOURCE_CONTINUE; } +/* LCOV_EXCL_STOP */ int wmesh_start_monitor_service(void *pdata) { @@ -238,9 +241,10 @@ int wmesh_start_monitor_service(void *pdata) wmeshd_check_null_ret_error("service", service, WMESHD_ERROR_INVALID_PARAMETER); if (service->monitor_timer) - wmesh_stop_monitor_service(pdata); + wmesh_stop_monitor_service(pdata); /* LCOV_EXCL_LINE */ - service->monitor_timer = g_timeout_add_seconds(MESH_MONITORING_TIME, _on_mesh_monitor_cb, service); + service->monitor_timer = g_timeout_add_seconds(MESH_MONITORING_TIME, + _on_mesh_monitor_cb, service); WMESH_LOGD("Peer Monitoring Service Started"); @@ -259,10 +263,5 @@ int wmesh_stop_monitor_service(void *pdata) } WMESH_LOGD("Peer Monitoring Service Stopped"); - - /* After mesh interface is removed then ethernet is disabled when ethernet - * interface is bridged, so try to enable ethernet again */ - WMESH_LOGD("Enable ethernet interface"); - wmesh_gdbus_enable_ethernet_interface(service, true); return ret; } diff --git a/src/wmesh-request.c b/src/wmesh-request.c index c975796..e842611 100644 --- a/src/wmesh-request.c +++ b/src/wmesh-request.c @@ -42,8 +42,10 @@ int wmesh_request_set_mesh_gate(const char* bridge_interface, ret = wmesh_interface_check_external_exists(external_interface, &state); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get external interface state !"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } WMESH_LOGD(" Ethernet cable state [%s]", (state) ? "Connected" : "Disconnected"); @@ -51,20 +53,22 @@ int wmesh_request_set_mesh_gate(const char* bridge_interface, /* Turn STP on */ ret = wmesh_bridge_set_stp(bridge_interface, TRUE); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to turn STP on !"); return ret; + /* LCOV_EXCL_STOP */ } /* Set mesh parameters */ ret = wmesh_netlink_set_mesh_parameter(mesh_interface, "mesh_hwmp_rootmode", 4); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to set [mesh_hwmp_rootmode] : 4"); + WMESH_LOGE("Failed to set [mesh_hwmp_rootmode] : 4"); //LCOV_EXCL_LINE ret = wmesh_netlink_set_mesh_parameter(mesh_interface, "mesh_gate_announcements", 1); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to set [mesh_gate_announcements] : 1"); + WMESH_LOGE("Failed to set [mesh_gate_announcements] : 1"); //LCOV_EXCL_LINE return WMESHD_ERROR_NONE; } @@ -80,23 +84,26 @@ int wmesh_request_unset_mesh_gate(const char* bridge_interface, ret = wmesh_netlink_set_mesh_parameter(mesh_interface, "mesh_hwmp_rootmode", 0); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to set [mesh_hwmp_rootmode] : 0"); + WMESH_LOGE("Failed to set [mesh_hwmp_rootmode] : 0"); //LCOV_EXCL_LINE ret = wmesh_netlink_set_mesh_parameter(mesh_interface, "mesh_gate_announcements", 0); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to set [mesh_gate_announcements] : 0"); + WMESH_LOGE("Failed to set [mesh_gate_announcements] : 0"); //LCOV_EXCL_LINE /* Turn STP off */ ret = wmesh_bridge_set_stp(bridge_interface, FALSE); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to turn STP off!"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; } +/* LCOV_EXCL_START */ int wmesh_request_add_bridge_interface(const char* bridge_interface, const char* interface) { @@ -132,6 +139,7 @@ int wmesh_request_add_bridge_interface(const char* bridge_interface, return WMESHD_ERROR_NONE; } +/* LCOV_EXCL_STOP */ int wmesh_request_remove_bridge_interface(const char* bridge_interface, const char* interface) @@ -139,18 +147,23 @@ int wmesh_request_remove_bridge_interface(const char* bridge_interface, int ret = WMESHD_ERROR_NONE; if (NULL == bridge_interface || NULL == interface) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameters"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("Removing interface[%s] from bridge[%s]...", interface, bridge_interface); ret = wmesh_interface_check_bridge_interface_exists(bridge_interface, interface); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGD("Interface is not exist in bridge"); return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } + /* LCOV_EXCL_START */ /* Remove external interface into bridge */ ret = wmesh_bridge_del_interface(bridge_interface, interface); if (WMESHD_ERROR_NONE != ret) { @@ -159,6 +172,7 @@ int wmesh_request_remove_bridge_interface(const char* bridge_interface, } return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } int wmesh_request_set_softap_config(const char* softap_interface, @@ -172,8 +186,10 @@ int wmesh_request_set_softap_config(const char* softap_interface, ret = wmesh_softap_set_configuration(softap_interface, ssid, mode, channel, visibility, max_sta, security, passphrase); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to set Configuration for SoftAP"); return ret; + /* LCOV_EXCL_STOP */ } return ret; @@ -190,8 +206,10 @@ int wmesh_request_get_softap_config(char **softap_interface, char **ssid, ret = wmesh_softap_get_configuration(softap_interface, ssid, mode, channel, visibility, max_sta, security, passphrase); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get Configuration for SoftAP"); return ret; + /* LCOV_EXCL_STOP */ } return ret; @@ -205,10 +223,13 @@ int wmesh_request_enable_softap( WMESH_LOGD("Request to turn SoftAP on"); ret = wmesh_softap_enable_softap(softap_interface); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to wmesh_softap_enable_softap"); return ret; + /* LCOV_EXCL_STOP */ } + /* LCOV_EXCL_START */ /* Add softAP interface into bridge */ ret = wmesh_request_add_bridge_interface(bridge_interface, softap_interface); if (WMESHD_ERROR_NONE != ret) { @@ -217,6 +238,7 @@ int wmesh_request_enable_softap( } return ret; + /* LCOV_EXCL_STOP */ } int wmesh_request_disable_softap( @@ -230,7 +252,7 @@ int wmesh_request_disable_softap( /* Remove softAP interface from bridge */ ret = wmesh_request_remove_bridge_interface(bridge_interface, softap_interface); if (WMESHD_ERROR_NONE != ret) - return ret; + return ret; //LCOV_EXCL_LINE return ret; } @@ -251,7 +273,7 @@ int wmesh_request_get_station_info(const char* mesh_interface, GList **station_l /* Get station info */ ret = wmesh_netlink_get_station_info(mesh_interface, station_list); if (WMESHD_ERROR_NONE != ret) - return ret; + return ret; //LCOV_EXCL_LINE return WMESHD_ERROR_NONE; } @@ -265,7 +287,7 @@ int wmesh_request_get_mpath_info(const char* mesh_interface, GList **mpath_list) /* Get MPath info */ ret = wmesh_netlink_get_mpath_info(mesh_interface, mpath_list); if (WMESHD_ERROR_NONE != ret) - return ret; + return ret; //LCOV_EXCL_LINE return WMESHD_ERROR_NONE; } @@ -279,7 +301,7 @@ int wmesh_request_get_meshconf_info(wmesh_service *service) /* Get MPath info */ ret = wmesh_netlink_get_meshconf_info(service); if (WMESHD_ERROR_NONE != ret) - return ret; + return ret; //LCOV_EXCL_LINE return WMESHD_ERROR_NONE; } @@ -293,7 +315,7 @@ int wmesh_request_register_event_handler(wmesh_service *service) /* Get MPath info */ ret = wmesh_netlink_register_event_handler(service); if (WMESHD_ERROR_NONE != ret) - return ret; + return ret; //LCOV_EXCL_LINE return WMESHD_ERROR_NONE; } @@ -307,7 +329,7 @@ int wmesh_request_unregister_event_handler() /* Get MPath info */ ret = wmesh_netlink_unregister_event_handler(); if (WMESHD_ERROR_NONE != ret) - return ret; + return ret; //LCOV_EXCL_LINE return WMESHD_ERROR_NONE; } @@ -318,8 +340,10 @@ int wmesh_request_enable_network(wmesh_service *service) wmesh_interface_s *info = NULL; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Enable mesh network"); @@ -328,14 +352,18 @@ int wmesh_request_enable_network(wmesh_service *service) info = service->interface_info; ret = wmesh_interface_check(info->mesh_interface); if (WMESHD_ERROR_NONE == ret) { + /* LCOV_EXCL_START */ /* Interface already exists */ return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } ret = wmesh_gdbus_create_mesh_interface(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to create mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -345,16 +373,20 @@ int wmesh_request_disable_network(wmesh_service *service) { int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Disable mesh network"); ret = wmesh_gdbus_remove_mesh_interface(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to disable mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -364,16 +396,20 @@ int wmesh_request_scan(wmesh_service *service) { int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Request scan for mesh network"); ret = wmesh_gdbus_mesh_scan(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to request scan for mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -383,16 +419,20 @@ int wmesh_request_specific_scan(wmesh_service *service, gchar *mesh_id, gint cha { int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Request specific scan for mesh network"); ret = wmesh_gdbus_mesh_specific_scan(service, mesh_id, channel); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to request specific scan for mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -402,16 +442,20 @@ int wmesh_request_cancel_scan(wmesh_service *service) { int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Cancel scan for mesh network"); ret = wmesh_gdbus_mesh_cancel_scan(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to cancel scan for mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -421,16 +465,20 @@ int wmesh_request_get_networks(wmesh_service *service) { int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Get mesh networks"); ret = wmesh_gdbus_get_mesh_networks(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get mesh networks !"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -463,7 +511,7 @@ static int _select_matched_network(GList *scanned_network, } if (FALSE == found) - return WMESHD_ERROR_NO_DATA; + return WMESHD_ERROR_NO_DATA; //LCOV_EXCL_LINE return ret; } @@ -473,16 +521,20 @@ int wmesh_request_get_joined_network(wmesh_service *service) int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Get joined mesh network"); ret = wmesh_gdbus_get_joined_mesh_network(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get joined mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -493,16 +545,20 @@ int wmesh_request_get_connected_peers(wmesh_service *service) int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Get connected mesh peers"); ret = wmesh_gdbus_get_connected_peers(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get connected mesh peers"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -514,16 +570,20 @@ int wmesh_request_create_mesh_network(wmesh_service *service, gchar *mesh_id, int ret; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Create a new mesh network"); ret = wmesh_gdbus_create_network(service, mesh_id, channel, sec); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to create mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -536,8 +596,10 @@ int wmesh_request_connect_mesh_network(wmesh_service *service, gchar *mesh_id, wmesh_scan_result_s *info = NULL; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Connect mesh network"); @@ -546,8 +608,10 @@ int wmesh_request_connect_mesh_network(wmesh_service *service, gchar *mesh_id, ret = _select_matched_network(service->scanned_mesh_network, mesh_id, channel, sec, &info); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to mesh_network_get_first_mesh_network"); return ret; + /* LCOV_EXCL_STOP */ } /* Set passphrase */ @@ -555,19 +619,25 @@ int wmesh_request_connect_mesh_network(wmesh_service *service, gchar *mesh_id, if (NULL != passphrase) { ret = wmesh_gdbus_set_passphrase(service, info, passphrase); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to set passphrase for mesh network"); return ret; + /* LCOV_EXCL_STOP */ } } else { + /* LCOV_EXCL_START */ WMESH_LOGE("Passphrase is required !"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } } ret = wmesh_gdbus_connect_network(service, info); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to connect mesh network"); return ret; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -580,8 +650,10 @@ int wmesh_request_disconnect_mesh_network(wmesh_service *service, wmesh_scan_result_s *info = NULL; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Disconnect mesh network"); @@ -590,10 +662,13 @@ int wmesh_request_disconnect_mesh_network(wmesh_service *service, ret = _select_matched_network(service->scanned_mesh_network, mesh_id, channel, sec, &info); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to _select_matched_network"); return ret; + /* LCOV_EXCL_STOP */ } + /* LCOV_EXCL_START */ ret = wmesh_gdbus_disconnect_network(service, info); if (WMESHD_ERROR_NONE != ret) { WMESH_LOGE("Failed to disconnect mesh network"); @@ -601,6 +676,7 @@ int wmesh_request_disconnect_mesh_network(wmesh_service *service, } return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } int wmesh_request_remove_mesh_network(wmesh_service *service, @@ -610,8 +686,10 @@ int wmesh_request_remove_mesh_network(wmesh_service *service, wmesh_scan_result_s *info = NULL; if (NULL == service) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("[IPC] Remove mesh network"); @@ -620,10 +698,13 @@ int wmesh_request_remove_mesh_network(wmesh_service *service, ret = _select_matched_network(service->scanned_mesh_network, mesh_id, channel, sec, &info); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to _select_matched_network"); return ret; + /* LCOV_EXCL_STOP */ } + /* LCOV_EXCL_START */ ret = wmesh_gdbus_remove_network(service, info); if (WMESHD_ERROR_NONE != ret) { WMESH_LOGE("Failed to remove mesh network"); @@ -631,6 +712,7 @@ int wmesh_request_remove_mesh_network(wmesh_service *service, } return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } /* Notifications */ diff --git a/src/wmesh-service-interface.c b/src/wmesh-service-interface.c index acb8c6b..ae4b668 100644 --- a/src/wmesh-service-interface.c +++ b/src/wmesh-service-interface.c @@ -48,6 +48,7 @@ typedef struct _meshd_dbus_client_s { #define CASE_TO_STR(x) case x: return #x; +/* LCOV_EXCL_START */ static const char* wifi_error_to_string(wifi_manager_error_e err) { switch (err) { @@ -73,12 +74,14 @@ static const char* wifi_error_to_string(wifi_manager_error_e err) return "WIFI_MANAGER_ERROR_UNKNOWN"; } } +/* LCOV_EXCL_STOP */ NetWmesh* wmeshd_dbus_get_object() { return meshd_dbus_object; } +/* LCOV_EXCL_START */ int64_t wmeshd_dbus_generate_signal_number() { static int64_t i = 0; @@ -108,6 +111,7 @@ static int _wmeshd_dbus_client_list_compare_bus_name(const void *a, const void * return g_strcmp0(client->bus_name, b); } +/* LCOV_EXCL_STOP */ static inline GList* _wmeshd_dbus_client_list_find_client(const gchar *owner) { @@ -140,15 +144,19 @@ static void _wmeshd_dbus_name_owner_changed_cb(GDBusConnection *conn, g_mutex_lock(&meshd_dbus_client_list_mutex); client = _wmeshd_dbus_client_list_find_client(old_owner); if (client) { /* found bus name in our bus list */ + /* LCOV_EXCL_START */ WMESH_LOGD("bus(%s) stopped", old_owner); meshd_dbus_client_list = g_list_remove_link(meshd_dbus_client_list, client); + /* LCOV_EXCL_STOP */ } g_mutex_unlock(&meshd_dbus_client_list_mutex); if (client) { + /* LCOV_EXCL_START */ ret = _wmeshd_dbus_client_list_cleanup(client); if (WMESHD_ERROR_NONE != ret) WMESH_LOGE("_wmeshd_dbus_client_list_cleanup() Fail(%d)", ret); + /* LCOV_EXCL_STOP */ } } } @@ -168,8 +176,10 @@ static int _wmeshd_dbus_subscribe_name_owner_changed(GDBusConnection *conn) NULL, NULL); if (0 == id) { + /* LCOV_EXCL_START */ WMESH_LOGE("g_dbus_connection_signal_subscribe() Fail"); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } return WMESHD_ERROR_NONE; @@ -188,23 +198,30 @@ static gboolean _wmeshd_dbus_handle_enable(Manager *object, /* Initialize Wi-Fi driver */ ret = wifi_manager_initialize(&wifi_handle); - if (WIFI_MANAGER_ERROR_NONE != ret) + if (WIFI_MANAGER_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to get wifi manager handle ! [%s(%X)]", wifi_error_to_string(ret), ret); + /* LCOV_EXCL_STOP */ + } wifi_manager_is_activated(wifi_handle, &wifi_activated); if (false == wifi_activated) { + /* LCOV_EXCL_START */ ret = wifi_manager_activate(wifi_handle, NULL, NULL); if (WIFI_MANAGER_ERROR_NONE != ret) WMESH_LOGE("Failed to activate wifi ! [%s(%X)]", wifi_error_to_string(ret), ret); + /* LCOV_EXCL_STOP */ } wifi_manager_deinitialize(wifi_handle); if (service->mesh_activated) { + /* LCOV_EXCL_START */ /* Already activated */ manager_complete_enable(object, invocation, WMESHD_ERROR_NONE); goto FINISH; + /* LCOV_EXCL_STOP */ } /* Do API response first */ @@ -216,16 +233,20 @@ static gboolean _wmeshd_dbus_handle_enable(Manager *object, /* Register event handler first */ ret = wmesh_request_register_event_handler(service); if (WMESHD_ERROR_IN_PROGRESS == ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Currently set netlink event handler !! [%d]", ret); ret = WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } else if (WMESHD_ERROR_NONE != ret) { - WMESH_LOGE("Failed to register mesh event handler !! [%d]", ret); + WMESH_LOGE("Failed to register mesh event handler !! [%d]", ret); //LCOV_EXCL_LINE } ret = wmesh_interface_initialize(service->interface_info); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to wmesh_interface_initialize [%d]", ret); goto FINISH; + /* LCOV_EXCL_STOP */ } FINISH: @@ -249,7 +270,7 @@ static gboolean _wmeshd_dbus_handle_disable(Manager *object, ret = wmesh_request_unregister_event_handler(); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to unregister mesh event handler !! [%d]", ret); + WMESH_LOGE("Failed to unregister mesh event handler !! [%d]", ret); //LCOV_EXCL_LINE /* Terminate daemon */ wmeshd_service_exit(service); @@ -269,7 +290,7 @@ static gboolean _wmeshd_dbus_handle_scan(NetWmesh *object, ret = wmesh_request_scan(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_scan !"); + WMESH_LOGE("Failed to wmesh_request_scan !"); //LCOV_EXCL_LINE net_wmesh_complete_scan(object, invocation, ret); @@ -290,7 +311,7 @@ static gboolean _wmeshd_dbus_handle_specific_scan(NetWmesh *object, ret = wmesh_request_specific_scan(service, mesh_id, channel); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_specific_scan !"); + WMESH_LOGE("Failed to wmesh_request_specific_scan !"); //LCOV_EXCL_LINE net_wmesh_complete_specific_scan(object, invocation, ret); @@ -306,13 +327,14 @@ static gboolean _wmeshd_dbus_handle_cancel_scan(NetWmesh *object, ret = wmesh_request_cancel_scan(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_cancel_scan"); + WMESH_LOGE("Failed to wmesh_request_cancel_scan"); //LCOV_EXCL_LINE net_wmesh_complete_cancel_scan(object, invocation, ret); return TRUE; } +/* LCOV_EXCL_START */ static void _on_scan_result_destroy(gpointer data) { wmesh_scan_result_s *scan_item = (wmesh_scan_result_s *)data; @@ -354,6 +376,7 @@ static void _on_mpath_list_destroy(gpointer data) g_free(info); } } +/* LCOV_EXCL_STOP */ static gboolean _wmeshd_dbus_handle_get_found_mesh_networks(NetWmesh *object, GDBusMethodInvocation *invocation, @@ -371,13 +394,14 @@ static gboolean _wmeshd_dbus_handle_get_found_mesh_networks(NetWmesh *object, ret = wmesh_request_get_networks(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_get_networks"); + WMESH_LOGE("Failed to wmesh_request_get_networks"); //LCOV_EXCL_LINE g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}")); /* scanned_mesh_network would be filled above request */ iter = service->scanned_mesh_network; while (iter != NULL) { + /* LCOV_EXCL_START */ scan_item = (wmesh_scan_result_s*)iter->data; g_variant_builder_open(&builder, G_VARIANT_TYPE_VARDICT); @@ -398,6 +422,7 @@ static gboolean _wmeshd_dbus_handle_get_found_mesh_networks(NetWmesh *object, g_variant_builder_close(&builder); iter = g_list_next(iter); + /* LCOV_EXCL_STOP */ } networks = g_variant_builder_end(&builder); @@ -417,7 +442,7 @@ static gboolean _wmeshd_dbus_handle_enable_mesh(NetWmesh *object, /* It handles creating virtual network and bridge */ ret = wmesh_request_enable_network(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_enable_network [%d]", ret); + WMESH_LOGE("Failed to wmesh_request_enable_network [%d]", ret); //LCOV_EXCL_LINE wmesh_start_monitor_service(service); @@ -437,15 +462,17 @@ static gboolean _wmeshd_dbus_handle_disable_mesh(NetWmesh *object, wmeshd_check_null_ret_error("info", info, FALSE); if (FALSE == service->mesh_activated) { + /* LCOV_EXCL_START */ WMESH_LOGD("Mesh network is not activated yet"); ret = WMESHD_ERROR_OPERATION_FAILED; net_wmesh_complete_disable_mesh(object, invocation, ret); return TRUE; + /* LCOV_EXCL_STOP */ } ret = wmesh_request_disable_network(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to disable mesh network !"); + WMESH_LOGE("Failed to disable mesh network !"); //LCOV_EXCL_LINE /* Stop Mesh Node Monitoring Service */ wmesh_stop_monitor_service(service); @@ -466,8 +493,10 @@ static gboolean _wmeshd_dbus_handle_is_mesh_enabled(NetWmesh *object, /* It handles creating virtual network and bridge */ ret = wmesh_interface_check(service->interface_info->mesh_interface); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Mesh Interface doesn't exists"); state = FALSE; + /* LCOV_EXCL_STOP */ } net_wmesh_complete_is_mesh_enabled(object, invocation, state); @@ -485,8 +514,10 @@ static gboolean _wmeshd_dbus_handle_is_joined(NetWmesh *object, ret = wmesh_request_get_joined_network(service); if (WMESHD_ERROR_NONE == ret) { + /* LCOV_EXCL_START */ if (service->joined_network) state = TRUE; + /* LCOV_EXCL_STOP */ } net_wmesh_complete_is_joined(object, invocation, state, ret); @@ -506,18 +537,20 @@ static gboolean _wmeshd_dbus_handle_get_joined_mesh_network(NetWmesh *object, if (WMESHD_ERROR_NONE == ret) { joined = service->joined_network; if (joined) { + /* LCOV_EXCL_START */ net_wmesh_complete_get_joined_mesh_network(object, invocation, joined->mesh_id, joined->bssid, joined->channel, (int)joined->security, joined->state, joined->ipv4_type, joined->ipv4_address, joined->ipv4_netmask, ret); + /* LCOV_EXCL_STOP */ } else { net_wmesh_complete_get_joined_mesh_network(object, invocation, - "", "", 0, 0, 0, 0, "", "", WMESHD_ERROR_NO_DATA); + "", "", 0, 0, 0, 0, "", "", WMESHD_ERROR_NO_DATA); /* LCOV_EXCL_LINE */ } } else { net_wmesh_complete_get_joined_mesh_network(object, invocation, - "", "", 0, 0, 0, 0, "", "", ret); + "", "", 0, 0, 0, 0, "", "", ret); /* LCOV_EXCL_LINE */ } return TRUE; @@ -539,11 +572,12 @@ static gboolean _wmeshd_dbus_handle_get_connected_peers(NetWmesh *object, ret = wmesh_request_get_connected_peers(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_get_connected_peers"); + WMESH_LOGE("Failed to wmesh_request_get_connected_peers"); //LCOV_EXCL_LINE g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}")); iter = service->connected_mesh_peers; while (iter != NULL) { + /* LCOV_EXCL_START */ peer = (wmesh_peer_info_s*)iter->data; g_variant_builder_open(&builder, G_VARIANT_TYPE_VARDICT); @@ -552,6 +586,7 @@ static gboolean _wmeshd_dbus_handle_get_connected_peers(NetWmesh *object, g_variant_builder_close(&builder); iter = g_list_next(iter); + /* LCOV_EXCL_STOP */ } peer_list = g_variant_builder_end(&builder); @@ -580,13 +615,13 @@ static gboolean _wmeshd_dbus_handle_set_gate(NetWmesh *object, /* Set STP and gate_announce for connmand */ ret = wmesh_gdbus_set_mesh_gate(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_gdbus_set_mesh_gate [%d]", ret); + WMESH_LOGE("Failed to wmesh_gdbus_set_mesh_gate [%d]", ret); //LCOV_EXCL_LINE /* Set STP and gate_announce right now */ ret = wmesh_request_set_mesh_gate(info->bridge_interface, info->mesh_interface, info->external_interface); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_gdbus_set_mesh_gate [%d]", ret); + WMESH_LOGE("Failed to wmesh_gdbus_set_mesh_gate [%d]", ret); //LCOV_EXCL_LINE net_wmesh_complete_set_gate(object, invocation, ret); @@ -609,13 +644,13 @@ static gboolean _wmeshd_dbus_handle_unset_gate(NetWmesh *object, /* Set STP and gate_announce for connmand */ ret = wmesh_gdbus_set_mesh_gate(service); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_gdbus_set_mesh_gate [%d]", ret); + WMESH_LOGE("Failed to wmesh_gdbus_set_mesh_gate [%d]", ret); //LCOV_EXCL_LINE /* Unset STP and Gate Annouce right now */ ret = wmesh_request_unset_mesh_gate(info->bridge_interface, info->mesh_interface, info->external_interface); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_unset_mesh_gate [%d]", ret); + WMESH_LOGE("Failed to wmesh_request_unset_mesh_gate [%d]", ret); //LCOV_EXCL_LINE net_wmesh_complete_unset_gate(object, invocation, ret); @@ -644,7 +679,7 @@ static gboolean _wmeshd_dbus_handle_set_softap(NetWmesh *object, ssid, mode, channel, visibility, max_sta, security, passphrase); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_set_softap_config [%d]", ret); + WMESH_LOGE("Failed to wmesh_request_set_softap_config [%d]", ret); //LCOV_EXCL_LINE net_wmesh_complete_set_softap(object, invocation, ret); @@ -664,10 +699,12 @@ static gboolean _wmeshd_dbus_handle_get_softap(NetWmesh *object, ret = wmesh_request_get_softap_config(&interface, &ssid, &mode, &channel, &visibility, &max_sta, &security, &passphrase); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to wmesh_request_get_softap_config [%d]", ret); net_wmesh_complete_get_softap(object, invocation, "", "", 0, 0, 0, 0, "", ret); return FALSE; + /* LCOV_EXCL_STOP */ } WMESH_LOGD("SSID : %s", ssid); @@ -680,10 +717,10 @@ static gboolean _wmeshd_dbus_handle_get_softap(NetWmesh *object, if (security == 1) net_wmesh_complete_get_softap(object, invocation, ssid, mode, channel, - visibility, max_sta, security, passphrase, ret); + visibility, max_sta, security, passphrase, ret); /* LCOV_EXCL_LINE */ else net_wmesh_complete_get_softap(object, invocation, ssid, mode, channel, - visibility, max_sta, security, "", ret); + visibility, max_sta, security, "", ret); /* LCOV_EXCL_LINE */ return TRUE; } @@ -698,7 +735,7 @@ static gboolean _wmeshd_dbus_handle_enable_softap(NetWmesh *object, /* Check softAP interface and execute it */ ret = wmesh_request_enable_softap(info->bridge_interface, info->softap_interface); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_enable_softap [%d]", ret); + WMESH_LOGE("Failed to wmesh_request_enable_softap [%d]", ret); //LCOV_EXCL_LINE net_wmesh_complete_enable_softap(object, invocation, ret); @@ -715,7 +752,7 @@ static gboolean _wmeshd_dbus_handle_disable_softap(NetWmesh *object, /* Destroy softAP */ ret = wmesh_request_disable_softap(info->bridge_interface, info->softap_interface); if (WMESHD_ERROR_NONE != ret) - WMESH_LOGE("Failed to wmesh_request_disable_softap [%d]", ret); + WMESH_LOGE("Failed to wmesh_request_disable_softap [%d]", ret); //LCOV_EXCL_LINE net_wmesh_complete_disable_softap(object, invocation, ret); @@ -844,6 +881,7 @@ static gboolean _wmeshd_dbus_handle_get_station_info(NetWmesh *object, wmesh_interface_s *info = service->interface_info; if (station_type == WMESHD_STATION_TYPE_MESH_POINT) { + /* LCOV_EXCL_START */ /* Clear mesh station list */ g_list_free_full(service->station_list, _on_station_list_destroy); service->station_list = NULL; @@ -866,47 +904,52 @@ static gboolean _wmeshd_dbus_handle_get_station_info(NetWmesh *object, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Invalid station type"); return FALSE; + /* LCOV_EXCL_STOP */ } if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to wmesh_request_get_station_info"); g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Request Failed"); + /* LCOV_EXCL_STOP */ } else { - /* - * sh-3.2# iw mesh0 station dump - * Station 7c:dd:90:62:37:cf (on mesh0) - * inactive time: 1685 ms - * rx bytes: 34174 - * rx packets: 1181 - * tx bytes: 6877 - * tx packets: 76 - * tx retries: 0 - * tx failed: 0 - * beacon loss: 0 - * signal: -64 dBm - * signal avg: -63 dBm - * tx bitrate: 54.0 MBit/s - * rx bitrate: 5.5 MBit/s - * mesh llid: 51731 - * mesh plid: 35432 - * mesh plink: ESTAB - * mesh local PS mode: ACTIVE - * mesh peer PS mode: ACTIVE - * mesh non-peer PS mode: ACTIVE - * authorized: yes - * authenticated: yes - * associated: yes - * preamble: long - * WMM/WME: yes - * MFP: no - * TDLS peer: no - * DTIM period: 0 - * beacon interval:1000 - * short slot time:yes - * connected time: 256 seconds - */ + /* + * sh-3.2# iw mesh0 station dump + * Station 7c:dd:90:62:37:cf (on mesh0) + * inactive time: 1685 ms + * rx bytes: 34174 + * rx packets: 1181 + * tx bytes: 6877 + * tx packets: 76 + * tx retries: 0 + * tx failed: 0 + * beacon loss: 0 + * signal: -64 dBm + * signal avg: -63 dBm + * tx bitrate: 54.0 MBit/s + * rx bitrate: 5.5 MBit/s + * mesh llid: 51731 + * mesh plid: 35432 + * mesh plink: ESTAB + * mesh local PS mode: ACTIVE + * mesh peer PS mode: ACTIVE + * mesh non-peer PS mode: ACTIVE + * authorized: yes + * authenticated: yes + * associated: yes + * preamble: long + * WMM/WME: yes + * MFP: no + * TDLS peer: no + * DTIM period: 0 + * beacon interval:1000 + * short slot time:yes + * connected time: 256 seconds + */ + + /* LCOV_EXCL_START */ /* Get station information and make variant data */ g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}")); @@ -995,6 +1038,7 @@ static gboolean _wmeshd_dbus_handle_get_station_info(NetWmesh *object, g_object_unref(station); } + /* LCOV_EXCL_STOP */ return TRUE; } @@ -1018,16 +1062,20 @@ static gboolean _wmeshd_dbus_handle_get_mpath_info(NetWmesh *object, ret = wmesh_request_get_mpath_info( info->mesh_interface, &service->mpath_list); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to wmesh_request_get_mpath_info"); g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Request Failed"); + /* LCOV_EXCL_STOP */ } else { - /* - * Example) sh-3.2# iw mesh0 mpath dump - * DEST ADDR NEXT HOP IFACE SN METRIC QLEN EXPTIME DTIM DRET FLAGS - * 7c:dd:90:62:37:cf 7c:dd:90:62:37:cf mesh0 221 152 0 10 100 0 0x5 - */ + /* + * Example) sh-3.2# iw mesh0 mpath dump + * DEST ADDR NEXT HOP IFACE SN METRIC QLEN EXPTIME DTIM DRET FLAGS + * 7c:dd:90:62:37:cf 7c:dd:90:62:37:cf mesh0 221 152 0 10 100 0 0x5 + */ + + /* LCOV_EXCL_START */ /* Get mesh path information and make variant data */ g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}")); @@ -1065,6 +1113,7 @@ static gboolean _wmeshd_dbus_handle_get_mpath_info(NetWmesh *object, net_wmesh_complete_get_mpath_info(object, invocation, mpath_data, ret); g_object_unref(mpath_data); + /* LCOV_EXCL_STOP */ } return TRUE; @@ -1083,10 +1132,12 @@ static gboolean _wmeshd_dbus_handle_get_meshconf_info(NetWmesh *object, ret = wmesh_request_get_meshconf_info(service); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to wmesh_request_get_mpath_info"); g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Request Failed"); + /* LCOV_EXCL_STOP */ } else { /* Get mesh path information and make variant data */ g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); @@ -1144,8 +1195,10 @@ static void _wmeshd_dbus_on_activator_bus_acquired(GDBusConnection *conn, meshd_activator_dbus_object = manager_skeleton_new(); if (NULL == meshd_activator_dbus_object) { + /* LCOV_EXCL_START */ WMESH_LOGE("manager_skeleton_new() Fail"); return; + /* LCOV_EXCL_STOP */ } g_signal_connect(meshd_activator_dbus_object, "handle-enable", @@ -1157,8 +1210,10 @@ static void _wmeshd_dbus_on_activator_bus_acquired(GDBusConnection *conn, G_DBUS_INTERFACE_SKELETON(meshd_activator_dbus_object), conn, WMESH_DBUS_MANAGER_OBJPATH, &error); if (FALSE == ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message); g_error_free(error); + /* LCOV_EXCL_STOP */ } } @@ -1173,8 +1228,10 @@ static void _wmeshd_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *nam meshd_dbus_object = net_wmesh_skeleton_new(); if (NULL == meshd_dbus_object) { + /* LCOV_EXCL_START */ WMESH_LOGE("net_wmesh_skeleton_new() Fail"); return; + /* LCOV_EXCL_STOP */ } g_signal_connect(meshd_dbus_object, "handle-scan", @@ -1231,17 +1288,22 @@ static void _wmeshd_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *nam ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(meshd_dbus_object), conn, WMESH_DBUS_OBJPATH, &error); if (FALSE == ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("g_dbus_interface_skeleton_export() Fail(%s)", error->message); g_error_free(error); + /* LCOV_EXCL_STOP */ } ret = _wmeshd_dbus_subscribe_name_owner_changed(conn); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("_wmeshd_dbus_subscribe_name_owner_changed() Fail(%d)", ret); return; + /* LCOV_EXCL_STOP */ } } +/* LCOV_EXCL_START */ static void _wmeshd_dbus_on_name_lost(GDBusConnection *conn, const gchar *name, gpointer user_data) { @@ -1250,6 +1312,7 @@ static void _wmeshd_dbus_on_name_lost(GDBusConnection *conn, const gchar *name, WMESH_LOGD("Lost the name %s", name); } +/* LCOV_EXCL_STOP */ static void _wmeshd_dbus_on_name_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) @@ -1275,8 +1338,10 @@ static gboolean _wmeshd_dbus_interface_init(wmesh_service *service) service, NULL); if (0 == id) { + /* LCOV_EXCL_START */ WMESH_LOGE("g_bus_own_name() Fail"); return FALSE; + /* LCOV_EXCL_STOP */ } /* Get D-Bus owner to activate mesh service daemon */ @@ -1325,36 +1390,37 @@ static void _wmeshd_dbus_deinit(wmesh_service *service) g_free(info->external_interface); if (service->joined_network) { + /* LCOV_EXCL_START */ g_free(service->joined_network->mesh_id); g_free(service->joined_network->bssid); g_free(service->joined_network); service->joined_network = NULL; + /* LCOV_EXCL_STOP */ } /* Clear scan list */ if (service->scanned_mesh_network) - g_list_free_full(service->scanned_mesh_network, _on_scan_result_destroy); + g_list_free_full(service->scanned_mesh_network, _on_scan_result_destroy); /* LCOV_EXCL_LINE */ service->scanned_mesh_network = NULL; /* Clear connected peers list */ if (service->connected_mesh_peers) - g_list_free_full(service->connected_mesh_peers, _on_peer_info_destroy); + g_list_free_full(service->connected_mesh_peers, _on_peer_info_destroy); /* LCOV_EXCL_LINE */ service->connected_mesh_peers = NULL; /* Clear mesh path list */ if (service->mpath_list) - g_list_free_full(service->mpath_list, _on_mpath_list_destroy); + g_list_free_full(service->mpath_list, _on_mpath_list_destroy); /* LCOV_EXCL_LINE */ service->mpath_list = NULL; /* Clear mesh station list */ if (service->station_list) - g_list_free_full(service->station_list, _on_station_list_destroy); + g_list_free_full(service->station_list, _on_station_list_destroy); /* LCOV_EXCL_LINE */ service->station_list = NULL; /* Clear mesh station list */ if (service->softap_station_list) - g_list_free_full(service->softap_station_list, - _on_station_list_destroy); + g_list_free_full(service->softap_station_list, _on_station_list_destroy); /* LCOV_EXCL_LINE */ service->softap_station_list = NULL; g_free(service->interface_info); @@ -1370,8 +1436,10 @@ gboolean wmeshd_service_interface_init(wmesh_service *service) /* Initialize dbus interface */ ret = _wmeshd_dbus_interface_init(service); if (FALSE == ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("_wmeshd_dbus_interface_init failed!!!"); return FALSE; + /* LCOV_EXCL_STOP */ } return TRUE; diff --git a/src/wmesh-service.c b/src/wmesh-service.c index 84262e6..407cd4a 100644 --- a/src/wmesh-service.c +++ b/src/wmesh-service.c @@ -32,9 +32,11 @@ wmesh_service *wmeshd_service_new() /* Create g-main loop */ service->main_loop = g_main_loop_new(NULL, FALSE); if (G_UNLIKELY(NULL == service->main_loop)) { + /* LCOV_EXCL_START */ WMESH_LOGE("g-main loop creation failed!!!"); g_free(service); return NULL; + /* LCOV_EXCL_STOP */ } return service; diff --git a/src/wmesh-softap.c b/src/wmesh-softap.c index b14f946..bd96348 100644 --- a/src/wmesh-softap.c +++ b/src/wmesh-softap.c @@ -85,15 +85,19 @@ static int __get_psk_hexascii(const char *pass, const unsigned char *salt, if (pass == NULL || salt == NULL || psk == NULL || psk_len < (SHA256_DIGEST_LENGTH * 2 + 1)) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } if (!PKCS5_PBKDF2_HMAC_SHA1(pass, strlen(pass), salt, strlen((const char *)salt), PSK_ITERATION_COUNT, sizeof(buf), buf)) { + /* LCOV_EXCL_START */ WMESH_LOGE("Getting psk is failed"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } for (i = 0; i < SHA256_DIGEST_LENGTH; i++) { @@ -121,7 +125,7 @@ static int __config_hostapd(const char *softap_interface, const char *ssid, char *hw_mode = NULL; if (mode == NULL) - hw_mode = g_strdup("g"); + hw_mode = g_strdup("g"); /* LCOV_EXCL_LINE */ else hw_mode = g_strdup(mode); @@ -153,9 +157,11 @@ static int __config_hostapd(const char *softap_interface, const char *ssid, ret = __get_psk_hexascii(passphrase, (const unsigned char *)ssid, key, sizeof(key)); if (ret != WMESHD_ERROR_NONE) { + /* LCOV_EXCL_START */ g_free(conf); WMESH_LOGE("hex conversion failed"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } snprintf(buf, sizeof(buf), "wpa=2\nrsn_pairwise=CCMP\nwpa_psk=%s\n", key); @@ -164,14 +170,16 @@ static int __config_hostapd(const char *softap_interface, const char *ssid, conf = g_strconcat(old_conf, buf, NULL); g_free(old_conf); } else { - WMESH_LOGD("Open connection [%s]", security); + WMESH_LOGD("Open connection [%s]", security); /* LCOV_EXCL_LINE */ } fp = fopen(HOSTAPD_MESH_CONF_FILE, "w"); if (NULL == fp) { + /* LCOV_EXCL_START */ WMESH_LOGE("Could not create the file [%s].", HOSTAPD_MESH_CONF_FILE); g_free(conf); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } if (conf) { @@ -192,14 +200,18 @@ static int __read_hostapd_config(char **softap_interface, char **ssid, fp = fopen(HOSTAPD_MESH_CONF_FILE, "r"); if (fp == NULL) { + /* LCOV_EXCL_START */ WMESH_LOGE("Failed to read file"); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } if (!softap_interface || !ssid || !security || !passphrase || !mode || !channel || !visibility || !max_sta) { + /* LCOV_EXCL_START */ fclose(fp); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } *security = 0; @@ -246,28 +258,34 @@ static int __open_hostapd_intf(const char* softap_interface, int *fd, struct stat stat_buf; if (fd == NULL || intf == NULL) { + /* LCOV_EXCL_START */ WMESH_LOGE("fd is NULL"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } *fd = socket(PF_UNIX, SOCK_DGRAM, 0); if (*fd < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("socket is failed"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } src.sun_family = AF_UNIX; g_strlcpy(src.sun_path, intf, sizeof(src.sun_path)); if (stat(src.sun_path, &stat_buf) == 0) - unlink(src.sun_path); + unlink(src.sun_path); /* LCOV_EXCL_LINE */ if (bind(*fd, (struct sockaddr *)&src, sizeof(src)) < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("bind is failed"); close(*fd); *fd = -1; unlink(src.sun_path); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } snprintf(ctrl_intf, sizeof(ctrl_intf), "%s/%s", @@ -277,12 +295,14 @@ static int __open_hostapd_intf(const char* softap_interface, int *fd, while (connect(*fd, (struct sockaddr *)&dest, sizeof(dest)) < 0) { if (++retry >= HOSTAPD_RETRY_MAX) - goto FAIL; + goto FAIL; //LCOV_EXCL_LINE usleep(HOSTAPD_RETRY_DELAY); } + /* LCOV_EXCL_START */ WMESH_LOGD("Successfully open interface[%s] to hostapd", intf); return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ FAIL: WMESH_LOGE("Cannot make connection to hostapd"); @@ -293,6 +313,7 @@ FAIL: return WMESHD_ERROR_OPERATION_FAILED; } +/* LCOV_EXCL_START */ static int __close_hostapd_intf(int *fd) { if (fd == NULL) { @@ -306,6 +327,7 @@ static int __close_hostapd_intf(int *fd) return WMESHD_ERROR_NONE; } +/* LCOV_EXCL_STOP */ static int __get_pid_of_hostapd(pid_t *pid) { @@ -318,16 +340,19 @@ static int __get_pid_of_hostapd(pid_t *pid) snprintf(file_path, 256, "%s", HOSTAPD_PID_FILE); if (0 == access(file_path, F_OK)) { + /* LCOV_EXCL_START */ fd = fopen(file_path, "r"); if (fd == NULL) { WMESH_LOGE("Error! Could not open pid file"); return WMESHD_ERROR_IO_ERROR; } + /* LCOV_EXCL_STOP */ } else { WMESH_LOGE("Error! Could not access pid file"); return WMESHD_ERROR_IO_ERROR; } + /* LCOV_EXCL_START */ errno = 0; rv = fscanf(fd, "%d", &ret); if (rv < 0) { @@ -343,6 +368,7 @@ static int __get_pid_of_hostapd(pid_t *pid) fclose(fd); return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP*/ } static int __terminate_hostapd() @@ -353,10 +379,13 @@ static int __terminate_hostapd() /* Get pid */ ret = __get_pid_of_hostapd(&hostapd_pid); if (WMESHD_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ WMESH_LOGE("There is no hostapd"); return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } + /* LCOV_EXCL_START */ if (hostapd_pid == 0) { WMESH_LOGE("There is no hostapd"); return WMESHD_ERROR_NONE; @@ -369,6 +398,7 @@ static int __terminate_hostapd() kill(hostapd_pid, SIGTERM); return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } static int __execute_hostapd() @@ -379,14 +409,18 @@ static int __execute_hostapd() ret = __get_pid_of_hostapd(&pid); if (0 != pid) { + /* LCOV_EXCL_START */ WMESH_LOGE("hostapd is running already"); return WMESHD_ERROR_NONE; + /* LCOV_EXCL_STOP */ } pid = fork(); if (pid < 0) { + /* LCOV_EXCL_START */ WMESH_LOGE("fork failed"); return WMESHD_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ } if (pid == 0) { @@ -396,11 +430,12 @@ static int __execute_hostapd() "-P", HOSTAPD_PID_FILE, "-ddd", "-B", (char *)NULL)) { - WMESH_LOGE("execl failed"); + WMESH_LOGE("execl failed"); /* LCOV_EXCL_LINE */ } - + /* LCOV_EXCL_START */ WMESH_LOGE("Should not get here!"); exit(1); + /* LCOV_EXCL_STOP */ } else { /* Reap child */ waitpid(pid, &status, 0); @@ -446,21 +481,27 @@ int wmesh_softap_enable_softap(const char* softap_interface) int ret = WMESHD_ERROR_NONE; if (NULL == softap_interface) { + /* LCOV_EXCL_START */ WMESH_LOGE("Invalid parameter"); return WMESHD_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ } ret = __execute_hostapd(); if (ret != WMESHD_ERROR_NONE) { + /* LCOV_EXCL_START */ WMESH_LOGE("__execute_hostapd is failed"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } ret = __open_hostapd_intf(softap_interface, &hostapd_ctrl_fd, MH_CTRL_INTF); if (ret != WMESHD_ERROR_NONE) { + /* LCOV_EXCL_START */ WMESH_LOGE("__open_hostapd_intf is failed"); __terminate_hostapd(); + /* LCOV_EXCL_STOP */ } return ret; @@ -472,8 +513,10 @@ int wmesh_softap_disable_softap() ret = __terminate_hostapd(); if (ret != WMESHD_ERROR_NONE) { + /* LCOV_EXCL_START */ WMESH_LOGE("__execute_hostapd is failed"); return WMESHD_ERROR_OPERATION_FAILED; + /* LCOV_EXCL_STOP */ } return ret; @@ -486,14 +529,18 @@ bool wmesh_softap_check_softap_status() ret = __get_pid_of_hostapd(&hostapd_pid); if (ret != WMESHD_ERROR_NONE) { + /* LCOV_EXCL_START */ WMESH_LOGE("hostapd is not running"); return false; + /* LCOV_EXCL_STOP */ } + /* LCOV_EXCL_START */ if (hostapd_pid == 0) { WMESH_LOGD("hostapd is not running"); return false; } return true; + /* LCOV_EXCL_STOP */ } diff --git a/src/wmeshd.c b/src/wmeshd.c index 33b88b3..1f5800b 100644 --- a/src/wmeshd.c +++ b/src/wmeshd.c @@ -32,13 +32,17 @@ /**< mesh service */ wmesh_service *meshsvc; +#if (BUILD_GCOV != 0) +extern void __gcov_flush(void); +#endif + int main(int argc, char *argv[]) { wmesh_service *service = NULL; int ret_code = 0; gboolean ret; - __WMESH_LOG_FUNC_ENTER__; + __WMESH_LOG_FUNC_ENTER__; //LCOV_EXCL_LINE #if !GLIB_CHECK_VERSION(2, 32, 0) if (!g_thread_supported()) @@ -53,21 +57,29 @@ int main(int argc, char *argv[]) WMESH_LOGI("service mainloop start"); +#if (BUILD_GCOV != 0) + setenv("GCOV_PREFIX", "/tmp/", 1); +#endif + /* Create mesh service */ meshsvc = service = wmeshd_service_new(); /* Initialize mesh service interface layer */ ret = wmeshd_service_interface_init(service); if (G_UNLIKELY(FALSE == ret)) { + /* LCOV_EXCL_START */ WMESH_LOGE("wmeshd_service_interface_init failed!"); goto END; + /* LCOV_EXCL_STOP */ } /* Run mesh service */ ret = wmeshd_service_run(service); if (G_UNLIKELY(FALSE == ret)) { + /* LCOV_EXCL_START */ WMESH_LOGE("Run service failed!"); ret_code = EXIT_FAILURE; + /* LCOV_EXCL_STOP */ } END: @@ -76,7 +88,11 @@ END: wmeshd_service_free(service); meshsvc = NULL; - __WMESH_LOG_FUNC_EXIT__; - return 0; +#if (BUILD_GCOV != 0) + __gcov_flush(); +#endif + + __WMESH_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE + return ret_code; } diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt new file mode 100644 index 0000000..233777a --- /dev/null +++ b/unittest/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(gtest-wifi-mesh-manager C CXX) + +SET(GTEST_TEST "gtest-wifi-mesh-manager") +ADD_DEFINITIONS("-DUSE_DLOG") + +SET(REQUIRES_LIST ${REQUIRES_LIST} + glib-2.0 + gio-2.0 + gmock + dlog +) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST}) + +FOREACH(flag ${GTEST_TEST_PKG_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +FILE(GLOB GTEST_TEST_SRCS *.cpp) +SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS}) + +ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS}) +TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl -lgcov) + +INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION ${BIN_DIR}) diff --git a/unittest/gdbus.cpp b/unittest/gdbus.cpp new file mode 100644 index 0000000..e882fea --- /dev/null +++ b/unittest/gdbus.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "gdbus.h" + +GDbus::GDbus() +{ + this->m_pConnection = NULL; + this->m_pCancellable = NULL; +} + +GDbus::~GDbus() +{ + GDBusConnection *conn = this->m_pConnection; + GCancellable *cancel = this->m_pCancellable; + + if (cancel) { + g_cancellable_cancel(cancel); + g_object_unref(cancel); + cancel = NULL; + } + + if (conn) { + g_object_unref(conn); + conn = NULL; + } +} + +error_e GDbus::Create(void) +{ + GError *err = NULL; + +#if !GLIB_CHECK_VERSION(2, 36, 0) + g_type_init(); +#endif + + this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (this->m_pConnection == NULL) { + if (err != NULL) { + GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message); + g_error_free(err); + } + + return ERROR_OPERATION_FAILED; + } + + this->m_pCancellable = g_cancellable_new(); + + return ERROR_NONE; +} + +error_e GDbus::Destroy(void) +{ + g_cancellable_cancel(this->m_pCancellable); + g_object_unref(this->m_pCancellable); + this->m_pCancellable = NULL; + + g_object_unref(this->m_pConnection); + this->m_pConnection = NULL; + + return ERROR_NONE; +} + +GDBusConnection *GDbus::GetConnection(void) +{ + return this->m_pConnection; +} + +GCancellable *GDbus::GetCancellable(void) +{ + return this->m_pCancellable; +} + +error_e GDbus::ConvertErrorStringToEnum(const char *error) +{ + if (NULL != strstr(error, "NoReply")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "Failed")) + return ERROR_OPERATION_FAILED; + else if (NULL != strstr(error, "UnknownMethod")) + return ERROR_INVALID_OPERATION; + else if (NULL != strstr(error, "InvalidArguments")) + return ERROR_INVALID_PARAMETER; + else if (NULL != strstr(error, "AccessDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "PermissionDenied")) + return ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "NotSupported")) + return ERROR_NOT_SUPPORTED; + else if (NULL != strstr(error, "InProgress")) + return ERROR_IN_PROGRESS; + + return ERROR_OPERATION_FAILED; +} + +GVariant *GDbus::InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error) +{ + GError *error = NULL; + GVariant *reply = NULL; + GDBusConnection *connection = NULL; + *dbus_error = ERROR_NONE; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + *dbus_error = ERROR_NOT_INITIALIZED; + return reply; + } + + reply = g_dbus_connection_call_sync(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, + GetCancellable(), + &error); + + if (reply == NULL) { + if (error != NULL) { + GLOGD("g_dbus_connection_call_sync() failed " + "error [%d: %s]", error->code, error->message); + *dbus_error = ConvertErrorStringToEnum(error->message); + g_error_free(error); + } else { + GLOGD("g_dbus_connection_call_sync() failed"); + *dbus_error = ERROR_OPERATION_FAILED; + } + + return NULL; + } + + return reply; +} + +error_e GDbus::InvokeMethodNonblock(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, int timeout, + GAsyncReadyCallback notify_func, void *user_data) +{ + GDBusConnection *connection = NULL; + + connection = GetConnection(); + if (connection == NULL) { + GLOGD("GDBusconnection is NULL"); + return ERROR_NOT_INITIALIZED; + } + + g_dbus_connection_call(connection, + dest, + path, + iface_name, + method, + params, + NULL, + G_DBUS_CALL_FLAGS_NONE, + timeout, + GetCancellable(), + (GAsyncReadyCallback) notify_func, + (gpointer)user_data); + + return ERROR_NONE; +} diff --git a/unittest/gdbus.h b/unittest/gdbus.h new file mode 100644 index 0000000..1c53966 --- /dev/null +++ b/unittest/gdbus.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __WIFI_MESH_MGR_GDBUS_H__ +#define __WIFI_MESH_MGR_GDBUS_H__ + +#include +#include + +#include "wmeshmgr.h" + +#define GMAINTIMEOUT 10000 +#define DBUS_REPLY_TIMEOUT (120 * 1000) + +#define WIFI_MESH_MGR_SERVICE "net.wmesh" +#define WIFI_MESH_MGR_INTERFACE WIFI_MESH_MGR_SERVICE + +#define WIFI_MESH_MGR_MANAGER_INTERFACE WIFI_MESH_MGR_SERVICE ".manager" + +#define WIFI_MESH_MGR_MANAGER_PATH "/net/wmesh/manager" +#define WIFI_MESH_MGR_PATH "/net/wmesh" + +#define WIFI_MESH_MGR_METHOD_MANAGER_START "enable" +#define WIFI_MESH_MGR_METHOD_MANAGER_STOP "disable" +#define WIFI_MESH_MGR_METHOD_SCAN "scan" +#define WIFI_MESH_MGR_METHOD_SPECIFIC_SCAN "specific_scan" +#define WIFI_MESH_MGR_METHOD_CANCEL_SCAN "cancel_scan" +#define WIFI_MESH_MGR_METHOD_GET_FOUND_MESH_NETWORKS "get_found_mesh_networks" +#define WIFI_MESH_MGR_METHOD_GET_CONNECTED_PEERS "get_connected_peers" +#define WIFI_MESH_MGR_METHOD_ENABLE_MESH "enable_mesh" +#define WIFI_MESH_MGR_METHOD_DISABLE_MESH "disable_mesh" +#define WIFI_MESH_MGR_METHOD_IS_MESH_ENABLED "is_mesh_enabled" +#define WIFI_MESH_MGR_METHOD_IS_JOINED "is_joined" +#define WIFI_MESH_MGR_METHOD_GET_JOINED_MESH_NETWORK "get_joined_mesh_network" +#define WIFI_MESH_MGR_METHOD_SET_GATE "set_gate" +#define WIFI_MESH_MGR_METHOD_UNSET_GATE "unset_gate" +#define WIFI_MESH_MGR_METHOD_SET_SOFTAP "set_softap" +#define WIFI_MESH_MGR_METHOD_GET_SOFTAP "get_softap" +#define WIFI_MESH_MGR_METHOD_ENABLE_SOFTAP "enable_softap" +#define WIFI_MESH_MGR_METHOD_DISABLE_SOFTAP "disable_softap" +#define WIFI_MESH_MGR_METHOD_IS_SOFTAP_ENABLED "is_softap_enabled" +#define WIFI_MESH_MGR_METHOD_CREATE_MESH_NETWORK "create_mesh_network" +#define WIFI_MESH_MGR_METHOD_CONNECT_MESH_NETWORK "connect_mesh_network" +#define WIFI_MESH_MGR_METHOD_DISCONNECT_MESH_NETWORK "disconnect_mesh_network" +#define WIFI_MESH_MGR_METHOD_FORGET_MESH_NETWORK "forget_mesh_network" +#define WIFI_MESH_MGR_METHOD_SET_INTERFACES "set_interfaces" +#define WIFI_MESH_MGR_METHOD_GET_STATION_INFO "get_station_info" +#define WIFI_MESH_MGR_METHOD_GET_MPATH_INFO "get_mpath_info" +#define WIFI_MESH_MGR_METHOD_GET_MESHCONF_INFO "get_meshconf_info" + + +class GDbus { +private: + GDBusConnection *m_pConnection; + GCancellable *m_pCancellable; +public: + GDbus(); + ~GDbus(); + error_e Create(void); + error_e Destroy(void); + GDBusConnection *GetConnection(void); + GCancellable *GetCancellable(void); + error_e ConvertErrorStringToEnum(const char *error); + GVariant *InvokeMethod(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, error_e *dbus_error); + error_e InvokeMethodNonblock(const char *dest, const char *path, + const char *iface_name, const char *method, GVariant *params, int timeout, + GAsyncReadyCallback notify_func, void *user_data); +}; + +#endif /* __WIFI_MESH_MGR_GDBUS_H__ */ diff --git a/unittest/manager.cpp b/unittest/manager.cpp new file mode 100644 index 0000000..4e612fe --- /dev/null +++ b/unittest/manager.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "manager.h" + +Manager::Manager() +{ + Create(); +} + +Manager::~Manager() +{ + Destroy(); +} + +error_e Manager::EnableManager(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + int result = 0; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE".manager", + WIFI_MESH_MGR_MANAGER_PATH, + WIFI_MESH_MGR_MANAGER_INTERFACE, + WIFI_MESH_MGR_METHOD_MANAGER_START, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + GLOGD("Successfully stop manager [%d]", result); + g_variant_unref(message); + + return ERROR_NONE; +} + +error_e Manager::DisableManager(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + int result = 0; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_MANAGER_PATH, + WIFI_MESH_MGR_MANAGER_INTERFACE, + WIFI_MESH_MGR_METHOD_MANAGER_STOP, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(message, "(i)", &result); + GLOGD("Successfully stop manager [%d]", result); + g_variant_unref(message); + + return ERROR_NONE; +} diff --git a/unittest/manager.h b/unittest/manager.h new file mode 100644 index 0000000..652b1e8 --- /dev/null +++ b/unittest/manager.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __WIFI_MESH_MANAGER_H__ +#define __WIFI_MESH_MANAGER_H__ + +#include "wmeshmgr.h" +#include "gdbus.h" + +#define WMESHD_STATION_TYPE_MESH_POINT 0 + +class Manager:public GDbus { +private: +public: + Manager(); + ~Manager(); + error_e EnableManager(void); + error_e DisableManager(void); +}; + + +#endif /* __WIFI_MESH_MANAGER_H__ */ diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp new file mode 100644 index 0000000..3f43338 --- /dev/null +++ b/unittest/unittest.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "manager.h" +#include "wmesh.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + +char *mesh_id = (char *)"gtestnetwork"; + +TEST(WifiMeshManager, Enable_p) +{ + error_e ret = ERROR_NONE; + Manager mgr; + + ret = mgr.EnableManager(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, EnableMesh_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.EnableMesh(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, Scan_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.Scan(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, SpecificScan_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.SpecificScan(mesh_id, 161); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, CancelScan_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.CancelScan(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, GetFoundMeshNetworks_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.GetFoundMeshNetworks(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, GetConnectedPeers_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.GetConnectedPeers(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, IsMeshEnabled_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.IsMeshEnabled(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, IsJoined_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.IsJoined(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, GetJoinedMeshNetwork_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.GetJoinedMeshNetwork(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, SetGate_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.SetGate(true, 4, true); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, UnsetGate_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.UnsetGate(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, SetSoftap_p) +{ + static char ssid[] = "gtestnetwork"; + static char passphrase[] = "00000000"; + static int channel = 1; + static int visibility = 1; + static int max_stations = 10; + static int security = 2; + + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.SetSoftap(ssid, passphrase, + channel, visibility, max_stations, security); + + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, GetSoftap_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.GetSoftap(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, EnableSoftap_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.EnableSoftap(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, DisableSoftap_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.DisableSoftap(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, IsSoftapEnabled_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.IsSoftapEnabled(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, CreateMeshNetwork_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.CreateMeshNetwork(mesh_id, 1, 2); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, ConnectMeshNetwork_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + char *passphrase = (char *)"00000000"; + + ret = w.ConnectMeshNetwork(mesh_id, 1, 2, passphrase); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, GetStationInfo_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.GetStationInfo(WMESHD_STATION_TYPE_MESH_POINT); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, GetMpathInfo_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.GetMpathInfo(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, GetMeshconfInfo_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.GetMeshconfInfo(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, DisconnectMeshNetwork_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.DisconnectMeshNetwork(mesh_id, 1, 2); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, ForgetMeshNetwork_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.ForgetMeshNetwork(mesh_id, 1, 2); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, SetInterfaces_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + char *mesh = (char *)"mesh0"; + char *gate = (char *)"eth0"; + char *softap = (char *)"wlan0"; + + ret = w.SetInterfaces(mesh, gate, softap); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, DisableMesh_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.DisableMesh(); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(WifiMeshManager, Disable_p) +{ + error_e ret = ERROR_NONE; + Manager mgr; + + ret = mgr.DisableManager(); + EXPECT_EQ(ERROR_NONE, ret); +} + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unittest/wmesh.cpp b/unittest/wmesh.cpp new file mode 100644 index 0000000..0e01381 --- /dev/null +++ b/unittest/wmesh.cpp @@ -0,0 +1,632 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "wmesh.h" + +Wmesh::Wmesh() +{ + Create(); +} + +Wmesh::~Wmesh() +{ + Destroy(); +} +error_e Wmesh::Scan(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_SCAN, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform scan"); + + return ERROR_NONE; +} +error_e Wmesh::SpecificScan(char *mesh_id, int channel) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_SPECIFIC_SCAN, + g_variant_new("(si)", mesh_id, channel), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform specific_scan"); + + return ERROR_NONE; +} +error_e Wmesh::CancelScan(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_CANCEL_SCAN, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform cancel_scan"); + + return ERROR_NONE; +} + +error_e Wmesh::GetFoundMeshNetworks(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_GET_FOUND_MESH_NETWORKS, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform get_found_mesh_networks"); + + return ERROR_NONE; +} +error_e Wmesh::GetConnectedPeers(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_GET_CONNECTED_PEERS, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform get_connceted_peers"); + + return ERROR_NONE; +} +error_e Wmesh::EnableMesh(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_ENABLE_MESH, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform enable_mesh"); + + return ERROR_NONE; +} +error_e Wmesh::DisableMesh(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_DISABLE_MESH, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform disable_mesh"); + + return ERROR_NONE; +} +error_e Wmesh::IsMeshEnabled(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_IS_MESH_ENABLED, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform is_mesh_enabled"); + + return ERROR_NONE; +} +error_e Wmesh::IsJoined(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_IS_JOINED, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform is_joined"); + + return ERROR_NONE; +} +error_e Wmesh::GetJoinedMeshNetwork(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_GET_JOINED_MESH_NETWORK, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform get_joined_mesh_network"); + + return ERROR_NONE; +} +error_e Wmesh::SetGate(bool gate_announce, int hwmp_root_mode, bool stp) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_SET_GATE, + g_variant_new("(bqq)", gate_announce, hwmp_root_mode, stp), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform set_gate"); + + return ERROR_NONE; +} +error_e Wmesh::UnsetGate(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_UNSET_GATE, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform unset_gate"); + + return ERROR_NONE; +} +error_e Wmesh::SetSoftap(char *ssid, char *passphrase, int channel, + int visibility, int max_stations, int security) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + char buf[2] = {0, }; + + if (channel <= 13) { + buf[0] = 'g'; + buf[1] = 0; + } else { + buf[0] = 'a'; + buf[1] = 0; + } + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_SET_SOFTAP, + g_variant_new("(sssiiii)", ssid, passphrase, buf, + channel, visibility, max_stations, security), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform set_softap"); + + return ERROR_NONE; +} +error_e Wmesh::GetSoftap(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_GET_SOFTAP, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform get_softap"); + + return ERROR_NONE; +} +error_e Wmesh::EnableSoftap(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_ENABLE_SOFTAP, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform enabe_softap"); + + return ERROR_NONE; +} +error_e Wmesh::DisableSoftap(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_DISABLE_SOFTAP, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform disable_softap"); + + return ERROR_NONE; +} +error_e Wmesh::IsSoftapEnabled(void) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_IS_SOFTAP_ENABLED, + NULL, + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform is_softap_enabled"); + + return ERROR_NONE; +} +error_e Wmesh::CreateMeshNetwork(char *mesh_id, int channel, int security) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_CREATE_MESH_NETWORK, + g_variant_new("(sii)", mesh_id, channel, security), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform create_mesh_network"); + + return ERROR_NONE; +} +error_e Wmesh::ConnectMeshNetwork(char *mesh_id, int channel, int security, + char *passphrase) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_CONNECT_MESH_NETWORK, + g_variant_new("(siis)", mesh_id, channel, security, passphrase), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform connect_mesh_network"); + + return ERROR_NONE; +} +error_e Wmesh::DisconnectMeshNetwork(char *mesh_id, int channel, int security) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_DISCONNECT_MESH_NETWORK, + g_variant_new("(sii)", mesh_id, channel, security), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform disconnect_mesh_network"); + + return ERROR_NONE; +} +error_e Wmesh::ForgetMeshNetwork(char *mesh_id, int channel, int security) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_FORGET_MESH_NETWORK, + g_variant_new("(sii)", mesh_id, channel, security), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform forget_mesh_network"); + + return ERROR_NONE; +} +error_e Wmesh::SetInterfaces(char *mesh, char *gate, char *softap) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_SET_INTERFACES, + g_variant_new("(sss)", mesh, gate, softap), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + GLOGD("Succeeded to perform set_interfaces"); + + return ERROR_NONE; +} +error_e Wmesh::GetStationInfo(int sta_type) +{ + bool is_started; + GVariant *msg1 = NULL; + GVariant *msg2 = NULL; + error_e error = ERROR_NONE; + + msg1 = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_IS_MESH_ENABLED, + NULL, + &error); + + if (msg1 == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(msg1, "(b)", &is_started); + g_variant_unref(msg1); + if (TRUE == is_started) { + msg2 = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_GET_STATION_INFO, + g_variant_new("(i)", sta_type), + &error); + + if (msg2 == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } else { + g_variant_unref(msg2); + } + + GLOGD("Succeeded to perform get_station_info"); + } + + return ERROR_NONE; +} +error_e Wmesh::GetMpathInfo(void) +{ + bool is_started; + GVariant *msg1 = NULL; + GVariant *msg2 = NULL; + error_e error = ERROR_NONE; + + msg1 = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_IS_MESH_ENABLED, + NULL, + &error); + + if (msg1 == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(msg1, "(b)", &is_started); + g_variant_unref(msg1); + if (TRUE == is_started) { + msg2 = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_GET_MPATH_INFO, + NULL, + &error); + + if (msg2 == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } else { + g_variant_unref(msg2); + } + + GLOGD("Succeeded to perform get_mpath_info"); + } + + return ERROR_NONE; +} +error_e Wmesh::GetMeshconfInfo(void) +{ + bool is_started; + GVariant *msg1 = NULL; + GVariant *msg2 = NULL; + error_e error = ERROR_NONE; + + msg1 = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_IS_MESH_ENABLED, + NULL, + &error); + + if (msg1 == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_get(msg1, "(b)", &is_started); + g_variant_unref(msg1); + if (TRUE == is_started) { + msg2 = InvokeMethod(WIFI_MESH_MGR_SERVICE, + WIFI_MESH_MGR_PATH, + WIFI_MESH_MGR_INTERFACE, + WIFI_MESH_MGR_METHOD_GET_MESHCONF_INFO, + NULL, + &error); + + if (msg2 == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } else { + g_variant_unref(msg2); + } + + GLOGD("Succeeded to perform get_meshconf_info"); + } + + return ERROR_NONE; +} + diff --git a/unittest/wmesh.h b/unittest/wmesh.h new file mode 100644 index 0000000..9317fe4 --- /dev/null +++ b/unittest/wmesh.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __WMESH_MGR_H__ +#define __WMESH_MGR_H__ + +#include "wmeshmgr.h" +#include "gdbus.h" + +class Wmesh:public GDbus { +public: + Wmesh(); + ~Wmesh(); + error_e Scan(void); + error_e SpecificScan(char *mesh_id, int channel); + error_e CancelScan(void); + error_e GetFoundMeshNetworks(void); + error_e GetConnectedPeers(void); + error_e EnableMesh(void); + error_e DisableMesh(void); + error_e IsMeshEnabled(void); + error_e IsJoined(void); + error_e GetJoinedMeshNetwork(void); + error_e SetGate(bool gate_announce, int hwmp_root_mode, bool stp); + error_e UnsetGate(void); + error_e SetSoftap(char *ssid, char *passphrase, int channel, + int visibility, int max_stations, int security); + error_e GetSoftap(void); + error_e EnableSoftap(void); + error_e DisableSoftap(void); + error_e IsSoftapEnabled(void); + error_e CreateMeshNetwork(char *mesh_id, int channel, int security); + error_e ConnectMeshNetwork(char *mesh_id, int channel, int security, + char *passphrase); + error_e DisconnectMeshNetwork(char *mesh_id, int channel, int security); + error_e ForgetMeshNetwork(char *mesh_id, int channel, int security); + error_e SetInterfaces(char *mesh, char *gate, char *softap); + error_e GetStationInfo(int sta_type); + error_e GetMpathInfo(void); + error_e GetMeshconfInfo(void); +}; + + +#endif /* __WMESH_MGR_H__ */ diff --git a/unittest/wmeshmgr.h b/unittest/wmeshmgr.h new file mode 100644 index 0000000..795490e --- /dev/null +++ b/unittest/wmeshmgr.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __WIFI_MESH_MGR_H__ +#define __WIFI_MESH_MGR_H__ + +#include + +#ifdef USE_DLOG +#include +#undef LOG_TAG +#define LOG_TAG "WIFI_MESH_GTEST" +#define GLOGD(format, args...) LOGD(format, ##args) +#else +#define GLOGD(format, args...) +#endif + +typedef enum { + ERROR_NONE = 0, + ERROR_NOT_PERMITTED = -1, + ERROR_OUT_OF_MEMORY = -2, + ERROR_PERMISSION_DENIED = -3, + ERROR_RESOURCE_BUSY = -4, + ERROR_INVALID_OPERATION = -5, + ERROR_INVALID_PARAMETER = -6, + ERROR_NOT_SUPPORTED = -7, + ERROR_OPERATION_FAILED = -8, + ERROR_NOT_INITIALIZED = -9, + ERROR_ALREADY_INITIALIZED = -10, + ERROR_IN_PROGRESS = -11, +} error_e; + + +#endif /* __WIFI_MESH_MGR_H__ */ -- 2.7.4