Add logging to run_tests.py and fix pylint issues.

Test: ./run_tests.py
Bug: http://b/34740564
Change-Id: I9ae1d2d386842e088db963b2b4eb611450cbe514
This commit is contained in:
Dan Albert
2017-01-26 18:47:23 -08:00
parent c0ecf33175
commit e92499f1c9

View File

@@ -14,11 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Runs the libc++ tests against the platform libc++."""
from __future__ import print_function
import argparse
import logging
import os
import subprocess
import sys
@@ -26,7 +27,27 @@ THIS_DIR = os.path.dirname(os.path.realpath(__file__))
ANDROID_DIR = os.path.realpath(os.path.join(THIS_DIR, '../..'))
def logger():
"""Returns the logger for the module."""
return logging.getLogger(__name__)
def call(cmd, *args, **kwargs):
"""subprocess.call with logging."""
import subprocess
logger().info('call %s', ' '.join(cmd))
return subprocess.call(cmd, *args, **kwargs)
def check_call(cmd, *args, **kwargs):
"""subprocess.check_call with logging."""
import subprocess
logger().info('check_call %s', ' '.join(cmd))
return subprocess.check_call(cmd, *args, **kwargs)
class ArgParser(argparse.ArgumentParser):
"""Parses command line arguments."""
def __init__(self):
super(ArgParser, self).__init__()
self.add_argument(
@@ -37,6 +58,7 @@ class ArgParser(argparse.ArgumentParser):
def gen_test_config(bitness, compiler, host):
"""Generates the test configuration makefile for buildcmds."""
testconfig_mk_path = os.path.join(THIS_DIR, 'buildcmds/testconfig.mk')
with open(testconfig_mk_path, 'w') as test_config:
if compiler == 'clang':
@@ -68,28 +90,38 @@ def gen_test_config(bitness, compiler, host):
def mmm(path):
"""Invokes the Android build command mmm."""
makefile = os.path.join(path, 'Android.mk')
main_mk = 'build/core/main.mk'
env = dict(os.environ)
env['ONE_SHOT_MAKEFILE'] = makefile
env['LIBCXX_TESTING'] = 'true'
cmd = ['make', '-j', '-C', ANDROID_DIR, '-f', main_mk, 'MODULES-IN-' + path.replace('/','-')]
subprocess.check_call(cmd, env=env)
cmd = [
'make', '-j', '-C', ANDROID_DIR, '-f', main_mk,
'MODULES-IN-' + path.replace('/', '-'),
]
check_call(cmd, env=env)
def gen_build_cmds(bitness, compiler, host):
"""Generates the build commands file for the test runner."""
gen_test_config(bitness, compiler, host)
mmm('external/libcxx/buildcmds')
def main():
"""Program entry point."""
logging.basicConfig(level=logging.INFO)
args, lit_args = ArgParser().parse_known_args()
lit_path = os.path.join(ANDROID_DIR, 'external/llvm/utils/lit/lit.py')
gen_build_cmds(args.bitness, args.compiler, args.host)
mode_str = 'host' if args.host else 'device'
android_mode_arg = '--param=android_mode=' + mode_str
site_cfg_path = os.path.join(THIS_DIR, 'test/lit.site.cfg')
site_cfg_arg = '--param=libcxx_site_config=' + site_cfg_path
default_test_path = os.path.join(THIS_DIR, 'test')
have_filter_args = False
@@ -105,11 +137,11 @@ def main():
have_filter_args = True
break # No need to keep scanning.
lit_args = ['-sv', android_mode_arg] + lit_args
lit_args = ['-sv', android_mode_arg, site_cfg_arg] + lit_args
cmd = ['python', lit_path] + lit_args
if not have_filter_args:
cmd.append(default_test_path)
sys.exit(subprocess.call(cmd))
sys.exit(call(cmd))
if __name__ == '__main__':