From 84009d82ef1b75ec6dab55e8dc5c888d845a956c Mon Sep 17 00:00:00 2001 From: Cosmin Stejerean Date: Fri, 19 Apr 2024 07:56:49 -0700 Subject: [PATCH] build: turn on integration tests in ctest by default (#1381) They can still be skipped by passing `-DSKIP_INTEGRATION_TESTS=ON` for the build configuration. Fix integration tests so they run correctly when building out of tree. Use FindPython3 in CMake to fix build and integration tests on Windows. --- CMakeLists.txt | 2 +- link-test/CMakeLists.txt | 2 +- packager/CMakeLists.txt | 26 +++++++++++---- packager/app/test/packager_app.py | 13 ++------ packager/app/test/packager_test.py | 16 ++++++---- packager/app/test/test_env.py | 27 +++++++++++++--- .../output.mpd | 32 +++++++++---------- packager/tools/CMakeLists.txt | 2 +- packager/tools/pssh/CMakeLists.txt | 6 ++++ packager/version/CMakeLists.txt | 2 +- 10 files changed, 80 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c1e8d132d9..5b96a2429e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ option(FULLY_STATIC "Attempt fully static linking of all CLI apps" OFF) # Enable CMake's test infrastructure. enable_testing() -option(SKIP_INTEGRATION_TESTS "Skip the packager integration tests" ON) +option(SKIP_INTEGRATION_TESTS "Skip the packager integration tests" OFF) # Subdirectories with their own CMakeLists.txt add_subdirectory(packager) diff --git a/link-test/CMakeLists.txt b/link-test/CMakeLists.txt index 3fc0d097d3b..4fce0f1b92c 100644 --- a/link-test/CMakeLists.txt +++ b/link-test/CMakeLists.txt @@ -13,7 +13,7 @@ if(BUILD_SHARED_LIBS) # Custom commands aren't targets, but have outputs. add_custom_command( - DEPENDS mpd_generator packager libpackager + DEPENDS mpd_generator packager libpackager pssh_box_py WORKING_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT ${TEST_INSTALL_DIR} COMMAND diff --git a/packager/CMakeLists.txt b/packager/CMakeLists.txt index a1f8bb25553..7238d243bb2 100644 --- a/packager/CMakeLists.txt +++ b/packager/CMakeLists.txt @@ -66,6 +66,11 @@ include("gtest.cmake") # Include our module for building protos. include("protobuf.cmake") +# Find Python3 used by integration tests, license notice and version string +if(NOT Python3_EXECUTABLE) + find_package(Python3 COMPONENTS Interpreter REQUIRED) +endif() + # Subdirectories with their own CMakeLists.txt, all of whose targets are built. add_subdirectory(file) add_subdirectory(kv_pairs) @@ -228,9 +233,22 @@ add_custom_target(packager_test_py_copy ALL if(NOT SKIP_INTEGRATION_TESTS) add_test (NAME packager_test_py - COMMAND ${PYTHON_EXECUTABLE} packager_test.py + COMMAND "${Python3_EXECUTABLE}" packager_test.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) + + set(test_environment_vars "PACKAGER_SRC_DIR=${CMAKE_SOURCE_DIR}") + list(APPEND test_environment_vars "PACKAGER_BIN=$") + list(APPEND test_environment_vars "MPD_GENERATOR_BIN=$") + if(BUILD_SHARED_LIBS) + list(APPEND test_environment_vars "BUILD_TYPE=shared") + else() + list(APPEND test_environment_vars "BUILD_TYPE=static") + endif() + + set_tests_properties(packager_test_py PROPERTIES + ENVIRONMENT "${test_environment_vars}" + ) endif() configure_file(packager.pc.in packager.pc @ONLY) @@ -238,12 +256,6 @@ configure_file(packager.pc.in packager.pc @ONLY) # Always install the binaries. install(TARGETS mpd_generator packager) -# Always install the python tools. -install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/pssh-box.py - DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pssh-box-protos - DESTINATION ${CMAKE_INSTALL_BINDIR}) - # With shared libraries, also install the library, headers, and pkgconfig. # The static library isn't usable as a standalone because it doesn't include # its static dependencies (zlib, absl, etc). diff --git a/packager/app/test/packager_app.py b/packager/app/test/packager_app.py index a8c87521594..c736749c3d0 100644 --- a/packager/app/test/packager_app.py +++ b/packager/app/test/packager_app.py @@ -17,10 +17,8 @@ class PackagerApp(object): """Main integration class for testing the packager binaries.""" def __init__(self): - self.packager_binary = os.path.join(test_env.SCRIPT_DIR, - self._GetBinaryName('packager')) - self.mpd_generator_binary = os.path.join( - test_env.SCRIPT_DIR, self._GetBinaryName('mpd_generator')) + self.packager_binary = test_env.PACKAGER_BIN + self.mpd_generator_binary = test_env.MPD_GENERATOR_BIN # Set this to empty for now in case GetCommandLine() is called before # Package(). self.packaging_command_line = '' @@ -28,15 +26,10 @@ def __init__(self): 'Please run from output directory, e.g. out/Debug/packager_test.py\n' ' Missing: ' + self.packager_binary) - def _GetBinaryName(self, name): - if platform.system() == 'Windows': - name += '.exe' - return name - def GetEnv(self): env = os.environ.copy() if (platform.system() == 'Darwin' and - test_env.options.libpackager_type == 'shared_library'): + test_env.BUILD_TYPE == 'shared'): env['DYLD_FALLBACK_LIBRARY_PATH'] = test_env.SCRIPT_DIR return env diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 7603e1fb6bb..6df148c753e 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -485,7 +485,7 @@ def _GetFlags(self, use_fake_clock=True, allow_codec_switching=False, dash_force_segment_list=False, - force_cl_index=False): + force_cl_index=None): flags = ['--single_threaded'] @@ -570,8 +570,10 @@ def _GetFlags(self, if allow_codec_switching: flags += ['--allow_codec_switching'] - if force_cl_index: + if force_cl_index is True: flags += ['--force_cl_index'] + elif force_cl_index is False: + flags += ['--noforce_cl_index'] if ad_cues: flags += ['--ad_cues', ad_cues] @@ -754,7 +756,8 @@ def testAudioVideoWithTwoTrickPlay(self): self._GetStream('video', trick_play_factor=2), ] - self.assertPackageSuccess(streams, self._GetFlags(output_dash=True)) + self.assertPackageSuccess(streams, self._GetFlags(output_dash=True, + force_cl_index=False)) self._CheckTestResults('audio-video-with-two-trick-play') def testAudioVideoWithTwoTrickPlayDecreasingRate(self): @@ -765,7 +768,8 @@ def testAudioVideoWithTwoTrickPlayDecreasingRate(self): self._GetStream('video', trick_play_factor=1), ] - self.assertPackageSuccess(streams, self._GetFlags(output_dash=True)) + self.assertPackageSuccess(streams, self._GetFlags(output_dash=True, + force_cl_index=False)) # Since the stream descriptors are sorted in packager app, a different # order of trick play factors gets the same mpd. self._CheckTestResults('audio-video-with-two-trick-play') @@ -1510,8 +1514,8 @@ def testWvmInput(self): # TODO(kqyang): Fix shared_library not supporting strip_parameter_set_nalus # problem. - @unittest.skipUnless( - test_env.options.libpackager_type == 'static_library', + @unittest.skipIf( + test_env.BUILD_TYPE == 'shared', 'libpackager shared_library does not support ' '--strip_parameter_set_nalus flag.' ) diff --git a/packager/app/test/test_env.py b/packager/app/test/test_env.py index 602d9b9bb39..f26a46523f7 100644 --- a/packager/app/test/test_env.py +++ b/packager/app/test/test_env.py @@ -14,21 +14,38 @@ import argparse import os +import platform import sys +def GetBinaryName(name): + if platform.system() == 'Windows': + name += '.exe' + return name + # Define static global objects and attributes. SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) -SRC_DIR = os.path.join(SCRIPT_DIR, os.pardir, os.pardir) +SRC_DIR = os.environ.get('PACKAGER_SRC_DIR') +if not SRC_DIR: + # fallback to computing src dir from script dir + SRC_DIR = os.path.join(SCRIPT_DIR, os.pardir, os.pardir) + +PACKAGER_BIN = os.environ.get('PACKAGER_BIN') +if not PACKAGER_BIN: + PACKAGER_BIN = os.path.join(SCRIPT_DIR, + GetBinaryName('packager')) + +MPD_GENERATOR_BIN = os.environ.get('MPD_GENERATOR_BIN') +if not MPD_GENERATOR_BIN: + MPD_GENERATOR_BIN = os.path.join(SCRIPT_DIR, + GetBinaryName('mpd_generator')) + +BUILD_TYPE = os.environ.get('BUILD_TYPE', 'static') # Parse arguments and calculate dynamic global objects and attributes. parser = argparse.ArgumentParser() - parser.add_argument('--test_update_golden_files', action='store_true') -parser.add_argument('--libpackager_type', default='static_library', - choices=['static_library', 'shared_library']) - parser.add_argument('--v') parser.add_argument('--vmodule') # Overwrite the test to encryption key/iv specified in the command line. diff --git a/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd b/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd index e9c0ec69eb1..bee30c7943a 100644 --- a/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd +++ b/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd @@ -2,35 +2,35 @@ - - - - bear-640x360-audio.mp4 - - + + + bear-640x360-video.mp4 + + - - - bear-640x360-video.mp4 + + + + bear-640x360-video-trick_play_factor_1.mp4 - - - bear-640x360-video-trick_play_factor_2.mp4 - - bear-640x360-video-trick_play_factor_1.mp4 - - + + + + + bear-640x360-audio.mp4 + + diff --git a/packager/tools/CMakeLists.txt b/packager/tools/CMakeLists.txt index a39e37d525c..cae3b2010de 100644 --- a/packager/tools/CMakeLists.txt +++ b/packager/tools/CMakeLists.txt @@ -5,7 +5,7 @@ # https://developers.google.com/open-source/licenses/bsd execute_process( - COMMAND python3 generate_license_notice.py "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND "${Python3_EXECUTABLE}" generate_license_notice.py "${CMAKE_CURRENT_BINARY_DIR}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" RESULT_VARIABLE STATUS) if(NOT STATUS EQUAL 0) diff --git a/packager/tools/pssh/CMakeLists.txt b/packager/tools/pssh/CMakeLists.txt index 8efa15f70d3..0b981cec29a 100644 --- a/packager/tools/pssh/CMakeLists.txt +++ b/packager/tools/pssh/CMakeLists.txt @@ -31,3 +31,9 @@ add_custom_command( ${CMAKE_BINARY_DIR}/packager/) add_custom_target(pssh_box_py ALL DEPENDS ${PSSH_BOX_OUTPUTS}) + +# Always install the python tools. +install(PROGRAMS ${CMAKE_BINARY_DIR}/packager/pssh-box.py + DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(DIRECTORY ${CMAKE_BINARY_DIR}/packager/pssh-box-protos + DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/packager/version/CMakeLists.txt b/packager/version/CMakeLists.txt index 3c3efac421f..fba4fb82823 100644 --- a/packager/version/CMakeLists.txt +++ b/packager/version/CMakeLists.txt @@ -5,7 +5,7 @@ # https://developers.google.com/open-source/licenses/bsd execute_process( - COMMAND python3 generate_version_string.py + COMMAND "${Python3_EXECUTABLE}" generate_version_string.py WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" RESULT_VARIABLE STATUS OUTPUT_VARIABLE PACKAGER_VERSION