From a67384786a2eccdff76c056701d638ea1d74bd6a Mon Sep 17 00:00:00 2001 From: nkader321 Date: Mon, 3 Feb 2025 10:39:08 +0000 Subject: [PATCH] RDK-53592 L1/L2 run_ut.sh script for OCDM client repository Reason for change : L1/L2 test framework for ocdm and run scripts added Test procedure: Run run.sh and check tests are executed and reports generated Risks: Low Signed-off-by: nkader321 --- .github/workflows/run_tests.yml | 148 +++++++++++++++++++++ CMakeLists.txt | 4 + Tests/CMakeLists.txt | 8 ++ Tests/L1Tests/CMakeLists.txt | 56 ++++++++ Tests/L1Tests/gtest_main.cpp | 26 ++++ Tests/L1Tests/run.sh | 24 ++++ Tests/L1Tests/tests/open_cdm_ext_tests.cpp | 43 ++++++ Tests/L1Tests/tests/open_cdm_tests.cpp | 39 ++++++ Tests/L2Tests/CMakeLists.txt | 56 ++++++++ Tests/L2Tests/gtest_main.cpp | 26 ++++ Tests/L2Tests/run.sh | 26 ++++ Tests/L2Tests/tests/open_cdm_ext_tests.cpp | 42 ++++++ Tests/run.sh | 61 +++++++++ 13 files changed, 559 insertions(+) create mode 100644 .github/workflows/run_tests.yml create mode 100644 Tests/L1Tests/CMakeLists.txt create mode 100755 Tests/L1Tests/gtest_main.cpp create mode 100755 Tests/L1Tests/run.sh create mode 100644 Tests/L1Tests/tests/open_cdm_ext_tests.cpp create mode 100644 Tests/L1Tests/tests/open_cdm_tests.cpp create mode 100644 Tests/L2Tests/CMakeLists.txt create mode 100755 Tests/L2Tests/gtest_main.cpp create mode 100755 Tests/L2Tests/run.sh create mode 100644 Tests/L2Tests/tests/open_cdm_ext_tests.cpp create mode 100755 Tests/run.sh diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml new file mode 100644 index 00000000..f2444d00 --- /dev/null +++ b/.github/workflows/run_tests.yml @@ -0,0 +1,148 @@ +name: Unit tests + +on: + pull_request: + branches: ["master"] + +jobs: + build: + runs-on: ubuntu-24.04 + + + - name: Install dependencies + run: | + sudo apt -y install build-essential pkg-config cmake ninja-build libusb-1.0-0-dev zlib1g-dev libssl-dev + sudo apt -y install nodejs npm + + - name: Install GStreamer + run: | + sudo apt update + sudo apt install -y libunwind-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + - run: pip install jsonref + + - name: Checkout ThunderTools + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderTools + ref: R5_1 + path: ThunderTools + + - name: Build ThunderTools + run: > + cmake -G Ninja -S ThunderTools -B build/ThunderTools -DCMAKE_INSTALL_PREFIX="install" + cmake --build build/ThunderTools --target install + + - name: Checkout Thunder + uses: actions/checkout@v3 + with: + repository: rdkcentral/Thunder + ref: R5_1 + path: Thunder + + - name: Build Thunder + run: > + 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 + + - name: Checkout ThunderInterfaces + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderInterfaces + ref: R5_1 + path: ThunderInterfaces + + - name: Build ThunderInterfaces + run: > + cmake -G Ninja -S ThunderInterfaces -B build/ThunderInterfaces \ + -DCMAKE_INSTALL_PREFIX="install" + cmake --build build/ThunderInterfaces --target install + + - name: Checkout ThunderNanoServices + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderNanoServices + ref: R5_1 + path: ThunderNanoServices + + - name: Build ThunderNanoServices + run: > + cmake -G Ninja -S ThunderNanoServices -B build/ThunderNanoServices \ + -DCMAKE_INSTALL_PREFIX="install" \ + -DPLUGIN_COMMANDER=ON \ + -DPLUGIN_DIALSERVER=ON \ + -DPLUGIN_DICTIONARY=ON \ + -DPLUGIN_FILETRANSFER=ON \ + -DPLUGIN_INPUTSWITCH=ON \ + -DPLUGIN_PROCESSMONITOR=ON \ + -DPLUGIN_RESOURCEMONITOR=ON \ + -DPLUGIN_SYSTEMCOMMANDS=ON \ + -DPLUGIN_SWITCHBOARD=ON \ + -DPLUGIN_WEBPROXY=ON \ + -DPLUGIN_WEBSHELL=ON + cmake --build build/ThunderNanoServices --target install + + - name: Checkout ThunderNanoServicesRDK + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderNanoServicesRDK + ref: R5_1 + path: ThunderNanoServicesRDK + + - name: Build ThunderNanoServicesRDK + run: > + cmake -G Ninja -S ThunderNanoServicesRDK -B build/ThunderNanoServicesRDK \ + -DCMAKE_INSTALL_PREFIX="install" \ + -DPLUGIN_DEVICEINFO=ON \ + -DPLUGIN_MESSAGECONTROL=ON \ + -DPLUGIN_MESSENGER=ON \ + -DPLUGIN_MONITOR=ON \ + -DPLUGIN_OPENCDMI=ON \ + -DPLUGIN_PERFORMANCEMETRICS=ON + cmake --build build/ThunderNanoServicesRDK --target install + + - name: Checkout ThunderClientLibraries + uses: actions/checkout@v3 + with: + repository: rdkcentral/ThunderClientLibraries + ref: R5_1 + path: ThunderClientLibraries + + - name: Build ThunderClientLibraries + run: > + cmake -G Ninja -S ThunderClientLibraries -B build/ThunderClientLibraries \ + -DCMAKE_INSTALL_PREFIX="install" \ + -DBLUETOOTHAUDIOSINK=ON \ + -DDEVICEINFO=ON \ + -DDISPLAYINFO=ON \ + -DSECURITYAGENT=ON \ + -DPLAYERINFO=ON \ + -DPROTOCOLS=ON \ + -DVIRTUALINPUT=ON \ + -DCDMI=ON \ + -DL1_TESTS=ON \ + -DL2_TESTS=ON + cmake --build build/ThunderClientLibraries --target install + + - name: Export path + run: > + export LD_LIBRARY_PATH=${PWD}/install/lib:${LD_LIBRARY_PATH} + export PATH=${PWD}/install/bin:${PATH} + + - name: Run unit tests + run: /bin/bash ThunderClientLibraries/run.sh -c + + - name: Upload test results to automatic test result management system + run: > + gtest-json-result-push.py ${{github.workspace}}/ThunderClientLibraries/TestReport.json https://rdkeorchestrationservice.as-g8.cf.comcast.net/rdke_orchestration_api/push_unit_test_results `pwd` + diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d195a1e..e99ecb7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,10 @@ option(CRYPTOGRAPHY option(INSTALL_TESTS "Install the test applications" OFF) +option(L1_TESTS "Install the test applications" OFF) + +option(L2_TESTS "Install the test applications" OFF) + if (BUILD_REFERENCE) add_definitions (-DBUILD_REFERENCE=${BUILD_REFERENCE}) endif() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index a9286436..179aca1e 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -19,4 +19,12 @@ if(CDMI) add_subdirectory(ocdmtest) endif() +if(L1_TESTS) + add_subdirectory(L1Tests) +endif() + +if(L2_TESTS) + add_subdirectory(L2Tests) +endif() + diff --git a/Tests/L1Tests/CMakeLists.txt b/Tests/L1Tests/CMakeLists.txt new file mode 100644 index 00000000..02afc48d --- /dev/null +++ b/Tests/L1Tests/CMakeLists.txt @@ -0,0 +1,56 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2024 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(L1Test) + +set(CMAKE_CXX_STANDARD 11) + +find_package(Thunder) +find_package(ClientOCDM REQUIRED) +find_package(${NAMESPACE}Core REQUIRED) +find_package(${NAMESPACE}COM REQUIRED) +find_package(${NAMESPACE}Messaging REQUIRED) +find_package(CompileSettingsDebug CONFIG REQUIRED) +find_package(GTest REQUIRED) +include(CTest) + +file(GLOB TESTS tests/*.cpp) + +add_executable(${PROJECT_NAME} + gtest_main.cpp + ${TESTS} + ) + +include_directories(../../Source/ocdm) +link_directories(../../Source/ocdm) + +target_link_libraries(${PROJECT_NAME} + ${NAMESPACE}Core::${NAMESPACE}Core + ${NAMESPACE}COM::${NAMESPACE}COM + ${NAMESPACE}Messaging::${NAMESPACE}Messaging + CompileSettingsDebug::CompileSettingsDebug + ClientOCDM::ClientOCDM + GTest::GTest + ) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + +gtest_add_tests(TARGET ${PROJECT_NAME}) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/Tests/L1Tests/gtest_main.cpp b/Tests/L1Tests/gtest_main.cpp new file mode 100755 index 00000000..056ecef8 --- /dev/null +++ b/Tests/L1Tests/gtest_main.cpp @@ -0,0 +1,26 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 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. +*/ + +#include + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/Tests/L1Tests/run.sh b/Tests/L1Tests/run.sh new file mode 100755 index 00000000..fc8e5b06 --- /dev/null +++ b/Tests/L1Tests/run.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# This script will build and run the L1 tests + +rm -rf build + +mkdir build + +cd build + +export GTEST_OUTPUT="json" + +cmake .. + +make + +./L1Test + +#Generate coverage report +if [ "$1" != "" ] && [ $1 = "-c" ]; then + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' --output-file coverage.info + lcov --list coverage.info + genhtml coverage.info --output-directory coverage_report +fi diff --git a/Tests/L1Tests/tests/open_cdm_ext_tests.cpp b/Tests/L1Tests/tests/open_cdm_ext_tests.cpp new file mode 100644 index 00000000..621929e6 --- /dev/null +++ b/Tests/L1Tests/tests/open_cdm_ext_tests.cpp @@ -0,0 +1,43 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 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. +*/ + +#include "open_cdm_impl.h" +#include "open_cdm_ext.h" +#include +using namespace testing; + +class OpenCDMExtTest : public ::testing::Test { +protected: + + void SetUp() override { + } + + void TearDown() override { + } +}; + +TEST_F(OpenCDMExtTest, opencdmCreateSystem) +{ + int status = 0; + const char keySystem[] = "playready"; + struct OpenCDMSystem* result; + result = opencdm_create_system(keySystem); + EXPECT_EQ(result, nullptr); +} + diff --git a/Tests/L1Tests/tests/open_cdm_tests.cpp b/Tests/L1Tests/tests/open_cdm_tests.cpp new file mode 100644 index 00000000..feea384e --- /dev/null +++ b/Tests/L1Tests/tests/open_cdm_tests.cpp @@ -0,0 +1,39 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 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. +*/ + +#include "open_cdm.h" +#include +using namespace testing; + +class OpenCDMTest : public ::testing::Test { +protected: + + void SetUp() override { + } + + void TearDown() override { + } +}; + +TEST_F(OpenCDMTest, status) +{ + int status = 1; + EXPECT_EQ(status, 1); +} + diff --git a/Tests/L2Tests/CMakeLists.txt b/Tests/L2Tests/CMakeLists.txt new file mode 100644 index 00000000..c5244785 --- /dev/null +++ b/Tests/L2Tests/CMakeLists.txt @@ -0,0 +1,56 @@ +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2024 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(L2Test) + +set(CMAKE_CXX_STANDARD 11) + +find_package(Thunder) +find_package(ClientOCDM REQUIRED) +find_package(${NAMESPACE}Core REQUIRED) +find_package(${NAMESPACE}COM REQUIRED) +find_package(${NAMESPACE}Messaging REQUIRED) +find_package(CompileSettingsDebug CONFIG REQUIRED) +find_package(GTest REQUIRED) +include(CTest) + +file(GLOB TESTS tests/*.cpp) + +add_executable(${PROJECT_NAME} + gtest_main.cpp + ${TESTS} + ) + +include_directories(../../Source/ocdm) +link_directories(../../Source/ocdm) + +target_link_libraries(${PROJECT_NAME} + ${NAMESPACE}Core::${NAMESPACE}Core + ${NAMESPACE}COM::${NAMESPACE}COM + ${NAMESPACE}Messaging::${NAMESPACE}Messaging + CompileSettingsDebug::CompileSettingsDebug + ClientOCDM::ClientOCDM + GTest::GTest + ) + +gtest_add_tests(TARGET ${PROJECT_NAME}) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/Tests/L2Tests/gtest_main.cpp b/Tests/L2Tests/gtest_main.cpp new file mode 100755 index 00000000..056ecef8 --- /dev/null +++ b/Tests/L2Tests/gtest_main.cpp @@ -0,0 +1,26 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 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. +*/ + +#include + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/Tests/L2Tests/run.sh b/Tests/L2Tests/run.sh new file mode 100755 index 00000000..c5278bba --- /dev/null +++ b/Tests/L2Tests/run.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# This script will build and run the L2 tests + +rm -rf build + +mkdir build + +cd build + +export GTEST_OUTPUT="json" + +cmake .. + +make + +./L2Test + +#Generate coverage report +if [ "$1" != "" ] && [ $1 = "-c" ]; then + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' --output-file coverage.info + lcov --list coverage.info + genhtml coverage.info --output-directory coverage_report +fi + + diff --git a/Tests/L2Tests/tests/open_cdm_ext_tests.cpp b/Tests/L2Tests/tests/open_cdm_ext_tests.cpp new file mode 100644 index 00000000..8984c51c --- /dev/null +++ b/Tests/L2Tests/tests/open_cdm_ext_tests.cpp @@ -0,0 +1,42 @@ +/* +* If not stated otherwise in this file or this component's license file the +* following copyright and licenses apply: +* +* Copyright 2024 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. +*/ + +#include "open_cdm_impl.h" +#include "open_cdm_ext.h" +#include +using namespace testing; + +class OpenCDMExt_Test : public ::testing::Test { +protected: + + void SetUp() override { + } + + void TearDown() override { + } +}; + +TEST_F(OpenCDMExt_Test, opencdm_CreateSystem) +{ + int status = 0; + const char keySystem[] = "playready"; + struct OpenCDMSystem* result; + result = opencdm_create_system(keySystem); + EXPECT_EQ(result, nullptr); +} diff --git a/Tests/run.sh b/Tests/run.sh new file mode 100755 index 00000000..52d669c9 --- /dev/null +++ b/Tests/run.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +#check and install required packages +function checkandInstallPackage(){ + dpkg -s "$1" &> /dev/null + if [ $? -eq 0 ]; then + echo "Package $1 is installed!" + else + echo "Installing package $1" + sudo apt-get install -y $1 + fi + return $? +} + +while getopts ":c" arg; do + case $arg in + c) + echo "set coverage" + coverage=1 + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + echo "Usage: [-c coverage]" >&2 + exit 1 + ;; + esac +done + +#Install required packages +checkandInstallPackage libgtest-dev +checkandInstallPackage libgmock-dev +checkandInstallPackage googletest +checkandInstallPackage lcov +checkandInstallPackage jq + +#Delete previous test report +rm TestReport.json + +#Run the L1 tests +cd L1Tests/ +if [ "$coverage" == 1 ]; then + ./run.sh -c +else + ./run.sh +fi + +cd ../ + + +#Run the L2 tests +cd L2Tests/ +if [ "$coverage" == 1 ]; then + ./run.sh -c +else + ./run.sh +fi + +cd ../ + +#Generate combined report of L1 and L2 test results +find . -name test_detail\*.json | xargs cat | jq -s '{test_cases_results: {tests: map(.tests) | add,failures: map(.failures) | add,disabled: map(.disabled) | add,errors: map(.errors) | add,time: ((map(.time | rtrimstr("s") | tonumber) | add) | tostring + "s"),name: .[0].name,testsuites: map(.testsuites[])}}' > TestReport.json