From: Jaehyun Kim Date: Fri, 27 Apr 2018 09:16:15 +0000 (+0900) Subject: Separate HAL TC code into a separate package X-Git-Tag: submit/tizen/20180427.093512^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a7d6a8345fd82a9c14356d99a104ab23e9011035;p=platform%2Fcore%2Fconnectivity%2Fnet-config.git Separate HAL TC code into a separate package Change-Id: Ic7d26b839fa950c4c4cfd79d49287a24f34b61e7 Signed-off-by: Jaehyun Kim --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b7d8fa8..6c372e7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,4 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/config/security-network-config.conf DESTINATIO ADD_SUBDIRECTORY(plugin/headed) ADD_SUBDIRECTORY(plugin/telephony) -IF(BUILD_GTESTS) - ADD_SUBDIRECTORY(unittest) -ENDIF(BUILD_GTESTS) +ADD_SUBDIRECTORY(unittest) diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 749aa5e..f162aa7 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.1.131 +Version: 1.1.132 Release: 3 Group: System/Network License: Apache-2.0 @@ -16,12 +16,6 @@ BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(key-manager) BuildRequires: pkgconfig(libnl-2.0) -%if 0%{?gtests:1} -BuildRequires: pkgconfig(gmock) -BuildRequires: pkgconfig(capi-network-wifi-manager) -BuildRequires: pkgconfig(capi-network-wifi-direct) -BuildRequires: pkgconfig(capi-network-softap) -%endif Requires: vconf Requires: connman Requires: systemd @@ -69,6 +63,16 @@ Requires: %{name} = %{version}-%{release} %description plugin-telephony TIZEN Network Configuration service extension for telephony FW. +%package hal-utest +Summary: net-config extension for HAL test +BuildRequires: pkgconfig(gmock) +BuildRequires: pkgconfig(capi-network-wifi-manager) +BuildRequires: pkgconfig(capi-network-wifi-direct) +BuildRequires: pkgconfig(capi-network-softap) +Requires: %{name} = %{version}-%{release} +%description hal-utest +TIZEN Network Configuration service extension for HAL test. + %prep %setup -q @@ -205,9 +209,6 @@ ln -sf %{_unitdir}/net-config.service %{_sysconfdir}/systemd/default-extra-depen %license LICENSE %attr(500,root,root) /opt/etc/dump.d/module.d/network_dump.sh %attr(500,network_fw,network_fw) /opt/var/lib/net-config/network_dump.sh -%if 0%{?gtests:1} -%{_bindir}/gtest* -%endif #### tv profile #### %post profile_tv @@ -243,3 +244,8 @@ mv net-config.wearable net-config %files plugin-telephony %manifest net-config.manifest %attr(500,network_fw,network_fw) %{_libdir}/net-config-plugin-telephony.so + +%files hal-utest +%manifest net-config.manifest +%{_bindir}/*hal_tc + diff --git a/unittest/gtest_hal_hostap.cpp b/unittest/gtest_hal_hostap.cpp deleted file mode 100755 index 342c623..0000000 --- a/unittest/gtest_hal_hostap.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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 -#include -#include "unittest.h" - -using ::testing::InitGoogleTest; -using ::testing::Test; -using ::testing::TestCase; - -static softap_h sa = NULL; -static bool g_is_requested; -static softap_error_e g_error; -static softap_disabled_cause_e g_code; - -static bool __check_feature_supported(char *key) -{ - bool value = false; - int ret = system_info_get_platform_bool(key, &value); - - EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; - EXPECT_EQ(true, value) << key << " feature is not supported"; - - return value; -} - -static gboolean __timeout_callback(gpointer data) -{ - EXPECT_TRUE(0) << "SoftAP callback timeout!"; - QUIT_GMAIN_LOOP; - return FALSE; -} - -static void __enabled_cb(softap_error_e error, bool is_requested, void *data) -{ - g_error = error; - g_is_requested = is_requested; - QUIT_GMAIN_LOOP; -} - -static void __disabled_cb(softap_error_e error, softap_disabled_cause_e code, void *data) -{ - g_error = error; - g_code = code; - QUIT_GMAIN_LOOP; -} - -TEST(Hal_softap, Init_p) -{ - g_bFeatureWifi = __check_feature_supported((char*)FEATURE_WIFI); - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int ret = SOFTAP_ERROR_NONE; - - ret = softap_create(&sa); - ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Initialization failure"; - - ret = softap_set_enabled_cb(sa, __enabled_cb, NULL); - EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to set enabled callback!!"; - - ret = softap_set_disabled_cb(sa, __disabled_cb, NULL); - EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to set disabled callback!!"; -} - -TEST(Hal_softap, Activate_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int ret = SOFTAP_ERROR_NONE; - bool enabled = false; - - ret = softap_is_enabled(sa, &enabled); - ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to get SoftAP state"; - - if (enabled) - goto done; - - ret = softap_enable(sa); - ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to enable SoftAP"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(SOFTAP_ERROR_NONE, g_error) << "Failed to enable SoftAP"; - EXPECT_EQ(true, g_is_requested) << "Failed to enable SoftAP"; - -done: - ret = access(WIFI_ADDRESS_PATH, F_OK); - EXPECT_EQ(0, ret) << "Could not access " << WIFI_ADDRESS_PATH; -} - -TEST(Hal_softap, Deactivate_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int ret = SOFTAP_ERROR_NONE; - - ret = softap_disable(sa); - ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to disable SoftAP"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(SOFTAP_ERROR_NONE, g_error) << "Failed to disable SoftAP" << g_code; - - ret = access(WIFI_ADDRESS_PATH, F_OK); - EXPECT_EQ(-1, ret) << WIFI_ADDRESS_PATH << " is exist"; -} - -TEST(Hal_softap, Deinit_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int ret = SOFTAP_ERROR_NONE; - - ret = softap_unset_enabled_cb(sa); - EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to unset enabled callback!!"; - - ret = softap_unset_disabled_cb(sa); - EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to unset disabled callback!!"; - - ret = softap_destroy(sa); - EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Deinitialization failure"; -} - -int main(int argc, char **argv) -{ - InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittest/gtest_hal_wifi.cpp b/unittest/gtest_hal_wifi.cpp deleted file mode 100755 index 8b92569..0000000 --- a/unittest/gtest_hal_wifi.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * 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 -#include -#include "unittest.h" - -using ::testing::InitGoogleTest; -using ::testing::Test; -using ::testing::TestCase; - -static char ap_name[MAX_AP_LENGTH]; -static wifi_manager_h wifi = NULL; -static wifi_manager_error_e rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; -wifi_manager_ap_h g_hWifiAP; - - -static bool __check_feature_supported(char *key) -{ - bool value = false; - int ret = system_info_get_platform_bool(key, &value); - - EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; - EXPECT_EQ(true, value) << key << " feature is not supported"; - - return value; -} - -static void __test_callback(wifi_manager_error_e result, void* user_data) -{ - rst = result; - QUIT_GMAIN_LOOP; -} - -static gboolean __timeout_callback(gpointer data) -{ - EXPECT_TRUE(0) << "Wi-Fi Manager callback timeout!"; - QUIT_GMAIN_LOOP; - return FALSE; -} - -static bool __found_ap_callback(wifi_manager_ap_h ap, void *user_data) -{ - char *ap_name = NULL; - char *ap_name_part = (char *)user_data; - size_t ap_name_len = strlen(ap_name_part); - int ret = WIFI_MANAGER_ERROR_NONE; - - if (ap) { - ret = wifi_manager_ap_get_essid(ap, &ap_name); - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Unable to get essid"; - - if (!ap_name) - return true; - - if (!strncmp(ap_name, ap_name_part, ap_name_len)) { - g_free(ap_name); - ret = wifi_manager_ap_clone(&g_hWifiAP, ap); - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Unable to clone the AP handle"; - if (g_hWifiAP) { - rst = WIFI_MANAGER_ERROR_NONE; - return false; - } - } - } - - return true; -} - -TEST(Hal_wifi, Init_p) -{ - g_bFeatureWifi = __check_feature_supported((char*)FEATURE_WIFI); - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int rv = wifi_manager_initialize(&wifi); - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Initialization failure"; -} - -TEST(Hal_wifi, Activate_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int rv; - bool activated; - - rv = wifi_manager_is_activated(wifi, &activated); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to get Wi-Fi device state"; - - if (activated) - goto done; - - rv = wifi_manager_activate(wifi, __test_callback, NULL); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to activate Wi-Fi device"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Activetion failure"; - rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; - -done: - rv = access(WIFI_ADDRESS_PATH, F_OK); - EXPECT_EQ(0, rv) << "Could not access " << WIFI_ADDRESS_PATH; -} - -TEST(Hal_wifi, Scan_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int rv = wifi_manager_scan(wifi, __test_callback, NULL); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to scan"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Scan failure"; - rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; -} - -TEST(Hal_wifi, Connect_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - wifi_manager_connection_state_e connection_state; - int ret = WIFI_MANAGER_ERROR_NONE; - - ret = wifi_manager_get_connection_state(wifi, &connection_state); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to get connection state"; - - if (connection_state == WIFI_MANAGER_CONNECTION_STATE_CONNECTED) - return; - - if (!ap_name[0]) - return; - - ret = wifi_manager_foreach_found_ap(wifi, __found_ap_callback, (char *)ap_name); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Failed to find the AP"; - rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; - - ret = wifi_manager_connect(wifi, g_hWifiAP, __test_callback, NULL); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to connect"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Connection failure"; - rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; -} - -TEST(Hal_wifi, Disconnect_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int ret = WIFI_MANAGER_ERROR_NONE; - wifi_manager_ap_h hAP = NULL; - - ret = wifi_manager_get_connected_ap(wifi, &hAP); - if (ret == WIFI_MANAGER_ERROR_NO_CONNECTION) - return; - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to get connected AP"; - - ret = wifi_manager_disconnect(wifi, hAP, __test_callback, NULL); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to disconnect"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Disconnection failure"; - rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; - - ret = wifi_manager_forget_ap(wifi, hAP); - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to forget AP"; -} - -TEST(Hal_wifi, Deactivate_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int rv = wifi_manager_deactivate(wifi, __test_callback, NULL); - ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to deactivate Wi-Fi device"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Deactivation failure"; - rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; - - rv = access(WIFI_ADDRESS_PATH, F_OK); - EXPECT_EQ(-1, rv) << WIFI_ADDRESS_PATH << " is exist"; -} - -TEST(Hal_wifi, Deinit_p) -{ - ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; - - int rv = wifi_manager_deinitialize(wifi); - EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Deinitialization failure"; -} - -int main(int argc, char **argv) -{ - if (argc > 1 && argv[argc - 1][0] != '-') { - g_strlcpy(ap_name, argv[argc - 1], MAX_AP_LENGTH); - argc--; - } - - InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittest/gtest_hal_wifi_direct.cpp b/unittest/gtest_hal_wifi_direct.cpp deleted file mode 100755 index bcfb5a9..0000000 --- a/unittest/gtest_hal_wifi_direct.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * 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 -#include -#include "unittest.h" - -using ::testing::InitGoogleTest; -using ::testing::Test; -using ::testing::TestCase; - -static int rst = WIFI_DIRECT_ERROR_OPERATION_FAILED; -static wifi_direct_device_state_e dev_state = WIFI_DIRECT_DEVICE_STATE_DEACTIVATED; -static char p2p_ifname[MAX_PATH_LENGTH]; - -static bool __check_feature_supported(char *key) -{ - bool value = false; - int ret = system_info_get_platform_bool(key, &value); - - EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; - EXPECT_EQ(true, value) << key << " feature is not supported"; - - return value; -} - -static gboolean __timeout_callback(gpointer data) -{ - EXPECT_TRUE(0) << "Wi-Fi Direct callback timeout!"; - QUIT_GMAIN_LOOP; - return FALSE; -} - -static void __device_state_changed_cb(int error_code, - wifi_direct_device_state_e device_state, void *user_data) -{ - rst = error_code; - dev_state = device_state; - QUIT_GMAIN_LOOP; -} - -static void __set_p2p_ifname(void) -{ - GKeyFile *key_file = NULL; - GError *error = NULL; - char *ifn = NULL; - - key_file = g_key_file_new(); - if (!g_key_file_load_from_file(key_file, WIFI_P2P_CONFIG_PATH, G_KEY_FILE_NONE, &error)) { - g_clear_error(&error); - g_key_file_free(key_file); - key_file = NULL; - return; - } - - ifn = g_key_file_get_string(key_file, WFD_CONF_GROUP_NAME, "p2p_interface", &error); - if (ifn) - g_snprintf(p2p_ifname, MAX_PATH_LENGTH, "/sys/class/net/%s/address", ifn); - - if (error) - g_clear_error(&error); - g_key_file_free(key_file); -} - - -TEST(Hal_wifi_direct, Init_p) -{ - g_bFeatureP2P = __check_feature_supported((char*)WIFIDIRECT_FEATURE); - ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; - - int rv = wifi_direct_initialize(); - EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Initialization failure"; -} - -TEST(Hal_wifi_direct, Activate_p) -{ - ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; - - int rv; - wifi_direct_state_e state = WIFI_DIRECT_STATE_ACTIVATED; - - rv = wifi_direct_get_state(&state); - ASSERT_EQ(0, rv) << "Failed to get Wi-Fi Direct device state"; - - if (state != WIFI_DIRECT_STATE_DEACTIVATED) - goto done; - - rv = wifi_direct_set_device_state_changed_cb(__device_state_changed_cb, NULL); - ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to set activation callback"; - - rv = wifi_direct_activate(); - ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to activate Wi-Fi Direct device"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rst) << "Activetion failure"; - rst = WIFI_DIRECT_ERROR_OPERATION_FAILED; - - rv = wifi_direct_get_state(&state); - EXPECT_EQ(0, rv) << "Failed to get Wi-Fi Direct device state"; - EXPECT_EQ(WIFI_DIRECT_STATE_ACTIVATED, state) << "Activetion failure"; - -done: - if (p2p_ifname[0]) - rv = access(p2p_ifname, F_OK); - else - rv = access(WIFI_P2P_PATH, F_OK); - EXPECT_EQ(0, rv) << "Could not access " << WIFI_ADDRESS_PATH; -} - -TEST(Hal_wifi_direct, Deactivate_p) -{ - ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; - - int rv; - - rv = wifi_direct_deactivate(); - ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to deactivate Wi-Fi Direct"; - - RUN_GMAIN_LOOP(__timeout_callback); - - EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rst) << "Deactivation failure"; - rst = WIFI_DIRECT_ERROR_OPERATION_FAILED; - - wifi_direct_state_e state = WIFI_DIRECT_STATE_ACTIVATED; - rv = wifi_direct_get_state(&state); - EXPECT_EQ(0, rv) << "Failed to get Wi-Fi Direct device state"; - - EXPECT_EQ(WIFI_DIRECT_STATE_DEACTIVATED, state) << "Deactivetion failure"; - - if (p2p_ifname[0]) - rv = access(p2p_ifname, F_OK); - else - rv = access(WIFI_P2P_PATH, F_OK); - EXPECT_EQ(-1, rv) << WIFI_P2P_PATH << " is exist"; - - rv = wifi_direct_unset_device_state_changed_cb(); - EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to unset activation callback"; -} - -TEST(Hal_wifi_direct, Deinit_p) -{ - ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; - - int rv = wifi_direct_deinitialize(); - EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Deinitialization failure"; -} - -int main(int argc, char **argv) -{ - __set_p2p_ifname(); - - InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/unittest/hostap_hal_tc.cpp b/unittest/hostap_hal_tc.cpp new file mode 100755 index 0000000..342c623 --- /dev/null +++ b/unittest/hostap_hal_tc.cpp @@ -0,0 +1,148 @@ +/* + * 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 +#include +#include "unittest.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + +static softap_h sa = NULL; +static bool g_is_requested; +static softap_error_e g_error; +static softap_disabled_cause_e g_code; + +static bool __check_feature_supported(char *key) +{ + bool value = false; + int ret = system_info_get_platform_bool(key, &value); + + EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; + EXPECT_EQ(true, value) << key << " feature is not supported"; + + return value; +} + +static gboolean __timeout_callback(gpointer data) +{ + EXPECT_TRUE(0) << "SoftAP callback timeout!"; + QUIT_GMAIN_LOOP; + return FALSE; +} + +static void __enabled_cb(softap_error_e error, bool is_requested, void *data) +{ + g_error = error; + g_is_requested = is_requested; + QUIT_GMAIN_LOOP; +} + +static void __disabled_cb(softap_error_e error, softap_disabled_cause_e code, void *data) +{ + g_error = error; + g_code = code; + QUIT_GMAIN_LOOP; +} + +TEST(Hal_softap, Init_p) +{ + g_bFeatureWifi = __check_feature_supported((char*)FEATURE_WIFI); + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int ret = SOFTAP_ERROR_NONE; + + ret = softap_create(&sa); + ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Initialization failure"; + + ret = softap_set_enabled_cb(sa, __enabled_cb, NULL); + EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to set enabled callback!!"; + + ret = softap_set_disabled_cb(sa, __disabled_cb, NULL); + EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to set disabled callback!!"; +} + +TEST(Hal_softap, Activate_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int ret = SOFTAP_ERROR_NONE; + bool enabled = false; + + ret = softap_is_enabled(sa, &enabled); + ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to get SoftAP state"; + + if (enabled) + goto done; + + ret = softap_enable(sa); + ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to enable SoftAP"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(SOFTAP_ERROR_NONE, g_error) << "Failed to enable SoftAP"; + EXPECT_EQ(true, g_is_requested) << "Failed to enable SoftAP"; + +done: + ret = access(WIFI_ADDRESS_PATH, F_OK); + EXPECT_EQ(0, ret) << "Could not access " << WIFI_ADDRESS_PATH; +} + +TEST(Hal_softap, Deactivate_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int ret = SOFTAP_ERROR_NONE; + + ret = softap_disable(sa); + ASSERT_EQ(SOFTAP_ERROR_NONE, ret) << "Failed to disable SoftAP"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(SOFTAP_ERROR_NONE, g_error) << "Failed to disable SoftAP" << g_code; + + ret = access(WIFI_ADDRESS_PATH, F_OK); + EXPECT_EQ(-1, ret) << WIFI_ADDRESS_PATH << " is exist"; +} + +TEST(Hal_softap, Deinit_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int ret = SOFTAP_ERROR_NONE; + + ret = softap_unset_enabled_cb(sa); + EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to unset enabled callback!!"; + + ret = softap_unset_disabled_cb(sa); + EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Fail to unset disabled callback!!"; + + ret = softap_destroy(sa); + EXPECT_EQ(SOFTAP_ERROR_NONE, ret) << "Deinitialization failure"; +} + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unittest/wifi_direct_hal_tc.cpp b/unittest/wifi_direct_hal_tc.cpp new file mode 100755 index 0000000..bcfb5a9 --- /dev/null +++ b/unittest/wifi_direct_hal_tc.cpp @@ -0,0 +1,174 @@ +/* + * 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 +#include +#include "unittest.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + +static int rst = WIFI_DIRECT_ERROR_OPERATION_FAILED; +static wifi_direct_device_state_e dev_state = WIFI_DIRECT_DEVICE_STATE_DEACTIVATED; +static char p2p_ifname[MAX_PATH_LENGTH]; + +static bool __check_feature_supported(char *key) +{ + bool value = false; + int ret = system_info_get_platform_bool(key, &value); + + EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; + EXPECT_EQ(true, value) << key << " feature is not supported"; + + return value; +} + +static gboolean __timeout_callback(gpointer data) +{ + EXPECT_TRUE(0) << "Wi-Fi Direct callback timeout!"; + QUIT_GMAIN_LOOP; + return FALSE; +} + +static void __device_state_changed_cb(int error_code, + wifi_direct_device_state_e device_state, void *user_data) +{ + rst = error_code; + dev_state = device_state; + QUIT_GMAIN_LOOP; +} + +static void __set_p2p_ifname(void) +{ + GKeyFile *key_file = NULL; + GError *error = NULL; + char *ifn = NULL; + + key_file = g_key_file_new(); + if (!g_key_file_load_from_file(key_file, WIFI_P2P_CONFIG_PATH, G_KEY_FILE_NONE, &error)) { + g_clear_error(&error); + g_key_file_free(key_file); + key_file = NULL; + return; + } + + ifn = g_key_file_get_string(key_file, WFD_CONF_GROUP_NAME, "p2p_interface", &error); + if (ifn) + g_snprintf(p2p_ifname, MAX_PATH_LENGTH, "/sys/class/net/%s/address", ifn); + + if (error) + g_clear_error(&error); + g_key_file_free(key_file); +} + + +TEST(Hal_wifi_direct, Init_p) +{ + g_bFeatureP2P = __check_feature_supported((char*)WIFIDIRECT_FEATURE); + ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; + + int rv = wifi_direct_initialize(); + EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Initialization failure"; +} + +TEST(Hal_wifi_direct, Activate_p) +{ + ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; + + int rv; + wifi_direct_state_e state = WIFI_DIRECT_STATE_ACTIVATED; + + rv = wifi_direct_get_state(&state); + ASSERT_EQ(0, rv) << "Failed to get Wi-Fi Direct device state"; + + if (state != WIFI_DIRECT_STATE_DEACTIVATED) + goto done; + + rv = wifi_direct_set_device_state_changed_cb(__device_state_changed_cb, NULL); + ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to set activation callback"; + + rv = wifi_direct_activate(); + ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to activate Wi-Fi Direct device"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rst) << "Activetion failure"; + rst = WIFI_DIRECT_ERROR_OPERATION_FAILED; + + rv = wifi_direct_get_state(&state); + EXPECT_EQ(0, rv) << "Failed to get Wi-Fi Direct device state"; + EXPECT_EQ(WIFI_DIRECT_STATE_ACTIVATED, state) << "Activetion failure"; + +done: + if (p2p_ifname[0]) + rv = access(p2p_ifname, F_OK); + else + rv = access(WIFI_P2P_PATH, F_OK); + EXPECT_EQ(0, rv) << "Could not access " << WIFI_ADDRESS_PATH; +} + +TEST(Hal_wifi_direct, Deactivate_p) +{ + ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; + + int rv; + + rv = wifi_direct_deactivate(); + ASSERT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to deactivate Wi-Fi Direct"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rst) << "Deactivation failure"; + rst = WIFI_DIRECT_ERROR_OPERATION_FAILED; + + wifi_direct_state_e state = WIFI_DIRECT_STATE_ACTIVATED; + rv = wifi_direct_get_state(&state); + EXPECT_EQ(0, rv) << "Failed to get Wi-Fi Direct device state"; + + EXPECT_EQ(WIFI_DIRECT_STATE_DEACTIVATED, state) << "Deactivetion failure"; + + if (p2p_ifname[0]) + rv = access(p2p_ifname, F_OK); + else + rv = access(WIFI_P2P_PATH, F_OK); + EXPECT_EQ(-1, rv) << WIFI_P2P_PATH << " is exist"; + + rv = wifi_direct_unset_device_state_changed_cb(); + EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Failed to unset activation callback"; +} + +TEST(Hal_wifi_direct, Deinit_p) +{ + ASSERT_EQ(true, g_bFeatureP2P) << WIFIDIRECT_FEATURE << " feature is not supported"; + + int rv = wifi_direct_deinitialize(); + EXPECT_EQ(WIFI_DIRECT_ERROR_NONE, rv) << "Deinitialization failure"; +} + +int main(int argc, char **argv) +{ + __set_p2p_ifname(); + + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/unittest/wifi_hal_tc.cpp b/unittest/wifi_hal_tc.cpp new file mode 100755 index 0000000..8b92569 --- /dev/null +++ b/unittest/wifi_hal_tc.cpp @@ -0,0 +1,223 @@ +/* + * 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 +#include +#include "unittest.h" + +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + +static char ap_name[MAX_AP_LENGTH]; +static wifi_manager_h wifi = NULL; +static wifi_manager_error_e rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; +wifi_manager_ap_h g_hWifiAP; + + +static bool __check_feature_supported(char *key) +{ + bool value = false; + int ret = system_info_get_platform_bool(key, &value); + + EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed"; + EXPECT_EQ(true, value) << key << " feature is not supported"; + + return value; +} + +static void __test_callback(wifi_manager_error_e result, void* user_data) +{ + rst = result; + QUIT_GMAIN_LOOP; +} + +static gboolean __timeout_callback(gpointer data) +{ + EXPECT_TRUE(0) << "Wi-Fi Manager callback timeout!"; + QUIT_GMAIN_LOOP; + return FALSE; +} + +static bool __found_ap_callback(wifi_manager_ap_h ap, void *user_data) +{ + char *ap_name = NULL; + char *ap_name_part = (char *)user_data; + size_t ap_name_len = strlen(ap_name_part); + int ret = WIFI_MANAGER_ERROR_NONE; + + if (ap) { + ret = wifi_manager_ap_get_essid(ap, &ap_name); + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Unable to get essid"; + + if (!ap_name) + return true; + + if (!strncmp(ap_name, ap_name_part, ap_name_len)) { + g_free(ap_name); + ret = wifi_manager_ap_clone(&g_hWifiAP, ap); + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Unable to clone the AP handle"; + if (g_hWifiAP) { + rst = WIFI_MANAGER_ERROR_NONE; + return false; + } + } + } + + return true; +} + +TEST(Hal_wifi, Init_p) +{ + g_bFeatureWifi = __check_feature_supported((char*)FEATURE_WIFI); + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int rv = wifi_manager_initialize(&wifi); + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Initialization failure"; +} + +TEST(Hal_wifi, Activate_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int rv; + bool activated; + + rv = wifi_manager_is_activated(wifi, &activated); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to get Wi-Fi device state"; + + if (activated) + goto done; + + rv = wifi_manager_activate(wifi, __test_callback, NULL); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to activate Wi-Fi device"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Activetion failure"; + rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; + +done: + rv = access(WIFI_ADDRESS_PATH, F_OK); + EXPECT_EQ(0, rv) << "Could not access " << WIFI_ADDRESS_PATH; +} + +TEST(Hal_wifi, Scan_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int rv = wifi_manager_scan(wifi, __test_callback, NULL); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to scan"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Scan failure"; + rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; +} + +TEST(Hal_wifi, Connect_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + wifi_manager_connection_state_e connection_state; + int ret = WIFI_MANAGER_ERROR_NONE; + + ret = wifi_manager_get_connection_state(wifi, &connection_state); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to get connection state"; + + if (connection_state == WIFI_MANAGER_CONNECTION_STATE_CONNECTED) + return; + + if (!ap_name[0]) + return; + + ret = wifi_manager_foreach_found_ap(wifi, __found_ap_callback, (char *)ap_name); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Failed to find the AP"; + rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; + + ret = wifi_manager_connect(wifi, g_hWifiAP, __test_callback, NULL); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to connect"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Connection failure"; + rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; +} + +TEST(Hal_wifi, Disconnect_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int ret = WIFI_MANAGER_ERROR_NONE; + wifi_manager_ap_h hAP = NULL; + + ret = wifi_manager_get_connected_ap(wifi, &hAP); + if (ret == WIFI_MANAGER_ERROR_NO_CONNECTION) + return; + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to get connected AP"; + + ret = wifi_manager_disconnect(wifi, hAP, __test_callback, NULL); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to disconnect"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Disconnection failure"; + rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; + + ret = wifi_manager_forget_ap(wifi, hAP); + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, ret) << "Failed to forget AP"; +} + +TEST(Hal_wifi, Deactivate_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int rv = wifi_manager_deactivate(wifi, __test_callback, NULL); + ASSERT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Failed to deactivate Wi-Fi device"; + + RUN_GMAIN_LOOP(__timeout_callback); + + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rst) << "Deactivation failure"; + rst = WIFI_MANAGER_ERROR_NOT_SUPPORTED; + + rv = access(WIFI_ADDRESS_PATH, F_OK); + EXPECT_EQ(-1, rv) << WIFI_ADDRESS_PATH << " is exist"; +} + +TEST(Hal_wifi, Deinit_p) +{ + ASSERT_EQ(true, g_bFeatureWifi) << FEATURE_WIFI << " feature is not supported"; + + int rv = wifi_manager_deinitialize(wifi); + EXPECT_EQ(WIFI_MANAGER_ERROR_NONE, rv) << "Deinitialization failure"; +} + +int main(int argc, char **argv) +{ + if (argc > 1 && argv[argc - 1][0] != '-') { + g_strlcpy(ap_name, argv[argc - 1], MAX_AP_LENGTH); + argc--; + } + + InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}