2023-12-01 17:32:19 +00:00
|
|
|
# Copyright 2014 Google LLC. All Rights Reserved.
|
2014-07-16 20:47:57 +00:00
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file or at
|
|
|
|
# https://developers.google.com/open-source/licenses/bsd
|
2018-05-30 20:16:30 +00:00
|
|
|
"""Test wrapper for the sample packager binaries."""
|
2014-07-16 20:47:57 +00:00
|
|
|
|
2019-02-01 02:33:25 +00:00
|
|
|
import logging
|
2014-07-16 20:47:57 +00:00
|
|
|
import os
|
2016-08-14 22:28:21 +00:00
|
|
|
import platform
|
2014-07-16 20:47:57 +00:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import test_env
|
|
|
|
|
|
|
|
|
|
|
|
class PackagerApp(object):
|
2018-05-30 20:16:30 +00:00
|
|
|
"""Main integration class for testing the packager binaries."""
|
2014-07-16 20:47:57 +00:00
|
|
|
|
2016-01-07 19:29:19 +00:00
|
|
|
def __init__(self):
|
2024-04-19 14:56:49 +00:00
|
|
|
self.packager_binary = test_env.PACKAGER_BIN
|
|
|
|
self.mpd_generator_binary = test_env.MPD_GENERATOR_BIN
|
2017-04-04 23:35:25 +00:00
|
|
|
# Set this to empty for now in case GetCommandLine() is called before
|
|
|
|
# Package().
|
|
|
|
self.packaging_command_line = ''
|
2021-06-17 04:32:05 +00:00
|
|
|
assert os.path.exists(self.packager_binary), (
|
|
|
|
'Please run from output directory, e.g. out/Debug/packager_test.py\n'
|
|
|
|
' Missing: ' + self.packager_binary)
|
2018-05-30 20:16:30 +00:00
|
|
|
|
2017-12-11 22:06:50 +00:00
|
|
|
def GetEnv(self):
|
|
|
|
env = os.environ.copy()
|
|
|
|
if (platform.system() == 'Darwin' and
|
2024-04-19 14:56:49 +00:00
|
|
|
test_env.BUILD_TYPE == 'shared'):
|
2017-12-11 22:06:50 +00:00
|
|
|
env['DYLD_FALLBACK_LIBRARY_PATH'] = test_env.SCRIPT_DIR
|
|
|
|
return env
|
|
|
|
|
2014-07-16 20:47:57 +00:00
|
|
|
def DumpStreamInfo(self, stream):
|
|
|
|
input_str = 'input=%s' % stream
|
2018-05-30 20:16:30 +00:00
|
|
|
cmd = [self.packager_binary, input_str, '--dump_stream_info']
|
2019-02-13 00:45:44 +00:00
|
|
|
return subprocess.check_output(cmd, env=self.GetEnv()).decode()
|
2014-07-16 20:47:57 +00:00
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
def Version(self):
|
2017-12-11 22:06:50 +00:00
|
|
|
return subprocess.check_output(
|
2019-02-13 00:45:44 +00:00
|
|
|
[self.packager_binary, '--version'], env=self.GetEnv()).decode()
|
2015-12-21 23:10:17 +00:00
|
|
|
|
2014-07-16 20:47:57 +00:00
|
|
|
def Package(self, streams, flags=None):
|
2017-04-25 19:29:28 +00:00
|
|
|
"""Executes packager command."""
|
2014-07-16 20:47:57 +00:00
|
|
|
if flags is None:
|
|
|
|
flags = []
|
2018-05-30 20:16:30 +00:00
|
|
|
cmd = [self.packager_binary]
|
2014-07-16 20:47:57 +00:00
|
|
|
cmd.extend(streams)
|
|
|
|
cmd.extend(flags)
|
2017-04-25 19:29:28 +00:00
|
|
|
|
|
|
|
if test_env.options.v:
|
|
|
|
cmd.extend(['--v=%s' % test_env.options.v])
|
|
|
|
if test_env.options.vmodule:
|
|
|
|
cmd.extend(['--vmodule="%s"' % test_env.options.vmodule])
|
|
|
|
|
2017-04-04 23:35:25 +00:00
|
|
|
# Put single-quotes around each entry so that things like '$' signs in
|
|
|
|
# segment templates won't be interpreted as shell variables.
|
|
|
|
self.packaging_command_line = ' '.join(["'%s'" % entry for entry in cmd])
|
2017-12-11 22:06:50 +00:00
|
|
|
packaging_result = subprocess.call(cmd, env=self.GetEnv())
|
2017-06-17 01:36:16 +00:00
|
|
|
if packaging_result != 0:
|
2019-02-01 02:33:25 +00:00
|
|
|
logging.error('%s returned non-0 status', self.packaging_command_line)
|
2017-06-17 01:36:16 +00:00
|
|
|
return packaging_result
|
2017-04-04 23:35:25 +00:00
|
|
|
|
|
|
|
def GetCommandLine(self):
|
|
|
|
return self.packaging_command_line
|
2018-05-30 20:16:30 +00:00
|
|
|
|
|
|
|
def MpdGenerator(self, flags):
|
|
|
|
"""Executes MPD Generator command."""
|
|
|
|
cmd = [self.mpd_generator_binary]
|
|
|
|
cmd.extend(flags)
|
|
|
|
|
|
|
|
if test_env.options.v:
|
|
|
|
cmd.extend(['--v=%s' % test_env.options.v])
|
|
|
|
if test_env.options.vmodule:
|
|
|
|
cmd.extend(['--vmodule="%s"' % test_env.options.vmodule])
|
|
|
|
|
|
|
|
return subprocess.call(cmd, env=self.GetEnv())
|