Skip to content

Commit

Permalink
build: turn on integration tests in ctest by default (shaka-project#1381
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
cosmin authored Apr 19, 2024
1 parent ceeb378 commit 84009d8
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 48 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion link-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 19 additions & 7 deletions packager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -228,22 +233,29 @@ 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=$<TARGET_FILE:packager>")
list(APPEND test_environment_vars "MPD_GENERATOR_BIN=$<TARGET_FILE:mpd_generator>")
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)

# 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).
Expand Down
13 changes: 3 additions & 10 deletions packager/app/test/packager_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,19 @@ 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 = ''
assert os.path.exists(self.packager_binary), (
'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

Expand Down
16 changes: 10 additions & 6 deletions packager/app/test/packager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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):
Expand All @@ -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')
Expand Down Expand Up @@ -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.'
)
Expand Down
27 changes: 22 additions & 5 deletions packager/app/test/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
<!--Generated with https://github.com/shaka-project/shaka-packager version <tag>-<hash>-<test>-->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT2.736067S">
<Period id="0">
<AdaptationSet id="0" contentType="audio" subsegmentStartsWithSAP="1" subsegmentAlignment="true">
<Representation id="0" bandwidth="133334" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<BaseURL>bear-640x360-audio.mp4</BaseURL>
<SegmentBase indexRange="804-871" timescale="44100">
<Initialization range="0-803"/>
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="30000/1001" subsegmentAlignment="true" par="16:9">
<Representation id="0" bandwidth="973483" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1">
<BaseURL>bear-640x360-video.mp4</BaseURL>
<SegmentBase indexRange="870-937" timescale="30000">
<Initialization range="0-869"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet id="1" contentType="video" width="640" height="360" frameRate="30000/1001" subsegmentAlignment="true" par="16:9">
<Representation id="1" bandwidth="973483" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1">
<BaseURL>bear-640x360-video.mp4</BaseURL>
<AdaptationSet id="1" contentType="video" width="640" height="360" maxFrameRate="30000/22022" par="16:9">
<EssentialProperty schemeIdUri="http://dashif.org/guidelines/trickmode" value="0"/>
<Representation id="1" bandwidth="211545" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" frameRate="30000/30030" maxPlayoutRate="30" codingDependency="false">
<BaseURL>bear-640x360-video-trick_play_factor_1.mp4</BaseURL>
<SegmentBase indexRange="870-937" timescale="30000">
<Initialization range="0-869"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet id="2" contentType="video" width="640" height="360" maxFrameRate="30000/22022" par="16:9">
<EssentialProperty schemeIdUri="http://dashif.org/guidelines/trickmode" value="1"/>
<Representation id="2" bandwidth="211545" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" frameRate="30000/22022" maxPlayoutRate="60" codingDependency="false">
<BaseURL>bear-640x360-video-trick_play_factor_2.mp4</BaseURL>
<SegmentBase indexRange="870-925" timescale="30000">
<Initialization range="0-869"/>
</SegmentBase>
</Representation>
<Representation id="3" bandwidth="211545" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" frameRate="30000/30030" maxPlayoutRate="30" codingDependency="false">
<BaseURL>bear-640x360-video-trick_play_factor_1.mp4</BaseURL>
<SegmentBase indexRange="870-937" timescale="30000">
<Initialization range="0-869"/>
</AdaptationSet>
<AdaptationSet id="2" contentType="audio" subsegmentStartsWithSAP="1" subsegmentAlignment="true">
<Representation id="3" bandwidth="133334" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<BaseURL>bear-640x360-audio.mp4</BaseURL>
<SegmentBase indexRange="804-871" timescale="44100">
<Initialization range="0-803"/>
</SegmentBase>
</Representation>
</AdaptationSet>
Expand Down
2 changes: 1 addition & 1 deletion packager/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions packager/tools/pssh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
2 changes: 1 addition & 1 deletion packager/version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 84009d8

Please sign in to comment.