Skip to content

Commit

Permalink
Run rialto-ocdm unittests on a rialto (#38)
Browse files Browse the repository at this point in the history
Summary: Run rialto-ocdm unittests on a rialto - OCDM
Type: Fix
Test Plan: Unit Tests
Jira: RIALTO-390
  • Loading branch information
skyshaha1 authored Nov 16, 2023
1 parent 2c7b5ff commit e747a46
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Build gstreamer library
run: |
sudo apt-get update
sudo apt-get install libunwind-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
sudo apt-get install libunwind-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-base
# Setup github for lcov 2.0
- name: Build lcov library
Expand Down
20 changes: 17 additions & 3 deletions build_ut.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import argparse
import multiprocessing
import sys
import shutil

# Default variables
resultOutput = "gtest_result"
Expand All @@ -41,6 +42,16 @@ def runcmd(*args, **kwargs):
args = ' '.join(status.args) if type(status.args) == list else status.args
sys.exit(f'Command: "{args}" returned with {status.returncode} error code!')

def checkAndRemoveFiles():
includeDirs = "tests/third-party/include"

try:
if os.path.exists(includeDirs):
print(f"Removing files within: {includeDirs}")
shutil.rmtree(includeDirs)

except Exception as e:
print(f"An error occurred: {e}")

def main ():
# Get arguments
Expand Down Expand Up @@ -72,6 +83,7 @@ def main ():
+ "Note: Valgrind can only write output to one source (log or xml). \n" \
+ "Note: Requires version valgrind 3.17.0+ installed. \n")
argParser.add_argument("-cov", "--coverage", action='store_true', help="Generates UT coverage report")
argParser.add_argument("-b", "--branch", default="", help="Rialto branch used to pull the API header files during the build and test process")
args = vars(argParser.parse_args())

# Set env variable to disable journald logging
Expand All @@ -85,6 +97,8 @@ def main ():

# Clean if required
if args['clean'] == True:
# Checks and removes the relevant header files in tests/third-party/include as well as tests/third-party/include/opencdm only on clean builds
checkAndRemoveFiles()
executeCmd = ["rm", "-rf", args['output'], resultOutput + ".log", valgrindOutput + ".log"]
runcmd(executeCmd, cwd=os.getcwd())

Expand All @@ -108,17 +122,17 @@ def main ():

# Build the test executables
if args['noBuild'] == False:
buildTargets(suitesToRun, args['output'], f, args['valgrind'], args['coverage'])
buildTargets(suitesToRun, args['output'], f, args['valgrind'], args['coverage'], args['branch'])

# Run the tests with the optional settings
if args['noTest'] == False:
runTests(suitesToRun, args['listTests'], args['googletestFilter'], args['output'], f, xml, args['valgrind'],
args['coverage'])

# Build the target executables
def buildTargets (suites, outputDir, resultsFile, debug, coverage):
def buildTargets (suites, outputDir, resultsFile, debug, coverage, branch):
# Run cmake
cmakeCmd = ["cmake", "-B", outputDir , "-DCMAKE_BUILD_FLAG=UnitTests"]
cmakeCmd = ["cmake", "-B", outputDir , "-DCMAKE_BUILD_FLAG=UnitTests", "-DBUILD_BRANCH=" + str(branch)]
# Coverage
if coverage:
cmakeCmd.append("-DCOVERAGE_ENABLED=1")
Expand Down
108 changes: 52 additions & 56 deletions tests/third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,61 @@ set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
include( CheckCXXCompilerFlag )

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/IMediaKeys.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/rialto/master/media/public/include/IMediaKeys.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/IMediaKeys.h)
# Default to 'master' if branch is not specified
if(BUILD_BRANCH)
message("======= Branch specified, using '${BUILD_BRANCH}' branch =======")
else()
set(BUILD_BRANCH "master")
message("======= No branch specified, using 'master' branch as default =======")
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/IMediaKeysClient.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/rialto/master/media/public/include/IMediaKeysClient.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/IMediaKeysClient.h)
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/MediaCommon.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/rialto/master/media/public/include/MediaCommon.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/MediaCommon.h)
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/ControlCommon.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/rialto/master/media/public/include/ControlCommon.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/ControlCommon.h)
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/IControlClient.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/rialto/master/media/public/include/IControlClient.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/IControlClient.h)
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/IControl.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/rialto/master/media/public/include/IControl.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/IControl.h)
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/IMediaKeysCapabilities.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/rialto/master/media/public/include/IMediaKeysCapabilities.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/IMediaKeysCapabilities.h)
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/opencdm/open_cdm.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/ThunderClientLibraries/master/Source/ocdm/open_cdm.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/opencdm/open_cdm.h)
endif()

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/opencdm/open_cdm_ext.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/ThunderClientLibraries/master/Source/ocdm/open_cdm_ext.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/opencdm/open_cdm_ext.h)
endif()
# Function to download the relevant files, and to check if the file downloaded is empty
function(downloadAndCheck URL FILE)
if((FILE MATCHES "open_cdm_adapter.h") OR (FILE MATCHES "open_cdm_ext.h") OR (FILE MATCHES "open_cdm.h")) # Special case for the different path files
set(FILE_PATH ${CMAKE_SOURCE_DIR}/tests/third-party/include/opencdm/${FILE})
else()
set(FILE_PATH ${CMAKE_SOURCE_DIR}/tests/third-party/include/${FILE})
endif()

if(NOT EXISTS ${FILE_PATH})
file(DOWNLOAD ${URL} ${FILE_PATH})
message("Downloaded ${FILE}")

# If the file is empty
file(READ ${FILE_PATH} fileContents)
if("${fileContents}" STREQUAL "")
message(FATAL_ERROR "The downloaded ${FILE} file is empty!")
endif()
endif()
endfunction()


# List of files to download
set(FILE_LIST
open_cdm_adapter.h
open_cdm_ext.h
open_cdm.h
ControlCommon.h
IControl.h
IControlClient.h
IMediaKeys.h
IMediaKeysCapabilities.h
IMediaKeysClient.h
MediaCommon.h
)

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tests/third-party/include/opencdm/open_cdm_adapter.h)
file(DOWNLOAD
https://raw.githubusercontent.com/rdkcentral/ThunderClientLibraries/master/Source/ocdm/adapter/open_cdm_adapter.h
${CMAKE_SOURCE_DIR}/tests/third-party/include/opencdm/open_cdm_adapter.h)
endif()
# Loop through the list and call the function
foreach(FILE_NAME ${FILE_LIST})
if((FILE_NAME MATCHES "open_cdm_ext.h") OR (FILE_NAME MATCHES "open_cdm.h")) # Special case for header file as the path is different
set(BASE_URL https://raw.githubusercontent.com/rdkcentral/ThunderClientLibraries/master/Source/ocdm/)
elseif(FILE_NAME MATCHES "open_cdm_adapter.h") # Special case for header file as the path is different
set(BASE_URL https://raw.githubusercontent.com/rdkcentral/ThunderClientLibraries/master/Source/ocdm/adapter/)
else()
set(BASE_URL https://raw.githubusercontent.com/rdkcentral/rialto/${BUILD_BRANCH}/media/public/include/)
endif()

downloadAndCheck(${BASE_URL}${FILE_NAME} ${FILE_NAME})
endforeach()

add_library(
ocdmRialtoThirdParty
Expand Down

0 comments on commit e747a46

Please sign in to comment.