diff --git a/.github/workflows/BuildThunder.sh b/.github/workflows/BuildThunder.sh deleted file mode 100755 index f6621cc266..0000000000 --- a/.github/workflows/BuildThunder.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -set -e - -############################ -# From https://rdkcentral.github.io/Thunder/introduction/build_linux/ -# DO NOT MODIFY - -############################ -# 1. Install Dependencies - -sudo apt install -y build-essential cmake ninja-build libusb-1.0-0-dev zlib1g-dev libssl-dev - -pip install jsonref - -############################ -# 2. Build Thunder Tools - -git clone https://github.com/rdkcentral/ThunderTools.git - -cmake -G Ninja -S ThunderTools -B build/ThunderTools -DCMAKE_INSTALL_PREFIX="install" - -cmake --build build/ThunderTools --target install - -############################ -# 3. Build Thunder - -git clone https://github.com/rdkcentral/Thunder.git - -cmake -G Ninja -S Thunder -B build/Thunder \ - -DBINDING="127.0.0.1" \ - -DCMAKE_BUILD_TYPE="Debug" \ - -DCMAKE_INSTALL_PREFIX="install" \ - -DPORT="55555" \ - -DTOOLS_SYSROOT="${PWD}" \ - -DINITV_SCRIPT=OFF - -cmake --build build/Thunder --target install - -############################ -# 4. Build ThunderInterfaces - -git clone https://github.com/rdkcentral/ThunderInterfaces.git - -cmake -G Ninja -S ThunderInterfaces -B build/ThunderInterfaces \ - -DCMAKE_INSTALL_PREFIX="install" - -cmake --build build/ThunderInterfaces --target install diff --git a/.github/workflows/L0-CloudStore-grpc.yml b/.github/workflows/L0-CloudStore-grpc.yml deleted file mode 100644 index c554f882a8..0000000000 --- a/.github/workflows/L0-CloudStore-grpc.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: L0-CloudStore-grpc - -on: - push: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - pull_request: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install valgrind, coverage, cmake, protoc, grpc_cpp_plugin, grpc - run: | - sudo apt update - sudo apt install -y valgrind lcov cmake protobuf-compiler protobuf-compiler-grpc libgrpc++-dev - - - name: Build Thunder - working-directory: ${{github.workspace}} - run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/CloudStore/grpc/l0test -B build/grpcl0test -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="--coverage -Wall -Werror" - cmake --build build/grpcl0test --target install - - - name: Run - working-directory: ${{github.workspace}} - run: PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try grpcl0test - - - name: Generate coverage - working-directory: ${{github.workspace}} - run: | - lcov -c -o coverage.info -d build/grpcl0test - genhtml -o coverage coverage.info - - - name: Upload artifacts - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v4 - with: - name: artifacts - path: | - coverage/ - valgrind_log - if-no-files-found: warn diff --git a/.github/workflows/L0-CloudStore.yml b/.github/workflows/L0-CloudStore.yml deleted file mode 100644 index c88ba400e1..0000000000 --- a/.github/workflows/L0-CloudStore.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: L0-CloudStore - -on: - push: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - pull_request: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install valgrind, coverage, cmake - run: | - sudo apt update - sudo apt install -y valgrind lcov cmake - - - name: Build Thunder - working-directory: ${{github.workspace}} - run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/CloudStore/l0test -B build/cloudstorel0test -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="--coverage -Wall -Werror" - cmake --build build/cloudstorel0test --target install - - - name: Run - working-directory: ${{github.workspace}} - run: PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try cloudstorel0test - - - name: Generate coverage - working-directory: ${{github.workspace}} - run: | - lcov -c -o coverage.info -d build/cloudstorel0test - genhtml -o coverage coverage.info - - - name: Upload artifacts - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v4 - with: - name: artifacts - path: | - coverage/ - valgrind_log - if-no-files-found: warn diff --git a/.github/workflows/L0-PersistentStore.yml b/.github/workflows/L0-PersistentStore.yml deleted file mode 100644 index 2931c97600..0000000000 --- a/.github/workflows/L0-PersistentStore.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: L0-PersistentStore - -on: - push: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - pull_request: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install valgrind, coverage, cmake - run: | - sudo apt update - sudo apt install -y valgrind lcov cmake - - - name: Build Thunder - working-directory: ${{github.workspace}} - run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/PersistentStore/l0test -B build/persistentstorel0test -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="--coverage -Wall -Werror" - cmake --build build/persistentstorel0test --target install - - - name: Run - working-directory: ${{github.workspace}} - run: PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try persistentstorel0test - - - name: Generate coverage - working-directory: ${{github.workspace}} - run: | - lcov -c -o coverage.info -d build/persistentstorel0test - genhtml -o coverage coverage.info - - - name: Upload artifacts - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v4 - with: - name: artifacts - path: | - coverage/ - valgrind_log - if-no-files-found: warn diff --git a/.github/workflows/L1-NetworkManager.yml b/.github/workflows/L1-NetworkManager.yml new file mode 100644 index 0000000000..f1158f0c47 --- /dev/null +++ b/.github/workflows/L1-NetworkManager.yml @@ -0,0 +1,207 @@ +name: NetworkManager-tests + +on: + push: + branches: [ main, 'sprint/**', 'release/**' ] + pull_request: + branches: [ main, 'sprint/**', 'release/**' ] + +env: + BUILD_TYPE: Debug + THUNDER_REF: "R4.4.1" + THUNDER_TOOLS_REF: "R4.4.1" + INTERFACES_REF: "R4.4.1" + +jobs: + l1-tests: + name: Build and run unit tests + runs-on: ubuntu-latest + strategy: + matrix: + compiler: [ gcc, clang ] + coverage: [ with-coverage, without-coverage ] + exclude: + - compiler: clang + coverage: with-coverage + - compiler: clang + coverage: without-coverage + - compiler: gcc + coverage: without-coverage + + steps: + - name: Set up cache + # Cache Thunder/ThunderInterfaces. + # https://github.com/actions/cache + # https://docs.github.com/en/rest/actions/cache + # Modify the key if changing the list. + if: ${{ !env.ACT }} + id: cache + uses: actions/cache@v3 + with: + path: | + build/Thunder + build/ThunderInterfaces + build/ThunderTools + install + !install/etc/WPEFramework/plugins + !install/usr/bin/RdkServicesL1Test + !install/usr/include/gmock + !install/usr/include/gtest + !install/usr/lib/libgmockd.a + !install/usr/lib/libgmock_maind.a + !install/usr/lib/libgtestd.a + !install/usr/lib/libgtest_maind.a + !install/usr/lib/cmake/GTest + !install/usr/lib/pkgconfig/gmock.pc + !install/usr/lib/pkgconfig/gmock_main.pc + !install/usr/lib/pkgconfig/gtest.pc + !install/usr/lib/pkgconfig/gtest_main.pc + !install/usr/lib/wpeframework/plugins + key: ${{ runner.os }}-${{ env.THUNDER_REF }}-${{ env.INTERFACES_REF }}-3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + - run: pip install jsonref + + - name: Set up CMake + uses: jwlawson/actions-setup-cmake@v1.13 + with: + cmake-version: '3.16.x' + + - name: Install packages + run: > + sudo apt update + && + sudo apt install -y libnm0 git pkg-config ninja-build libssl-dev libglib2.0-dev libnm-dev libcurl4-openssl-dev valgrind lcov clang + + - name: Checkout ThunderTools + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderTools + path: ThunderTools + ref: ${{env.THUNDER_TOOLS_REF}} + - name: Build ThunderTools + if: steps.cache.outputs.cache-hit != 'true' + run: > + cmake + -S "${{github.workspace}}/ThunderTools" + -B build/ThunderTools + -DEXCEPTIONS_ENABLE=ON + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + -DGENERIC_CMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + && + cmake --build build/ThunderTools -j8 + && + cmake --install build/ThunderTools + + - name: Checkout Thunder + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v3 + with: + repository: rdkcentral/Thunder + path: Thunder + ref: ${{env.THUNDER_REF}} + + - name: Build Thunder + if: steps.cache.outputs.cache-hit != 'true' + run: > + cmake + -S "${{github.workspace}}/Thunder" + -B build/Thunder + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + -DBUILD_TYPE=${{env.BUILD_TYPE}} + -DBINDING=127.0.0.1 + -DPORT=55555 + -DEXCEPTIONS_ENABLE=ON + && + cmake --build build/Thunder -j8 + && + cmake --install build/Thunder + + - name: Checkout ThunderInterfaces + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderInterfaces + path: ThunderInterfaces + ref: ${{env.INTERFACES_REF}} + + - name: Build ThunderInterfaces + if: steps.cache.outputs.cache-hit != 'true' + run: > + cmake + -S "${{github.workspace}}/ThunderInterfaces" + -B build/ThunderInterfaces + -DEXCEPTIONS_ENABLE=ON + -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" + -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" + && + cmake --build build/ThunderInterfaces -j8 + && + cmake --install build/ThunderInterfaces + + - name: Checkout rdkservices + uses: actions/checkout@v3 + with: + path: rdkservices + + - name: Generate external headers + # Empty headers to mute errors + run: > + cd "${{github.workspace}}/rdkservices/NetworkManager/Tests/" + && + mkdir -p + headers + headers/rdk/iarmbus + headers/network + && + cd headers + && + touch + rdk/iarmbus/libIARM.h + rdk/iarmbus/libIBus.h + rdk/iarmbus/libIBusDaemon.h + network/wifiSrvMgrIarmIf.h + network/netsrvmgrIarm.h + + - name: Set clang toolchain + if: ${{ matrix.compiler == 'clang' }} + run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/NetworkManager/Tests/clang.cmake" >> $GITHUB_ENV + + - name: Set gcc/with-coverage toolchain + if: ${{ matrix.compiler == 'gcc' && matrix.coverage == 'with-coverage' && !env.ACT }} + run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/NetworkManager/Tests/gcc-with-coverage.cmake" >> $GITHUB_ENV + + - name: Build NetworkManager + run: > + cmake + -S "${{github.workspace}}/rdkservices" + -B build/rdkservices + -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 + -DEXCEPTIONS_ENABLE=ON + -I ${{github.workspace}}/rdkservices/NetworkManager/Tests/headers + -I ${{github.workspace}}/rdkservices/NetworkManager/Tests/headers/rdk/iarmbus + -I ${{github.workspace}}/rdkservices/NetworkManager/Tests/headers/network + -Wall -Werror -Wno-error=format= + -Wl,-wrap,system -Wl,-wrap,popen -Wl,-wrap,syslog" + -DCOMCAST_CONFIG=OFF + -DCMAKE_DISABLE_FIND_PACKAGE_IARMBus=ON + -DDS_FOUND=ON + -DPLUGIN_NETWORK=OFF + -DPLUGIN_WIFIMANAGER=OFF + -DPLUGIN_NETWORKMANAGER=ON + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + && + cmake --build build/rdkservices -j16 + && + cmake --install build/rdkservices diff --git a/.github/workflows/L1-PersistentStore-sqlite.yml b/.github/workflows/L1-PersistentStore-sqlite.yml deleted file mode 100644 index a414e5fbfc..0000000000 --- a/.github/workflows/L1-PersistentStore-sqlite.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: L1-PersistentStore-sqlite - -on: - push: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - pull_request: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install valgrind, coverage, cmake, sqlite - run: | - sudo apt update - sudo apt install -y valgrind lcov cmake libsqlite3-dev - - - name: Build Thunder - working-directory: ${{github.workspace}} - run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/PersistentStore/sqlite/l1test -B build/sqlitel1test -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="--coverage -Wall -Werror" - cmake --build build/sqlitel1test --target install - - - name: Run - working-directory: ${{github.workspace}} - run: PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try sqlitel1test - - - name: Generate coverage - working-directory: ${{github.workspace}} - run: | - lcov -c -o coverage.info -d build/sqlitel1test - genhtml -o coverage coverage.info - - - name: Upload artifacts - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v4 - with: - name: artifacts - path: | - coverage/ - valgrind_log - if-no-files-found: warn diff --git a/.github/workflows/L1-PersistentStore.yml b/.github/workflows/L1-PersistentStore.yml deleted file mode 100644 index 63e4ac47c2..0000000000 --- a/.github/workflows/L1-PersistentStore.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: L1-PersistentStore - -on: - push: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - pull_request: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install valgrind, coverage, cmake - run: | - sudo apt update - sudo apt install -y valgrind lcov cmake - - - name: Build Thunder - working-directory: ${{github.workspace}} - run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/PersistentStore/l1test -B build/persistentstorel1test -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="--coverage -Wall -Werror" - cmake --build build/persistentstorel1test --target install - - - name: Run - working-directory: ${{github.workspace}} - run: PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try persistentstorel1test - - - name: Generate coverage - working-directory: ${{github.workspace}} - run: | - lcov -c -o coverage.info -d build/persistentstorel1test - genhtml -o coverage coverage.info - - - name: Upload artifacts - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v4 - with: - name: artifacts - path: | - coverage/ - valgrind_log - if-no-files-found: warn diff --git a/.github/workflows/L2-CloudStore-grpc.yml b/.github/workflows/L2-CloudStore-grpc.yml deleted file mode 100644 index f03c278da6..0000000000 --- a/.github/workflows/L2-CloudStore-grpc.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: L2-CloudStore-grpc - -on: - push: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - pull_request: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install cmake, protoc, grpc_cpp_plugin, grpc - run: | - sudo apt update - sudo apt install -y cmake protobuf-compiler protobuf-compiler-grpc libgrpc++-dev - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/CloudStore/grpc/l2test -B build/grpcl2test -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="-Wall -Werror" - cmake --build build/grpcl2test --target install - -# Usage: -# Build with real token (here: "Bearer TOKEN")!!! -# PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try grpcl2test diff --git a/.github/workflows/L2-CloudStore.yml b/.github/workflows/L2-CloudStore.yml deleted file mode 100644 index 4f76c4b7fd..0000000000 --- a/.github/workflows/L2-CloudStore.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: L2-CloudStore - -on: - push: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - pull_request: - paths: - - CloudStore/** - - .github/workflows/*CloudStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install cmake, protoc, grpc_cpp_plugin, grpc - run: | - sudo apt update - sudo apt install -y cmake protobuf-compiler protobuf-compiler-grpc libgrpc++-dev - - - name: Build Thunder - working-directory: ${{github.workspace}} - run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/CloudStore -B build/CloudStore -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="-Wall -Werror" -DPLUGIN_CLOUDSTORE_MODE=Local -DPLUGIN_CLOUDSTORE_URI=ss.eu.prod.developer.comcast.com:443 - cmake --build build/CloudStore --target install - -# Usage: -# PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try Thunder -f -c ${PWD}/install/etc/Thunder/config.json -# (to stop press q & enter) -# curl -d '{"jsonrpc":"2.0","id":0,"method":"org.rdk.CloudStore.setValue","params":{"namespace":"test","key":"key1","value":"1","ttl":100}}' http://localhost:55555/jsonrpc diff --git a/.github/workflows/L2-PersistentStore.yml b/.github/workflows/L2-PersistentStore.yml deleted file mode 100644 index fd21d9356f..0000000000 --- a/.github/workflows/L2-PersistentStore.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: L2-PersistentStore - -on: - push: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - pull_request: - paths: - - PersistentStore/** - - .github/workflows/*PersistentStore*.yml - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - path: ${{github.repository}} - - - name: Install cmake, sqlite - run: | - sudo apt update - sudo apt install -y cmake libsqlite3-dev - - - name: Build Thunder - working-directory: ${{github.workspace}} - run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh - - - name: Build - working-directory: ${{github.workspace}} - run: | - cmake -S ${GITHUB_REPOSITORY}/PersistentStore -B build/PersistentStore -DCMAKE_INSTALL_PREFIX="install" -DCMAKE_CXX_FLAGS="-Wall -Werror" -DPLUGIN_PERSISTENTSTORE_PATH="/tmp/persistentstore/l2test/test" -DPLUGIN_PERSISTENTSTORE_MODE=Local - cmake --build build/PersistentStore --target install - -# Usage: -# PATH=${PWD}/install/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try Thunder -f -c ${PWD}/install/etc/Thunder/config.json -# (to stop press q & enter) -# curl -d '{"jsonrpc":"2.0","id":0,"method":"org.rdk.PersistentStore.setValue","params":{"namespace":"test","key":"key1","value":"1","ttl":100}}' http://localhost:55555/jsonrpc diff --git a/.github/workflows/L2-tests-R4-4-1.yml b/.github/workflows/L2-tests-R4-4-1.yml deleted file mode 100755 index 884845c8e1..0000000000 --- a/.github/workflows/L2-tests-R4-4-1.yml +++ /dev/null @@ -1,423 +0,0 @@ -name: L2-tests-R4-4-1 - -on: - push: - branches: [ main, 'sprint/**', 'release/**' ] - pull_request: - branches: [ main, 'sprint/**', 'release/**' ] - -env: - BUILD_TYPE: Debug - THUNDER_REF: "R4.4.1" - INTERFACES_REF: "R4.4.1" - -jobs: - L2-tests-R4-4-1: - name: Run L2 with Thunder R4.4.1 - runs-on: ubuntu-latest - strategy: - matrix: - compiler: [ gcc, clang ] - coverage: [ with-coverage, without-coverage ] - exclude: - - compiler: clang - coverage: with-coverage - - compiler: clang - coverage: without-coverage - - compiler: gcc - coverage: without-coverage - - steps: - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - run: pip install jsonref - - - name: Set up CMake - uses: jwlawson/actions-setup-cmake@v1.13 - with: - cmake-version: '3.16.x' - - - name: Install packages - run: > - sudo apt update - && - sudo apt install -y libsqlite3-dev libcurl4-openssl-dev valgrind lcov clang libsystemd-dev libboost-all-dev libwebsocketpp-dev meson libcunit1 libcunit1-dev protobuf-compiler protobuf-compiler-grpc libgrpc-dev libgrpc++-dev - - - name: Install GStreamer - run: | - sudo apt update - sudo apt install -y libunwind-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev - - - name: Build trevor-base64 - run: | - if [ ! -d "trower-base64" ]; then - git clone https://github.com/xmidt-org/trower-base64.git - fi - cd trower-base64 - meson setup --warnlevel 3 --werror build - ninja -C build - sudo ninja -C build install - - - name: Checkout Thunder - uses: actions/checkout@v3 - with: - repository: rdkcentral/Thunder - path: Thunder - ref: ${{env.THUNDER_REF}} - - - name: Checkout ThunderTools - if: steps.cache.outputs.cache-hit != 'true' - uses: actions/checkout@v3 - with: - repository: rdkcentral/ThunderTools - path: ThunderTools - ref: ${{env.THUNDER_REF}} - - - name: Build ThunderTools - if: steps.cache.outputs.cache-hit != 'true' - run: > - cmake - -S "${{github.workspace}}/ThunderTools" - -B build/ThunderTools - -DEXCEPTIONS_ENABLE=ON - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DGENERIC_CMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - && - cmake --build build/ThunderTools -j8 - && - cmake --install build/ThunderTools - - - name: Checkout rdkservices - uses: actions/checkout@v3 - with: - path: rdkservices - - - name: Checkout rdkservices - run: | - cd ${{github.workspace}}/rdkservices - patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0003-R4.4.1-LocationSync-compilation-error.patch - patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0003-R4.4.1-SystemAudioPlayer-compilation-error.patch - cd - - - - name: Build Thunder - if: steps.cache.outputs.cache-hit != 'true' - run: > - cmake - -S "${{github.workspace}}/Thunder" - -B build/Thunder - -DMESSAGING=ON - -DHIDE_NON_EXTERNAL_SYMBOLS=OFF - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DBUILD_TYPE=${{env.BUILD_TYPE}} - -DBINDING=127.0.0.1 - -DPORT=9998 - -DEXCEPTIONS_ENABLE=ON - && - cmake --build build/Thunder -j8 - && - cmake --install build/Thunder - - - name: Checkout ThunderInterfaces - uses: actions/checkout@v3 - with: - repository: rdkcentral/ThunderInterfaces - path: ThunderInterfaces - ref: ${{env.INTERFACES_REF}} - run: rm -rf ${{github.workspace}}/ThunderInterfaces/jsonrpc/DTV.json - - - name: Apply patch ThunderInterfaces - run: | - cd ThunderInterfaces - echo "Current branch is: $(git branch --show-current)" - patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/R.4.4.1-0001-Add-TextToSpeech-Interface.patch - patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/SplitDeviceCapablities.patch - patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0007-RDK-IDeviceInfo-Changes.patch - patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0001-RDK-45037-Secure-Storage-Thunder-Plugin.patch - patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/RDKV-48604-User-Settings-Thunder-Plugin.patch - cd .. - - - name: Build ThunderInterfaces - run: > - cmake - -S "${{github.workspace}}/ThunderInterfaces" - -B build/ThunderInterfaces - -DEXCEPTIONS_ENABLE=ON - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - && - cmake --build build/ThunderInterfaces -j8 - && - cmake --install build/ThunderInterfaces - - - name: Generate external headers - # Empty headers to mute errors - run: > - cd "${{github.workspace}}/rdkservices/Tests/" - && - mkdir -p - headers - headers/rdk/ds - headers/rdk/iarmbus - headers/rdk/iarmmgrs-hal - headers/systemservices - headers/systemservices/proc - && - cd headers - && - touch - rdk/ds/host.hpp - rdk/ds/videoOutputPort.hpp - rdk/ds/audioOutputPort.hpp - rdk/ds/sleepMode.hpp - rdk/iarmbus/libIARM.h - rdk/iarmbus/libIBus.h - rdk/iarmbus/libIBusDaemon.h - rdk/iarmmgrs-hal/mfrMgr.h - rdk/iarmmgrs-hal/pwrMgr.h - rdk/iarmmgrs-hal/sysMgr.h - rfcapi.h - rbus.h - libudev.h - systemservices/proc/readproc.h - systemservices/secure_wrapper.h - maintenanceMGR.h - pkg.h - && - cp -r /usr/include/gstreamer-1.0/gst /usr/include/glib-2.0/* /usr/lib/x86_64-linux-gnu/glib-2.0/include/* /usr/local/include/trower-base64/base64.h . - - - name: Set clang toolchain - if: ${{ matrix.compiler == 'clang' }} - run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/Tests/clang.cmake" >> $GITHUB_ENV - - - name: Set gcc/with-coverage toolchain - if: ${{ matrix.compiler == 'gcc' && matrix.coverage == 'with-coverage' && !env.ACT }} - run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/Tests/gcc-with-coverage.cmake" >> $GITHUB_ENV - - - name: Build mocks - run: > - cmake - -S "${{github.workspace}}/rdkservices/Tests/mocks" - -B build/mocks - -DBUILD_SHARED_LIBS=ON - -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - && - cmake --build build/mocks -j8 - && - cmake --install build/mocks - - - name: Build rdkservices - run: > - cmake - -S "${{github.workspace}}/rdkservices" - -B build/rdkservices - -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DHIDE_NON_EXTERNAL_SYMBOLS=OFF - -DCMAKE_CXX_FLAGS=" - -DEXCEPTIONS_ENABLE=ON - -fprofile-arcs - -ftest-coverage - -DUSE_THUNDER_R4=ON - -DTHUNDER_VERSION=4 - -DTHUNDER_VERSION_MAJOR=4 - -DTHUNDER_VERSION_MINOR=4 - -DPLUGIN_PERSISTENTSTORE_PATH="/tmp/secure/persistent/rdkservicestore" - -DPLUGIN_PERSISTENTSTORE_LEGACYPATH="/tmp/persistent/rdkservicestore" - -I ${{github.workspace}}/rdkservices/Tests/headers - -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/ds - -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/iarmbus - -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/iarmmgrs-hal - -I ${{github.workspace}}/rdkservices/Tests/headers/systemservices - -I ${{github.workspace}}/rdkservices/Tests/headers/systemservices/proc - -include ${{github.workspace}}/rdkservices/Tests/mocks/devicesettings.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Iarm.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Rfc.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/RBus.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Udev.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Wraps.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/maintenanceMGR.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/pkg.h - -Werror -Wall -Wunused-variable -Wno-deprecated-declarations -Wno-error=format= - -DUSE_IARMBUS - -DENABLE_THERMAL_PROTECTION" - -DPLUGIN_PERSISTENTSTORE_PATH="/tmp/secure/persistent/rdkservicestore" - -DPLUGIN_PERSISTENTSTORE_LEGACYPATH="/tmp/persistent/rdkservicestore" - -DCOMCAST_CONFIG=OFF - -DCMAKE_DISABLE_FIND_PACKAGE_DS=ON - -DCMAKE_DISABLE_FIND_PACKAGE_IARMBus=ON - -DCMAKE_DISABLE_FIND_PACKAGE_Udev=ON - -DCMAKE_DISABLE_FIND_PACKAGE_RFC=ON - -DCMAKE_DISABLE_FIND_PACKAGE_RBus=ON - -DPLUGIN_SYSTEMSERVICES=ON - -DPLUGIN_TELEMETRY=ON - -DPLUGIN_HDCPPROFILE=ON - -DPLUGIN_NETWORK=ON - -DPLUGIN_TEXTTOSPEECH=ON - -DPLUGIN_USBACCESS=ON - -DPLUGIN_USERSETTINGS=ON - -DPLUGIN_PERSISTENTSTORE=ON - -DUSE_THUNDER_R4=ON - -DPLUGIN_L2Tests=ON - -DRDK_SERVICE_L2_TEST=ON - -DDS_FOUND=ON - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - && - cmake --build build/rdkservices -j8 - && - cmake --install build/rdkservices - - - name: Set up files - run: > - sudo mkdir -p -m 777 - /opt/persistent - /opt/secure - /opt/secure/reboot - /opt/secure/persistent - /opt/secure/persistent/System - /tmp/secure/persistent - /tmp/persistent - /tmp/persistent/rdkservicestore - /opt/logs - /lib/rdk - /run/media/sda1/logs/PreviousLogs - /run/media/sda2/logs/PreviousLogs - /run/sda1/UsbTestFWUpdate - /run/sda1/UsbProdFWUpdate - /run/media/sda1/Logs - /run/sda2 - && - sudo touch - /opt/standbyReason.txt - /opt/tmtryoptout - /opt/fwdnldstatus.txt - /opt/dcm.properties - /etc/device.properties - /etc/dcm.properties - /etc/authService.conf - /version.txt - /run/media/sda1/logs/PreviousLogs/logFile.txt - /run/media/sda1/logs/test.txt - /run/media/sda1/logs/test.png - /run/media/sda1/logs/test.docx - /run/media/sda2/logs/test.txt - /run/media/sda2/logs/test.png - /run/media/sda1/Logs/5C3400F15492_Logs_12-05-22-10-41PM.tgz - /run/sda1/HSTP11MWR_5.11p5s1_VBN_sdy.bin - /run/sda1/UsbTestFWUpdate/HSTP11MWR_3.11p5s1_VBN_sdy.bin - /run/sda1/UsbProdFWUpdate/HSTP11MWR_4.11p5s1_VBN_sdy.bin - /lib/rdk/getMaintenanceStartTime.sh - /tmp/opkg.conf - /tmp/system_service_temp.conf - /tmp/secure/persistent/rdkservicestore - && - sudo chmod -R 777 - /opt/standbyReason.txt - /opt/tmtryoptout - /opt/fwdnldstatus.txt - /opt/dcm.properties - /etc/device.properties - /etc/dcm.properties - /etc/authService.conf - /version.txt - /lib/rdk/getMaintenanceStartTime.sh - /tmp/opkg.conf - /tmp/system_service_temp.conf - /tmp/persistent/rdkservicestore - /tmp/secure/persistent/rdkservicestore - - - name: Download pact_verifier_cli - run: > - echo "Copying pact plugins" && - sudo mkdir -p ~/.pact/plugins/websockets-0.4.1 && - sudo cp "${{github.workspace}}/rdkservices/Tests/L2Tests/pact/pact-plugin-websockets" ~/.pact/plugins/websockets-0.4.1/ && - sudo cp "${{github.workspace}}/rdkservices/Tests/L2Tests/pact/pact-plugin.json" ~/.pact/plugins/websockets-0.4.1/ && - sudo chmod +x ~/.pact/plugins/websockets-0.4.1/pact-plugin-websockets && - PATH=${{github.workspace}}/install/usr/bin:${PATH} - ${{github.workspace}}/rdkservices/Tests/L2Tests/pact/install-verifier-cli.sh - - - 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} - RdkServicesL2Test && - cp -rf $(pwd)/rdkL2TestResults.json ${{github.workspace}}/rdkL2TestResultsWithoutValgrind.json && - rm -rf $(pwd)/rdkL2TestResults.json - - - name: Run unit tests with valgrind - if: ${{ !env.ACT }} - 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} - valgrind - --tool=memcheck - --log-file=valgrind_log - --leak-check=yes - --show-reachable=yes - --track-fds=yes - --fair-sched=try - RdkServicesL2Test && - cp -rf $(pwd)/rdkL2TestResults.json ${{github.workspace}}/rdkL2TestResultsWithValgrind.json && - rm -rf $(pwd)/rdkL2TestResults.json - - - name: Generate coverage - if: ${{ matrix.coverage == 'with-coverage' && !env.ACT }} - run: > - cp ${{github.workspace}}/rdkservices/Tests/L2Tests/.lcovrc_l2 ~/.lcovrc - && - lcov -c - -o coverage.info - -d build/rdkservices - && - lcov - -r coverage.info - '/usr/include/*' - '*/build/rdkservices/_deps/*' - '*/install/usr/include/*' - '*/Tests/headers/*' - '*/Tests/mocks/*' - '*/Tests/L2Tests/*' - -o filtered_coverage.info - && - genhtml - -o coverage - -t "rdkservices coverage" - filtered_coverage.info - - - name: Upload artifacts - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v3 - with: - name: artifacts - path: | - coverage/ - valgrind_log - rdkL2TestResultsWithoutValgrind.json - rdkL2TestResultsWithValgrind.json - if-no-files-found: warn - - - name: Run contract tests - if: ${{ !env.ACT }} - env: - PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }} - 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} - RdkServicesL2Test CTVerifierMain - - - name: Upload contract test results - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v3 - with: - name: Contract test results - path: | - contract-test-results.json - contract-test-statistics.txt - if-no-files-found: warn diff --git a/.github/workflows/L2-tests.yml b/.github/workflows/L2-tests.yml deleted file mode 100755 index cfbf0a70e2..0000000000 --- a/.github/workflows/L2-tests.yml +++ /dev/null @@ -1,384 +0,0 @@ -name: l2-tests - -on: - push: - branches: [ main, 'sprint/**', 'release/**' ] - pull_request: - branches: [ main, 'sprint/**', 'release/**' ] - -env: - BUILD_TYPE: Debug - THUNDER_REF: "5e7c0b1ed3c3dd0fc31c86518a364388dc24273b" - INTERFACES_REF: "669d9c6e5ed7a5938ff26e1e7736adf485c7a205" - -jobs: - l2-tests: - name: Build and run L2 tests - runs-on: ubuntu-latest - strategy: - matrix: - compiler: [ gcc, clang ] - coverage: [ with-coverage, without-coverage ] - exclude: - - compiler: clang - coverage: with-coverage - - compiler: clang - coverage: without-coverage - - compiler: gcc - coverage: without-coverage - - steps: - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - run: pip install jsonref - - - name: Set up CMake - uses: jwlawson/actions-setup-cmake@v1.13 - with: - cmake-version: '3.16.x' - - - name: Install packages - run: > - sudo apt update - && - sudo apt install -y libsqlite3-dev libcurl4-openssl-dev valgrind lcov clang libsystemd-dev libboost-all-dev libwebsocketpp-dev meson libcunit1 libcunit1-dev - - - name: Install GStreamer - run: | - sudo apt update - sudo apt install -y libunwind-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev - - - name: Build trevor-base64 - run: | - if [ ! -d "trower-base64" ]; then - git clone https://github.com/xmidt-org/trower-base64.git - fi - cd trower-base64 - meson setup --warnlevel 3 --werror build - ninja -C build - sudo ninja -C build install - - - name: Checkout Thunder - uses: actions/checkout@v3 - with: - repository: rdkcentral/Thunder - path: Thunder - ref: ${{env.THUNDER_REF}} - - - name: Checkout rdkservices - uses: actions/checkout@v3 - with: - path: rdkservices - - - name: Apply patch Thunder - run: > - cd "${{github.workspace}}/Thunder" - && - git apply "${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0001-RDK-30034-callsign.patch" - - - name: Build Thunder - run: > - cmake - -S "${{github.workspace}}/Thunder/Tools" - -B build/ThunderTools - -DEXCEPTIONS_ENABLE=ON - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DGENERIC_CMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - && - cmake --build build/ThunderTools -j8 - && - cmake --install build/ThunderTools - && - cmake - -S "${{github.workspace}}/Thunder" - -B build/Thunder - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DBUILD_TYPE=${{env.BUILD_TYPE}} - -DBINDING=127.0.0.1 - -DPORT=9998 - -DEXCEPTIONS_ENABLE=ON - && - cmake --build build/Thunder -j8 - && - cmake --install build/Thunder - - - name: Checkout ThunderInterfaces - uses: actions/checkout@v3 - with: - repository: rdkcentral/ThunderInterfaces - path: ThunderInterfaces - ref: ${{env.INTERFACES_REF}} - - - name: Apply patch ThunderInterfaces - run: > - cd "${{github.workspace}}/ThunderInterfaces" - && - git apply "${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0001-Add-TextToSpeech-Interface.patch" - - - name: Build ThunderInterfaces - run: > - cmake - -S "${{github.workspace}}/ThunderInterfaces" - -B build/ThunderInterfaces - -DEXCEPTIONS_ENABLE=ON - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - && - cmake --build build/ThunderInterfaces -j8 - && - cmake --install build/ThunderInterfaces - - - name: Generate external headers - # Empty headers to mute errors - run: > - cd "${{github.workspace}}/rdkservices/Tests/" - && - mkdir -p - headers - headers/rdk/ds - headers/rdk/iarmbus - headers/rdk/iarmmgrs-hal - headers/systemservices - headers/systemservices/proc - && - cd headers - && - touch - rdk/ds/host.hpp - rdk/ds/videoOutputPort.hpp - rdk/ds/audioOutputPort.hpp - rdk/ds/sleepMode.hpp - rdk/iarmbus/libIARM.h - rdk/iarmbus/libIBus.h - rdk/iarmbus/libIBusDaemon.h - rdk/iarmmgrs-hal/mfrMgr.h - rdk/iarmmgrs-hal/pwrMgr.h - rdk/iarmmgrs-hal/sysMgr.h - rfcapi.h - rbus.h - libudev.h - systemservices/proc/readproc.h - systemservices/secure_wrapper.h - maintenanceMGR.h - pkg.h - && - cp -r /usr/include/gstreamer-1.0/gst /usr/include/glib-2.0/* /usr/lib/x86_64-linux-gnu/glib-2.0/include/* /usr/local/include/trower-base64/base64.h . - - - name: Set clang toolchain - if: ${{ matrix.compiler == 'clang' }} - run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/Tests/clang.cmake" >> $GITHUB_ENV - - - name: Set gcc/with-coverage toolchain - if: ${{ matrix.compiler == 'gcc' && matrix.coverage == 'with-coverage' && !env.ACT }} - run: echo "TOOLCHAIN_FILE=${{github.workspace}}/rdkservices/Tests/gcc-with-coverage.cmake" >> $GITHUB_ENV - - - name: Build mocks - run: > - cmake - -S "${{github.workspace}}/rdkservices/Tests/mocks" - -B build/mocks - -DBUILD_SHARED_LIBS=ON - -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - && - cmake --build build/mocks -j8 - && - cmake --install build/mocks - - - - name: Build rdkservices - run: > - cmake - -S "${{github.workspace}}/rdkservices" - -B build/rdkservices - -DCMAKE_TOOLCHAIN_FILE="${{ env.TOOLCHAIN_FILE }}" - -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/install/usr" - -DCMAKE_MODULE_PATH="${{github.workspace}}/install/tools/cmake" - -DCMAKE_CXX_FLAGS=" - -DEXCEPTIONS_ENABLE=ON - -fprofile-arcs - -ftest-coverage - -I ${{github.workspace}}/rdkservices/Tests/headers - -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/ds - -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/iarmbus - -I ${{github.workspace}}/rdkservices/Tests/headers/rdk/iarmmgrs-hal - -I ${{github.workspace}}/rdkservices/Tests/headers/systemservices - -I ${{github.workspace}}/rdkservices/Tests/headers/systemservices/proc - -include ${{github.workspace}}/rdkservices/Tests/mocks/devicesettings.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Iarm.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Rfc.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/RBus.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Udev.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/Wraps.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/maintenanceMGR.h - -include ${{github.workspace}}/rdkservices/Tests/mocks/pkg.h - -Wall -Werror -Wno-error=format= - -DUSE_IARMBUS - -DENABLE_THERMAL_PROTECTION" - -DCOMCAST_CONFIG=OFF - -DCMAKE_DISABLE_FIND_PACKAGE_DS=ON - -DCMAKE_DISABLE_FIND_PACKAGE_IARMBus=ON - -DCMAKE_DISABLE_FIND_PACKAGE_Udev=ON - -DCMAKE_DISABLE_FIND_PACKAGE_RFC=ON - -DCMAKE_DISABLE_FIND_PACKAGE_RBus=ON - -DPLUGIN_SYSTEMSERVICES=ON - -DPLUGIN_TELEMETRY=ON - -DPLUGIN_WAREHOUSE=ON - -DPLUGIN_HDCPPROFILE=ON - -DPLUGIN_NETWORK=ON - -DPLUGIN_TEXTTOSPEECH=ON - -DPLUGIN_USBACCESS=ON - -DPLUGIN_L2Tests=ON - -DRDK_SERVICE_L2_TEST=ON - -DDS_FOUND=ON - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - && - cmake --build build/rdkservices -j8 - && - cmake --install build/rdkservices - - - name: Set up files - run: > - sudo mkdir -p -m 777 - /opt/persistent - /opt/secure - /opt/secure/reboot - /opt/secure/persistent - /opt/secure/persistent/System - /opt/logs - /lib/rdk - /run/media/sda1/logs/PreviousLogs - /run/media/sda2/logs/PreviousLogs - /run/sda1/UsbTestFWUpdate - /run/sda1/UsbProdFWUpdate - /run/sda2 - && - sudo touch - /opt/standbyReason.txt - /opt/tmtryoptout - /opt/fwdnldstatus.txt - /opt/dcm.properties - /etc/device.properties - /etc/dcm.properties - /etc/authService.conf - /version.txt - /run/media/sda1/logs/PreviousLogs/logFile.txt - /run/media/sda1/logs/test.txt - /run/media/sda1/logs/test.png - /run/media/sda1/logs/test.docx - /run/media/sda2/logs/test.txt - /run/media/sda2/logs/test.png - /run/sda1/HSTP11MWR_5.11p5s1_VBN_sdy.bin - /run/sda1/UsbTestFWUpdate/HSTP11MWR_3.11p5s1_VBN_sdy.bin - /run/sda1/UsbProdFWUpdate/HSTP11MWR_4.11p5s1_VBN_sdy.bin - /lib/rdk/getMaintenanceStartTime.sh - /tmp/opkg.conf - /tmp/system_service_temp.conf - && - sudo chmod 777 - /opt/standbyReason.txt - /opt/tmtryoptout - /opt/fwdnldstatus.txt - /opt/dcm.properties - /etc/device.properties - /etc/dcm.properties - /etc/authService.conf - /version.txt - /lib/rdk/getMaintenanceStartTime.sh - /tmp/opkg.conf - /tmp/system_service_temp.conf - - - name: Download pact_verifier_cli - run: > - echo "Copying pact plugins" && - sudo mkdir -p ~/.pact/plugins/websockets-0.4.1 && - sudo cp "${{github.workspace}}/rdkservices/Tests/L2Tests/pact/pact-plugin-websockets" ~/.pact/plugins/websockets-0.4.1/ && - sudo cp "${{github.workspace}}/rdkservices/Tests/L2Tests/pact/pact-plugin.json" ~/.pact/plugins/websockets-0.4.1/ && - sudo chmod +x ~/.pact/plugins/websockets-0.4.1/pact-plugin-websockets && - PATH=${{github.workspace}}/install/usr/bin:${PATH} - ${{github.workspace}}/rdkservices/Tests/L2Tests/pact/install-verifier-cli.sh - - - 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} - RdkServicesL2Test && - cp -rf $(pwd)/rdkL2TestResults.json ${{github.workspace}}/rdkL2TestResultsWithoutValgrind.json && - rm -rf $(pwd)/rdkL2TestResults.json - - - name: Run unit tests with valgrind - if: ${{ !env.ACT }} - 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} - valgrind - --tool=memcheck - --log-file=valgrind_log - --leak-check=yes - --show-reachable=yes - --track-fds=yes - --fair-sched=try - RdkServicesL2Test && - cp -rf $(pwd)/rdkL2TestResults.json ${{github.workspace}}/rdkL2TestResultsWithValgrind.json && - rm -rf $(pwd)/rdkL2TestResults.json - - - name: Generate coverage - if: ${{ matrix.coverage == 'with-coverage' && !env.ACT }} - run: > - cp ${{github.workspace}}/rdkservices/Tests/L2Tests/.lcovrc_l2 ~/.lcovrc - && - lcov -c - -o coverage.info - -d build/rdkservices - && - lcov - -r coverage.info - '/usr/include/*' - '*/build/rdkservices/_deps/*' - '*/install/usr/include/*' - '*/Tests/headers/*' - '*/Tests/mocks/*' - '*/Tests/L2Tests/*' - -o filtered_coverage.info - && - genhtml - -o coverage - -t "rdkservices coverage" - filtered_coverage.info - - - name: Upload artifacts - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v3 - with: - name: artifacts - path: | - coverage/ - valgrind_log - rdkL2TestResultsWithoutValgrind.json - rdkL2TestResultsWithValgrind.json - if-no-files-found: warn - - - name: Run contract tests - if: ${{ !env.ACT }} - env: - PACTFLOW_TOKEN: ${{ secrets.PACTFLOW_TOKEN }} - 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} - RdkServicesL2Test CTVerifierMain - - - name: Upload contract test results - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v3 - with: - name: Contract test results - path: | - contract-test-results.json - contract-test-statistics.txt - if-no-files-found: warn diff --git a/CMakeLists.txt b/CMakeLists.txt index 31a5f514fe..c0d693eee8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -401,6 +401,11 @@ if(PLUGIN_SHAREDSTORAGE) add_subdirectory(SharedStorage) endif() +if(PLUGIN_NETWORKMANAGER) + include(NetworkManager/l1networkmanager.cmake) + add_subdirectory(NetworkManager) +endif() + if(WPEFRAMEWORK_CREATE_IPKG_TARGETS) set(CPACK_GENERATOR "DEB") set(CPACK_DEB_COMPONENT_INSTALL ON) diff --git a/NetworkManager/CMakeLists.txt b/NetworkManager/CMakeLists.txt index f3ef6ea5ff..9aef165fc1 100644 --- a/NetworkManager/CMakeLists.txt +++ b/NetworkManager/CMakeLists.txt @@ -32,7 +32,7 @@ if(ENABLE_GNOME_NETWORKMANAGER) pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(LIBNM REQUIRED libnm) else() -find_package(IARMBus REQUIRED) +find_package(IARMBus) # REQUIRED removed to workflow work endif () diff --git a/NetworkManager/NetworkManagerRDKProxy.cpp b/NetworkManager/NetworkManagerRDKProxy.cpp index 5741ddb0bf..23f3a40fb4 100644 --- a/NetworkManager/NetworkManagerRDKProxy.cpp +++ b/NetworkManager/NetworkManagerRDKProxy.cpp @@ -538,7 +538,6 @@ namespace WPEFramework } void NetworkManagerImplementation::threadEventRegistration() { - IARM_Result_t res = IARM_RESULT_SUCCESS; IARM_Result_t retVal = IARM_RESULT_SUCCESS; do { @@ -1214,38 +1213,38 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { signalStrength = ssidInfo.m_signalStrength; if (!signalStrength.empty()) - { + { signalStrengthOut = std::stof(signalStrength.c_str()); - NMLOG_INFO ("WiFiSignalStrength in dB = %s",signalStrengthOut); - } + NMLOG_INFO ("WiFiSignalStrength in dB = %f",signalStrengthOut); + } if (signalStrengthOut == 0) - { - quality = WIFI_SIGNAL_DISCONNECTED; - signalStrength = "0"; - } - else if (signalStrengthOut >= signalStrengthThresholdExcellent && signalStrengthOut < 0) - { - quality = WIFI_SIGNAL_EXCELLENT; - signalStrength = "100"; - } - else if (signalStrengthOut >= signalStrengthThresholdGood && signalStrengthOut < signalStrengthThresholdExcellent) - { - quality = WIFI_SIGNAL_GOOD; - signalStrength = "75"; - } - else if (signalStrengthOut >= signalStrengthThresholdFair && signalStrengthOut < signalStrengthThresholdGood) - { - quality = WIFI_SIGNAL_FAIR; - signalStrength = "50"; - } - else - { - quality = WIFI_SIGNAL_WEAK; - signalStrength = "25"; - } + { + quality = WIFI_SIGNAL_DISCONNECTED; + signalStrength = "0"; + } + else if (signalStrengthOut >= signalStrengthThresholdExcellent && signalStrengthOut < 0) + { + quality = WIFI_SIGNAL_EXCELLENT; + signalStrength = "100"; + } + else if (signalStrengthOut >= signalStrengthThresholdGood && signalStrengthOut < signalStrengthThresholdExcellent) + { + quality = WIFI_SIGNAL_GOOD; + signalStrength = "75"; + } + else if (signalStrengthOut >= signalStrengthThresholdFair && signalStrengthOut < signalStrengthThresholdGood) + { + quality = WIFI_SIGNAL_FAIR; + signalStrength = "50"; + } + else + { + quality = WIFI_SIGNAL_WEAK; + signalStrength = "25"; + } - NMLOG_INFO ("GetWiFiSignalStrength success"); + NMLOG_TRACE ("GetWiFiSignalStrength success"); rc = Core::ERROR_NONE; } else @@ -1311,7 +1310,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { { LOG_ENTRY_FUNCTION(); uint32_t rc = Core::ERROR_RPC_CALL_FAILED; - IARM_Result_t retVal = IARM_RESULT_SUCCESS; + IARM_Bus_WiFiSrvMgr_Param_t param; memset(¶m, 0, sizeof(param)); diff --git a/NetworkManager/Tests/.clang-format b/NetworkManager/Tests/.clang-format new file mode 100644 index 0000000000..423360be10 --- /dev/null +++ b/NetworkManager/Tests/.clang-format @@ -0,0 +1,108 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: WebKit +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeCategories: + - Regex: '^"config\.h"' + Priority: -1 + # The main header for a source file automatically gets category 0 + - Regex: '.*' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... diff --git a/NetworkManager/Tests/L1Tests/.lcovrc_l1 b/NetworkManager/Tests/L1Tests/.lcovrc_l1 new file mode 100644 index 0000000000..879fe2ce58 --- /dev/null +++ b/NetworkManager/Tests/L1Tests/.lcovrc_l1 @@ -0,0 +1,181 @@ +# +# /etc/lcovrc - system-wide defaults for LCOV +# +# To change settings for a single user, place a customized copy of this file +# at location ~/.lcovrc +# + +# Specify an external style sheet file (same as --css-file option of genhtml) +#genhtml_css_file = gcov.css + +# Specify coverage rate limits (in %) for classifying file entries +# HI: hi_limit <= rate <= 100 graph color: green +# MED: med_limit <= rate < hi_limit graph color: orange +# LO: 0 <= rate < med_limit graph color: red +genhtml_hi_limit = 75 +genhtml_med_limit = 50 + +# Width of line coverage field in source code view +genhtml_line_field_width = 12 + +# Width of branch coverage field in source code view +genhtml_branch_field_width = 16 + +# Width of overview image (used by --frames option of genhtml) +genhtml_overview_width = 80 + +# Resolution of overview navigation: this number specifies the maximum +# difference in lines between the position a user selected from the overview +# and the position the source code window is scrolled to (used by --frames +# option of genhtml) +genhtml_nav_resolution = 4 + +# Clicking a line in the overview image should show the source code view at +# a position a bit further up so that the requested line is not the first +# line in the window. This number specifies that offset in lines (used by +# --frames option of genhtml) +genhtml_nav_offset = 10 + +# Do not remove unused test descriptions if non-zero (same as +# --keep-descriptions option of genhtml) +genhtml_keep_descriptions = 0 + +# Do not remove prefix from directory names if non-zero (same as --no-prefix +# option of genhtml) +genhtml_no_prefix = 0 + +# Do not create source code view if non-zero (same as --no-source option of +# genhtml) +genhtml_no_source = 0 + +# Replace tabs with number of spaces in source view (same as --num-spaces +# option of genhtml) +genhtml_num_spaces = 8 + +# Highlight lines with converted-only data if non-zero (same as --highlight +# option of genhtml) +genhtml_highlight = 0 + +# Include color legend in HTML output if non-zero (same as --legend option of +# genhtml) +genhtml_legend = 0 + +# Use FILE as HTML prolog for generated pages (same as --html-prolog option of +# genhtml) +#genhtml_html_prolog = FILE + +# Use FILE as HTML epilog for generated pages (same as --html-epilog option of +# genhtml) +#genhtml_html_epilog = FILE + +# Use custom filename extension for pages (same as --html-extension option of +# genhtml) +#genhtml_html_extension = html + +# Compress all generated html files with gzip. +#genhtml_html_gzip = 1 + +# Include sorted overview pages (can be disabled by the --no-sort option of +# genhtml) +genhtml_sort = 1 + +# Include function coverage data display (can be disabled by the +# --no-func-coverage option of genhtml) +#genhtml_function_coverage = 1 + +# Include branch coverage data display (can be disabled by the +# --no-branch-coverage option of genhtml) +#genhtml_branch_coverage = 1 + +# Specify the character set of all generated HTML pages +genhtml_charset=UTF-8 + +# Allow HTML markup in test case description text if non-zero +genhtml_desc_html=0 + +# Specify the precision for coverage rates +#genhtml_precision=1 + +# Show missed counts instead of hit counts +#genhtml_missed=1 + +# Demangle C++ symbols +#genhtml_demangle_cpp=1 + +# Name of the tool used for demangling C++ function names +#genhtml_demangle_cpp_tool = c++filt + +# Specify extra parameters to be passed to the demangling tool +#genhtml_demangle_cpp_params = "" + +# Location of the gcov tool (same as --gcov-info option of geninfo) +#geninfo_gcov_tool = gcov + +# Adjust test names to include operating system information if non-zero +#geninfo_adjust_testname = 0 + +# Calculate checksum for each source code line if non-zero (same as --checksum +# option of geninfo if non-zero, same as --no-checksum if zero) +#geninfo_checksum = 1 + +# Specify whether to capture coverage data for external source files (can +# be overridden by the --external and --no-external options of geninfo/lcov) +#geninfo_external = 1 + +# Enable libtool compatibility mode if non-zero (same as --compat-libtool option +# of geninfo if non-zero, same as --no-compat-libtool if zero) +#geninfo_compat_libtool = 0 + +# Use gcov's --all-blocks option if non-zero +#geninfo_gcov_all_blocks = 1 + +# Specify compatiblity modes (same as --compat option of geninfo). +#geninfo_compat = libtool=on, hammer=auto, split_crc=auto + +# Adjust path to source files by removing or changing path components that +# match the specified pattern (Perl regular expression format) +#geninfo_adjust_src_path = /tmp/build => /usr/src + +# Specify if geninfo should try to automatically determine the base-directory +# when collecting coverage data. +geninfo_auto_base = 1 + +# Use gcov intermediate format? Valid values are 0, 1, auto +geninfo_intermediate = auto + +# Specify if exception branches should be excluded from branch coverage. +geninfo_no_exception_branch = 0 + +# Directory containing gcov kernel files +# lcov_gcov_dir = /proc/gcov + +# Location of the insmod tool +lcov_insmod_tool = /sbin/insmod + +# Location of the modprobe tool +lcov_modprobe_tool = /sbin/modprobe + +# Location of the rmmod tool +lcov_rmmod_tool = /sbin/rmmod + +# Location for temporary directories +lcov_tmp_dir = /tmp + +# Show full paths during list operation if non-zero (same as --list-full-path +# option of lcov) +lcov_list_full_path = 0 + +# Specify the maximum width for list output. This value is ignored when +# lcov_list_full_path is non-zero. +lcov_list_width = 80 + +# Specify the maximum percentage of file names which may be truncated when +# choosing a directory prefix in list output. This value is ignored when +# lcov_list_full_path is non-zero. +lcov_list_truncate_max = 20 + +# Specify if function coverage data should be collected and processed. +lcov_function_coverage = 1 + +# Specify if branch coverage data should be collected and processed. +lcov_branch_coverage = 0 diff --git a/NetworkManager/Tests/L1Tests/CMakeLists.txt b/NetworkManager/Tests/L1Tests/CMakeLists.txt new file mode 100755 index 0000000000..453d624de0 --- /dev/null +++ b/NetworkManager/Tests/L1Tests/CMakeLists.txt @@ -0,0 +1,68 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2020 RDK Management +# +# 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. + +cmake_minimum_required(VERSION 3.8) +project(RdkServicesL1Test) + +set(CMAKE_CXX_STANDARD 11) + +find_package(${NAMESPACE}Plugins REQUIRED) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip +) +FetchContent_MakeAvailable(googletest) +file(GLOB TESTS tests/*.cpp) +add_executable(${PROJECT_NAME} + ${TESTS} + ../mocks/Iarm.cpp + ../mocks/Udev.cpp + ../mocks/thunder/Module.cpp + ../mocks/Wraps.cpp + ) + +set_source_files_properties( + tests/test_Network.cpp + PROPERTIES COMPILE_FLAGS "-fexceptions") + +include_directories( + ../../Network + ../../WifiManager + ) +link_directories( + ../../Network + ../../WifiManager + ) + +target_link_libraries(${PROJECT_NAME} + gmock_main + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}Network + ${NAMESPACE}WifiManager + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + ../mocks + ../mocks/thunder + ) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/NetworkManager/Tests/L1Tests/README.md b/NetworkManager/Tests/L1Tests/README.md new file mode 100755 index 0000000000..551d048414 --- /dev/null +++ b/NetworkManager/Tests/L1Tests/README.md @@ -0,0 +1,66 @@ +# Unit Tests # + +## How to run locally ## + +Install [act](https://github.com/nektos/act) and docker: + +##### Ubuntu ##### + +```shell script +curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash +sudo apt update +sudo apt -y install docker.io +``` + +##### macOS ##### + +```shell script +brew install act +brew install --cask docker +``` + +Create a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). + +Invoke the workflow: + +```shell script +act -W .github/workflows/l1-tests.yml -s GITHUB_TOKEN=[token] +``` + +`-r, --reuse` to reuse the container. + +Get a bash shell in the container, if needed: + +```shell script +docker ps +docker exec -it /bin/bash +``` + +## FAQ ## + +1. The commands to build and run tests are in [l1-tests.yml](../.github/workflows/l1-tests.yml). + For the queries on syntax please refer to the [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions). + +2. External dependencies need to be mocked. + For each external header, add one into the [l1tests.cmake](../l1tests.cmake) (preserve the original path parts, if needed). + For each external declaration, add one into the [mocks folder](./mocks). + For the queries on mocks please refer to the [gMock Cookbook](http://google.github.io/googletest/gmock_cook_book.html). + +3. For the queries on how to write tests please refer to the [GoogleTest User’s Guide](https://google.github.io/googletest/). + Common recommendations: + - Tests should be fast. + - Tests should be independent and repeatable. + - Find the smallest piece of logic you can test, isolate it from other parts. + - Use One-Assert-per-Test and Arrange-Act-Assert patterns. + If two or more tests operate on similar data, use a test fixture. + - Having more constraints than necessary is bad. + If a test over-specifies, it doesn’t leave enough freedom to the implementation. + Use `ON_CALL` by default, and only use `EXPECT_CALL` when intend to verify that the call is made. + +4. Before review: + - Enable [ClangFormat](./.clang-format) and make sure the tests code is formatted. + - Make sure the code builds without warnings. + - At the bottom of the workflow summary page on GitHub, there is a section with artifacts. + Artifacts include coverage report and valgrind log. + They help to understand how much code is covered by tests and whether there are memory leaks. + Make sure you check both. \ No newline at end of file diff --git a/NetworkManager/Tests/L1Tests/tests/test_Network.cpp b/NetworkManager/Tests/L1Tests/tests/test_Network.cpp new file mode 100755 index 0000000000..9db8a1fc8e --- /dev/null +++ b/NetworkManager/Tests/L1Tests/tests/test_Network.cpp @@ -0,0 +1,1411 @@ +#include +#include +#include +#include "Network.h" +#include "NetworkConnectivity.h" + +#include "FactoriesImplementation.h" +#include "ServiceMock.h" +#include "IarmBusMock.h" +#include "WrapsMock.h" + +using namespace std; +using namespace WPEFramework; + +using ::testing::NiceMock; + +extern "C" FILE* __real_popen(const char* command, const char* type); + +class NetworkTestBase : public ::testing::Test { +public: + + WrapsImplMock *p_wrapsImplMock = nullptr ; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + + NetworkTestBase() + { + p_wrapsImplMock = new NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + + ofstream file("/etc/device.properties"); + file << "DEVICE_TYPE=mediaclient\n"; + file << "WIFI_SUPPORT=true\n"; + file << "MOCA_INTERFACE=true\n"; + file <<"WIFI_INTERFACE==wlan0\n"; + file <<"MOCA_INTERFACE=eth0\n"; + file <<"ETHERNET_INTERFACE=eth0\n"; + file.close(); + + ON_CALL(*p_wrapsImplMock, popen(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* command, const char* type) -> FILE* { + return __real_popen(command, type); + })); + } +}; + +class NetworkTest : public NetworkTestBase { +protected: + + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + Core::JSONRPC::Connection connection; + string response; + + Core::JSONRPC::Message message; + ServiceMock service; + + NetworkTest() : plugin(Core::ProxyType::Create()), + handler(*plugin), + connection(1, 0) + { + IARM_EventHandler_t interfaceEnabled; + IARM_EventHandler_t interfaceConnection; + IARM_EventHandler_t interfaceIpaddress; + IARM_EventHandler_t defaultInterface; + + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call_with_IPCTimeout) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen, int timeout) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isAvailable))); + return IARM_RESULT_SUCCESS; + }); + + ON_CALL(*p_iarmBusImplMock, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) { + if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS)) { + interfaceEnabled = handler; + } + if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS)) { + interfaceConnection = handler; + } + if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS)) { + interfaceIpaddress = handler; + } + if ((string(IARM_BUS_NM_SRV_MGR_NAME) == string(ownerName)) && (eventId == IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE)) { + defaultInterface = handler; + } + return IARM_RESULT_SUCCESS; + })); + + EXPECT_EQ(string(""), plugin->Initialize(&service)); + } + + virtual ~NetworkTest() override + { + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + } +}; + +class NetworkInitializedEventTest : public NetworkTest { +protected: + FactoriesImplementation factoriesImplementation; + PluginHost::IDispatcher* dispatcher; + + + NetworkInitializedEventTest() + : NetworkTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PluginHost::IDispatcher::ID)); + dispatcher->Activate(&service); + } + + virtual ~NetworkInitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + PluginHost::IFactories::Assign(nullptr); + + } +}; + +TEST_F(NetworkTest, RegisteredMethods) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getStbIp"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getInterfaces"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isInterfaceEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setInterfaceEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getDefaultInterface"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getIPSettings"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isConnectedToInternet"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getInternetConnectionState"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPublicIP"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSTBIPFamily"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setConnectivityTestEndpoints"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getCaptivePortalURI"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startConnectivityMonitoring"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("stopConnectivityMonitoring"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setDefaultInterface"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setIPSettings"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("trace"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("traceNamedEndpoint"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getNamedEndpoints"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("pingNamedEndpoint"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("ping"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getQuirks"))); +} + +TEST_F(NetworkTest, getStbIp) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + memcpy(¶m->activeIfaceIpaddr, "192.168.1.101", sizeof("192.168.1.101")); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T("192.168.1.101"))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ip\":\"192.168.1.101\",\"success\":true}")); +} + +TEST_F(NetworkTest, getStbIp_cache) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + memcpy(¶m->activeIfaceIpaddr, "192.168.1.101", sizeof("192.168.1.101")); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T("192.168.1.101"))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ip\":\"192.168.1.101\",\"success\":true}")); + +} + +TEST_F(NetworkTest, getNullStbIp) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T(""))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ip\":\"\",\"success\":true}")); +} + +TEST_F(NetworkTest, getFailedStbIp) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getSTBip))); + + auto param = static_cast(arg); + EXPECT_EQ(string(param->activeIfaceIpaddr), string(_T(""))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getStbIp"), _T("{}"), response)); + +} + +TEST_F(NetworkTest, getInterfaces) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getInterfaceList))); + auto param = static_cast(arg); + + param->size = 1; + memcpy(¶m->interfaces[0].name, "eth0", sizeof("eth0")); + memcpy(¶m->interfaces[0].mac, "AA:AA:AA:AA:AA:AA", sizeof("AA:AA:AA:AA:AA:AA")); + param->interfaces[0].flags = 69699; + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInterfaces"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"macAddress\":\"AA:AA:AA:AA:AA:AA\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"enabled\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"connected\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getInterfacesFailed) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getInterfaceList))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getInterfaces"), _T("{}"), response)); +} + +TEST_F(NetworkTest, isInterfaceEnabled) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"ETHERNET\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"enabled\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, isInterfaceEnabled_failed) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"ETHERNET\"}"), response)); +} + +TEST_F(NetworkTest, getDefaultInterface) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getDefaultInterface_cache) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, isInterfaceEnabled_WrongIface) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"TEST\"}"), response)); +} + +TEST_F(NetworkTest, isInterfaceEnabled_Fail) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_isInterfaceEnabled))); + auto param = static_cast(arg); + + memcpy(¶m->setInterface, "ETHERNET", sizeof("ETHERNET")); + param->isInterfaceEnabled = true; + + EXPECT_EQ(string(param->setInterface), string(_T("ETHERNET"))); + EXPECT_EQ(param->isInterfaceEnabled, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("isInterfaceEnabled"), _T("{\"interface\": \"TEST\"}"), response)); +} + +TEST_F(NetworkTest, getIPSettings) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV4\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getIP6Settings) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV6", sizeof("IPV6")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV6"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV6\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV6\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getIPSettings_wifi) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "WIFI", sizeof("WIFI")); + memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("WIFI"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"WIFI\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"WIFI\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV4\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + +} + +TEST_F(NetworkTest, getIP6Settings_wifi) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "WIFI", sizeof("WIFI")); + memcpy(¶m->ipversion, "IPV6", sizeof("IPV6")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("WIFI"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV6"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"WIFI\",\"ipversion\": \"IPV6\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"WIFI\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipversion\":\"IPV6\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"autoconfig\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ipaddr\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"netmask\":\"255.255.255.0\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"gateway\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"primarydns\":\"192.168.1.1\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"secondarydns\":\"192.168.1.2\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + +} + +TEST_F(NetworkTest, getIPSettings_Failed) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); +} + +TEST_F(NetworkTest, getIPSettings_WrongIface) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"TEST\",\"ipversion\": \"IPV4\"}"), response)); +} + +TEST_F(NetworkTest, getPublicIP) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getPublicIP))); + auto param = static_cast(arg); + memcpy(¶m->public_ip, "69.136.49.95", sizeof("69.136.49.95")); + + EXPECT_EQ(string(param->public_ip), string(_T("69.136.49.95"))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPublicIP"), _T("{\"iface\": \"WIFI\", \"ipv6\": false}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"public_ip\":\"69.136.49.95\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, setInterfaceEnabled) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setInterfaceEnabled"), _T("{\"interface\": \"WIFI\", \"enabled\": true, \"persist\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setInterfaceEnabled_Failed) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setInterfaceEnabled"), _T("{\"interface\": \"WIFI\", \"enabled\": true, \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, setInterfaceEnabled_WrongIface) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setInterfaceEnabled"), _T("{\"interface\": \"TEST\", \"enabled\": true, \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, getSTBIPFamily) +{ + + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSTBIPFamily"), _T("{\"family\": \"AF_INET\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ip\":\"192.168.1.101\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(NetworkTest, getSTBIPFamily_Error) +{ + + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getSTBIPFamily"), _T("{\"test\": \"AF_INET\"}"), response)); +} + +TEST_F(NetworkTest, getSTBIPFamily_Failed) +{ + + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getIPSettings))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "ETHERNET", sizeof("ETHERNET")); + memcpy(¶m->ipversion, "IPV4", sizeof("IPV4")); + param->autoconfig = true; + memcpy(¶m->ipaddress, "192.168.1.101", sizeof("192.168.1.101")); + memcpy(¶m->netmask, "255.255.255.0", sizeof("255.255.255.0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->primarydns, "192.168.1.1", sizeof("192.168.1.1")); + memcpy(¶m->secondarydns, "192.168.1.2", sizeof("192.168.1.2")); + + EXPECT_EQ(string(param->interface), string(_T("ETHERNET"))); + EXPECT_EQ(string(param->ipversion), string(_T("IPV4"))); + EXPECT_EQ(string(param->ipaddress), string(_T("192.168.1.101"))); + EXPECT_EQ(string(param->netmask), string(_T("255.255.255.0"))); + EXPECT_EQ(string(param->gateway), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->primarydns), string(_T("192.168.1.1"))); + EXPECT_EQ(string(param->secondarydns), string(_T("192.168.1.2"))); + EXPECT_EQ(param->autoconfig, true); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getIPSettings"), _T("{\"interface\": \"ETHERNET\",\"ipversion\": \"IPV4\"}"), response)); +} + +TEST_F(NetworkTest, setDefaultInterface) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setDefaultInterface))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setDefaultInterface"), _T("{\"interface\": \"WIFI\", \"persist\": true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setDefaultInterface_WrongIface) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setDefaultInterface))); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setDefaultInterface"), _T("{\"interface\": \"TEST\", \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, setDefaultInterface_failed) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setDefaultInterface))); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("setDefaultInterface"), _T("{\"interface\": \"TEST\", \"persist\": true}"), response)); +} + +TEST_F(NetworkTest, setIPSettings) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setIPSettings))); + + auto param = static_cast(arg); + param->isSupported = true; + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setIPSettings"), _T("{\"interface\": \"WIFI\", \"ipversion\": \"IPV4\",\"autoconfig\": true,\"ipaddr\": \"192.168.1.101\",\"netmask\": \"255.255.255.0\",\"gateway\": \"192.168.1.1\",\"primarydns\": \"192.168.1.1\",\"secondarydns\": \"192.168.1.2\"}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"supported\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + + + +//TEST_F(NetworkTest, trace) +//{ +// EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) +// .Times(::testing::AnyNumber()) +// .WillRepeatedly( +// [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { +// EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("trace"), _T("{\"endpoint\":\"45.57.221.20\", \"packets\":5}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +//} +// +TEST_F(NetworkTest, trace_fail) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("trace"), _T("{\"endpoint\":\"45.57.221.20\", \"packets\":5}"), response)); +} + +TEST_F(NetworkTest, trace_noiface) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("trace"), _T("{\"test\":\"45.57.221.20\", \"packets\":5}"), response)); +} + +//TEST_F(NetworkTest, traceNamedEndpoint) +//{ +// EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) +// .Times(::testing::AnyNumber()) +// .WillRepeatedly( +// [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { +// EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("traceNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +//} + +TEST_F(NetworkTest, traceNamedEndpoint_noendoint) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("traceNamedEndpoint"), _T("{\"test\": \"CMTS\", \"packets\": 5}"), response)); +} + +TEST_F(NetworkTest, traceNamedEndpoint_fail) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "45.57.221.20", sizeof("45.57.221.20")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("traceNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5}"), response)); +} + +TEST_F(NetworkTest, getNamedEndpoints) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getNamedEndpoints"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"endpoints\":[\"CMTS\"],\"success\":true}")); +} + +//TEST_F(NetworkTest, pingNamedEndpoint) +//{ +// EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) +// .Times(::testing::AnyNumber()) +// .WillRepeatedly( +// [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { +// EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "127.0.0.1", sizeof("127.0.0.1")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("pingNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5, \"guid\": \"...\"}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"target\":\"127.0.0.1\""))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsTransmitted\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsReceived\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetLoss\":\" 0\""))); +//} + +TEST_F(NetworkTest, pingNamedEndpoint_noarg) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "127.0.0.1", sizeof("127.0.0.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("pingNamedEndpoint"), _T("{\"test\": \"CMTS\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, pingNamedEndpoint_fail) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "127.0.0.1", sizeof("127.0.0.1")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("pingNamedEndpoint"), _T("{\"endpointName\": \"CMTS\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +//TEST_F(NetworkTest, ping) +//{ +// EXPECT_CALL(iarmBusImplMock, IARM_Bus_Call) +// .Times(::testing::AnyNumber()) +// .WillRepeatedly( +// [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { +// EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); +// EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); +// +// auto param = static_cast(arg); +// memcpy(¶m->interface, "eth0", sizeof("eth0")); +// memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); +// +// return IARM_RESULT_SUCCESS; +// }); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); +// EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("ping"), _T("{\"endpoint\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"target\":\"127.0.0.1\""))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsTransmitted\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetsReceived\":5"))); +// EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"packetLoss\":\" 0\""))); +//} + +TEST_F(NetworkTest, ping_noendpoint) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getDefaultInterface"), _T("{}"), response)); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("ping"), _T("{\"test\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, ping_fail) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("ping"), _T("{\"endpoint\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, ping_fail1) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getDefaultInterface))); + + auto param = static_cast(arg); + memcpy(¶m->interface, "eth0", sizeof("eth0")); + memcpy(¶m->gateway, "192.168.1.1", sizeof("192.168.1.1")); + + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("ping"), _T("{\"test\": \"127.0.0.1\", \"packets\": 5, \"guid\": \"...\"}"), response)); +} + +TEST_F(NetworkTest, getQuirks) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getQuirks"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"quirks\":[\"RDK-20093\"],\"success\":true}")); +} + +TEST_F(NetworkTest, getInternetConnectionState) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"success\":true}")); +} + +TEST_F(NetworkTest, getInternetConnectionState_cache) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInternetConnectionState"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"state\":0,\"ipversion\":\"IPV4\",\"success\":true}")); +} + + +TEST_F(NetworkTest, isConnectedToInternet) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"success\":true}")); +} + +TEST_F(NetworkTest, isConnectedToInternet_cache) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV6\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV6\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{\"ipversion\": \"IPV4\"}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"ipversion\":\"IPV4\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isConnectedToInternet"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"connectedToInternet\":false,\"success\":true}")); +} + +TEST_F(NetworkTest, getCaptivePortalURI) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getCaptivePortalURI"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"URI\":\"\",\"success\":true}")); +} + +TEST_F(NetworkInitializedEventTest, ConnectivityMonitoring) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + Core::Event onInternetStatusChange(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInternetStatusChange\",\"params\":{\"state\":0,\"status\":\"NO_INTERNET\"}}"))); + onInternetStatusChange.SetEvent(); + return Core::ERROR_NONE; + })); + + handler.Subscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startConnectivityMonitoring"), _T("{\"interval\":6}"), response)); + EXPECT_EQ(Core::ERROR_NONE, onInternetStatusChange.Lock()); + handler.Unsubscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + EXPECT_NE(Core::ERROR_GENERAL, handler.Invoke(connection, _T("stopConnectivityMonitoring"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setConnectivityTestEndpoints) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://clients3.google.com/generate_204\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkTest, setStunEndPoint) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setStunEndPoint"), _T("{}"), response)); + //EXPECT_EQ(response, string("{\"quirks\":[\"RDK-20093\"],\"success\":true}")); +} + +TEST_F(NetworkTest, configurePNI) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_configurePNI))); + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("configurePNI"), _T("{}"), response)); +} + +TEST_F(NetworkTest, configurePNI_fail) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_configurePNI))); + return IARM_RESULT_IPCCORE_FAIL; + }); + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("configurePNI"), _T("{}"), response)); +} + +TEST_F(NetworkInitializedEventTest, onInterfaceStatusChanged) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_getInterfaceList))); + auto param = static_cast(arg); + + param->size = 1; + memcpy(¶m->interfaces[0].name, "eth0", sizeof("eth0")); + memcpy(¶m->interfaces[0].mac, "AA:AA:AA:AA:AA:AA", sizeof("AA:AA:AA:AA:AA:AA")); + param->interfaces[0].flags = 69699; + + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInterfaces"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"macAddress\":\"AA:AA:AA:AA:AA:AA\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"enabled\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"connected\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInterfaceStatusChanged\",\"params\":{\"interface\":\"ETHERNET\",\"enabled\":true}}"))); + return Core::ERROR_NONE; + })); + IARM_BUS_NetSrvMgr_Iface_EventInterfaceEnabledStatus_t intData; + intData.status = 1; + strcpy(intData.interface,"eth0"); + handler.Subscribe(0, _T("onInterfaceStatusChanged"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS, static_cast(&intData), sizeof(intData)); + handler.Unsubscribe(0, _T("onInterfaceStatusChanged"), _T("org.rdk.Network"), message); +} + +TEST_F(NetworkInitializedEventTest, onConnectionStatusChanged) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setConnectivityTestEndpoints"), _T("{\"endpoints\": [\"http://localhost:8000\"]}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + Core::Event onInternetStatusChange(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(2) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onConnectionStatusChanged\",\"params\":{\"interface\":\"ETHERNET\",\"status\":\"CONNECTED\"}}"))); + return Core::ERROR_NONE; + })) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInternetStatusChange\",\"params\":{\"state\":0,\"status\":\"NO_INTERNET\"}}"))); + onInternetStatusChange.SetEvent(); + return Core::ERROR_NONE; + })); + + IARM_BUS_NetSrvMgr_Iface_EventInterfaceConnectionStatus_t intData; + intData.status = 1; + strcpy(intData.interface,"eth0"); + handler.Subscribe(0, _T("onConnectionStatusChanged"), _T("org.rdk.Network"), message); + handler.Subscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS, static_cast(&intData), sizeof(intData)); + handler.Unsubscribe(0, _T("onConnectionStatusChanged"), _T("org.rdk.Network"), message); + EXPECT_EQ(Core::ERROR_NONE, onInternetStatusChange.Lock()); + handler.Unsubscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + EXPECT_NE(Core::ERROR_GENERAL, handler.Invoke(connection, _T("stopConnectivityMonitoring"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(NetworkInitializedEventTest, onIPAddressStatusChanged) +{ + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onIPAddressStatusChanged\",\"params\":{\"interface\":\"ETHERNET\",\"ip4Address\":\"192.168.1.10\",\"status\":\"ACQUIRED\"}}"))); + return Core::ERROR_NONE; + })); + IARM_BUS_NetSrvMgr_Iface_EventInterfaceIPAddress_t intData; + intData.is_ipv6 = 0; + strcpy(intData.interface,"eth0"); + intData.acquired = 1; + strcpy(intData.ip_address,"192.168.1.10"); + handler.Subscribe(0, _T("onIPAddressStatusChanged"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS, static_cast(&intData), sizeof(intData)); + handler.Unsubscribe(0, _T("onIPAddressStatusChanged"), _T("org.rdk.Network"), message); +} + +TEST_F(NetworkInitializedEventTest, onDefaultInterfaceChanged) +{ +/* + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInterfaces"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"interface\":\"ETHERNET\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"macAddress\":\"AA:AA:AA:AA:AA:AA\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"enabled\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"connected\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +*/ + Core::Event onDefaultInterfaceChanged(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onDefaultInterfaceChanged\",\"params\":{\"oldInterfaceName\":\"\",\"newInterfaceName\":\"ETHERNET\"}}"))); + onDefaultInterfaceChanged.SetEvent(); + return Core::ERROR_NONE; + })); + IARM_BUS_NetSrvMgr_Iface_EventDefaultInterface_t intData; + strcpy(intData.newInterface,"eth0"); + handler.Subscribe(0, _T("onDefaultInterfaceChanged"), _T("org.rdk.Network"), message); + plugin->eventHandler("NET_SRV_MGR", IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE, static_cast(&intData), sizeof(intData)); + EXPECT_EQ(Core::ERROR_NONE, onDefaultInterfaceChanged.Lock()); + handler.Unsubscribe(0, _T("onDefaultInterfaceChanged"), _T("org.rdk.Network"), message); +} + +TEST_F(NetworkInitializedEventTest, onInternetStatusChange) +{ + Core::Event onInternetStatusChange(false, true); + EXPECT_CALL(service, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.Network.onInternetStatusChange\",\"params\":{\"state\":0,\"status\":\"NO_INTERNET\"}}"))); + onInternetStatusChange.SetEvent(); + return Core::ERROR_NONE; + })); + nsm_internetState intData = NO_INTERNET; + handler.Subscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); + plugin->notifyInternetStatusChange(intData); + EXPECT_EQ(Core::ERROR_NONE, onInternetStatusChange.Lock()); + handler.Unsubscribe(0, _T("onInternetStatusChange"), _T("org.rdk.Network"), message); +} diff --git a/NetworkManager/Tests/L1Tests/tests/test_WifiManager.cpp b/NetworkManager/Tests/L1Tests/tests/test_WifiManager.cpp new file mode 100755 index 0000000000..99b8e54616 --- /dev/null +++ b/NetworkManager/Tests/L1Tests/tests/test_WifiManager.cpp @@ -0,0 +1,591 @@ +#include +#include +#include "WifiManager.h" + +#include "ServiceMock.h" +#include "IarmBusMock.h" +#include "WrapsMock.h" +#include "FactoriesImplementation.h" +#include "WifiManagerDefines.h" + +using namespace WPEFramework; + +using ::testing::NiceMock; + +class WifiManagerTest : public ::testing::Test { +protected: + Core::ProxyType plugin; + Core::JSONRPC::Handler& handler; + Core::JSONRPC::Connection connection; + string response; + Core::JSONRPC::Message message; + WrapsImplMock *p_wrapsImplMock = nullptr ; + NiceMock iarmBusImplMock; + IarmBusImplMock *p_iarmBusImplMock = nullptr ; + ServiceMock services; + + WifiManagerTest() + : plugin(Core::ProxyType::Create()) + , handler(*(plugin)) + , connection(1, 0) + { + p_wrapsImplMock = new NiceMock ; + Wraps::setImpl(p_wrapsImplMock); + + p_iarmBusImplMock = new NiceMock ; + IarmBus::setImpl(p_iarmBusImplMock); + } + virtual ~WifiManagerTest() override + { + Wraps::setImpl(nullptr); + if (p_wrapsImplMock != nullptr) + { + delete p_wrapsImplMock; + p_wrapsImplMock = nullptr; + } + + IarmBus::setImpl(nullptr); + if (p_iarmBusImplMock != nullptr) + { + delete p_iarmBusImplMock; + p_iarmBusImplMock = nullptr; + } + } +}; + +class WifiInitializedEventTest : public WifiManagerTest { +protected: + FactoriesImplementation factoriesImplementation; + PluginHost::IDispatcher* dispatcher; + + + WifiInitializedEventTest() + : WifiManagerTest() + { + PluginHost::IFactories::Assign(&factoriesImplementation); + + dispatcher = static_cast( + plugin->QueryInterface(PluginHost::IDispatcher::ID)); + dispatcher->Activate(&services); + } + + virtual ~WifiInitializedEventTest() override + { + dispatcher->Deactivate(); + dispatcher->Release(); + PluginHost::IFactories::Assign(nullptr); + + } +}; + + +TEST_F(WifiManagerTest, TestedAPIsShouldExist) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("startScan"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("stopScan"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("connect"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("disconnect"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("cancelWPSPairing"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("saveSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("clearSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("setSignalThresholdChangeEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPairedSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getPairedSSIDInfo"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isPaired"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getCurrentState"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getConnectedSSID"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getQuirks"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("isSignalThresholdChangeEnabled"))); + EXPECT_EQ(Core::ERROR_NONE, handler.Exists(_T("getSupportedSecurityModes"))); +} + + +TEST_F(WifiManagerTest, setEnabled) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_NETSRVMGR_API_setInterfaceEnabled))); + auto param = static_cast(arg); + EXPECT_EQ(param->isInterfaceEnabled, true); + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setEnabled"), _T("{\"enable\":true}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, getCurrentState) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getCurrentState))); + auto param = static_cast(arg); + param->data.wifiStatus = WIFI_DISCONNECTED; + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getCurrentState"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"state\":2,\"success\":true}")); // WIFI_PAIRING enum 3 +} + +TEST_F(WifiManagerTest, getPairedSSID) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSID, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ssid\":\"rdk.test.wifi.network\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, getPairedSSIDi_cache) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSID, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ssid\":\"rdk.test.wifi.network\",\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"ssid\":\"rdk.test.wifi.network\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, getPairedSSID_failed) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSID, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + return IARM_RESULT_IPCCORE_FAIL; + }); + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getPairedSSID"), _T("{}"), response)); +} + +TEST_F(WifiManagerTest, getPairedSSIDInfo) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getPairedSSIDInfo.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); +} + +TEST_F(WifiManagerTest, getPairedSSIDInfo_cache) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getPairedSSIDInfo.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); +} + +TEST_F(WifiManagerTest, getPairedSSIDInfo_fail) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getPairedSSIDInfo.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + return IARM_RESULT_IPCCORE_FAIL; + }); + + EXPECT_EQ(Core::ERROR_GENERAL, handler.Invoke(connection, _T("getPairedSSIDInfo"), _T("{}"), response)); +} + + +TEST_F(WifiManagerTest, getConnectedSSID) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getConnectedSSID))); + auto param = static_cast(arg); + memcpy(¶m->data.getConnectedSSID.ssid, "rdk.test.wifi.network", sizeof("rdk.test.wifi.network")); + memcpy(¶m->data.getConnectedSSID.bssid, "ff:ff:ff:ff:ff:ff", sizeof("ff:ff:ff:ff:ff:ff")); + param->data.getConnectedSSID.rate = 130.000; + param->data.getConnectedSSID.noise = -88.000; + param->data.getConnectedSSID.securityMode = NET_WIFI_SECURITY_WPA2_PSK_AES; + param->data.getConnectedSSID.signalStrength = -33.00; + param->data.getConnectedSSID.frequency = 2437.00; + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getConnectedSSID"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"ssid\":\"rdk.test.wifi.network\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"bssid\":\"ff:ff:ff:ff:ff:ff\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"rate\":\"130.000000\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"noise\":\"-88.000000\""))); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"frequency\":\"2.437000\""))); +} + +TEST_F(WifiManagerTest, connect) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_connect))); + auto param = static_cast(arg); + param->status = true; + EXPECT_EQ(string(param->data.connect.ssid), string(_T("123412341234"))); + EXPECT_EQ(string(param->data.connect.passphrase), string(_T("password"))); + EXPECT_EQ(param->data.connect.security_mode, NET_WIFI_SECURITY_WEP_128); //securityMode: 2 (NET_WIFI_SECURITY_WEP_128) + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("connect"), _T("{\"ssid\": \"123412341234\",\"passphrase\": \"password\",\"securityMode\": 2}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, disconnect) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_disconnectSSID))); + auto param = static_cast(arg); + param->status = true; + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("disconnect"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, saveSSID) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_saveSSID))); + auto param = static_cast(arg); + param->status = true; + EXPECT_EQ(string(param->data.connect.ssid), string(_T("123412341234"))); + EXPECT_EQ(string(param->data.connect.passphrase), string(_T("password"))); + EXPECT_EQ(param->data.connect.security_mode, NET_WIFI_SECURITY_WEP_128); //securityMode: 2 (NET_WIFI_SECURITY_WEP_128) + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("saveSSID"), _T("{\"ssid\": \"123412341234\",\"passphrase\": \"password\",\"securityMode\": 2}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, clearSSID) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_clearSSID))); + auto param = static_cast(arg); + param->status = true; + return IARM_RESULT_SUCCESS; + }); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("clearSSID"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, isPaired) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "123412341234", sizeof("123412341234")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isPaired"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, isPaired_cache) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo))); + auto param = static_cast(arg); + memcpy(¶m->data.getPairedSSIDInfo.ssid, "123412341234", sizeof("123412341234")); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isPaired"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isPaired"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); +} + +TEST_F(WifiManagerTest, startScan) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsync))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startScan"), _T("{\"incremental\": false,\"ssid\": \"...\",\"frequency\": \"...\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsyncIncr))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("startScan"), _T("{\"incremental\": true,\"ssid\": \"...\",\"frequency\": \"...\"}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, stopScan) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_stopProgressiveWifiScanning))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("stopScan"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); +} + +TEST_F(WifiManagerTest, cancelWPSPairing) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_cancelWPSPairing))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("cancelWPSPairing"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":\"\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, initiateWPSPairing) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_initiateWPSPairing))); + return IARM_RESULT_SUCCESS; + }); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("initiateWPSPairing"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":\"\",\"success\":true}")); +} + +TEST_F(WifiManagerTest, initiateWPSPairing2) +{ + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_NM_SRV_MGR_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_WIFI_MGR_API_initiateWPSPairing2))); + return IARM_RESULT_SUCCESS; + }); + + + JsonObject jsonObj; + JsonObject res; + jsonObj["method"] = "PIN"; + jsonObj["wps_pin"] = "88888888"; + uint32_t result = plugin->initiateWPSPairing2(jsonObj,res); + EXPECT_EQ(result, 0); +} + + +TEST_F(WifiManagerTest, SignalThresholdChangeEnabled) +{ + ServiceMock service; + EXPECT_EQ(string(""), plugin->Initialize(&service)); + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isSignalThresholdChangeEnabled"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":1,\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("setSignalThresholdChangeEnabled"), _T("{\"enabled\": true, \"interval\":2000}"), response)); + EXPECT_EQ(response, string("{\"success\":true}")); + + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("isSignalThresholdChangeEnabled"), _T("{}"), response)); + EXPECT_EQ(response, string("{\"result\":0,\"success\":true}")); + plugin->Deinitialize(&service); +} + +TEST_F(WifiManagerTest, getSupportedSecurityModes) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getSupportedSecurityModes"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(WifiManagerTest, getQuirks) +{ + EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getQuirks"), _T("{}"), response)); + EXPECT_THAT(response, ::testing::ContainsRegex(_T("\"success\":true"))); +} + +TEST_F(WifiInitializedEventTest, onWIFIStateChanged) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onWIFIStateChanged\",\"params\":{\"state\":1,\"isLNF\":false}}"))); + return Core::ERROR_NONE; + })); + WPEFramework::Plugin::WifiState intData = WPEFramework::Plugin::WifiState::DISABLED; + handler.Subscribe(0, _T("onWIFIStateChanged"), _T("org.rdk.WifiManager"), message); + plugin->onWIFIStateChanged(intData,false); + handler.Unsubscribe(0, _T("onWIFIStateChanged"), _T("org.rdk.WifiManager"), message); +} + +TEST_F(WifiInitializedEventTest, onSSIDsChanged) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onSSIDsChanged\",\"params\":{}}"))); + return Core::ERROR_NONE; + })); + handler.Subscribe(0, _T("onSSIDsChanged"), _T("org.rdk.WifiManager"), message); + plugin->onSSIDsChanged(); + handler.Unsubscribe(0, _T("onSSIDsChanged"), _T("org.rdk.WifiManager"), message); +} +TEST_F(WifiInitializedEventTest, onWifiSignalThresholdChanged) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onWifiSignalThresholdChanged\",\"params\":{\"signalStrength\":\"-27.000000\",\"strength\":\"Excellent\"}}"))); + return Core::ERROR_NONE; + })); + handler.Subscribe(0, _T("onWifiSignalThresholdChanged"), _T("org.rdk.WifiManager"), message); + plugin->onWifiSignalThresholdChanged(-27.000000,"Excellent"); + handler.Unsubscribe(0, _T("onWifiSignalThresholdChanged"), _T("org.rdk.WifiManager"), message); +} + +TEST_F(WifiInitializedEventTest, onError) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onError\",\"params\":{\"code\":2}}"))); + return Core::ERROR_NONE; + })); + WPEFramework::Plugin::ErrorCode intData = WPEFramework::Plugin::ErrorCode::CONNECTION_FAILED; + handler.Subscribe(0, _T("onError"), _T("org.rdk.WifiManager"), message); + plugin->onError(intData); + handler.Unsubscribe(0, _T("onError"), _T("org.rdk.WifiManager"), message); +} + + +TEST_F(WifiInitializedEventTest, onAvailableSSIDs) +{ + EXPECT_CALL(services, Submit(::testing::_, ::testing::_)) + .Times(1) + .WillOnce(::testing::Invoke( + [&](const uint32_t, const Core::ProxyType& json) { + string text; + EXPECT_TRUE(json->ToString(text)); + EXPECT_EQ(text, string(_T("{\"jsonrpc\":\"2.0\",\"method\":\"org.rdk.WifiManager.onAvailableSSIDs\",\"params\":{\"ssid\":\"123412341234\",\"security\":2,\"signalStrength\":\"-27.000000\",\"frequency\":\"2.442000\"}}"))); + return Core::ERROR_NONE; + })); + JsonObject jsonObj; + jsonObj["ssid"] = "123412341234"; + jsonObj["security"] = 2; + jsonObj["signalStrength"] = "-27.000000"; + jsonObj["frequency"] = "2.442000"; + handler.Subscribe(0, _T("onAvailableSSIDs"), _T("org.rdk.WifiManager"), message); + plugin->onAvailableSSIDs(jsonObj); + handler.Unsubscribe(0, _T("onAvailableSSIDs"), _T("org.rdk.WifiManager"), message); +} + diff --git a/NetworkManager/Tests/clang.cmake b/NetworkManager/Tests/clang.cmake new file mode 100644 index 0000000000..f5a97f56a3 --- /dev/null +++ b/NetworkManager/Tests/clang.cmake @@ -0,0 +1,12 @@ +set(CMAKE_C_COMPILER "/usr/bin/clang") +set(CMAKE_CXX_COMPILER "/usr/bin/clang++") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-command-line-argument") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=missing-braces") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=dangling-gsl") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-const-variable") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=inconsistent-missing-override") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-parameter") + +# clang Valgrind: debuginfo reader: ensure_valid failed +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-4") diff --git a/NetworkManager/Tests/gcc-with-coverage.cmake b/NetworkManager/Tests/gcc-with-coverage.cmake new file mode 100644 index 0000000000..cb8d689eb7 --- /dev/null +++ b/NetworkManager/Tests/gcc-with-coverage.cmake @@ -0,0 +1 @@ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") diff --git a/NetworkManager/Tests/mocks/CMakeLists.txt b/NetworkManager/Tests/mocks/CMakeLists.txt new file mode 100755 index 0000000000..5029fabefd --- /dev/null +++ b/NetworkManager/Tests/mocks/CMakeLists.txt @@ -0,0 +1,48 @@ +#if not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2023 Synamedia +# +# 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. + +cmake_minimum_required(VERSION 3.8) +set(MODULE_NAME TestMocklib) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/e39786088138f2749d64e9e90e0f9902daa77c40.zip +) +FetchContent_MakeAvailable(googletest) + + +add_library(${MODULE_NAME} SHARED + Rfc.cpp + Iarm.cpp + Wraps.cpp + RBus.cpp + Telemetry.cpp + devicesettings.cpp + Udev.cpp +) +target_link_libraries(${MODULE_NAME} PRIVATE gmock_main) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + + +install(TARGETS ${MODULE_NAME} + DESTINATION lib) + + diff --git a/NetworkManager/Tests/mocks/Iarm.cpp b/NetworkManager/Tests/mocks/Iarm.cpp new file mode 100755 index 0000000000..63afa6f610 --- /dev/null +++ b/NetworkManager/Tests/mocks/Iarm.cpp @@ -0,0 +1,104 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* 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 "Iarm.h" +#include + +IarmBusImpl* IarmBus::impl = nullptr; + +IarmBus::IarmBus() {} + +void IarmBus::setImpl(IarmBusImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +IARM_Result_t IarmBus::IARM_Bus_Init(const char* name) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Init(name); +} + +IARM_Result_t IarmBus::IARM_Bus_Connect() +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Connect(); +} + +IARM_Result_t IarmBus::IARM_Bus_IsConnected(const char* memberName, int* isRegistered) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_IsConnected(memberName, isRegistered); +} + +IARM_Result_t IarmBus::IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_RegisterEventHandler(ownerName, eventId, handler); +} + +IARM_Result_t IarmBus::IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_UnRegisterEventHandler(ownerName, eventId); +} + +IARM_Result_t IarmBus::IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_RemoveEventHandler(ownerName, eventId, handler); +} + +IARM_Result_t IarmBus::IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Call(ownerName, methodName, arg, argLen); +} + +IARM_Result_t IarmBus::IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_BroadcastEvent(ownerName, eventId, arg, argLen); +} + + +IARM_Result_t IarmBus::IARM_Bus_RegisterCall(const char* methodName, IARM_BusCall_t handler) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_RegisterCall(methodName, handler); +} + +IARM_Result_t IarmBus::IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout) +{ + EXPECT_NE(impl, nullptr); + return impl->IARM_Bus_Call_with_IPCTimeout(ownerName, methodName, arg, argLen, timeout); +} + +IARM_Result_t (*IARM_Bus_Init)(const char*) = &IarmBus::IARM_Bus_Init; +IARM_Result_t (*IARM_Bus_Connect)() = &IarmBus::IARM_Bus_Connect; +IARM_Result_t (*IARM_Bus_IsConnected)(const char*,int*) = &IarmBus::IARM_Bus_IsConnected; +IARM_Result_t (*IARM_Bus_RegisterEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t) = &IarmBus::IARM_Bus_RegisterEventHandler; +IARM_Result_t (*IARM_Bus_UnRegisterEventHandler)(const char*,IARM_EventId_t) = &IarmBus::IARM_Bus_UnRegisterEventHandler; +IARM_Result_t (*IARM_Bus_RemoveEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t) = &IarmBus::IARM_Bus_RemoveEventHandler; +IARM_Result_t (*IARM_Bus_Call)(const char*,const char*,void*,size_t) = &IarmBus::IARM_Bus_Call; +IARM_Result_t (*IARM_Bus_BroadcastEvent)(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) = &IarmBus::IARM_Bus_BroadcastEvent; +IARM_Result_t (*IARM_Bus_RegisterCall)(const char*,IARM_BusCall_t) = &IarmBus::IARM_Bus_RegisterCall; +IARM_Result_t (*IARM_Bus_Call_with_IPCTimeout)(const char*,const char*,void*,size_t,int) = &IarmBus::IARM_Bus_Call_with_IPCTimeout; diff --git a/NetworkManager/Tests/mocks/Iarm.h b/NetworkManager/Tests/mocks/Iarm.h new file mode 100644 index 0000000000..417a2bb418 --- /dev/null +++ b/NetworkManager/Tests/mocks/Iarm.h @@ -0,0 +1,754 @@ +#pragma once + +#include + +typedef int IARM_EventId_t; + +typedef enum _IARM_Result_t { + IARM_RESULT_SUCCESS, + IARM_RESULT_INVALID_PARAM, + IARM_RESULT_INVALID_STATE, + IARM_RESULT_IPCCORE_FAIL, + IARM_RESULT_OOM, +} IARM_Result_t; + +#define IARM_BUS_DAEMON_NAME "Daemon" + +typedef IARM_Result_t (*IARM_BusCall_t)(void* arg); +typedef void (*IARM_EventHandler_t)(const char* owner, IARM_EventId_t eventId, void* data, size_t len); + +class IarmBusImpl { +public: + virtual ~IarmBusImpl() = default; + + virtual IARM_Result_t IARM_Bus_Init(const char* name) = 0; + virtual IARM_Result_t IARM_Bus_Connect() = 0; + virtual IARM_Result_t IARM_Bus_IsConnected(const char* memberName, int* isRegistered) = 0; + virtual IARM_Result_t IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) = 0; + virtual IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId) = 0; + virtual IARM_Result_t IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler) = 0; + virtual IARM_Result_t IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen) = 0; + virtual IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) = 0; + virtual IARM_Result_t IARM_Bus_RegisterCall(const char* methodName, IARM_BusCall_t handler) = 0; + virtual IARM_Result_t IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout) = 0; +}; + +class IarmBus { +protected: + static IarmBusImpl* impl; +public: + IarmBus(); + IarmBus(const IarmBus &obj) = delete; // deleted copy constructor so that copy of the instance cannot be created. + static void setImpl(IarmBusImpl* newImpl); + static IARM_Result_t IARM_Bus_Init(const char* name); + static IARM_Result_t IARM_Bus_Connect(); + static IARM_Result_t IARM_Bus_IsConnected(const char* memberName, int* isRegistered); + static IARM_Result_t IARM_Bus_RegisterEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler); + static IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char* ownerName, IARM_EventId_t eventId); + static IARM_Result_t IARM_Bus_RemoveEventHandler(const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler); + static IARM_Result_t IARM_Bus_Call(const char* ownerName, const char* methodName, void* arg, size_t argLen); + static IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) ; + + static IARM_Result_t IARM_Bus_RegisterCall(const char* methodName, IARM_BusCall_t handler); + static IARM_Result_t IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout); +}; + +extern IARM_Result_t (*IARM_Bus_Init)(const char*); +extern IARM_Result_t (*IARM_Bus_Connect)(); +extern IARM_Result_t (*IARM_Bus_IsConnected)(const char*,int*); +extern IARM_Result_t (*IARM_Bus_RegisterEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t); +extern IARM_Result_t (*IARM_Bus_UnRegisterEventHandler)(const char*,IARM_EventId_t); +extern IARM_Result_t (*IARM_Bus_RemoveEventHandler)(const char*,IARM_EventId_t,IARM_EventHandler_t); +extern IARM_Result_t (*IARM_Bus_Call)(const char*,const char*,void*,size_t); +extern IARM_Result_t (*IARM_Bus_BroadcastEvent)(const char *,IARM_EventId_t,void *,size_t); +extern IARM_Result_t (*IARM_Bus_RegisterCall)(const char*,IARM_BusCall_t); +extern IARM_Result_t (*IARM_Bus_Call_with_IPCTimeout)(const char*,const char*,void*,size_t,int); + +#define IARM_BUS_COMMON_API_SysModeChange "SysModeChange" + +typedef enum _IARM_Bus_Daemon_PowerState_t { + IARM_BUS_PWRMGR_POWERSTATE_OFF, + IARM_BUS_PWRMGR_POWERSTATE_STANDBY, + IARM_BUS_PWRMGR_POWERSTATE_ON, + IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP, + IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP +} IARM_Bus_PowerState_t; + +typedef IARM_Bus_PowerState_t IARM_Bus_PWRMgr_PowerState_t; + +typedef enum _IARM_Bus_Daemon_SysMode_t { + IARM_BUS_SYS_MODE_NORMAL, + IARM_BUS_SYS_MODE_EAS, + IARM_BUS_SYS_MODE_WAREHOUSE +} IARM_Bus_Daemon_SysMode_t; + +#define IARMBUS_AUDIOCAPTUREMGR_NAME "audiocapturemgr" +#define IARMBUS_AUDIOCAPTUREMGR_REQUEST_SAMPLE "requestSample" + +#define IARMBUS_AUDIOCAPTUREMGR_OPEN "open" +#define IARMBUS_AUDIOCAPTUREMGR_CLOSE "close" +#define IARMBUS_AUDIOCAPTUREMGR_START "start" +#define IARMBUS_AUDIOCAPTUREMGR_STOP "stop" +#define IARMBUS_AUDIOCAPTUREMGR_GET_DEFAULT_AUDIO_PROPS "getDefaultAudioProperties" +#define IARMBUS_AUDIOCAPTUREMGR_GET_AUDIO_PROPS "getAudioProperties" +#define IARMBUS_AUDIOCAPTUREMGR_GET_OUTPUT_PROPS "getOutputProperties" +#define IARMBUS_AUDIOCAPTUREMGR_SET_AUDIO_PROPERTIES "setAudioProperties" +#define IARMBUS_AUDIOCAPTUREMGR_SET_OUTPUT_PROPERTIES "setOutputProperties" + +#define AUDIOCAPTUREMGR_FILENAME_PREFIX "audio_sample" +#define AUDIOCAPTUREMGR_FILE_PATH "/opt/" + +#define DATA_CAPTURE_IARM_EVENT_AUDIO_CLIP_READY 100 + +#define ACM_RESULT_GENERAL_FAILURE 0 +#define ACM_RESULT_PRECAPTURE_NOT_SUPPORTED 1 +#define ACM_RESULT_STREAM_UNAVAILABLE 2 +#define ACM_RESULT_DURATION_OUT_OF_BOUNDS 3 +#define BUFFERED_FILE_OUTPUT "" + +enum Format { + acmFormate16BitStereo, + acmFormate16BitMonoLeft, + acmFormate16BitMonoRight, + acmFormate16BitMono, + acmFormate24BitStereo, + acmFormate24Bit5_1 +}; + +enum Sampling_frequency { + acmFreqe48000, + acmFreqe44100, + acmFreqe32000, + acmFreqe24000, + acmFreqe16000 +}; + +namespace audiocapturemgr { +using session_id_t = int; + +struct audio_properties_ifce_t { + Format format; + Sampling_frequency sampling_frequency; +}; +} + +struct iarmbus_notification_payload_t { + char dataLocator[64]; +}; + +struct iarmbus_acm_arg_t { + struct iarmbus_open_args { + int source; + std::string output_type; + }; + + struct iarmbus_request_payload_t { + float duration; + bool is_precapture; + }; + + struct output_t { + unsigned int buffer_duration; + unsigned int max_buffer_duration; + }; + + struct arg_output_props_t { + output_t output; + }; + + struct Details { + iarmbus_open_args arg_open; + audiocapturemgr::audio_properties_ifce_t arg_audio_properties; + iarmbus_request_payload_t arg_sample_request; + arg_output_props_t arg_output_props; + }; + + int session_id; + int result; + Details details; +}; + +#define IARM_BUS_CECMGR_NAME "CECMgr" +#define IARM_BUS_CECMGR_MAX_DATA_LENGTH 62 +#define IARM_BUS_CECMGR_API_Send "Send" + +typedef struct _IARM_Bus_CECMgr_Send_Param_t { + uint8_t length; + uint8_t data[IARM_BUS_CECMGR_MAX_DATA_LENGTH + 1]; + uint8_t retVal; +} IARM_Bus_CECMgr_Send_Param_t; + +#define IARM_BUS_DEEPSLEEPMGR_NAME "DEEPSLEEPMgr" + +#define IARM_BUS_DEEPSLEEPMGR_API_GetLastWakeupReason "GetLastWakeupReason" +#define IARM_BUS_DEEPSLEEPMGR_API_GetLastWakeupKeyCode "GetLastWakeupKeycode" + +typedef enum _DeepSleep_WakeupReason_t { + DEEPSLEEP_WAKEUPREASON_IR = 0, + DEEPSLEEP_WAKEUPREASON_RCU_BT, + DEEPSLEEP_WAKEUPREASON_RCU_RF4CE, + DEEPSLEEP_WAKEUPREASON_GPIO, + DEEPSLEEP_WAKEUPREASON_LAN, + DEEPSLEEP_WAKEUPREASON_WLAN, + DEEPSLEEP_WAKEUPREASON_TIMER, + DEEPSLEEP_WAKEUPREASON_FRONT_PANEL, + DEEPSLEEP_WAKEUPREASON_WATCHDOG, + DEEPSLEEP_WAKEUPREASON_SOFTWARE_RESET, + DEEPSLEEP_WAKEUPREASON_THERMAL_RESET, + DEEPSLEEP_WAKEUPREASON_WARM_RESET, + DEEPSLEEP_WAKEUPREASON_COLDBOOT, + DEEPSLEEP_WAKEUPREASON_STR_AUTH_FAILURE, + DEEPSLEEP_WAKEUPREASON_CEC, + DEEPSLEEP_WAKEUPREASON_PRESENCE, + DEEPSLEEP_WAKEUPREASON_VOICE, + DEEPSLEEP_WAKEUPREASON_UNKNOWN +} DeepSleep_WakeupReason_t; + +typedef struct _DeepSleepMgr_WakeupKeyCode_Param_t { + unsigned int keyCode; +} DeepSleepMgr_WakeupKeyCode_Param_t; + +#define IARM_BUS_MFRLIB_NAME "MFRLib" +#define IARM_BUS_MFRLIB_API_SetBootLoaderPattern "mfrSetBootloaderPattern" +#define IARM_BUS_MFRLIB_API_SetBlSplashScreen "mfrSetBlSplashScreen" +#define IARM_BUS_MFRLIB_API_GetSerializedData "mfrGetManufacturerData" + +typedef enum _mfrSerializedType_t { + mfrSERIALIZED_TYPE_MANUFACTURER = 0, + mfrSERIALIZED_TYPE_MANUFACTUREROUI, + mfrSERIALIZED_TYPE_MODELNAME, + mfrSERIALIZED_TYPE_DESCRIPTION, + mfrSERIALIZED_TYPE_PRODUCTCLASS, + mfrSERIALIZED_TYPE_SERIALNUMBER, + mfrSERIALIZED_TYPE_HARDWAREVERSION, + mfrSERIALIZED_TYPE_SOFTWAREVERSION, + mfrSERIALIZED_TYPE_PROVISIONINGCODE, + mfrSERIALIZED_TYPE_FIRSTUSEDATE, + mfrSERIALIZED_TYPE_DEVICEMAC, + mfrSERIALIZED_TYPE_MOCAMAC, + mfrSERIALIZED_TYPE_HDMIHDCP, + mfrSERIALIZED_TYPE_PDRIVERSION, + mfrSERIALIZED_TYPE_WIFIMAC, + mfrSERIALIZED_TYPE_BLUETOOTHMAC, + mfrSERIALIZED_TYPE_WPSPIN, + mfrSERIALIZED_TYPE_MANUFACTURING_SERIALNUMBER, + mfrSERIALIZED_TYPE_ETHERNETMAC, + mfrSERIALIZED_TYPE_ESTBMAC, + mfrSERIALIZED_TYPE_RF4CEMAC, + mfrSERIALIZED_TYPE_PROVISIONED_MODELNAME, + mfrSERIALIZED_TYPE_PMI, + mfrSERIALIZED_TYPE_HWID, + mfrSERIALIZED_TYPE_MODELNUMBER, + /* boot data */ + mfrSERIALIZED_TYPE_SOC_ID, + mfrSERIALIZED_TYPE_IMAGENAME, + mfrSERIALIZED_TYPE_IMAGETYPE, + mfrSERIALIZED_TYPE_BLVERSION, + /* provisional data */ + mfrSERIALIZED_TYPE_REGION, + /* other data */ + mfrSERIALIZED_TYPE_BDRIVERSION, + /* led data */ + mfrSERIALIZED_TYPE_LED_WHITE_LEVEL, + mfrSERIALIZED_TYPE_LED_PATTERN, + mfrSERIALIZED_TYPE_MAX, +#ifdef PANEL_SERIALIZATION_TYPES + mfrSERIALIZED_TYPE_COREBOARD_SERIALNUMBER=0x51, + mfrSERIALIZED_TYPE_FACTORYBOOT, + mfrSERIALIZED_TYPE_COUNTRYCODE, + mfrSERIALIZED_TYPE_LANGUAGECODE, + mfrSERIALIZED_TYPE_MANUFACTURERDATA, + mfrSERIALIZED_TYPE_CPD_SIZE, + mfrSERIALIZED_TYPE_PANEL_ID, + mfrSERIALIZED_TYPE_PANEL_TYPE, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_NORMAL, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_COLD, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_WARM, + mfrSERIALIZED_TYPE_PANEL_HDMI_WB_DATA_USER, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_NORMAL, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_COLD, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_WARM, + mfrSERIALIZED_TYPE_PANEL_TV_WB_DATA_USER, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_NORMAL, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_COLD, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_WARM, + mfrSERIALIZED_TYPE_PANEL_AV_WB_DATA_USER, + mfrSERIALIZED_TYPE_PANEL_DTB_VERSION, + mfrSERIALIZED_TYPE_PANEL_DTB_DATA_SIZE, + mfrSERIALIZED_TYPE_PANEL_DTB_DATA, + /* panel data*/ + mfrSERIALIZED_TYPE_PANEL_DATA_FUNCTION_STATUS, + mfrSERIALIZED_TYPE_PANEL_DATA_AGEING_TIME, + mfrSERIALIZED_TYPE_PANEL_DATA_POWER_ON_TIME, + mfrSERIALIZED_TYPE_PANEL_DATA_BACKLIGHT_TIME, + mfrSERIALIZED_TYPE_PANEL_DATA_VALID, + mfrSERIALIZED_TYPE_PANEL_DATA_TPV_APP_VERSION, + mfrSERIALIZED_TYPE_PANEL_ALS_CALIBRATION_INDEX0, + mfrSERIALIZED_TYPE_PANEL_ALS_CALIBRATION_INDEX1, + mfrSERIALIZED_TYPE_MAX_PANEL, +#endif +} mfrSerializedType_t; + +typedef enum _mfrBlPattern_t { + mfrBL_PATTERN_NORMAL = 0, + mfrBL_PATTERN_SILENT, + mfrBL_PATTERN_SILENT_LED_ON +} mfrBlPattern_t; + +typedef struct _IARM_Bus_MFRLib_SetBLPattern_Param_t { + mfrBlPattern_t pattern; +} IARM_Bus_MFRLib_SetBLPattern_Param_t; + +typedef struct _IARM_Bus_MFRLib_GetSerializedData_Param_t { + mfrSerializedType_t type; + char buffer[1280]; + int bufLen; +} IARM_Bus_MFRLib_GetSerializedData_Param_t; + +#define PWRMGR_MAX_REBOOT_REASON_LENGTH 100 + +#define MAX_PWR_STATE_BEF_REBOOR_STR_LEN (32) +#define IARM_BUS_PWRMGR_API_GetPowerStateBeforeReboot "GetPowerStateBeforeReboot" +#define IARM_BUS_PWRMGR_API_SetStandbyVideoState "SetStandbyVideoState" +#define IARM_BUS_PWRMGR_API_GetStandbyVideoState "GetStandbyVideoState" +#define IARM_BUS_PWRMGR_API_SetNetworkStandbyMode "SetNetworkStandbyMode" +#define IARM_BUS_PWRMGR_API_GetNetworkStandbyMode "GetNetworkStandbyMode" +#define IARM_BUS_PWRMGR_API_Reboot "performReboot" +#define IARM_BUS_PWRMGR_API_WareHouseClear "WarehouseClear" /*!< */ +#define IARM_BUS_PWRMGR_API_ColdFactoryReset "ColdFactoryReset" /*!< Reset the box to cold factory state*/ +#define IARM_BUS_PWRMGR_API_FactoryReset "FactoryReset" /*!< Reset the box to factory state*/ +#define IARM_BUS_PWRMGR_API_UserFactoryReset "UserFactoryReset" /*!< Reset the box to user factory state*/ +#define IARM_BUS_PWRMGR_API_WareHouseReset "WareHouseReset" /*!< Reset the box to warehouse state*/ + +typedef struct _IARM_Bus_PWRMgr_NetworkStandbyMode_Param_t { + bool bStandbyMode; +} IARM_Bus_PWRMgr_NetworkStandbyMode_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetPowerStateBeforeReboot_Param_t { + char powerStateBeforeReboot[MAX_PWR_STATE_BEF_REBOOR_STR_LEN]; +} IARM_Bus_PWRMgr_GetPowerStateBeforeReboot_Param_t; + +typedef struct _IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t { + unsigned int timeout; +} IARM_Bus_PWRMgr_SetDeepSleepTimeOut_Param_t; + +typedef enum _IARM_Bus_PWRMgr_ThermalState_t { + IARM_BUS_PWRMGR_TEMPERATURE_NORMAL = 0, + IARM_BUS_PWRMGR_TEMPERATURE_HIGH, + IARM_BUS_PWRMGR_TEMPERATURE_CRITICAL +} IARM_Bus_PWRMgr_ThermalState_t; + +typedef enum _WakeupSrcType_t { + WAKEUPSRC_VOICE = 0, + WAKEUPSRC_PRESENCE_DETECTION, + WAKEUPSRC_BLUETOOTH, + WAKEUPSRC_WIFI, + WAKEUPSRC_IR, + WAKEUPSRC_POWER_KEY, + WAKEUPSRC_TIMER, + WAKEUPSRC_CEC, + WAKEUPSRC_LAN, + WAKEUPSRC_MAX +} WakeupSrcType_t; + +typedef struct _PWRMgr_EventData_t { + union { + struct _MODE_DATA { + IARM_Bus_PWRMgr_PowerState_t curState; + IARM_Bus_PWRMgr_PowerState_t newState; + uint32_t deep_sleep_timeout; + bool nwStandbyMode; + } state; + struct _THERM_DATA { + IARM_Bus_PWRMgr_ThermalState_t curLevel; + IARM_Bus_PWRMgr_ThermalState_t newLevel; + float curTemperature; + } therm; + bool bNetworkStandbyMode; + int32_t reset_sequence_progress; + } data; +} IARM_Bus_PWRMgr_EventData_t; + +typedef struct _IARM_Bus_PWRMgr_GetThermalState_Param_t { + IARM_Bus_PWRMgr_ThermalState_t curLevel; + float curTemperature; +} IARM_Bus_PWRMgr_GetThermalState_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetTempThresholds_Param_t { + float tempHigh; + float tempCritical; +} IARM_Bus_PWRMgr_GetTempThresholds_Param_t; + +typedef struct _IARM_Bus_PWRMgr_SetTempThresholds_Param_t { + float tempHigh; + float tempCritical; +} IARM_Bus_PWRMgr_SetTempThresholds_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetOvertempGraceInterval_Param_t { + int graceInterval; +} IARM_Bus_PWRMgr_GetOvertempGraceInterval_Param_t; + +typedef struct _IARM_Bus_PWRMgr_SetOvertempGraceInterval_Param_t { + int graceInterval; +} IARM_Bus_PWRMgr_SetOvertempGraceInterval_Param_t; + +typedef struct _IARM_Bus_CommonAPI_SysModeChange_Param_t { + IARM_Bus_Daemon_SysMode_t oldMode; + IARM_Bus_Daemon_SysMode_t newMode; +} IARM_Bus_CommonAPI_SysModeChange_Param_t; + +typedef enum _PWRMgr_EventId_t { + IARM_BUS_PWRMGR_EVENT_MODECHANGED = 0, + IARM_BUS_PWRMGR_EVENT_DEEPSLEEP_TIMEOUT, + IARM_BUS_PWRMGR_EVENT_RESET_SEQUENCE, + IARM_BUS_PWRMGR_EVENT_REBOOTING, + IARM_BUS_PWRMGR_EVENT_THERMAL_MODECHANGED, + IARM_BUS_PWRMGR_EVENT_WAREHOUSEOPS_STATUSCHANGED, + IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED, + IARM_BUS_PWRMGR_EVENT_MAX, +} IARM_Bus_PWRMgr_EventId_t; + +typedef struct _IARM_Bus_PWRMgr_RebootParam_t { + char reboot_reason_custom[PWRMGR_MAX_REBOOT_REASON_LENGTH]; + char reboot_reason_other[PWRMGR_MAX_REBOOT_REASON_LENGTH]; + char requestor[PWRMGR_MAX_REBOOT_REASON_LENGTH]; +} IARM_Bus_PWRMgr_RebootParam_t; + +#define IARM_BUS_PWRMGR_NAME "PWRMgr" +#define IARM_BUS_PWRMGR_API_SetPowerState "SetPowerState" +#define IARM_BUS_PWRMGR_API_GetPowerState "GetPowerState" + +typedef struct _IARM_Bus_PWRMgr_SetPowerState_Param_t { + IARM_Bus_PWRMgr_PowerState_t newState; + int keyCode; +} IARM_Bus_PWRMgr_SetPowerState_Param_t; + +typedef struct _IARM_Bus_PWRMgr_GetPowerState_Param_t { + IARM_Bus_PWRMgr_PowerState_t curState; +} IARM_Bus_PWRMgr_GetPowerState_Param_t; + +#define IARM_BUS_PWRMGR_API_GetThermalState "GetThermalState" +#define IARM_BUS_PWRMGR_API_GetTemperatureThresholds "GetTemperatureThresholds" +#define IARM_BUS_PWRMGR_API_SetTemperatureThresholds "SetTemperatureThresholds" +#define IARM_BUS_PWRMGR_API_GetOvertempGraceInterval "GetOvertempGraceInterval" +#define IARM_BUS_PWRMGR_API_SetOvertempGraceInterval "SetOvertempGraceInterval" + +/** + * @brief Structure which holds the wakeup source type and the value to be set and the power state. + */ +typedef struct _IARM_Bus_PWRMgr_WakeupSrcConfig_Param_t{ + uint32_t pwrMode; + uint32_t srcType; + uint32_t config; +} IARM_Bus_PWRMgr_WakeupSrcConfig_Param_t; +/** + * @brief Structure which holds the ware house reset time. + */ +typedef struct _IARM_Bus_PWRMgr_WareHouseReset_Param_t { + bool suppressReboot; /*!< STB should not be rebooted */ +} IARM_Bus_PWRMgr_WareHouseReset_Param_t; + +/** + * @brief Enumerator which represents the possible warehouse ops + */ +typedef enum _IARM_Bus_PWRMgr_WareHouseOpsStatus_t{ + IARM_BUS_PWRMGR_WAREHOUSE_COMPLETED = 0, /* warehouse operation completed sucessfully */ + IARM_BUS_PWRMGR_WAREHOUSE_INPROGRESS, /* warehouse operation in progress*/ + IARM_BUS_PWRMGR_WAREHOUSE_FAILED, /* warehouse operation failed.*/ +} IARM_Bus_PWRMgr_WareHouseOpsStatus_t; + +/** + * @brief Enumerator which represents the possible warehouse ops + */ +typedef enum _IARM_Bus_PWRMgr_WareHouseOps_t{ + IARM_BUS_PWRMGR_WAREHOUSE_RESET = 0, /* warehouse reset */ + IARM_BUS_PWRMGR_WAREHOUSE_CLEAR, /* warehouse clear*/ +} IARM_Bus_PWRMgr_WareHouseOps_t; + +/** + * @brief Structure which holds warehouse opn status value. + */ +typedef struct _IARM_BUS_PWRMgr_WareHouseOpn_EventData_t { + IARM_Bus_PWRMgr_WareHouseOps_t wareHouseOpn; /*!< WareHouse operation*/ + IARM_Bus_PWRMgr_WareHouseOpsStatus_t status; /*!< WareHouse operation status*/ +} IARM_BUS_PWRMgr_WareHouseOpn_EventData_t; + +#define IARM_BUS_PWRMGR_API_SetWakeupSrcConfig "setWakeupSrcConfig" +#define IARM_BUS_PWRMGR_API_GetWakeupSrcConfig "getWakeupSrcConfig" /*!< gets wakup configuration*/ + +#define IARM_BUS_SYSMGR_NAME "SYSMgr" +#define IARM_BUS_SYSMGR_API_GetSystemStates "GetSystemStates" + +/** + * @brief Structure which holds RFC device management update information. + */ +typedef struct _IARM_BUS_SYSMGR_DeviceMgtUpdateInfo_Param_t +{ + char source[10]; /*!< Device Management Update source. Ex: rfc */ + char type[10]; /*!< Device Management Update type. Ex: initial */ + bool status; /*!< Device Management Update status. true/false */ +} IARM_BUS_SYSMGR_DeviceMgtUpdateInfo_Param_t; + +typedef enum _SYSMgr_EventId_t { + IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE, + IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_REQUEST, /*!< Xupnp data request frm Receiver to UPNP*/ + IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_UPDATE, /*!< Xupnp data frm UPNP to Receiver*/ + IARM_BUS_SYSMGR_EVENT_IMAGE_DNLD, /*Image download status to Receiver */ + IARM_BUS_SYSMGR_EVENT_CARD_FWDNLD, /*!< CARD FW download event to Receiver - Valid on Cisco CA*/ + IARM_BUS_SYSMGR_EVENT_HDCP_PROFILE_UPDATE, /*!< HDCP Profile Update */ + IARM_BUS_SYSMGR_EVENT_INTRUSION, /*!< Intrusion Detection */ + IARM_BUS_SYSMGR_EVENT_EISS_FILTER_STATUS, /*!< EISS Filter status event */ + IARM_BUS_SYSMGR_EVENT_EISS_APP_ID_UPDATE, /*!< EISS App ID update */ + IARM_BUS_SYSMGR_EVENT_KEYCODE_LOGGING_CHANGED, /*!< Key Code logging status update */ + IARM_BUS_SYSMGR_EVENT_USB_MOUNT_CHANGED, /*!< Fires when USB mounts change */ + IARM_BUS_SYSMGR_EVENT_APP_RELEASE_FOCUS, /*!< Application fires event to release focus*/ + IARM_BUS_SYSMGR_EVENT_DEVICE_UPDATE_RECEIVED, /*!< Received Device Management update information */ + IARM_BUS_SYSMGR_EVENT_MAX /*!< Max Event Id */ +} IARM_Bus_SYSMgr_EventId_t; + +typedef struct _IARM_BUS_SYSMGR_KEYCodeLoggingInfo_Param_t { + int logStatus; /*!< HDCP Profile Data */ +} IARM_BUS_SYSMGR_KEYCodeLoggingInfo_Param_t; + +#define IARM_BUS_SYSMGR_API_GetKeyCodeLoggingPref "GetKeyCodeLoggingPref" +#define IARM_BUS_SYSMGR_API_SetKeyCodeLoggingPref "SetKeyCodeLoggingPref" + +typedef enum _SYSMgr_SystemState_t { + IARM_BUS_SYSMGR_SYSSTATE_CHANNELMAP, //0 + IARM_BUS_SYSMGR_SYSSTATE_DISCONNECTMGR, //1 + IARM_BUS_SYSMGR_SYSSTATE_TUNEREADY, //2 + IARM_BUS_SYSMGR_SYSSTATE_EXIT_OK, //3 + IARM_BUS_SYSMGR_SYSSTATE_CMAC, //4 + IARM_BUS_SYSMGR_SYSSTATE_MOTO_ENTITLEMENT, //5 + IARM_BUS_SYSMGR_SYSSTATE_MOTO_HRV_RX, //6 + IARM_BUS_SYSMGR_SYSSTATE_CARD_CISCO_STATUS, //7 + IARM_BUS_SYSMGR_SYSSTATE_VIDEO_PRESENTING, //8 + IARM_BUS_SYSMGR_SYSSTATE_HDMI_OUT, //9 + IARM_BUS_SYSMGR_SYSSTATE_HDCP_ENABLED, //10 + IARM_BUS_SYSMGR_SYSSTATE_HDMI_EDID_READ, //11 + IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_DWNLD, //12 + IARM_BUS_SYSMGR_SYSSTATE_TIME_SOURCE, //13 + IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE, //14 + IARM_BUS_SYSMGR_SYSSTATE_CA_SYSTEM, //15 + IARM_BUS_SYSMGR_SYSSTATE_ESTB_IP, //16 + IARM_BUS_SYSMGR_SYSSTATE_ECM_IP, //17 + IARM_BUS_SYSMGR_SYSSTATE_LAN_IP, //18 + IARM_BUS_SYSMGR_SYSSTATE_MOCA, //19 + IARM_BUS_SYSMGR_SYSSTATE_DOCSIS, //20 + IARM_BUS_SYSMGR_SYSSTATE_DSG_BROADCAST_CHANNEL, //21 + IARM_BUS_SYSMGR_SYSSTATE_DSG_CA_TUNNEL, //22 + IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD, //23 + IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_DWNLD, //24 + IARM_BUS_SYSMGR_SYSSTATE_CVR_SUBSYSTEM, //25 + IARM_BUS_SYSMGR_SYSSTATE_DOWNLOAD, //26 + IARM_BUS_SYSMGR_SYSSTATE_VOD_AD, //27 + IARM_BUS_SYSMGR_SYSSTATE_DAC_INIT_TIMESTAMP, //28 + IARM_BUS_SYSMGR_SYSSTATE_CABLE_CARD_SERIAL_NO, //29 + IARM_BUS_SYSMGR_SYSSTATE_ECM_MAC, //30 + IARM_BUS_SYSMGR_SYSSTATE_DAC_ID, //31 + IARM_BUS_SYSMGR_SYSSTATE_PLANT_ID, //32 + IARM_BUS_SYSMGR_SYSSTATE_STB_SERIAL_NO, //33 + IARM_BUS_SYSMGR_SYSSTATE_BOOTUP, //34 + IARM_BUS_SYSMGR_SYSSTATE_GATEWAY_CONNECTION, //35 + IARM_BUS_SYSMGR_SYSSTATE_DST_OFFSET, //36 + IARM_BUS_SYSMGR_SYSSTATE_RF_CONNECTED, //37 + IARM_BUS_SYSMGR_SYSSTATE_PARTNERID_CHANGE, //38 + IARM_BUS_SYSMGR_SYSSTATE_IP_MODE, //39 + IARM_BUS_SYSMGR_SYSSTATE_LP_CONNECTION_RESET, //40 + IARM_BUS_SYSMGR_SYSSTATE_RWS_CONNECTION_RESET, //41 + IARM_BUS_SYSMGR_SYSSTATE_QAM_READY, //42 + IARM_BUS_SYSMGR_SYSSTATE_FIRMWARE_UPDATE_STATE, //43, Added as part of RDK-19978, As the IARM + IARM_BUS_SYSMGR_SYSSTATE_USB_DETECTED, //44 + IARM_BUS_SYSMGR_SYSSTATE_LOG_UPLOAD, //45 + IARM_BUS_SYSMGR_SYSSTATE_RED_RECOV_UPDATE_STATE, //46 +} IARM_Bus_SYSMgr_SystemState_t; + +typedef enum _SYSMgr_FirmwareUpdateState_t { + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_UNINITIALIZED = 0, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_REQUESTING = 1, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_DOWNLOADING = 2, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_FAILED = 3, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_DOWNLOAD_COMPLETE = 4, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_VALIDATION_COMPLETE = 5, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_PREPARING_TO_REBOOT = 6, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_ONHOLD_FOR_OPTOUT = 7, /* On Hold for opt-out */ + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_CRITICAL_REBOOT = 8, + IARM_BUS_SYSMGR_FIRMWARE_UPDATE_STATE_NO_UPGRADE_REQUIRED = 9 +} IARM_Bus_SYSMGR_FirmwareUpdateState_t; + +typedef enum _SYSMgr_RecoveryState_t { + IARM_BUS_SYSMGR_RECOVERY_STATE_COMPLETED = 0, + IARM_BUS_SYSMGR_RECOVERY_STATE_STARTED = 1, + IARM_BUS_SYSMGR_RECOVERY_STATE_DOWNLOADED = 2, + IARM_BUS_SYSMGR_RECOVERY_STATE_PROGRAMMED = 3, +} IARM_Bus_SYSMGR_RecoveryState_t; + +typedef enum _SYSMgr_LogUpload_t +{ + IARM_BUS_SYSMGR_LOG_UPLOAD_SUCCESS = 0, + IARM_BUS_SYSMGR_LOG_UPLOAD_FAILED = 1, + IARM_BUS_SYSMGR_LOG_UPLOAD_ABORTED = 2, +} IARM_Bus_SYSMGR_SYSMgr_LogUpload_t; + +typedef struct _IARM_BUS_SYSMgr_EventData_t { + union { + struct _CARD_FWDNLD_DATA { + char eventType; + char status; + } cardFWDNLD; + struct _IMAGE_FWDNLD_DATA { + char status; + } imageFWDNLD; + struct _XUPNP_DATA { + unsigned long deviceInfoLength; + } xupnpData; + struct _HDCP_PROFILE { + unsigned int hdcpProfile; + } hdcpProfileData; + struct _SystemStates { + IARM_Bus_SYSMgr_SystemState_t stateId; + int state; + int error; + char payload[128]; + } systemStates; + struct _EISS_STATUS { + int filterStatus; + } eissEventData; + struct _EISS_APP_ID { + unsigned char idList[4][6]; + int count; + } eissAppIDList; + struct _KEY_CODE_LOG { + int logStatus; + } keyCodeLogData; + struct _USB_MOUNT { + int mounted; + char device[128]; + char dir[256]; + } usbMountData; + + } data; +} IARM_Bus_SYSMgr_EventData_t; + +typedef struct _propertyValue { + int state; + int error; + char payload[128]; +} state_property; + +typedef struct _IARM_Bus_SYSMgr_GetSystemStates_Param_t { + state_property channel_map; + state_property disconnect_mgr_state; + state_property TuneReadyStatus; + state_property exit_ok_key_sequence; + state_property cmac; + state_property card_moto_entitlements; + state_property card_moto_hrv_rx; + state_property dac_init_timestamp; + state_property card_cisco_status; + state_property video_presenting; + state_property hdmi_out; + state_property hdcp_enabled; + state_property hdmi_edid_read; + state_property firmware_download; + state_property time_source; + state_property time_zone_available; + state_property ca_system; + state_property estb_ip; + state_property ecm_ip; + state_property lan_ip; + state_property moca; + state_property docsis; + state_property dsg_broadcast_tunnel; + state_property dsg_ca_tunnel; + state_property cable_card; + state_property cable_card_download; + state_property cvr_subsystem; + state_property download; + state_property vod_ad; + state_property card_serial_no; + state_property ecm_mac; + state_property dac_id; + state_property plant_id; + state_property stb_serial_no; + state_property bootup; + state_property dst_offset; + state_property rf_connected; + state_property ip_mode; + state_property qam_ready_status; + state_property firmware_update_state; + state_property red_recov_state; +} IARM_Bus_SYSMgr_GetSystemStates_Param_t; + +#define IARM_BUS_DSMGR_NAME "DSMgr" + +/*! Events published from DS Mananger */ +typedef enum _DSMgr_EventId_t { + IARM_BUS_DSMGR_EVENT_RES_PRECHANGE = 0, /*!< Resolution Pre Change Event */ + IARM_BUS_DSMGR_EVENT_RES_POSTCHANGE, /*!< Resolution Post Change Event */ + IARM_BUS_DSMGR_EVENT_ZOOM_SETTINGS, /*!< Zoom Settings Events */ + IARM_BUS_DSMGR_EVENT_HDMI_HOTPLUG, /*!< HDMI HPD DETECT Change Event */ + IARM_BUS_DSMGR_EVENT_AUDIO_MODE, /*!< HDMI HPD DETECT Change Event */ + IARM_BUS_DSMGR_EVENT_HDCP_STATUS, /*!< HDMI HDCP status */ + IARM_BUS_DSMGR_EVENT_RX_SENSE, /*!< HDMI Rx Sense status */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG, /*!< HDMI IN HPD change event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS, /*!< HDMI IN signal status change event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS, /*!< HDMI IN status change event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_AV_LATENCY, /*!< HDMI IN AV Latency Event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE, /*!< HDMI IN video mode update event */ + IARM_BUS_DSMGR_EVENT_HDMI_IN_ALLM_STATUS, /*!< HDMI IN ALLM mode update event */ + IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG, /*!< COMPOSITE IN HPD change event */ + IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_SIGNAL_STATUS, /*!< COMPOSITE IN signal status change event */ + IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_STATUS, /*!< COMPOSITE IN status change event */ + IARM_BUS_DSMGR_EVENT_TIME_FORMAT_CHANGE, /*!< Clock Time Format Change Event*/ + IARM_BUS_DSMGR_EVENT_AUDIO_LEVEL_CHANGED, /*!< Audio Level Change Event*/ + IARM_BUS_DSMGR_EVENT_AUDIO_OUT_HOTPLUG, /*!< AUDIO OUT HPD change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_FORMAT_UPDATE, /*!< Audio Format change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_PRIMARY_LANGUAGE_CHANGED, /*!< Audio Primary Language change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_SECONDARY_LANGUAGE_CHANGED, /*!< Audio Secondary Language change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_FADER_CONTROL_CHANGED, /*!< Audio Fader Control change event */ + IARM_BUS_DSMGR_EVENT_AUDIO_ASSOCIATED_AUDIO_MIXING_CHANGED, /*!< Audio Associated Audio Mixing change event */ + IARM_BUS_DSMGR_EVENT_VIDEO_FORMAT_UPDATE, /*!< Video Format change event */ + IARM_BUS_DSMGR_EVENT_DISPLAY_FRAMRATE_PRECHANGE, /*!< Frame rate pre change */ + IARM_BUS_DSMGR_EVENT_DISPLAY_FRAMRATE_POSTCHANGE, /*!< Frame rate post change */ + IARM_BUS_DSMGR_EVENT_AUDIO_PORT_STATE, /*!< Audio Port Init State */ + IARM_BUS_DSMGR_EVENT_SLEEP_MODE_CHANGED, /*!< Sleep Mode Change Event*/ + IARM_BUS_DSMGR_EVENT_HDMI_IN_AVI_CONTENT_TYPE, /*Register(__VA_ARGS__) + + + +#define IARM_BUS_SYSMGR_API_RunScript "RunScript" +/*! Parameter for RunScript call*/ +typedef struct _IARM_Bus_SYSMgr_RunScript_t{ + char script_path [256]; //[in] Null terminated path name of the script. + int return_value; //[out] Returns the ret value of system. +} IARM_Bus_SYSMgr_RunScript_t; + +typedef enum _CECMgr_EventId_t { + IARM_BUS_CECMGR_EVENT_SEND, + IARM_BUS_CECMGR_EVENT_RECV, + IARM_BUS_CECMGR_EVENT_ENABLE, + IARM_BUS_CECMGR_EVENT_DAEMON_INITIALIZED, + IARM_BUS_CECMGR_EVENT_MAX, + IARM_BUS_CECMGR_EVENT_STATUS_UPDATED +} IARM_Bus_CECMgr_EventId_t; + +typedef struct _IARM_Bus_CECMgr_Status_Updated_Param_t +{ + int logicalAddress; +}IARM_Bus_CECMgr_Status_Updated_Param_t; + +typedef struct _IARM_Bus_MFRLib_SetBLSplashScreen_Param{ + char path[255]; +} IARM_Bus_MFRLib_SetBLSplashScreen_Param_t; + +#define IARM_BUS_CECMGR_API_isAvailable "isAvailable" +#define IARM_BUS_DSMGR_API_dsHdmiInGetNumberOfInputs "dsHdmiInGetNumberOfInputs" +#define IARM_BUS_DSMGR_API_dsHdmiInGetStatus "dsHdmiInGetStatus" +#define IARM_BUS_DSMGR_API_dsGetHDMIARCPortId "dsGetHDMIARCPortId" diff --git a/NetworkManager/Tests/mocks/IarmBusMock.h b/NetworkManager/Tests/mocks/IarmBusMock.h new file mode 100644 index 0000000000..61d1c51367 --- /dev/null +++ b/NetworkManager/Tests/mocks/IarmBusMock.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +#include "libIBus.h" + +class IarmBusImplMock : public IarmBusImpl { +public: + IarmBusImplMock() + : IarmBusImpl() + { + // Defaults: + ON_CALL(*this, IARM_Bus_IsConnected(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [](const char*, int* isRegistered) { + *isRegistered = 1; + return IARM_RESULT_SUCCESS; + })); + ON_CALL(*this, IARM_Bus_Init(::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_Connect()) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_RegisterEventHandler(::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_UnRegisterEventHandler(::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_Call(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_BroadcastEvent(::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_RegisterCall(::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + ON_CALL(*this, IARM_Bus_Call_with_IPCTimeout(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_)) + .WillByDefault(::testing::Return(IARM_RESULT_SUCCESS)); + } + virtual ~IarmBusImplMock() = default; + + MOCK_METHOD(IARM_Result_t, IARM_Bus_Init, (const char* name), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_Connect, (), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_IsConnected, (const char* memberName, int* isRegistered), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_RegisterEventHandler, (const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_UnRegisterEventHandler, (const char* ownerName, IARM_EventId_t eventId), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_RemoveEventHandler, (const char* ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_Call, (const char* ownerName, const char* methodName, void* arg, size_t argLen), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_RegisterCall, (const char* methodName, IARM_BusCall_t handler), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_BroadcastEvent, (const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen), (override)); + MOCK_METHOD(IARM_Result_t, IARM_Bus_Call_with_IPCTimeout, (const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout), (override)); +}; diff --git a/NetworkManager/Tests/mocks/Udev.cpp b/NetworkManager/Tests/mocks/Udev.cpp new file mode 100755 index 0000000000..a6b8638b5b --- /dev/null +++ b/NetworkManager/Tests/mocks/Udev.cpp @@ -0,0 +1,124 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2023 Synamedia +* +* 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 "Udev.h" +#include + +UdevImpl* Udev::impl = nullptr; + +Udev::Udev() {} + + void Udev::setImpl(UdevImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +struct udev* Udev::udev_new() +{ + EXPECT_NE(impl, nullptr); + return impl->udev_new(); +} + +udev_enumerate* Udev::udev_enumerate_new(struct udev* udev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_new(udev); +} + +void Udev::udev_enumerate_add_match_subsystem(struct udev_enumerate* enumerate, const char* subsystem) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_add_match_subsystem(enumerate, subsystem); +} + +void Udev::udev_enumerate_scan_devices(struct udev_enumerate* enumerate) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_scan_devices(enumerate); +} + +struct udev_list_entry* Udev::udev_enumerate_get_list_entry(struct udev_enumerate* enumerate) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_get_list_entry(enumerate); +} + +void Udev::udev_enumerate_unref(struct udev_enumerate* enumerate) + { + EXPECT_NE(impl, nullptr); + return impl->udev_enumerate_unref(enumerate); +} + +void Udev::udev_unref(struct udev* udev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_unref(udev); +} + +const char* Udev::udev_list_entry_get_name(struct udev_list_entry* entry) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_list_entry_get_name(entry); +} + +struct udev_device* Udev::udev_device_new_from_syspath(struct udev* udev, const char* path) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_new_from_syspath(udev, path); +} + +void Udev::udev_device_unref(struct udev_device* dev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_unref(dev); +} + +struct udev_device* Udev::udev_device_get_parent_with_subsystem_devtype(struct udev_device* dev, const char* subsystem, const char* devtype) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_get_parent_with_subsystem_devtype(dev, subsystem, devtype); +} + +const char* Udev::udev_device_get_devtype(struct udev_device* dev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_get_devtype(dev); +} + +const char* Udev::udev_device_get_devnode(struct udev_device* dev) +{ + EXPECT_NE(impl, nullptr); + return impl->udev_device_get_devnode(dev); +} + +struct udev* (*udev_new)() = &Udev::udev_new; +udev_enumerate* (*udev_enumerate_new)(struct udev*) = &Udev::udev_enumerate_new; +void (*udev_enumerate_add_match_subsystem)(struct udev_enumerate*, const char*) = &Udev::udev_enumerate_add_match_subsystem; +void (*udev_enumerate_scan_devices)(struct udev_enumerate*) = &Udev::udev_enumerate_scan_devices; +struct udev_list_entry* (*udev_enumerate_get_list_entry)(struct udev_enumerate*) = &Udev::udev_enumerate_get_list_entry; +void (*udev_enumerate_unref)(struct udev_enumerate*) = &Udev::udev_enumerate_unref; +void (*udev_unref)(struct udev*) = &Udev::udev_unref; +const char* (*udev_list_entry_get_name)(struct udev_list_entry*) = &Udev::udev_list_entry_get_name; +struct udev_device* (*udev_device_new_from_syspath)(struct udev*, const char*) = &Udev::udev_device_new_from_syspath; +void (*udev_device_unref)(struct udev_device*) = &Udev::udev_device_unref; +struct udev_device* (*udev_device_get_parent_with_subsystem_devtype)(struct udev_device*, const char*, const char*) = &Udev::udev_device_get_parent_with_subsystem_devtype; +const char* (*udev_device_get_devtype)(struct udev_device*) = &Udev::udev_device_get_devtype; +const char* (*udev_device_get_devnode)(struct udev_device*) = &Udev::udev_device_get_devnode; diff --git a/NetworkManager/Tests/mocks/Udev.h b/NetworkManager/Tests/mocks/Udev.h new file mode 100644 index 0000000000..a9681734be --- /dev/null +++ b/NetworkManager/Tests/mocks/Udev.h @@ -0,0 +1,73 @@ +#pragma once + +struct udev { +}; + +struct udev_enumerate { +}; + +struct udev_list_entry { +}; + +struct udev_device { +}; + +class UdevImpl { +public: + virtual ~UdevImpl() = default; + + virtual struct udev* udev_new() = 0; + virtual struct udev_enumerate* udev_enumerate_new(struct udev* udev) = 0; + virtual void udev_enumerate_add_match_subsystem(struct udev_enumerate* enumerate, const char* subsystem) = 0; + virtual void udev_enumerate_scan_devices(struct udev_enumerate* enumerate) = 0; + virtual struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate* enumerate) = 0; + virtual void udev_enumerate_unref(struct udev_enumerate* enumerate) = 0; + virtual void udev_unref(struct udev* udev) = 0; + virtual const char* udev_list_entry_get_name(struct udev_list_entry* entry) = 0; + virtual struct udev_device* udev_device_new_from_syspath(struct udev* udev, const char* path) = 0; + virtual void udev_device_unref(struct udev_device* dev) = 0; + virtual struct udev_device* udev_device_get_parent_with_subsystem_devtype(struct udev_device* dev, const char* subsystem, const char* devtype) = 0; + virtual const char* udev_device_get_devtype(struct udev_device* dev) = 0; + virtual const char* udev_device_get_devnode(struct udev_device* dev) = 0; +}; + +class Udev { +protected: + static UdevImpl* impl; +public: + Udev(); + Udev(const Udev &obj) = delete; + static void setImpl(UdevImpl* newImpl); + static struct udev* udev_new(); + static udev_enumerate* udev_enumerate_new(struct udev* udev); + static void udev_enumerate_add_match_subsystem(struct udev_enumerate* enumerate, const char* subsystem); + static void udev_enumerate_scan_devices(struct udev_enumerate* enumerate); + static struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate* enumerate); + static void udev_enumerate_unref(struct udev_enumerate* enumerate); + static void udev_unref(struct udev* udev); + static const char* udev_list_entry_get_name(struct udev_list_entry* entry); + static struct udev_device* udev_device_new_from_syspath(struct udev* udev, const char* path); + static void udev_device_unref(struct udev_device* dev); + static struct udev_device* udev_device_get_parent_with_subsystem_devtype(struct udev_device* dev, const char* subsystem, const char* devtype); + static const char* udev_device_get_devtype(struct udev_device* dev); + static const char* udev_device_get_devnode(struct udev_device* dev); +}; + +extern struct udev* (*udev_new)(); +extern udev_enumerate* (*udev_enumerate_new)(struct udev*); +extern void (*udev_enumerate_add_match_subsystem)(struct udev_enumerate*, const char*); +extern void (*udev_enumerate_scan_devices)(struct udev_enumerate*); +extern struct udev_list_entry* (*udev_enumerate_get_list_entry)(struct udev_enumerate*); +extern void (*udev_enumerate_unref)(struct udev_enumerate*); +extern void (*udev_unref)(struct udev*); +extern const char* (*udev_list_entry_get_name)(struct udev_list_entry*); +extern struct udev_device* (*udev_device_new_from_syspath)(struct udev*, const char*); +extern void (*udev_device_unref)(struct udev_device*); +extern struct udev_device* (*udev_device_get_parent_with_subsystem_devtype)(struct udev_device*, const char*, const char*); +extern const char* (*udev_device_get_devtype)(struct udev_device*); +extern const char* (*udev_device_get_devnode)(struct udev_device*); + +#define udev_list_entry_foreach(list_entry, first_entry) \ + for (list_entry = first_entry; \ + list_entry; \ + list_entry = nullptr) diff --git a/NetworkManager/Tests/mocks/UdevMock.h b/NetworkManager/Tests/mocks/UdevMock.h new file mode 100644 index 0000000000..8f34275e61 --- /dev/null +++ b/NetworkManager/Tests/mocks/UdevMock.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Udev.h" + +class UdevImplMock : public UdevImpl { +public: + virtual ~UdevImplMock() = default; + + MOCK_METHOD(struct udev*, udev_new, (), (override)); + MOCK_METHOD(struct udev_enumerate*, udev_enumerate_new, (struct udev * udev), (override)); + MOCK_METHOD(void, udev_enumerate_add_match_subsystem, (struct udev_enumerate * enumerate, const char* subsystem), (override)); + MOCK_METHOD(void, udev_enumerate_scan_devices, (struct udev_enumerate * enumerate), (override)); + MOCK_METHOD(struct udev_list_entry*, udev_enumerate_get_list_entry, (struct udev_enumerate * enumerate), (override)); + MOCK_METHOD(void, udev_enumerate_unref, (struct udev_enumerate * enumerate), (override)); + MOCK_METHOD(void, udev_unref, (struct udev * udev), (override)); + MOCK_METHOD(const char*, udev_list_entry_get_name, (struct udev_list_entry * entry), (override)); + MOCK_METHOD(struct udev_device*, udev_device_new_from_syspath, (struct udev * udev, const char* path), (override)); + MOCK_METHOD(void, udev_device_unref, (struct udev_device * dev), (override)); + MOCK_METHOD(struct udev_device*, udev_device_get_parent_with_subsystem_devtype, (struct udev_device * dev, const char* subsystem, const char* devtype), (override)); + MOCK_METHOD(const char*, udev_device_get_devtype, (struct udev_device * dev), (override)); + MOCK_METHOD(const char*, udev_device_get_devnode, (struct udev_device * dev), (override)); +}; diff --git a/NetworkManager/Tests/mocks/Wraps.cpp b/NetworkManager/Tests/mocks/Wraps.cpp new file mode 100644 index 0000000000..8a61086adf --- /dev/null +++ b/NetworkManager/Tests/mocks/Wraps.cpp @@ -0,0 +1,151 @@ +#include +#include +#include "Wraps.h" +#include +#include + +extern "C" int __wrap_system(const char* command) +{ + return Wraps::getInstance().system(command); +} + +extern "C" FILE* __wrap_popen(const char* command, const char* type) +{ + return Wraps::getInstance().popen(command, type); +} + +extern "C" int __wrap_pclose(FILE* pipe) +{ + return Wraps::getInstance().pclose(pipe); +} + +//This function will be called for syslog() in the code (added -Wl,-wrap,syslog) +extern "C" void __wrap_syslog(int pri, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + Wraps::getInstance().syslog(pri, fmt, args); + vsyslog(pri, fmt, args); + va_end(args); +} + +extern "C" FILE* __wrap_setmntent(const char* command, const char* type) +{ + return Wraps::getInstance().setmntent(command, type); +} + +extern "C" struct mntent* __wrap_getmntent(FILE* pipe) +{ + return Wraps::getInstance().getmntent(pipe); +} + +extern "C" FILE * __wrap_v_secure_popen(const char *direction, const char *command, ...) +{ + va_list args; + FILE *retFp = nullptr; + va_start(args, command); + retFp = Wraps::getInstance().v_secure_popen(direction, command, args); + va_end(args); + return retFp; +} + + +extern "C" int __wrap_v_secure_pclose(FILE *file) +{ + return Wraps::getInstance().v_secure_pclose(file); +} + + +extern "C" int __wrap_v_secure_system(const char *command, ...) +{ + int ret; + va_list args; + va_start(args,command); + ret = Wraps::getInstance().v_secure_system(command, args); + va_end(args); + return ret; +} + +extern "C" ssize_t __wrap_readlink(const char *pathname, char *buf, size_t bufsiz) +{ + return Wraps::getInstance().readlink(pathname, buf, bufsiz); +} + +WrapsImpl* Wraps::impl = nullptr; + +Wraps::Wraps() {} + +void Wraps::setImpl(WrapsImpl* newImpl) +{ + // Handles both resetting 'impl' to nullptr and assigning a new value to 'impl' + EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl)); + impl = newImpl; +} + +Wraps& Wraps::getInstance() +{ + static Wraps instance; + return instance; +} + +int Wraps::system(const char* command) +{ + EXPECT_NE(impl, nullptr); + return impl->system(command); +} + +FILE* Wraps::popen(const char* command, const char* type) +{ + EXPECT_NE(impl, nullptr); + return impl->popen(command, type); +} + +int Wraps::pclose(FILE* pipe) +{ + EXPECT_NE(impl, nullptr); + return impl->pclose(pipe); +} + +void Wraps::syslog(int pri, const char* fmt, va_list args) +{ + EXPECT_NE(impl, nullptr); + impl->syslog(pri, fmt, args); +} + +FILE* Wraps::setmntent(const char* command, const char* type) +{ + EXPECT_NE(impl, nullptr); + return impl->setmntent(command,type); +} + +struct mntent* Wraps::getmntent(FILE* pipe) +{ + EXPECT_NE(impl, nullptr); + return impl->getmntent(pipe); +} + +FILE * Wraps::v_secure_popen(const char *direction, const char *command, va_list args) +{ + EXPECT_NE(impl, nullptr); + return impl->v_secure_popen(direction, command, args); +} + +int Wraps::v_secure_pclose(FILE *file) +{ + EXPECT_NE(impl, nullptr); + return impl->v_secure_pclose(file); +} + +int Wraps::v_secure_system(const char *command, va_list args) +{ + EXPECT_NE(impl, nullptr); + return impl->v_secure_system(command,args); +} + + +ssize_t Wraps::readlink(const char *pathname, char *buf, size_t bufsiz) +{ + EXPECT_NE(impl, nullptr); + return impl->readlink(pathname,buf,bufsiz); +} + diff --git a/NetworkManager/Tests/mocks/Wraps.h b/NetworkManager/Tests/mocks/Wraps.h new file mode 100644 index 0000000000..8dd7da37a7 --- /dev/null +++ b/NetworkManager/Tests/mocks/Wraps.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include "secure_wrappermock.h" + +class WrapsImpl { +public: + virtual ~WrapsImpl() = default; + + virtual int system(const char* command) = 0; + virtual FILE* popen(const char* command, const char* type) = 0; + virtual int pclose(FILE *pipe) = 0; + virtual void syslog(int pri, const char* fmt, va_list args) = 0; + virtual FILE* setmntent(const char* command, const char* type) = 0; + virtual struct mntent* getmntent(FILE *pipe) = 0; + virtual FILE *v_secure_popen(const char *direction, const char *command, va_list args) = 0; + virtual int v_secure_pclose(FILE *) = 0; + virtual int v_secure_system(const char *command, va_list args) =0; + virtual ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) = 0; +}; + +class Wraps { +protected: + static WrapsImpl* impl; + +public: + Wraps(); + Wraps(const Wraps &obj) = delete; + static void setImpl(WrapsImpl* newImpl); + static Wraps& getInstance(); + + static int system(const char* command); + + static FILE* popen(const char* command, const char* type); + + static int pclose(FILE* pipe); + + static void syslog(int pri, const char* fmt, va_list args); + + static FILE* setmntent(const char* command, const char* type); + + static struct mntent* getmntent(FILE* pipe); + + static FILE *v_secure_popen(const char *direction, const char *command, va_list args); + + static int v_secure_pclose(FILE *file); + + static int v_secure_system(const char *command, va_list args); + + ssize_t readlink(const char *pathname, char *buf, size_t bufsiz); +}; diff --git a/NetworkManager/Tests/mocks/WrapsMock.h b/NetworkManager/Tests/mocks/WrapsMock.h new file mode 100644 index 0000000000..2041eab9ee --- /dev/null +++ b/NetworkManager/Tests/mocks/WrapsMock.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include "Wraps.h" + +extern "C" FILE* __real_setmntent(const char* command, const char* type); + +class WrapsImplMock : public WrapsImpl { +public: + WrapsImplMock():WrapsImpl() + { + /*Setting up Default behavior for setmntent: + * We are mocking setmntent in this file below with __wrap_setmntent, + * and the actual setmntent will be called via this interface */ + ON_CALL(*this, setmntent(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const char* command, const char* type) -> FILE* { + return __real_setmntent(command, type); + })); + } + virtual ~WrapsImplMock() = default; + + MOCK_METHOD(int, system, (const char* command), (override)); + MOCK_METHOD(FILE*, popen, (const char* command, const char* type), (override)); + MOCK_METHOD(int, pclose, (FILE* pipe), (override)); + MOCK_METHOD(void, syslog, (int pri, const char* fmt, va_list args), (override)); + MOCK_METHOD(FILE*, setmntent, (const char* command, const char* type), (override)); + MOCK_METHOD(struct mntent*, getmntent, (FILE* pipe), (override)); + MOCK_METHOD(FILE*, v_secure_popen, (const char *direction, const char *command, va_list args), (override)); + MOCK_METHOD(int, v_secure_pclose, (FILE *file), (override)); + MOCK_METHOD(int, v_secure_system,(const char *command, va_list args), (override)); + MOCK_METHOD(ssize_t, readlink, (const char *pathname, char *buf, size_t bufsiz), (override)); +}; \ No newline at end of file diff --git a/NetworkManager/Tests/mocks/thunder/COMLinkMock.h b/NetworkManager/Tests/mocks/thunder/COMLinkMock.h new file mode 100644 index 0000000000..a16d8701dc --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/COMLinkMock.h @@ -0,0 +1,18 @@ +#ifndef RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ +#define RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ + +#include + +#include "Module.h" + +class COMLinkMock : public WPEFramework::PluginHost::IShell::ICOMLink { +public: + virtual ~COMLinkMock() = default; + + MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override)); + MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&, const string&, const string&), (override)); +}; + +#endif //RDKSERVICES_TESTS_MOCKS_COMLINKMOCK_H_ diff --git a/NetworkManager/Tests/mocks/thunder/DispatcherMock.h b/NetworkManager/Tests/mocks/thunder/DispatcherMock.h new file mode 100644 index 0000000000..df31c8a2da --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/DispatcherMock.h @@ -0,0 +1,37 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2023 RDK Management + * + * 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 DISPATCHERMOCK_H +#define DISPATCHERMOCK_H + +#include + +#include "Module.h" + + class DispatcherMock: public WPEFramework::PluginHost::IDispatcher{ + public: + virtual ~DispatcherMock() = default; + MOCK_METHOD(void, AddRef, (), (const, override)); + MOCK_METHOD(uint32_t, Release, (), (const, override)); + MOCK_METHOD(void*, QueryInterface, (const uint32_t interfaceNummer), (override)); + MOCK_METHOD(void, Activate, (WPEFramework::PluginHost::IShell* service)); + MOCK_METHOD(void, Deactivate, ()); + MOCK_METHOD(WPEFramework::Core::ProxyType, Invoke, (const string&, uint32_t, const WPEFramework::Core::JSONRPC::Message&), (override)); +}; +#endif //DISPATCHERMOCK_H diff --git a/NetworkManager/Tests/mocks/thunder/FactoriesImplementation.h b/NetworkManager/Tests/mocks/thunder/FactoriesImplementation.h new file mode 100644 index 0000000000..e571fbb7eb --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/FactoriesImplementation.h @@ -0,0 +1,47 @@ +#pragma once + +#include + +#include "Module.h" + +class FactoriesImplementation : public WPEFramework::PluginHost::IFactories { +public: + FactoriesImplementation(const FactoriesImplementation&) = delete; + FactoriesImplementation& operator=(const FactoriesImplementation&) = delete; + + FactoriesImplementation() + : _requestFactory(5) + , _responseFactory(5) + , _fileBodyFactory(5) + , _jsonRPCFactory(5) + { + // Defaults: + ON_CALL(*this, Request()) + .WillByDefault(::testing::Invoke( + [&]() { return (_requestFactory.Element()); })); + ON_CALL(*this, Response()) + .WillByDefault(::testing::Invoke( + [&]() { return (_responseFactory.Element()); })); + ON_CALL(*this, FileBody()) + .WillByDefault(::testing::Invoke( + [&]() { return (_fileBodyFactory.Element()); })); + ON_CALL(*this, JSONRPC()) + .WillByDefault(::testing::Invoke( + [&]() { + return (WPEFramework::Core::ProxyType>(_jsonRPCFactory.Element())); + })); + } + + virtual ~FactoriesImplementation() = default; + + MOCK_METHOD(WPEFramework::Core::ProxyType, Request, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType, Response, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType, FileBody, (), (override)); + MOCK_METHOD(WPEFramework::Core::ProxyType>, JSONRPC, (), (override)); + +private: + WPEFramework::Core::ProxyPoolType _requestFactory; + WPEFramework::Core::ProxyPoolType _responseFactory; + WPEFramework::Core::ProxyPoolType _fileBodyFactory; + WPEFramework::Core::ProxyPoolType _jsonRPCFactory; +}; diff --git a/NetworkManager/Tests/mocks/thunder/Module.cpp b/NetworkManager/Tests/mocks/thunder/Module.cpp new file mode 100644 index 0000000000..2d85ed902b --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/Module.cpp @@ -0,0 +1,3 @@ +#include "Module.h" + +MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/NetworkManager/Tests/mocks/thunder/Module.h b/NetworkManager/Tests/mocks/thunder/Module.h new file mode 100644 index 0000000000..289d820778 --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/Module.h @@ -0,0 +1,8 @@ +#pragma once + +#ifndef MODULE_NAME +#define MODULE_NAME RdkServicesL1Test +#endif + +#include +#include diff --git a/NetworkManager/Tests/mocks/thunder/ServiceMock.h b/NetworkManager/Tests/mocks/thunder/ServiceMock.h new file mode 100644 index 0000000000..47b9c28514 --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/ServiceMock.h @@ -0,0 +1,77 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 RDK Management + * + * 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 SERVICEMOCK_H +#define SERVICEMOCK_H + +#include + +#include "Module.h" + +class ServiceMock : public WPEFramework::PluginHost::IShell { +public: + virtual ~ServiceMock() = default; + + MOCK_METHOD(void, AddRef, (), (const, override)); + MOCK_METHOD(uint32_t, Release, (), (const, override)); + MOCK_METHOD(string, Versions, (), (const, override)); + MOCK_METHOD(string, Locator, (), (const, override)); + MOCK_METHOD(string, ClassName, (), (const, override)); + MOCK_METHOD(string, Callsign, (), (const, override)); + MOCK_METHOD(string, WebPrefix, (), (const, override)); + MOCK_METHOD(string, ConfigLine, (), (const, override)); + MOCK_METHOD(string, PersistentPath, (), (const, override)); + MOCK_METHOD(string, VolatilePath, (), (const, override)); + MOCK_METHOD(string, DataPath, (), (const, override)); + MOCK_METHOD(state, State, (), (const, override)); + MOCK_METHOD(bool, AutoStart, (), (const, override)); + MOCK_METHOD(bool, Resumed, (), (const, override)); + MOCK_METHOD(bool, IsSupported, (const uint8_t), (const, override)); + MOCK_METHOD(void, EnableWebServer, (const string&, const string&), (override)); + MOCK_METHOD(void, DisableWebServer, (), (override)); + MOCK_METHOD(WPEFramework::PluginHost::ISubSystem*, SubSystems, (), (override)); + MOCK_METHOD(uint32_t, Submit, (const uint32_t, const WPEFramework::Core::ProxyType&), (override)); + MOCK_METHOD(void, Notify, (const string&), (override)); + MOCK_METHOD(void*, QueryInterface, (const uint32_t), (override)); + MOCK_METHOD(void*, QueryInterfaceByCallsign, (const uint32_t, const string&), (override)); + MOCK_METHOD(void, Register, (WPEFramework::PluginHost::IPlugin::INotification*), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::PluginHost::IPlugin::INotification*), (override)); + MOCK_METHOD(string, Version, (), (const, override)); + MOCK_METHOD(string, Model, (), (const, override)); + MOCK_METHOD(bool, Background, (), (const, override)); + MOCK_METHOD(string, Accessor, (), (const, override)); + MOCK_METHOD(string, ProxyStubPath, (), (const, override)); + MOCK_METHOD(string, HashKey, (), (const, override)); + MOCK_METHOD(string, Substitute, (const string&), (const, override)); + MOCK_METHOD(WPEFramework::PluginHost::IShell::ICOMLink*, COMLink, (), (override)); + MOCK_METHOD(uint32_t, Activate, (const reason), (override)); + MOCK_METHOD(uint32_t, Deactivate, (const reason), (override)); + MOCK_METHOD(uint32_t, Unavailable, (const reason), (override)); + MOCK_METHOD(reason, Reason, (), (const, override)); + MOCK_METHOD(uint8_t, Major, (), (const, override)); + MOCK_METHOD(uint8_t, Minor, (), (const, override)); + MOCK_METHOD(uint8_t, Patch, (), (const, override)); + MOCK_METHOD(uint32_t, ConfigLine, (const string& config), (override)); + MOCK_METHOD(string, SystemRootPath, (), (const, override)); + MOCK_METHOD(uint32_t, SystemRootPath, (const string& systemRootPath), (override)); + MOCK_METHOD(uint32_t, Hibernate, (const string &processSequence, const uint32_t timeout), (override)); + MOCK_METHOD(uint32_t, Wakeup, (const string &processSequence, const uint32_t timeout), (override)); +}; + +#endif //SERVICEMOCK_H diff --git a/NetworkManager/Tests/mocks/thunder/SystemInfo.h b/NetworkManager/Tests/mocks/thunder/SystemInfo.h new file mode 100644 index 0000000000..db48b29484 --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/SystemInfo.h @@ -0,0 +1,63 @@ +#pragma once + +#include + +#include "Module.h" + +class SystemInfo : public WPEFramework::PluginHost::ISubSystem { +private: + SystemInfo(const SystemInfo&) = delete; + SystemInfo& operator=(const SystemInfo&) = delete; + +public: + SystemInfo() + : _flags(0) + { + // Defaults: + ON_CALL(*this, Set(::testing::_, ::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type, WPEFramework::Core::IUnknown* information) { + _subsystems.emplace(type, information); + + if (type >= NEGATIVE_START) { + _flags &= ~(1 << (type - NEGATIVE_START)); + } else { + _flags |= (1 << type); + } + })); + ON_CALL(*this, Get(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type) -> const WPEFramework::Core::IUnknown* { + const WPEFramework::Core::IUnknown* result(nullptr); + + auto it = _subsystems.find(type); + if (it != _subsystems.end()) { + result = it->second; + } + + return result; + })); + ON_CALL(*this, IsActive(::testing::_)) + .WillByDefault(::testing::Invoke( + [&](const subsystem type) -> bool { + return ((type < END_LIST) && ((_flags & (1 << type)) != 0)); + })); + } + virtual ~SystemInfo() = default; + +public: + MOCK_METHOD(void, Register, (WPEFramework::PluginHost::ISubSystem::INotification * notification), (override)); + MOCK_METHOD(void, Unregister, (WPEFramework::PluginHost::ISubSystem::INotification * notification), (override)); + MOCK_METHOD(string, BuildTreeHash, (), (const, override)); + MOCK_METHOD(void, Set, (const subsystem type, WPEFramework::Core::IUnknown* information), (override)); + MOCK_METHOD(const WPEFramework::Core::IUnknown*, Get, (const subsystem type), (const, override)); + MOCK_METHOD(bool, IsActive, (const subsystem type), (const, override)); + + BEGIN_INTERFACE_MAP(SystemInfo) + INTERFACE_ENTRY(WPEFramework::PluginHost::ISubSystem) + END_INTERFACE_MAP + +private: + std::map _subsystems; + uint32_t _flags; +}; diff --git a/NetworkManager/Tests/mocks/thunder/WorkerPoolImplementation.h b/NetworkManager/Tests/mocks/thunder/WorkerPoolImplementation.h new file mode 100644 index 0000000000..dbc5b9e5b6 --- /dev/null +++ b/NetworkManager/Tests/mocks/thunder/WorkerPoolImplementation.h @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include "Module.h" + +class WorkerPoolImplementation : public WPEFramework::Core::WorkerPool { +private: + class Dispatcher : public WPEFramework::Core::ThreadPool::IDispatcher { + public: + Dispatcher(const Dispatcher&) = delete; + Dispatcher& operator=(const Dispatcher&) = delete; + + Dispatcher() = default; + ~Dispatcher() override = default; + + private: + void Initialize() override {} + void Deinitialize() override {} + void Dispatch(WPEFramework::Core::IDispatch* job) override + { + job->Dispatch(); + } + }; + +public: + WorkerPoolImplementation() = delete; + WorkerPoolImplementation(const WorkerPoolImplementation&) = delete; + WorkerPoolImplementation& operator=(const WorkerPoolImplementation&) = delete; + + WorkerPoolImplementation(const uint8_t threads, const uint32_t stackSize, const uint32_t queueSize) + : WPEFramework::Core::WorkerPool(threads - 1, stackSize, queueSize, &_dispatcher) + , _dispatcher() + { + } + + virtual ~WorkerPoolImplementation() + { + WPEFramework::Core::WorkerPool::Stop(); + } + +private: + Dispatcher _dispatcher; +}; diff --git a/NetworkManager/WiFiSignalStrengthMonitor.cpp b/NetworkManager/WiFiSignalStrengthMonitor.cpp index 0230095b52..966fe2d4e7 100644 --- a/NetworkManager/WiFiSignalStrengthMonitor.cpp +++ b/NetworkManager/WiFiSignalStrengthMonitor.cpp @@ -27,7 +27,7 @@ namespace WPEFramework FILE *fp = popen(command, "r"); if (!fp) { - NMLOG_ERROR("Failed in getting output from command %s \n",command); + NMLOG_ERROR("Failed in getting output from command %s",command); return keystr; } @@ -99,7 +99,6 @@ namespace WPEFramework isRunning = true; monitorThread = std::thread(&WiFiSignalStrengthMonitor::monitorThreadFunction, this, interval); monitorThread.detach(); - std::thread::id threadId = monitorThread.get_id(); NMLOG_INFO("Thread started with interval: %d seconds", interval); } diff --git a/NetworkManager/l1networkmanager.cmake b/NetworkManager/l1networkmanager.cmake new file mode 100644 index 0000000000..4466647ace --- /dev/null +++ b/NetworkManager/l1networkmanager.cmake @@ -0,0 +1,50 @@ +message("Building for unit tests...") + +message("Generating empty headers to suppress compiler errors") + +file(GLOB BASEDIR Tests) +set(BASEDIR ${BASEDIR}/headers) +set(EMPTY_HEADERS_DIRS + ${BASEDIR} + ${BASEDIR}/rdk/iarmbus + ${BASEDIR}/network + ) + +set(EMPTY_HEADERS + ${BASEDIR}/rdk/iarmbus/libIARM.h + ${BASEDIR}/rdk/iarmbus/libIBus.h + ${BASEDIR}/rdk/iarmbus/libIBusDaemon.h + ${BASEDIR}/network/wifiSrvMgrIarmIf.h + ${BASEDIR}/network/netsrvmgrIarm.h + ) + +file(MAKE_DIRECTORY ${EMPTY_HEADERS_DIRS}) + +file(GLOB_RECURSE EMPTY_HEADERS_AVAILABLE "${BASEDIR}/*") +if (EMPTY_HEADERS_AVAILABLE) + message("Skip already generated headers to avoid rebuild") + list(REMOVE_ITEM EMPTY_HEADERS ${EMPTY_HEADERS_AVAILABLE}) +endif () +if (EMPTY_HEADERS) + file(TOUCH ${EMPTY_HEADERS}) +endif () + +include_directories(${EMPTY_HEADERS_DIRS}) + +message("Adding compiler and linker options for all targets") + +file(GLOB BASEDIR Tests/mocks) +set(FAKE_HEADERS + ${BASEDIR}/Iarm.h + ) + +foreach (file ${FAKE_HEADERS}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${file}") +endforeach () + +add_compile_options(-Wall -Werror) + +add_link_options(-Wl,-wrap,system -Wl,-wrap,popen -Wl,-wrap,syslog -Wl,-wrap,pclose -Wl,-wrap,getmntent -Wl,-wrap,setmntent -Wl,-wrap,v_secure_popen -Wl,-wrap,v_secure_pclose -Wl,-wrap,v_secure_system) + +message("Setting build options") +set(CMAKE_DISABLE_FIND_PACKAGE_IARMBus ON) diff --git a/Tests/mocks/Iarm.h b/Tests/mocks/Iarm.h index 07bd83bcb3..a0b6e33975 100644 --- a/Tests/mocks/Iarm.h +++ b/Tests/mocks/Iarm.h @@ -718,207 +718,6 @@ typedef enum _DSMgr_EventId_t { } IARM_Bus_DSMgr_EventId_t; -/* ############################# wifiSrvMgrIarmIf.h ################################# */ - -#define IARM_BUS_NM_SRV_MGR_NAME "NET_SRV_MGR" - -#define SSID_SIZE 33 -#define BSSID_BUFF 20 -#define PASSPHRASE_BUFF 385 -#define MAX_SSIDLIST_BUF (48*1024) -/*IARM Interface for wifiManager_2 */ -#define IARM_BUS_WIFI_MGR_API_getAvailableSSIDs "getAvailableSSIDs" /**< Retrieve array of strings representing SSIDs */ -#define IARM_BUS_WIFI_MGR_API_getAvailableSSIDsWithName "getAvailableSSIDsWithName" /**< Retrieve array of strings representing SSIDs info for a specific SSID and band */ -#define IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsync "getAvailableSSIDsAsync" /**< Retrieve array of strings representing SSIDs */ -#define IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsyncIncr "getAvailableSSIDsAsyncIncr" /**< Retrieve array of strings representing SSIDs in an incremental way */ -#define IARM_BUS_WIFI_MGR_API_stopProgressiveWifiScanning "stopProgressiveWifiScanning" /**< Stop any in-progress wifi progressive scanning thread */ -#define IARM_BUS_WIFI_MGR_API_getCurrentState "getCurrentState" /**< Retrieve current state */ -#define IARM_BUS_WIFI_MGR_API_getConnectedSSID "getConnectedSSID" /**< Return properties of the currently connected SSID */ -#define IARM_BUS_WIFI_MGR_API_cancelWPSPairing "cancelWPSPairing" /**< Cancel in-progress WPS */ -#define IARM_BUS_WIFI_MGR_API_getPairedSSID "getPairedSSID" /**< Return paired SSID as a string */ -#define IARM_BUS_WIFI_MGR_API_setEnabled "setEnabled" /**< Enable wifi adapter on the box */ -#define IARM_BUS_WIFI_MGR_API_connect "connect" /**< Connect with given or saved SSID and passphrase */ -#define IARM_BUS_WIFI_MGR_API_initiateWPSPairing "initiateWPSPairing" /**< Initiate connection via WPS */ -#define IARM_BUS_WIFI_MGR_API_initiateWPSPairing2 "initiateWPSPairing2" /**< Initiate connection via WPS via either Push Button or PIN */ -#define IARM_BUS_WIFI_MGR_API_saveSSID "saveSSID" /**< Save SSID and passphrase */ -#define IARM_BUS_WIFI_MGR_API_clearSSID "clearSSID" /**< Clear given SSID */ -#define IARM_BUS_WIFI_MGR_API_disconnectSSID "disconnectSSID" /**< Disconnect from current SSID */ -#define IARM_BUS_WIFI_MGR_API_getPairedSSID "getPairedSSID" /**< Get paired SSID */ -#define IARM_BUS_WIFI_MGR_API_isPaired "isPaired" /**< Retrieve the paired status */ -#define IARM_BUS_WIFI_MGR_API_getLNFState "getLNFState" /**< Retrieve the LNF state */ -#define IARM_BUS_WIFI_MGR_API_isStopLNFWhileDisconnected "isStopLNFWhileDisconnected" /**< Check if LNF is stopped */ -#define IARM_BUS_WIFI_MGR_API_getConnectionType "getConnectionType" /**< Get connection type the current state */ -#define IARM_BUS_WIFI_MGR_API_getSwitchToPrivateResults "getSwitchToPrivateResults" /**< Get all switch to private results */ -#define IARM_BUS_WIFI_MGR_API_isAutoSwitchToPrivateEnabled "isAutoSwitchToPrivateEnabled" /**< Inform whether switch to private is enabled */ -#define IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo "getPairedSSIDInfo" /**< Get last paired ssid info */ - - -/*! Event states associated with WiFi connection */ -typedef enum _WiFiStatusCode_t { - WIFI_UNINSTALLED, /**< The device was in an installed state, and was uninstalled */ - WIFI_DISABLED, /**< The device is installed (or was just installed) and has not yet been enabled */ - WIFI_DISCONNECTED, /**< The device is not connected to a network */ - WIFI_PAIRING, /**< The device is not connected to a network, but not yet connecting to a network */ - WIFI_CONNECTING, /**< The device is attempting to connect to a network */ - WIFI_CONNECTED, /**< The device is successfully connected to a network */ - WIFI_FAILED /**< The device has encountered an unrecoverable error with the wifi adapter */ -} WiFiStatusCode_t; - -/*! Error code: A recoverable, unexpected error occurred, - * as defined by one of the following values */ -typedef enum _WiFiErrorCode_t { - WIFI_SSID_CHANGED, /**< The SSID of the network changed */ - WIFI_CONNECTION_LOST, /**< The connection to the network was lost */ - WIFI_CONNECTION_FAILED, /**< The connection failed for an unknown reason */ - WIFI_CONNECTION_INTERRUPTED, /**< The connection was interrupted */ - WIFI_INVALID_CREDENTIALS, /**< The connection failed due to invalid credentials */ - WIFI_NO_SSID, /**< The SSID does not exist */ - WIFI_UNKNOWN, /**< Any other error */ - WIFI_AUTH_FAILED /**< The connection failed due to auth failure */ -} WiFiErrorCode_t; - -/*! Supported values are NONE - 0, WPA - 1, WEP - 2*/ -typedef enum _SsidSecurity -{ - NET_WIFI_SECURITY_NONE = 0, - NET_WIFI_SECURITY_WEP_64, - NET_WIFI_SECURITY_WEP_128, - NET_WIFI_SECURITY_WPA_PSK_TKIP, - NET_WIFI_SECURITY_WPA_PSK_AES, - NET_WIFI_SECURITY_WPA2_PSK_TKIP, - NET_WIFI_SECURITY_WPA2_PSK_AES, - NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP, - NET_WIFI_SECURITY_WPA_ENTERPRISE_AES, - NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP, - NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES, - NET_WIFI_SECURITY_WPA_WPA2_PSK, - NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE, - NET_WIFI_SECURITY_WPA3_PSK_AES, - NET_WIFI_SECURITY_WPA3_SAE, - NET_WIFI_SECURITY_NOT_SUPPORTED = 99, -} SsidSecurity; - -typedef struct _WiFiConnection -{ - char ssid[SSID_SIZE]; - char passphrase[PASSPHRASE_BUFF]; - SsidSecurity security_mode; -} WiFiConnection; - -typedef struct _WiFiConnectedSSIDInfo -{ - char ssid[SSID_SIZE]; /**< The name of connected SSID. */ - char bssid[BSSID_BUFF]; /**< The the Basic Service Set ID (mac address). */ - int securityMode; /**< Current WiFi Security Mode used for connection. */ - int frequency; /**< The Frequency wt which the client is connected to. */ - float rate; /**< The Physical data rate in Mbps */ - float noise; /**< The average noise strength in dBm. */ - float signalStrength; /**< The RSSI value in dBm. */ - -} WiFiConnectedSSIDInfo_t; - -typedef struct _WiFiPairedSSIDInfo -{ - char ssid[SSID_SIZE]; /**< The name of connected SSID. */ - char bssid[BSSID_BUFF]; /**< The the Basic Service Set ID (mac address). */ -} WiFiPairedSSIDInfo_t; - -/*! Get/Set Data associated with WiFi Service Manager */ -typedef struct _IARM_Bus_WiFiSrvMgr_SsidList_Param_t { - bool status; -} IARM_Bus_WiFiSrvMgr_SsidList_Param_t; - -typedef struct _IARM_Bus_WiFiSrvMgr_Param_t { - union { - WiFiStatusCode_t wifiStatus; - WiFiConnection connect; - WiFiConnectedSSIDInfo_t getConnectedSSID; - WiFiPairedSSIDInfo_t getPairedSSIDInfo; - struct getPairedSSID { - char ssid[SSID_SIZE]; - } getPairedSSID; - bool isPaired; - } data; - bool status; -} IARM_Bus_WiFiSrvMgr_Param_t; - -typedef struct _IARM_Bus_WiFiSrvMgr_WPS_Parameters_t -{ - bool pbc; - char pin[9]; - bool status; -} IARM_Bus_WiFiSrvMgr_WPS_Parameters_t; - -/*! Event Data associated with WiFi Service Manager */ -typedef struct _IARM_BUS_WiFiSrvMgr_EventData_t { - union { - struct _WIFI_STATECHANGE_DATA { - WiFiStatusCode_t state; - } wifiStateChange; - struct _WIFI_ERROR { - WiFiErrorCode_t code; - } wifiError; - struct _WIFI_SSID_LIST { - char ssid_list[MAX_SSIDLIST_BUF]; - bool more_data; - } wifiSSIDList; - } data; -} IARM_BUS_WiFiSrvMgr_EventData_t; - -/*! Events published from WiFi Service Manager */ -typedef enum _IARM_Bus_NMgr_WiFi_EventId_t { - IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged = 1, - IARM_BUS_WIFI_MGR_EVENT_onError, - IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged, - IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs, - IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDsIncr, - IARM_BUS_WIFI_MGR_EVENT_MAX, /*!< Maximum event id*/ -} IARM_Bus_NMgr_WiFi_EventId_t; - -/* ############################## Network Manager ####################### */ -#define IARM_BUS_NM_SRV_MGR_NAME "NET_SRV_MGR" -#define INTERFACE_SIZE 10 -#define INTERFACE_LIST 50 -#define MAX_IP_ADDRESS_LEN 46 -#define MAX_IP_FAMILY_SIZE 10 -#define MAX_HOST_NAME_LEN 128 -#define IARM_BUS_NETSRVMGR_API_getActiveInterface "getActiveInterface" -#define IARM_BUS_NETSRVMGR_API_getNetworkInterfaces "getNetworkInterfaces" -#define IARM_BUS_NETSRVMGR_API_getInterfaceList "getInterfaceList" -#define IARM_BUS_NETSRVMGR_API_getDefaultInterface "getDefaultInterface" -#define IARM_BUS_NETSRVMGR_API_setDefaultInterface "setDefaultInterface" -#define IARM_BUS_NETSRVMGR_API_isInterfaceEnabled "isInterfaceEnabled" -#define IARM_BUS_NETSRVMGR_API_setInterfaceEnabled "setInterfaceEnabled" -#define IARM_BUS_NETSRVMGR_API_getSTBip "getSTBip" -#define IARM_BUS_NETSRVMGR_API_setIPSettings "setIPSettings" -#define IARM_BUS_NETSRVMGR_API_getIPSettings "getIPSettings" -#define IARM_BUS_NETSRVMGR_API_getSTBip_family "getSTBip_family" -#define IARM_BUS_NETSRVMGR_API_isConnectedToInternet "isConnectedToInternet" -#define IARM_BUS_NETSRVMGR_API_setConnectivityTestEndpoints "setConnectivityTestEndpoints" -#define IARM_BUS_NETSRVMGR_API_getInternetConnectionState "getInternetConnectionState" -#define IARM_BUS_NETSRVMGR_API_startConnectivityMonitoring "startConnectivityMonitoring" -#define IARM_BUS_NETSRVMGR_API_stopConnectivityMonitoring "stopConnectivityMonitoring" -#define IARM_BUS_NETSRVMGR_API_isAvailable "isAvailable" -#define IARM_BUS_NETSRVMGR_API_getPublicIP "getPublicIP" -#define IARM_BUS_NETSRVMGR_API_configurePNI "configurePNI" - -// TODO: remove this -#define registerMethod(...) for (uint8_t i = 1; GetHandler(i); i++) GetHandler(i)->Register(__VA_ARGS__) - -/* Netsrvmgr Based Macros & Structures */ -typedef struct _IARM_BUS_NetSrvMgr_Iface_EventData_t { - union { - char activeIface[INTERFACE_SIZE]; - char allNetworkInterfaces[INTERFACE_LIST]; - char setInterface[INTERFACE_SIZE]; - char activeIfaceIpaddr[MAX_IP_ADDRESS_LEN]; - }; - char interfaceCount; - bool isInterfaceEnabled; - bool persist; - char ipfamily[MAX_IP_FAMILY_SIZE]; -} IARM_BUS_NetSrvMgr_Iface_EventData_t; - #define IARM_BUS_SYSMGR_API_RunScript "RunScript" /*! Parameter for RunScript call*/ typedef struct _IARM_Bus_SYSMgr_RunScript_t{