diff --git a/.github/workflows/gnome_unit_test.yml b/.github/workflows/gnome_unit_test.yml index 4dcb52e8..107e6e45 100644 --- a/.github/workflows/gnome_unit_test.yml +++ b/.github/workflows/gnome_unit_test.yml @@ -110,7 +110,7 @@ jobs: run: > PATH=${{github.workspace}}/install/usr/bin:${PATH} LD_LIBRARY_PATH=${{github.workspace}}/install/usr/lib:${{github.workspace}}/install/usr/lib/wpeframework/plugins:${LD_LIBRARY_PATH} - unit_tests + tests - name: Generate coverage run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 3670fe97..6937da5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,6 @@ write_config(PLUGINS LegacyPlugin_NetworkAPIs CLASSNAME Network LOCATOR lib${PLU write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_WIFI}.so) if(ENABLE_UNIT_TESTING) - include(Tests/unit_test/unit_tests.cmake) + include(Tests/unit_test/tests.cmake) endif(ENABLE_UNIT_TESTING) diff --git a/NetworkManagerConnectivity.cpp b/NetworkManagerConnectivity.cpp index 1a4667e1..f76c8b4b 100644 --- a/NetworkManagerConnectivity.cpp +++ b/NetworkManagerConnectivity.cpp @@ -158,7 +158,7 @@ namespace WPEFramework curl_easy_setopt(curl_easy_handle, CURLOPT_TIMEOUT_MS, deadline - current_time()); if ((ipversion == CURL_IPRESOLVE_V4) || (ipversion == CURL_IPRESOLVE_V6)) { - NMLOG_DEBUG("curlopt ipversion = %s reqtyp = %s", ipversion == CURL_IPRESOLVE_V4?"IPv4":"IPv6", headReq? "HEAD":"GET"); + NMLOG_DEBUG("curlopt ipversion = %s reqtyp = %s", ipversion == CURL_IPRESOLVE_V4?"ipv4 only":"ipv6 only", headReq? "HEAD":"GET"); curl_easy_setopt(curl_easy_handle, CURLOPT_IPRESOLVE, ipversion); } else @@ -324,9 +324,10 @@ namespace WPEFramework doContinuousMonitor = false; doConnectivityMonitor = false; - m_InternetState = nsm_internetState::UNKNOWN; - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; + gInternetState = nsm_internetState::UNKNOWN; + gIpv4InternetState = nsm_internetState::UNKNOWN; + gIpv6InternetState = nsm_internetState::UNKNOWN; + ginterfaceStatus = false; } ConnectivityMonitor::~ConnectivityMonitor() @@ -389,15 +390,15 @@ namespace WPEFramework // If monitor connectivity is running take the cache value if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V4 == ipversion || nsm_ipversion::NSM_IPRESOLVE_WHATEVER == ipversion) - && m_Ipv4InternetState != nsm_internetState::UNKNOWN ) { - NMLOG_WARNING("Reading Ipv4 internet state cached value %s", getInternetStateString(m_Ipv4InternetState)); - internetState = m_Ipv4InternetState; + && gIpv4InternetState != nsm_internetState::UNKNOWN ) { + NMLOG_WARNING("Reading Ipv4 internet state cached value %s", getInternetStateString(gIpv4InternetState)); + internetState = gIpv4InternetState; ipversion = NSM_IPRESOLVE_V4; } else if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V6 == ipversion || nsm_ipversion::NSM_IPRESOLVE_WHATEVER == ipversion) - && m_Ipv6InternetState != nsm_internetState::UNKNOWN ) { - NMLOG_WARNING("Reading Ipv6 internet state cached value %s", getInternetStateString(m_Ipv6InternetState)); - internetState = m_Ipv6InternetState; + && gIpv6InternetState != nsm_internetState::UNKNOWN ) { + NMLOG_WARNING("Reading Ipv6 internet state cached value %s", getInternetStateString(gIpv6InternetState)); + internetState = gIpv6InternetState; ipversion = NSM_IPRESOLVE_V6; } else @@ -424,8 +425,6 @@ namespace WPEFramework bool ConnectivityMonitor::startContinuousConnectivityMonitor(int timeoutInSeconds) { - if(_instance != nullptr ) - NMLOG_INFO("interface status eth - %s wlan - %s ", _instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down"); continuousMonitorTimeout.store(timeoutInSeconds >= NMCONNECTIVITY_MONITOR_MIN_INTERVAL ? timeoutInSeconds : NMCONNECTIVITY_MONITOR_DEFAULT_INTERVAL); if (doContinuousMonitor) { @@ -473,11 +472,12 @@ namespace WPEFramework * --> when IP address accuired * --> when etherenet/wifi disconnected */ - bool ConnectivityMonitor::startConnectivityMonitor() + bool ConnectivityMonitor::startConnectivityMonitor(bool interfaceStatus) { - m_InternetState = nsm_internetState::UNKNOWN; - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; + ginterfaceStatus = interfaceStatus; /* this will give interface status connected/ disconnected */ + gInternetState = UNKNOWN; + gIpv4InternetState = UNKNOWN; + gIpv6InternetState = UNKNOWN; if (doConnectivityMonitor) { cvConnectivityMonitor.notify_one(); @@ -497,26 +497,21 @@ namespace WPEFramework return false; } - if(_instance != nullptr) { - NMLOG_INFO("connectivity monitor started %d sec - eth %s - wlan %s", NMCONNECTIVITY_MONITOR_MIN_INTERVAL, - _instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down"); - } + NMLOG_ERROR("connectivity monitor started %d", NMCONNECTIVITY_MONITOR_MIN_INTERVAL); return true; } void ConnectivityMonitor::notifyInternetStatusChangedEvent(nsm_internetState newInternetState) { - static Exchange::INetworkManager::InternetStatus oldState = Exchange::INetworkManager::InternetStatus::INTERNET_UNKNOWN; if(_instance != nullptr) { - NMLOG_INFO("notify internet state %s", getInternetStateString(newInternetState)); + Exchange::INetworkManager::InternetStatus oldState = static_cast(gInternetState.load()); Exchange::INetworkManager::InternetStatus newState = static_cast(newInternetState); _instance->ReportInternetStatusChange(oldState , newState); - m_InternetState = newInternetState; - oldState = newState; // 'm_InternetState' not exactly previous state, it may change to unknow when interface changed + gInternetState = newInternetState; } else - NMLOG_FATAL("NetworkManagerImplementation Instance NULL notifyInternetStatusChange failed."); + NMLOG_WARNING("NetworkManagerImplementation Instance NULL notifyInternetStatusChange failed."); } void ConnectivityMonitor::continuousMonitorFunction() @@ -529,31 +524,20 @@ namespace WPEFramework do { - if(_instance != nullptr && (!_instance->m_ethConnected && !_instance->m_wlanConnected)) // no wifi no ethernet connected - { - NMLOG_DEBUG("no interface connected; no ccm check"); - m_Ipv4InternetState = NO_INTERNET; - m_Ipv6InternetState = NO_INTERNET; - std::unique_lock lock(connMutex); - cvContinuousMonitor.wait_for(lock, std::chrono::seconds(continuousMonitorTimeout.load())); - ipResolveTyp = NSM_IPRESOLVE_WHATEVER; - continue; - } - if(doConnectivityMonitor) { NMLOG_DEBUG("connectivity monitor running so skiping ccm check"); - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; + gIpv4InternetState = UNKNOWN; + gIpv6InternetState = UNKNOWN; std::unique_lock lock(connMutex); cvContinuousMonitor.wait_for(lock, std::chrono::seconds(continuousMonitorTimeout.load())); - ipResolveTyp = NSM_IPRESOLVE_WHATEVER; /* some interface change happense */ + ipResolveTyp = NSM_IPRESOLVE_WHATEVER; /* some interface change happense*/ continue; } else if (ipResolveTyp == NSM_IPRESOLVE_WHATEVER) { - nsm_internetState ipV4InternetState = nsm_internetState::UNKNOWN; - nsm_internetState ipV6InternetState = nsm_internetState::UNKNOWN; + nsm_internetState ipV4InternetState = UNKNOWN; + nsm_internetState ipV6InternetState = UNKNOWN; auto curlCheckThrdIpv4 = [&]() { TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, NMCONNECTIVITY_CURL_GET_REQUEST, NSM_IPRESOLVE_V4); @@ -589,17 +573,17 @@ namespace WPEFramework NMCONNECTIVITY_CURL_HEAD_REQUEST, ipResolveTyp); currentInternetState = testInternet.getInternetState(); if(ipResolveTyp == NSM_IPRESOLVE_V4) - m_Ipv4InternetState = currentInternetState; + gIpv4InternetState = currentInternetState; else if(ipResolveTyp == NSM_IPRESOLVE_V6) - m_Ipv6InternetState = currentInternetState; + gIpv6InternetState = currentInternetState; } if (currentInternetState == NO_INTERNET) { - if(m_InternetState == FULLY_CONNECTED && notifyPreRetry < NMCONNECTIVITY_NO_INTERNET_RETRY_COUNT) + if(gInternetState == FULLY_CONNECTED && notifyPreRetry < NMCONNECTIVITY_NO_INTERNET_RETRY_COUNT) { /* it will prevent posting notification */ - currentInternetState = m_InternetState; + currentInternetState = gInternetState; TempInterval = 5; NMLOG_INFO("No internet retrying connection check %d ...", notifyPreRetry); notifyPreRetry++; @@ -617,8 +601,9 @@ namespace WPEFramework TempInterval = continuousMonitorTimeout.load(); } - if(m_InternetState != currentInternetState) + if(gInternetState != currentInternetState) { + NMLOG_INFO("Internet state changed to %s", getInternetStateString(currentInternetState)); /* Notify Internet state change */ notifyInternetStatusChangedEvent(currentInternetState); } @@ -634,8 +619,8 @@ namespace WPEFramework } while(doContinuousMonitor); - m_Ipv4InternetState = nsm_internetState::UNKNOWN; - m_Ipv6InternetState = nsm_internetState::UNKNOWN; + gIpv4InternetState = UNKNOWN; + gIpv6InternetState = UNKNOWN; NMLOG_DEBUG("continous connectivity monitor exit"); } @@ -678,8 +663,8 @@ namespace WPEFramework NMLOG_INFO("Connectivity check retrying %d ...", notifyPreRetry); } - if(m_InternetState != nsm_internetState::UNKNOWN) - currentInternetState = m_InternetState; + if(gInternetState != UNKNOWN) + currentInternetState = gInternetState; TempInterval = 5; } else if(tempInternetState != currentInternetState) // last state have change @@ -696,9 +681,8 @@ namespace WPEFramework doConnectivityMonitor = false; // self exit notifyNow = true; // post current state when retry complete } - else if(_instance != nullptr && (_instance->m_ethConnected | _instance->m_wlanConnected)) + else if(ginterfaceStatus) // interface is active and still no internet, continue check every 30 sec { - /* interface is connected and still no internet, continue check every 30 sec */ TempInterval = NMCONNECTIVITY_CONN_MONITOR_RETRY_INTERVAL; /* notify if retry completed and state stil no internet state */ if(notifyPreRetry == NMCONNECTIVITY_CONN_MONITOR_RETRY_COUNT) @@ -715,9 +699,10 @@ namespace WPEFramework } } - if(m_InternetState != currentInternetState || notifyNow) + if(gInternetState != currentInternetState || notifyNow) { notifyNow = false; + NMLOG_INFO("notify internet state %s", getInternetStateString(currentInternetState)); notifyInternetStatusChangedEvent(currentInternetState); } @@ -734,7 +719,7 @@ namespace WPEFramework } while(doConnectivityMonitor); if(!doContinuousMonitor) - m_InternetState = nsm_internetState::UNKNOWN; // no continous monitor running reset to unknow + gInternetState = nsm_internetState::UNKNOWN; // no continous monitor running reset to unknow NMLOG_DEBUG("initial connectivity monitor exit"); } diff --git a/NetworkManagerConnectivity.h b/NetworkManagerConnectivity.h index 3a5b215a..26f256fa 100644 --- a/NetworkManagerConnectivity.h +++ b/NetworkManagerConnectivity.h @@ -114,7 +114,7 @@ namespace WPEFramework ~ConnectivityMonitor(); bool startContinuousConnectivityMonitor(int timeoutInSeconds); bool stopContinuousConnectivityMonitor(); - bool startConnectivityMonitor(); + bool startConnectivityMonitor(bool interfaceStatus); void setConnectivityMonitorEndpoints(const std::vector &endpoints); std::vector getConnectivityMonitorEndpoints(); bool isConnectedToInternet(nsm_ipversion ipversion); @@ -140,9 +140,10 @@ namespace WPEFramework EndpointCache endpointCache; std::mutex endpointMutex; - std::atomic m_InternetState; - std::atomic m_Ipv4InternetState; - std::atomic m_Ipv6InternetState; + std::atomic ginterfaceStatus; + std::atomic gInternetState; + std::atomic gIpv4InternetState; + std::atomic gIpv6InternetState; }; } // namespace Plugin } // namespace WPEFramework diff --git a/NetworkManagerGnomeProxy.cpp b/NetworkManagerGnomeProxy.cpp index fe1faddd..eb84bef6 100644 --- a/NetworkManagerGnomeProxy.cpp +++ b/NetworkManagerGnomeProxy.cpp @@ -84,25 +84,23 @@ namespace WPEFramework { NMDeviceState deviceState = NM_DEVICE_STATE_UNKNOWN; Exchange::INetworkManager::InterfaceDetails interface; - interface.mac = nm_device_get_hw_address(device); - deviceState = nm_device_get_state(device); - interface.enabled = (deviceState >= NM_DEVICE_STATE_UNAVAILABLE)? true : false; - if(deviceState > NM_DEVICE_STATE_DISCONNECTED && deviceState < NM_DEVICE_STATE_DEACTIVATING) - interface.connected = true; - else - interface.connected = false; - if(ifaceStr == wifiname) { interface.type = INTERFACE_TYPE_WIFI; interface.name = wifiname; - m_wlanConnected = interface.connected; } if(ifaceStr == ethname) { interface.type = INTERFACE_TYPE_ETHERNET; interface.name = ethname; - m_ethConnected = interface.connected; } - + interface.mac = nm_device_get_hw_address(device); + deviceState = nm_device_get_state(device); + interface.enabled = (deviceState >= NM_DEVICE_STATE_UNAVAILABLE) ? true : false; + if(deviceState > NM_DEVICE_STATE_DISCONNECTED && deviceState < NM_DEVICE_STATE_DEACTIVATING){ + interface.connected = true; + m_defaultInterface = interface.name; + } + else + interface.connected = false; interfaceList.push_back(interface); rc = Core::ERROR_NONE; } diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index f08fe09c..6ca6bd9b 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -50,8 +50,6 @@ namespace WPEFramework m_stunCacheTimeout = 0; m_defaultInterface = ""; m_publicIP = ""; - m_ethConnected = false; - m_wlanConnected = false; } NetworkManagerImplementation::~NetworkManagerImplementation() @@ -572,22 +570,13 @@ namespace WPEFramework void NetworkManagerImplementation::ReportInterfaceStateChange(const Exchange::INetworkManager::InterfaceState state, const string interface) { LOG_ENTRY_FUNCTION(); - if(Exchange::INetworkManager::INTERFACE_LINK_DOWN == state || Exchange::INetworkManager::INTERFACE_REMOVED == state) { + if(Exchange::INetworkManager::INTERFACE_LINK_DOWN == state) { // Start the connectivity monitor with 'false' to indicate the interface is down. // The monitor will automatically exit after the retry attempts are completed, posting a 'noInternet' event. - if(interface == "eth0") - m_ethConnected = false; - else - m_wlanConnected = false; - connectivityMonitor.startConnectivityMonitor(); + connectivityMonitor.startConnectivityMonitor(false); } - /* Only the Ethernet connection status is changing here. The WiFi status is updated in the WiFi state callback. */ - if(Exchange::INetworkManager::INTERFACE_LINK_UP == state && interface == "eth0") - m_ethConnected = true; - _notificationLock.Lock(); - NMLOG_INFO("Posting onInterfaceChange %s - %u", interface.c_str(), (unsigned)state); for (const auto callback : _notificationCallbacks) { callback->onInterfaceStateChange(state, interface); } @@ -596,8 +585,8 @@ namespace WPEFramework void NetworkManagerImplementation::ReportActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface) { - _notificationLock.Lock(); NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str()); + _notificationLock.Lock(); for (const auto callback : _notificationCallbacks) { callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface); } @@ -610,11 +599,11 @@ namespace WPEFramework if (Exchange::INetworkManager::IP_ACQUIRED == status) { // Start the connectivity monitor with 'true' to indicate the interface is up. // The monitor will conntinoue even after no internet retry completed, Exit when fully connectd. - connectivityMonitor.startConnectivityMonitor(); + connectivityMonitor.startConnectivityMonitor(true); } + NMLOG_INFO("Posting onIPAddressChange %s", ipaddress.c_str()); _notificationLock.Lock(); - NMLOG_INFO("Posting onIPAddressChange %s - %s", ipaddress.c_str(), interface.c_str()); for (const auto callback : _notificationCallbacks) { callback->onIPAddressChange(interface, ipversion, ipaddress, status); } @@ -623,8 +612,8 @@ namespace WPEFramework void NetworkManagerImplementation::ReportInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState) { - _notificationLock.Lock(); NMLOG_INFO("Posting onInternetStatusChange with current state as %u", (unsigned)currState); + _notificationLock.Lock(); for (const auto callback : _notificationCallbacks) { callback->onInternetStatusChange(prevState, currState); } @@ -655,15 +644,10 @@ namespace WPEFramework { /* start signal strength monitor when wifi connected */ if(INetworkManager::WiFiState::WIFI_STATE_CONNECTED == state) - { - m_wlanConnected = true; m_wifiSignalMonitor.startWiFiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC); - } - else - m_wlanConnected = false; /* Any other state is considered as WiFi not connected. */ + NMLOG_INFO("Posting onWiFiStateChange"); _notificationLock.Lock(); - NMLOG_INFO("Posting onWiFiStateChange (%d)", state); for (const auto callback : _notificationCallbacks) { callback->onWiFiStateChange(state); } @@ -672,10 +656,11 @@ namespace WPEFramework void NetworkManagerImplementation::ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality) { + NMLOG_INFO("Posting onWiFiSignalStrengthChange"); _notificationLock.Lock(); - NMLOG_INFO("Posting onWiFiSignalStrengthChange %s", strength.c_str()); for (const auto callback : _notificationCallbacks) { callback->onWiFiSignalStrengthChange(ssid, strength, quality); + } _notificationLock.Unlock(); } diff --git a/NetworkManagerImplementation.h b/NetworkManagerImplementation.h index 64767f98..e8cbd532 100644 --- a/NetworkManagerImplementation.h +++ b/NetworkManagerImplementation.h @@ -25,7 +25,6 @@ #include #include #include -#include using namespace std; @@ -223,14 +222,9 @@ namespace WPEFramework void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state); void ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality); - public: - std::atomic m_ethConnected; - std::atomic m_wlanConnected; - private: void platform_init(); void retryIarmEventRegistration(); - void getInitialConnectionState(); void threadEventRegistration(); void executeExternally(NetworkEvents event, const string commandToExecute, string& response); void filterScanResults(JsonArray &ssids); diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index 45785711..89181872 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -457,7 +457,8 @@ namespace WPEFramework { IARM_BUS_NetSrvMgr_Iface_EventInterfaceIPAddress_t *e = (IARM_BUS_NetSrvMgr_Iface_EventInterfaceIPAddress_t*) data; interface = e->interface; - NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS: %s - %s - %s", interface.c_str(), e->ip_address, e->acquired?"Acquired":"Lost"); + NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS: %s - %s - %s", interface.c_str(), e->ip_address, e->acquired?"Acquired":"Lost" +); if(interface == "eth0" || interface == "wlan0") { string ipversion("IPv4"); @@ -574,57 +575,10 @@ namespace WPEFramework IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs, NetworkManagerInternalEventHandler); NMLOG_INFO("threadEventRegistration successfully subscribed to IARM event for NetworkManager Plugin"); - /* - * Read current network state and post the event. - * Useful if NetworkManager plugin or WPEFramework is restarted - * or netsrvmgr misses to post iarm events during bootup. - */ - getInitialConnectionState(); } } - void NetworkManagerImplementation::getInitialConnectionState() - { - // check the connection state and post event - Exchange::INetworkManager::IInterfaceDetailsIterator* _interfaces{}; - uint32_t rc = GetAvailableInterfaces(_interfaces); - - if (Core::ERROR_NONE == rc) - { - if (_interfaces != nullptr) - { - Exchange::INetworkManager::InterfaceDetails iface{}; - while (_interfaces->Next(iface) == true) - { - Core::JSON::EnumType type{iface.type}; - if(iface.enabled) - { - NMLOG_INFO("'%s' interface is enabled", iface.name.c_str()); - // ReportInterfaceStateChange(Exchange::INetworkManager::INTERFACE_ADDED, iface.name); - if(iface.connected) - { - NMLOG_INFO("'%s' interface is connected", iface.name.c_str()); - ReportActiveInterfaceChange(iface.name, iface.name); - std::string ipversion = {}; - Exchange::INetworkManager::IPAddress addr; - rc = GetIPSettings(iface.name, ipversion, addr); - if (Core::ERROR_NONE == rc) - { - if(!addr.ipaddress.empty()) { - NMLOG_INFO("'%s' interface have ip '%s'", iface.name.c_str(), addr.ipaddress.c_str()); - ReportIPAddressChange(iface.name, addr.ipversion, addr.ipaddress, Exchange::INetworkManager::IP_ACQUIRED); - } - } - } - } - } - - _interfaces->Release(); - } - } - } - void NetworkManagerImplementation::platform_init() { LOG_ENTRY_FUNCTION(); @@ -669,14 +623,7 @@ namespace WPEFramework IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged, NetworkManagerInternalEventHandler); IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onError, NetworkManagerInternalEventHandler); IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs, NetworkManagerInternalEventHandler); - /* - * Read current network state and post the event. - * Useful if NetworkManager plugin or WPEFramework is restarted - * or netsrvmgr misses to post iarm events during bootup. - */ - getInitialConnectionState(); } - } uint32_t NetworkManagerImplementation::GetAvailableInterfaces (Exchange::INetworkManager::IInterfaceDetailsIterator*& interfacesItr/* @out */) @@ -695,19 +642,15 @@ namespace WPEFramework { InterfaceDetails tmp; /* Update the interface as per RDK NetSrvMgr */ + if ("eth0" == interfaceName) + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_ETHERNET; + else if ("wlan0" == interfaceName) + tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_WIFI; + tmp.name = interfaceName; tmp.mac = string(list.interfaces[i].mac); tmp.enabled = ((list.interfaces[i].flags & IFF_UP) != 0); tmp.connected = ((list.interfaces[i].flags & IFF_RUNNING) != 0); - if ("eth0" == interfaceName) { - tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_ETHERNET; - m_ethConnected = tmp.connected; - } - else if ("wlan0" == interfaceName) { - tmp.type = Exchange::INetworkManager::INTERFACE_TYPE_WIFI; - m_wlanConnected = tmp.connected; - } - interfaceList.push_back(tmp); } } diff --git a/Tests/unit_test/test_NetworkManagerConnectivity.cpp b/Tests/unit_test/test_NetworkManagerConnectivity.cpp index 74f4309f..f175a929 100644 --- a/Tests/unit_test/test_NetworkManagerConnectivity.cpp +++ b/Tests/unit_test/test_NetworkManagerConnectivity.cpp @@ -1,6 +1,6 @@ #include "NetworkManagerImplementation.h" #include "NetworkManagerConnectivity.h" - +#include "WiFiSignalStrengthMonitor.h" #include #include #include @@ -20,30 +20,36 @@ using namespace std; using namespace WPEFramework; - + class ConnectivityMonitorTest : public ::testing::Test { protected: - WPEFramework::Plugin::ConnectivityMonitor cm; -}; + + WPEFramework::Plugin::ConnectivityMonitor cm; -TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_Success) { - int timeout = 30; + void SetUp() override { + + } + + void TearDown() override { + + } +}; + + TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_Success) { + int timeout = 30; bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StartContinuousMonitor_FailureNegativeTimeout) { - int timeout = -1; + int timeout = -1; bool result = cm.startContinuousConnectivityMonitor(timeout); - EXPECT_TRUE(result); -} - + EXPECT_TRUE(result); +} TEST_F(ConnectivityMonitorTest, StartMonitorWithTimeoutLessThanMinimum) { - int timeout = 3; + int timeout = 3; bool result = cm.startContinuousConnectivityMonitor(timeout); EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, MonitorFailsToStart) { int timeout = 0; bool result = cm.startContinuousConnectivityMonitor(timeout); @@ -54,19 +60,17 @@ TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenStarted) { int timeout = 30; cm.startContinuousConnectivityMonitor(timeout); bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_WhenNotStarted) { bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_AfterMultipleStartsAndStops) { int timeout = 30; cm.startContinuousConnectivityMonitor(timeout); bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); cm.startContinuousConnectivityMonitor(timeout); result = cm.stopContinuousConnectivityMonitor(); @@ -74,51 +78,55 @@ TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_AfterMultipleStartsAndStop cm.startContinuousConnectivityMonitor(timeout); result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StopContinuousMonitor_LongRunningMonitor) { int timeout = 1000; cm.startContinuousConnectivityMonitor(timeout); std::this_thread::sleep_for(std::chrono::seconds(2)); bool result = cm.stopContinuousConnectivityMonitor(); - EXPECT_TRUE(result); + EXPECT_TRUE(result); } -TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatus) { - bool result = cm.startConnectivityMonitor(); - EXPECT_TRUE(result); + TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatusTrue) { + bool interfaceStatus = true; + bool result = cm.startConnectivityMonitor(interfaceStatus); + EXPECT_TRUE(result); +} +TEST_F(ConnectivityMonitorTest, StartMonitor_WithInterfaceStatusFalse) { + bool interfaceStatus = false; + bool result = cm.startConnectivityMonitor(interfaceStatus); + EXPECT_TRUE(result); } - TEST_F(ConnectivityMonitorTest, StartMonitor_NotifyIfAlreadyMonitoring) { - bool result = false; - result = cm.startConnectivityMonitor(); - EXPECT_TRUE(result); - result = cm.startConnectivityMonitor(); - EXPECT_TRUE(result); + bool interfaceStatus = true; + cm.startConnectivityMonitor(interfaceStatus); + bool result = cm.startConnectivityMonitor(interfaceStatus); + EXPECT_TRUE(result); } TEST_F(ConnectivityMonitorTest, SetEndpoints_Valid) { std::vector endpoints = {"https://github.com/rdkcentral", "https://github.com/rdkcentral/rdkservices"}; cm.setConnectivityMonitorEndpoints(endpoints); EXPECT_EQ(cm.getConnectivityMonitorEndpoints(), endpoints); -} - +} TEST_F(ConnectivityMonitorTest, SetEndpoints_EmptyList) { std::vector endpoints; cm.setConnectivityMonitorEndpoints(endpoints); EXPECT_TRUE(cm.getConnectivityMonitorEndpoints().empty()); } - TEST_F(ConnectivityMonitorTest, SetEndpoints_InvalidShortEndpoints) { std::vector endpoints = {"ab", "htt", "xyz"}; cm.setConnectivityMonitorEndpoints(endpoints); EXPECT_TRUE(cm.getConnectivityMonitorEndpoints().empty()); } - TEST_F(ConnectivityMonitorTest, SetEndpoints_DuplicateEndpoints) { std::vector endpoints = {"https://github.com", "https://github.com"}; cm.setConnectivityMonitorEndpoints(endpoints); EXPECT_EQ(cm.getConnectivityMonitorEndpoints().size(), 2); } + + + + diff --git a/Tests/unit_test/test_NetworkManagerStunClient.cpp b/Tests/unit_test/test_NetworkManagerStunClient.cpp index 5276344a..b235eb2d 100644 --- a/Tests/unit_test/test_NetworkManagerStunClient.cpp +++ b/Tests/unit_test/test_NetworkManagerStunClient.cpp @@ -1,3 +1,23 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include "NetworkManagerStunClient.h" @@ -8,30 +28,42 @@ using namespace stun; class AddressTest : public ::testing::Test { protected: stun::attributes::address ad; + void SetUp() override { + + } + void TearDown() override { + + } }; class ClientTest : public ::testing::Test { protected: - stun::client _client; + stun::client cl; + void SetUp() override { + + } + void TearDown() override { + + } }; TEST_F(ClientTest, BindSuccess) { stun::bind_result result; - bool success = _client.bind("https://github.com/", 3478, "eth0", stun::protocol::af_inet, 5000, 10000, result); + bool success = cl.bind("https://github.com/", 3478, "eth0", stun::protocol::af_inet, 5000, 10000, result); EXPECT_FALSE(success); EXPECT_FALSE(result.is_valid()); } TEST_F(ClientTest, BindFailure) { stun::bind_result result; - bool success = _client.bind("http//tata.com", 3478, "eth0", stun::protocol::af_inet, 5000, 10000, result); + bool success = cl.bind("http//tata.com", 3478, "eth0", stun::protocol::af_inet, 5000, 10000, result); EXPECT_FALSE(success); EXPECT_FALSE(result.is_valid()); } - TEST_F(ClientTest, BindWithInvalidInterface) { stun::bind_result result; - bool success = _client.bind("https://github.com/", 3478, "invalid_interface", stun::protocol::af_inet, 5000, 10000, result); + bool success = cl.bind("https://github.com/", 3478, "invalid_interface", stun::protocol::af_inet, 5000, 10000, result); EXPECT_FALSE(success); EXPECT_FALSE(result.is_valid()); } + diff --git a/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp b/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp index 5618a6cb..a2e1d3f9 100644 --- a/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp +++ b/Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp @@ -17,12 +17,11 @@ namespace WPEFramework { namespace Plugin { - NetworkManagerImplementation* _instance = nullptr; + NetworkManagerImplementation* _instance; void NetworkManagerImplementation::ReportWiFiSignalStrengthChange(const string ssid, const string strength, const WiFiSignalQuality quality) - { + { return; } - void NetworkManagerImplementation::ReportInternetStatusChange(const InternetStatus prevState, const InternetStatus currState) { return; @@ -33,7 +32,12 @@ namespace WPEFramework class WiFiSignalStrengthMonitorTest : public ::testing::Test { protected: WPEFramework::Plugin::WiFiSignalStrengthMonitor monitor; + void SetUp() override { + } + void TearDown() override { + } }; +#define BUFFER_SIZE 1024 TEST_F(WiFiSignalStrengthMonitorTest, GetSignalData_Connected) { std::string ssid = "TestSSID"; @@ -43,10 +47,12 @@ TEST_F(WiFiSignalStrengthMonitorTest, GetSignalData_Connected) { } TEST_F(WiFiSignalStrengthMonitorTest, StartWiFiSignalStrengthMonitor) { - monitor.startWiFiSignalStrengthMonitor(1); + monitor.startWiFiSignalStrengthMonitor(1); + } int main(int argc, char **argv) { ::testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); } + diff --git a/Tests/unit_test/unit_tests.cmake b/Tests/unit_test/tests.cmake similarity index 96% rename from Tests/unit_test/unit_tests.cmake rename to Tests/unit_test/tests.cmake index 9c56c242..82d2cd92 100644 --- a/Tests/unit_test/unit_tests.cmake +++ b/Tests/unit_test/tests.cmake @@ -1,4 +1,5 @@ -set(UNIT_TEST "unit_tests") +cmake_minimum_required(VERSION 3.10) +set(UNIT_TEST "tests") find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB REQUIRED glib-2.0) @@ -21,12 +22,10 @@ add_executable(${UNIT_TEST} NetworkManagerConnectivity.cpp NetworkManagerStunClient.cpp ) - set_target_properties(${UNIT_TEST} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES ) - target_compile_options(${UNIT_TEST} PRIVATE -Wall -include ${CMAKE_SOURCE_DIR}/INetworkManager.h) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") @@ -44,3 +43,4 @@ target_include_directories(${UNIT_TEST} PRIVATE target_link_libraries(${UNIT_TEST} PRIVATE gmock_main ${NAMESPACE}Core::${NAMESPACE}Core ${GLIB_LIBRARIES} ${GIO_LIBRARIES} ${LIBNM_LIBRARIES} ${CURL_LIBRARIES}) target_include_directories(${UNIT_TEST} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS ${UNIT_TEST} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +