From: Abhishek Sansanwal Date: Tue, 14 Aug 2018 06:06:54 +0000 (+0530) Subject: Added Haltest for wifi-mesh-manager X-Git-Tag: accepted/tizen/unified/20180816.134720^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=750b7aa62921e9d356f6223ed55cbf08a37852c9;p=platform%2Fcore%2Fconnectivity%2Fwifi-mesh-manager.git Added Haltest for wifi-mesh-manager Signed-off-by: Abhishek Sansanwal Change-Id: I2f4482531ea487e1145f361c35a42e7004c6abdf --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bc9748d..479ced0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,3 +92,4 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/wmesh.sh DESTINATION ${SBIN_DIR}) IF(BUILD_GTESTS) ADD_SUBDIRECTORY(unittest) ENDIF(BUILD_GTESTS) +ADD_SUBDIRECTORY(haltest) diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt new file mode 100644 index 0000000..dc907d6 --- /dev/null +++ b/haltest/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(gtest-haltest-wifi-mesh-manager C CXX) + +SET(GTEST_TEST "wifi_mesh_manager_hal_tc") +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/haltest/gdbus.cpp b/haltest/gdbus.cpp new file mode 100644 index 0000000..e882fea --- /dev/null +++ b/haltest/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/haltest/gdbus.h b/haltest/gdbus.h new file mode 100644 index 0000000..1c53966 --- /dev/null +++ b/haltest/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/haltest/manager.cpp b/haltest/manager.cpp new file mode 100644 index 0000000..4e612fe --- /dev/null +++ b/haltest/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/haltest/manager.h b/haltest/manager.h new file mode 100644 index 0000000..652b1e8 --- /dev/null +++ b/haltest/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/haltest/wifi_mesh_manager_hal_tc.cpp b/haltest/wifi_mesh_manager_hal_tc.cpp new file mode 100644 index 0000000..b857b75 --- /dev/null +++ b/haltest/wifi_mesh_manager_hal_tc.cpp @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2018 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 *)"haltestnetwork"; + +/* +@testcase Enable_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Enable wifi-mesh-manager +@apicovered "enable" dbus method on net.wmesh.manager interface +@passcase when EnableManager() returns ERROR_NONE +@failcase when EnableManager() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +TEST(WifiMeshManager, Enable_p) +{ + error_e ret = ERROR_NONE; + Manager mgr; + + ret = mgr.EnableManager(); + EXPECT_EQ(ERROR_NONE, ret); +} + +/* +@testcase StartMesh_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Start wifi-mesh-manager +@apicovered "enable_mesh" dbus method on net.wmesh.manager interface +@passcase when EnableMesh() returns ERROR_NONE +@failcase when EnableMesh() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +TEST(WifiMeshManager, EnableMesh_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.EnableMesh(); + EXPECT_EQ(ERROR_NONE, ret); +} + +/* +@testcase Scan_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Scan using wifi-mesh-manager +@apicovered "scan" dbus method on net.wmesh.manager interface +@passcase when Scan() returns ERROR_NONE +@failcase when Scan() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +TEST(WifiMeshManager, Scan_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.Scan(); + EXPECT_EQ(ERROR_NONE, ret); +} + +/* +@testcase EnableSoftap_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Enable softap using wifi-mesh-manager +@apicovered "enable_softap" dbus method on net.wmesh.manager interface +@passcase when EnableSoftap() returns ERROR_NONE +@failcase when EnableSoftap() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +TEST(WifiMeshManager, SetSoftap_p) +{ + static char ssid[] = "haltestnetwork"; + 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); + + ret = w.GetSoftap(); + EXPECT_EQ(ERROR_NONE, ret); + + ret = w.EnableSoftap(); + EXPECT_EQ(ERROR_NONE, ret); +} + +/* +@testcase DisableSoftap_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Disable softap using wifi-mesh-manager +@apicovered "disable_softap" dbus method on net.wmesh.manager interface +@passcase when DisableSoftap() returns ERROR_NONE +@failcase when DisableSoftap() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +TEST(WifiMeshManager, DisableSoftap_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.DisableSoftap(); + EXPECT_EQ(ERROR_NONE, ret); +} + +/* +@testcase CreateMeshNetwork_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Create mesh network using wifi-mesh-manager +@apicovered "create_mesh_network" dbus method on net.wmesh.manager interface +@passcase when CreateMeshNetwork() returns ERROR_NONE +@failcase when CreateMeshNetwork() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +TEST(WifiMeshManager, CreateMeshNetwork_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.CreateMeshNetwork(mesh_id, 1, 2, 1); + EXPECT_EQ(ERROR_NONE, ret); +} + +/* +@testcase ConnectMeshNetwork_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Connect to a mesh network using wifi-mesh-manager +@apicovered "connect_mesh_network" dbus method on net.wmesh.manager interface +@passcase when ConnectMeshNetwork() returns ERROR_NONE +@failcase when ConnectMeshNetwork() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +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); +} + + +/* +@testcase Stop_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Stop wifi-mesh-manager +@apicovered "disable_mesh" dbus method on net.wmesh.manager interface +@passcase when DisableMesh() returns ERROR_NONE +@failcase when DisableMesh() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +TEST(WifiMeshManager, DisableMesh_p) +{ + error_e ret = ERROR_NONE; + Wmesh w; + + ret = w.DisableMesh(); + EXPECT_EQ(ERROR_NONE, ret); +} + +/* +@testcase Disable_p +@since_tizen 5.0 +@author SRID(abhishek.s94) +@reviewer HQ(saerome.kim) +@type auto +@description Positive, Disable wifi-mesh-manager +@apicovered "disable" dbus method on net.wmesh.manager interface +@passcase when DisableManager() returns ERROR_NONE +@failcase when DisableManager() does not return ERROR_NONE +@precondition None +@postcondition None +*/ +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) +{ + int ret = 0; + try { + testing::InitGoogleTest(&argc, argv); + } catch (const ::testing::internal::GoogleTestFailureException& ex) { + std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl; + } catch (...) { + std::cerr << "Caught: unknown exception" << std::endl; + } + + try { + ret = RUN_ALL_TESTS(); + } catch (const ::testing::internal::GoogleTestFailureException& ex) { + std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl; + } catch (...) { + std::cerr << "Caught: unknown exception" << std::endl; + } + return ret; +} diff --git a/haltest/wmesh.cpp b/haltest/wmesh.cpp new file mode 100644 index 0000000..2152972 --- /dev/null +++ b/haltest/wmesh.cpp @@ -0,0 +1,633 @@ +/* + * 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, + int pmf) +{ + 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("(siii)", mesh_id, channel, security, pmf), + &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/haltest/wmesh.h b/haltest/wmesh.h new file mode 100644 index 0000000..13f99b5 --- /dev/null +++ b/haltest/wmesh.h @@ -0,0 +1,57 @@ +/* + * 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, + int pmf); + 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/haltest/wmeshmgr.h b/haltest/wmeshmgr.h new file mode 100644 index 0000000..795490e --- /dev/null +++ b/haltest/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__ */ diff --git a/packaging/wifi-mesh-manager.spec b/packaging/wifi-mesh-manager.spec index bf9591d..a497f9c 100644 --- a/packaging/wifi-mesh-manager.spec +++ b/packaging/wifi-mesh-manager.spec @@ -34,6 +34,16 @@ Requires: security-config %description Manager for handling Wi-Fi mesh network +%package haltests +Summary: wifi-mesh-manager extension for HAL test +BuildRequires: pkgconfig(gmock) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(dlog) +Requires: %{name} = %{version}-%{release} +%description haltests +TIZEN wifi-mesh-manager extension for HAL test. + %prep %setup -q chmod 644 %{SOURCE0} @@ -97,3 +107,7 @@ chmod 755 %{_sbindir}/wmesh.sh %{_bindir}/gtest* %endif +%files haltests +%manifest wmeshd.manifest +%{_bindir}/*hal_tc +