Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
karuna2git authored Nov 13, 2024
2 parents 2654421 + 480170c commit 88d63dc
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 3 deletions.
31 changes: 28 additions & 3 deletions .github/workflows/gnome_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
unit-tests:
name: Build and run unit tests
runs-on: ubuntu-latest

steps:
- name: Configure cache
if: ${{ !env.ACT }}
Expand All @@ -32,7 +32,7 @@ jobs:
- name: Install packages
run: |
sudo apt update
sudo apt-get install -y pkg-config libglib2.0-dev libnm-dev libcurl4-openssl-dev ninja-build
sudo apt-get install -y pkg-config libglib2.0-dev libnm-dev libcurl4-openssl-dev lcov ninja-build
- name: Configure Python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
uses: actions/checkout@v3
with:
path: networkmanager

- name: Build networkmanager with Gnome Proxy
run: >
cmake
Expand All @@ -99,7 +99,32 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}"
-DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr"
-DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake"
-DCMAKE_CXX_FLAGS=" -fprofile-arcs -ftest-coverage "
-DENABLE_GNOME_NETWORKMANAGER=ON
-DENABLE_UNIT_TESTING=ON
&&
cmake --build build/GnomeNetworkmanager --target install -j8
- name: Run unit tests without valgrind
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}
tests
- name: Generate coverage
run: |
lcov -c -o coverage.info -d build/GnomeNetworkmanager
lcov -r coverage.info '/usr/include/*' '*/build/GnomeNetworkmanager/*' \
'*/install/usr/include/*' '*/Tests/*' 'googlemock/*' 'googletest/*' \
-o filtered_coverage.info
- name: Generate the html report
run: |
genhtml filtered_coverage.info --output-directory /tmp/coverage_report
- name: Upload the coverage report to Pull request using actions
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: /tmp/coverage_report

6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
include(CmakeHelperFunctions)

option(USE_RDK_LOGGER "Enable RDK Logger for logging" OFF )
option(ENABLE_UNIT_TESTING "Enable unit tests" OFF)


string(TOLOWER ${NAMESPACE} STORAGE_DIRECTORY)
get_directory_property(SEVICES_DEFINES COMPILE_DEFINITIONS)
Expand Down Expand Up @@ -167,3 +169,7 @@ write_config()
write_config(PLUGINS LegacyPlugin_NetworkAPIs CLASSNAME Network LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_NETWORK}.so)
write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_WIFI}.so)

if(ENABLE_UNIT_TESTING)
include(Tests/unit_test/tests.cmake)
endif(ENABLE_UNIT_TESTING)

58 changes: 58 additions & 0 deletions Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "WiFiSignalStrengthMonitor.h"
#include "NetworkManagerImplementation.h"
#include "NetworkManagerLogger.h"
#include "INetworkManager.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <iostream>
#include <thread>
#include <chrono>
#include <list>
#include <string>

using namespace std;
using namespace WPEFramework;
using namespace WPEFramework::Plugin;
namespace WPEFramework
{
namespace Plugin
{
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;
}
}
}

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";
Exchange::INetworkManager::WiFiSignalQuality quality;
std::string strengthOut= "-55";
monitor.getSignalData(ssid, quality, strengthOut);
}

TEST_F(WiFiSignalStrengthMonitorTest, StartWiFiSignalStrengthMonitor) {
monitor.startWiFiSignalStrengthMonitor(1);

}

int main(int argc, char **argv) {
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}

43 changes: 43 additions & 0 deletions Tests/unit_test/tests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.10)
set(UNIT_TEST "tests")

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GIO REQUIRED gio-2.0)
pkg_check_modules(LIBNM REQUIRED libnm)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)

FetchContent_MakeAvailable(googletest)
add_executable(${UNIT_TEST}
Tests/unit_test/test_WiFiSignalStrengthMonitor.cpp
WiFiSignalStrengthMonitor.cpp
NetworkManagerLogger.cpp
NetworkManagerConnectivity.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")

target_include_directories(${UNIT_TEST} PRIVATE
${GLIB_INCLUDE_DIRS}
${LIBNM_INCLUDE_DIRS}
${GIO_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
Tests
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR}/../googlemock/include
)

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)

1 change: 1 addition & 0 deletions WiFiSignalStrengthMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <thread>
#include <chrono>
#include <atomic>
#include <stdlib.h>
#include "NetworkManagerLogger.h"
#include "NetworkManagerImplementation.h"
#include "WiFiSignalStrengthMonitor.h"
Expand Down

0 comments on commit 88d63dc

Please sign in to comment.