Skip to content

Commit

Permalink
Merge changes from topic 'libcxx-allocator-tests'
Browse files Browse the repository at this point in the history
* changes:
  Remove xfail for a fixed libc++ test.
  Time phases of run_tests.py.
  Parallelize device discovery, fixup pylint issues.
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Jun 29, 2017
2 parents 9608d18 + 63b46dd commit 355d3d6
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 96 deletions.
25 changes: 0 additions & 25 deletions build/lib/build_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
# limitations under the License.
#
import argparse
import datetime
import multiprocessing
import os
import shutil
import subprocess
import sys
import tempfile
import timeit
import zipfile


Expand Down Expand Up @@ -80,29 +78,6 @@ def minimum_platform_level(abi):
return 14


class Timer(object):
def __init__(self):
self.start_time = None
self.end_time = None
self.duration = None

def start(self):
self.start_time = timeit.default_timer()

def finish(self):
self.end_time = timeit.default_timer()

# Not interested in partial seconds at this scale.
seconds = int(self.end_time - self.start_time)
self.duration = datetime.timedelta(seconds=seconds)

def __enter__(self):
self.start()

def __exit__(self, _exc_type, _exc_value, _traceback):
self.finish()


def arch_to_toolchain(arch):
return dict(zip(ALL_ARCHITECTURES, ALL_TOOLCHAINS))[arch]

Expand Down
11 changes: 6 additions & 5 deletions checkbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import ndk.paths
import ndk.test.builder
import ndk.test.spec
import ndk.timer
import ndk.workqueue

import tests.printers
Expand Down Expand Up @@ -1121,7 +1122,7 @@ def parse_args():
def main():
logging.basicConfig()

total_timer = build_support.Timer()
total_timer = ndk.timer.Timer()
total_timer.start()

# It seems the build servers run us in our own session, in which case we
Expand Down Expand Up @@ -1200,7 +1201,7 @@ def main():
if not os.path.exists(log_dir):
os.makedirs(log_dir)

build_timer = build_support.Timer()
build_timer = ndk.timer.Timer()
with build_timer:
workqueue = ndk.workqueue.WorkQueue(args.jobs)
try:
Expand Down Expand Up @@ -1237,22 +1238,22 @@ def main():
workqueue.join()

ndk_dir = ndk.paths.get_install_path(out_dir)
install_timer = build_support.Timer()
install_timer = ndk.timer.Timer()
with install_timer:
if not os.path.exists(ndk_dir):
os.makedirs(ndk_dir)
for module in ALL_MODULES:
if module.name in modules:
module.install(out_dir, dist_dir, args)

package_timer = build_support.Timer()
package_timer = ndk.timer.Timer()
with package_timer:
if do_package:
host_tag = build_support.host_to_tag(args.system)
package_ndk(ndk_dir, dist_dir, host_tag, args.build_number)

good = True
test_timer = build_support.Timer()
test_timer = ndk.timer.Timer()
with test_timer:
if args.test:
good = build_ndk_tests(out_dir, dist_dir, args)
Expand Down
74 changes: 45 additions & 29 deletions ndk/test/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Device(adb.AndroidDevice):
"""A device to be used for testing."""
# pylint: disable=super-on-old-class
# pylint: disable=no-member
def __init__(self, serial):
def __init__(self, serial, precache=False):
super(Device, self).__init__(serial)
self._did_cache = False
self._cached_abis = None
Expand All @@ -48,32 +48,25 @@ def __init__(self, serial):
self._ro_debuggable = None
self._ro_product_name = None

if precache:
self.cache_properties()

def cache_properties(self):
"""Returns a cached copy of the device's system properties."""
if not self._did_cache:
self._ro_build_characteristics = self.get_prop('ro.build.characteristics')
self._ro_build_characteristics = self.get_prop(
'ro.build.characteristics')
self._ro_build_id = self.get_prop('ro.build.id')
self._ro_build_version_sdk = self.get_prop('ro.build.version.sdk')
self._ro_build_version_codename = self.get_prop('ro.build.version.codename')
self._ro_build_version_codename = self.get_prop(
'ro.build.version.codename')
self._ro_debuggable = self.get_prop('ro.debuggable')
self._ro_product_name = self.get_prop('ro.product.name')
self._did_cache = True
return self

@property
def name(self):
return self.cache_properties()._ro_product_name

@property
def version(self):
return int(self.cache_properties()._ro_build_version_sdk)

@property
def abis(self):
"""Returns a list of ABIs supported by the device."""
if self._cached_abis is None:
# 64-bit devices list their ABIs differently than 32-bit devices. Check
# all the possible places for stashing ABI info and merge them.
# 64-bit devices list their ABIs differently than 32-bit devices.
# Check all the possible places for stashing ABI info and merge
# them.
abi_properties = [
'ro.product.cpu.abi',
'ro.product.cpu.abi2',
Expand All @@ -85,27 +78,45 @@ def abis(self):
if value is not None:
abis.update(value.split(','))

_cached_abis = sorted(list(abis))
self._cached_abis = sorted(list(abis))

@property
def name(self):
self.cache_properties()
return self._ro_product_name

return _cached_abis
@property
def version(self):
self.cache_properties()
return int(self._ro_build_version_sdk)

@property
def abis(self):
"""Returns a list of ABIs supported by the device."""
self.cache_properties()
return self._cached_abis

@property
def build_id(self):
return self.cache_properties()._ro_build_id
self.cache_properties()
return self._ro_build_id

@property
def is_release(self):
codename = self.cache_properties()._ro_build_version_codename
self.cache_properties()
codename = self._ro_build_version_codename
return codename == 'REL'

@property
def is_emulator(self):
chars = self.cache_properties()._ro_build_characteristics
self.cache_properties()
chars = self._ro_build_characteristics
return chars == 'emulator'

@property
def is_debuggable(self):
return int(self.cache_properties()._ro_debuggable) != 0
self.cache_properties()
return int(self._ro_debuggable) != 0

def can_run_build_config(self, config):
if self.version < config.api:
Expand Down Expand Up @@ -254,7 +265,7 @@ def get_abis(self, version):
return self.devices[version].keys()


def get_all_attached_devices():
def get_all_attached_devices(workqueue):
"""Returns a list of all connected devices."""
if distutils.spawn.find_executable('adb') is None:
raise RuntimeError('Could not find adb.')
Expand All @@ -269,7 +280,6 @@ def get_all_attached_devices():

# The first line of `adb devices` just says "List of attached devices", so
# skip that.
devices = []
for line in out.split('\n')[1:]:
if not line.strip():
continue
Expand All @@ -283,22 +293,28 @@ def get_all_attached_devices():
logger().info('Ignoring unauthorized device: %s', serial)
continue

device = Device(serial)
# Caching all the device details via getprop can actually take quite a
# bit of time. Do it in parallel to minimize the cost.
workqueue.add_task(Device, serial, True)

devices = []
while not workqueue.finished():
device = workqueue.get_result()
logger().info('Found device %s', device)
devices.append(device)

return devices


def find_devices(sought_devices):
def find_devices(sought_devices, workqueue):
"""Detects connected devices and returns a set for testing.
We get a list of devices by scanning the output of `adb devices` and
matching that with the list of desired test configurations specified by
`sought_devices`.
"""
fleet = DeviceFleet(sought_devices)
for device in get_all_attached_devices():
for device in get_all_attached_devices(workqueue):
fleet.add_device(device)

return fleet
40 changes: 40 additions & 0 deletions ndk/timer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import datetime
import timeit


class Timer(object):
def __init__(self):
self.start_time = None
self.end_time = None
self.duration = None

def start(self):
self.start_time = timeit.default_timer()

def finish(self):
self.end_time = timeit.default_timer()

# Not interested in partial seconds at this scale.
seconds = int(self.end_time - self.start_time)
self.duration = datetime.timedelta(seconds=seconds)

def __enter__(self):
self.start()

def __exit__(self, _exc_type, _exc_value, _traceback):
self.finish()
Loading

0 comments on commit 355d3d6

Please sign in to comment.