Skip to content

Commit

Permalink
Add a --force-unified-headers flag to the tests.
Browse files Browse the repository at this point in the history
Test: ./validate.py --force-unified-headers
Bug: android/ndk#120
Change-Id: I3e32989e3658d64e421845e46a7cb7630a37e57a
  • Loading branch information
DanAlbert committed Nov 3, 2016
1 parent dd740ee commit b4c00af
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
7 changes: 6 additions & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def __init__(self):
'--toolchain', default='clang', choices=('4.9', 'clang'),
help='Toolchain for building tests. Defaults to clang.')

self.add_argument(
'--force-unified-headers', action='store_true',
help='Set `APP_UNIFIED_HEADERS=true` for all builds.')

self.add_argument(
'--show-commands', action='store_true',
help='Show build commands for each test.')
Expand Down Expand Up @@ -173,7 +177,8 @@ def main():
good, _ = tests.runners.run_single_configuration(
ndk_path, out_dir, printer, args.abi, args.toolchain, args.platform,
args.show_commands, suites=suites, test_filter=args.filter,
skip_run=args.skip_run)
skip_run=args.skip_run,
force_unified_headers=args.force_unified_headers)
sys.exit(not good)


Expand Down
27 changes: 13 additions & 14 deletions tests/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def _analyze_results(self, results):
def run_single_configuration(ndk_path, out_dir, printer, abi, toolchain,
build_api_level=None, verbose_build=False,
suites=None, test_filter=None,
device_serial=None, skip_run=False):
device_serial=None, skip_run=False,
force_unified_headers=False):
"""Runs all the tests for the given configuration.
Sets up the necessary build flags and environment, checks that the device
Expand All @@ -155,6 +156,7 @@ def run_single_configuration(ndk_path, out_dir, printer, abi, toolchain,
attached device.
skip_run: Skip running the tests; just build. Useful for post-build
steps if CI doesn't have the device available.
force_unified_headers: Set `APP_UNIFIED_HEADERS=true` for every build.
Returns:
Tuple of (result, details).
Expand All @@ -177,15 +179,11 @@ def run_single_configuration(ndk_path, out_dir, printer, abi, toolchain,

os.environ['NDK'] = ndk_path

ndk_build_flags = []
cmake_flags = []
if verbose_build:
# Don't decrease our log level.
root_logger = logging.getLogger()
if root_logger.getEffectiveLevel() != logging.DEBUG:
root_logger.setLevel(logging.INFO)
ndk_build_flags.append('V=1')
cmake_flags.append('-DCMAKE_VERBOSE_MAKEFILE=ON')

force_pie = False

Expand All @@ -201,8 +199,6 @@ def run_single_configuration(ndk_path, out_dir, printer, abi, toolchain,
# if we're running on a newer device.
if device_api_level >= 21:
force_pie = True
ndk_build_flags.append('APP_PIE=true')
cmake_flags.append('-DANDROID_PIE=TRUE')

os.environ['ANDROID_SERIAL'] = device.serial

Expand Down Expand Up @@ -230,13 +226,14 @@ def run_single_configuration(ndk_path, out_dir, printer, abi, toolchain,
if 'build' in suites:
build_scanner = tests.testlib.BuildTestScanner()
build_scanner.add_build_configuration(
abi, build_api_level, toolchain, force_pie, verbose_build)
abi, build_api_level, toolchain, force_pie, verbose_build,
force_unified_headers)
runner.add_suite('build', 'build', build_scanner)
if 'device' in suites:
device_scanner = tests.testlib.DeviceTestScanner()
device_scanner.add_device_configuration(
abi, build_api_level, toolchain, force_pie, verbose_build, device,
device_api_level, skip_run)
abi, build_api_level, toolchain, force_pie, verbose_build,
force_unified_headers, device, device_api_level, skip_run)
runner.add_suite('device', 'device', device_scanner)

test_filters = tests.filters.TestFilter.from_string(test_filter)
Expand All @@ -248,7 +245,8 @@ def run_single_configuration(ndk_path, out_dir, printer, abi, toolchain,
return stats.global_stats['fail'] == 0, results


def run_tests(ndk_path, device, abi, toolchain, out_dir, log_dir, test_filter):
def run_tests(ndk_path, device, abi, toolchain, out_dir, log_dir, test_filter,
force_unified_headers):
print('Running {} {} tests for {}... '.format(toolchain, abi, device),
end='')
sys.stdout.flush()
Expand All @@ -259,13 +257,14 @@ def run_tests(ndk_path, device, abi, toolchain, out_dir, log_dir, test_filter):
printer = tests.printers.FilePrinter(log_file)
good, details = run_single_configuration(
ndk_path, out_dir, printer, abi, toolchain,
device_serial=device.serial, test_filter=test_filter)
device_serial=device.serial, test_filter=test_filter,
force_unified_headers=force_unified_headers)
print('PASS' if good else 'FAIL')
return good, details


def run_for_fleet(ndk_path, fleet, out_dir, log_dir, test_filter,
use_color=False):
use_color=False, force_unified_headers=False):
# Note that we are duplicating some testing here.
#
# * The awk tests only need to be run once because they do not vary by
Expand All @@ -291,7 +290,7 @@ def run_for_fleet(ndk_path, fleet, out_dir, log_dir, test_filter,

result, run_details = run_tests(
ndk_path, device, abi, toolchain, out_dir, log_dir,
test_filter)
test_filter, force_unified_headers)
pass_label = tests.util.maybe_color('PASS', 'green', use_color)
fail_label = tests.util.maybe_color('FAIL', 'red', use_color)
results.append('android-{} {} {}: {}'.format(
Expand Down
34 changes: 25 additions & 9 deletions tests/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import filecmp
import glob
import imp
import logging
import multiprocessing
import os
import posixpath
Expand All @@ -37,6 +38,11 @@
# pylint: disable=no-self-use


def logger():
"""Return the logger for this module."""
return logging.getLogger(__name__)


def _get_jobs_arg():
return '-j{}'.format(multiprocessing.cpu_count() * 2)

Expand Down Expand Up @@ -64,12 +70,14 @@ def find_tests(self, path, name):


class BuildConfiguration(object):
def __init__(self, abi, api, toolchain, force_pie, verbose):
def __init__(self, abi, api, toolchain, force_pie, verbose,
force_unified_headers):
self.abi = abi
self.api = api
self.toolchain = toolchain
self.force_pie = force_pie
self.verbose = verbose
self.force_unified_headers = force_unified_headers

def __eq__(self, other):
if self.abi != other.abi:
Expand All @@ -82,6 +90,8 @@ def __eq__(self, other):
return False
if self.verbose != other.verbose:
return False
if self.force_unified_headers != other.force_unified_headers:
return False
return True

def get_extra_ndk_build_flags(self):
Expand All @@ -90,6 +100,8 @@ def get_extra_ndk_build_flags(self):
extra_flags.append('APP_PIE=true')
if self.verbose:
extra_flags.append('V=1')
if self.force_unified_headers:
extra_flags.append('APP_UNIFIED_HEADERS=true')
return extra_flags

def get_extra_cmake_flags(self):
Expand All @@ -98,14 +110,16 @@ def get_extra_cmake_flags(self):
extra_flags.append('-DANDROID_PIE=TRUE')
if self.verbose:
extra_flags.append('-DCMAKE_VERBOSE_MAKEFILE=ON')
if self.force_unified_headers:
logger().warning('cmake does not support unified headers')
return extra_flags


class DeviceConfiguration(BuildConfiguration):
def __init__(self, abi, api, toolchain, force_pie, verbose, device,
device_api, skip_run):
def __init__(self, abi, api, toolchain, force_pie, verbose,
force_unified_headers, device, device_api, skip_run):
super(DeviceConfiguration, self).__init__(
abi, api, toolchain, force_pie, verbose)
abi, api, toolchain, force_pie, verbose, force_unified_headers)
self.device = device
self.device_api = device_api
self.skip_run = skip_run
Expand Down Expand Up @@ -147,9 +161,10 @@ class BuildTestScanner(TestScanner):
def __init__(self):
self.build_configurations = set()

def add_build_configuration(self, abi, api, toolchain, force_pie, verbose):
def add_build_configuration(self, abi, api, toolchain, force_pie, verbose,
force_unified_headers):
self.build_configurations.add(BuildConfiguration(
abi, api, toolchain, force_pie, verbose))
abi, api, toolchain, force_pie, verbose, force_unified_headers))

def find_tests(self, path, name):
# If we have a build.sh, that takes precedence over the Android.mk.
Expand Down Expand Up @@ -211,10 +226,11 @@ def __init__(self):
self.device_configurations = set()

def add_device_configuration(self, abi, api, toolchain, force_pie, verbose,
device, device_api, skip_run):
force_unified_headers, device, device_api,
skip_run):
self.device_configurations.add(DeviceConfiguration(
abi, api, toolchain, force_pie, verbose, device, device_api,
skip_run))
abi, api, toolchain, force_pie, verbose, force_unified_headers,
device, device_api, skip_run))

def find_tests(self, path, name):
# If we have a build.sh, that takes precedence over the Android.mk.
Expand Down
6 changes: 5 additions & 1 deletion validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def parse_args():
parser.add_argument(
'--log-dir', type=os.path.realpath, default='test-logs',
help='Directory to store test logs.')
parser.add_argument(
'--force-unified-headers', action='store_true',
help='Set `APP_UNIFIED_HEADERS=true` for all builds.')

return parser.parse_args()

Expand Down Expand Up @@ -264,7 +267,8 @@ def main():
try:
import tests.runners
good, details = tests.runners.run_for_fleet(
args.ndk, fleet, out_dir, args.log_dir, args.filter, use_color)
args.ndk, fleet, out_dir, args.log_dir, args.filter, use_color,
args.force_unified_headers)
finally:
shutil.rmtree(out_dir)

Expand Down

0 comments on commit b4c00af

Please sign in to comment.