Commit d47b98b2 authored by Peter Collingbourne's avatar Peter Collingbourne Committed by Commit Bot

Set $UBSAN_OPTIONS during executable tests and disable UBSan's signal handlers.

The signal handlers interfere with the breakpad and sandbox tests, so
we need to disable them there. We will also want to use the same set of
UBSan options during executable tests as we do during instrumentation
tests, so move the $UBSAN_OPTIONS value into the test harness, and
pass it into the instrumentation test runner using a string extra.

Bug: 469376
Change-Id: I76ffdd4a8221a54a23e257ac4d2321b8f28d2f42
Reviewed-on: https://chromium-review.googlesource.com/812982Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Peter Collingbourne <pcc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522393}
parent a1b64f89
...@@ -115,6 +115,13 @@ UPSTREAM_FLAKINESS_SERVER = 'test-results.appspot.com' ...@@ -115,6 +115,13 @@ UPSTREAM_FLAKINESS_SERVER = 'test-results.appspot.com'
# TODO(jbudorick): Remove once unused. # TODO(jbudorick): Remove once unused.
DEVICE_LOCAL_PROPERTIES_PATH = '/data/local.prop' DEVICE_LOCAL_PROPERTIES_PATH = '/data/local.prop'
# Configure ubsan to print stack traces in the format understood by "stack" so
# that they will be symbolized, and disable signal handlers because they
# interfere with the breakpad and sandbox tests.
UBSAN_OPTIONS = (
'print_stacktrace=1 stack_trace_format=\'#%n pc %o %m\' '
'handle_segv=0 handle_sigbus=0 handle_sigfpe=0')
# TODO(jbudorick): Rework this into testing/buildbot/ # TODO(jbudorick): Rework this into testing/buildbot/
PYTHON_UNIT_TEST_SUITES = { PYTHON_UNIT_TEST_SUITES = {
'pylib_py_unittests': { 'pylib_py_unittests': {
......
...@@ -44,6 +44,8 @@ _EXTRA_TEST = ( ...@@ -44,6 +44,8 @@ _EXTRA_TEST = (
_EXTRA_TEST_LIST = ( _EXTRA_TEST_LIST = (
'org.chromium.native_test.NativeTestInstrumentationTestRunner' 'org.chromium.native_test.NativeTestInstrumentationTestRunner'
'.TestList') '.TestList')
_EXTRA_UBSAN_OPTIONS = (
'org.chromium.native_test.NativeTest.UBSAN_OPTIONS')
_MAX_SHARD_SIZE = 256 _MAX_SHARD_SIZE = 256
_SECONDS_TO_NANOS = int(1e9) _SECONDS_TO_NANOS = int(1e9)
...@@ -171,6 +173,8 @@ class _ApkDelegate(object): ...@@ -171,6 +173,8 @@ class _ApkDelegate(object):
device.adb, dir=device.GetExternalStoragePath(), suffix='.gtest_out') device.adb, dir=device.GetExternalStoragePath(), suffix='.gtest_out')
extras[_EXTRA_STDOUT_FILE] = stdout_file.name extras[_EXTRA_STDOUT_FILE] = stdout_file.name
extras[_EXTRA_UBSAN_OPTIONS] = constants.UBSAN_OPTIONS
if self._wait_for_java_debugger: if self._wait_for_java_debugger:
cmd = ['am', 'set-debug-app', '-w', self._package] cmd = ['am', 'set-debug-app', '-w', self._package]
device.RunShellCommand(cmd, check_return=True) device.RunShellCommand(cmd, check_return=True)
...@@ -245,7 +249,8 @@ class _ExeDelegate(object): ...@@ -245,7 +249,8 @@ class _ExeDelegate(object):
cwd = constants.TEST_EXECUTABLE_DIR cwd = constants.TEST_EXECUTABLE_DIR
env = { env = {
'LD_LIBRARY_PATH': self._device_dist_dir 'LD_LIBRARY_PATH': self._device_dist_dir,
'UBSAN_OPTIONS': constants.UBSAN_OPTIONS,
} }
try: try:
gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP'] gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
......
...@@ -38,6 +38,8 @@ public class NativeTest { ...@@ -38,6 +38,8 @@ public class NativeTest {
"org.chromium.native_test.NativeTest.Shard"; "org.chromium.native_test.NativeTest.Shard";
public static final String EXTRA_STDOUT_FILE = public static final String EXTRA_STDOUT_FILE =
"org.chromium.native_test.NativeTest.StdoutFile"; "org.chromium.native_test.NativeTest.StdoutFile";
public static final String EXTRA_UBSAN_OPTIONS =
"org.chromium.native_test.NativeTest.UBSAN_OPTIONS";
private static final String TAG = "cr_NativeTest"; private static final String TAG = "cr_NativeTest";
......
...@@ -38,16 +38,15 @@ public class NativeUnitTest extends NativeTest { ...@@ -38,16 +38,15 @@ public class NativeUnitTest extends NativeTest {
// Needed by system_monitor_unittest.cc // Needed by system_monitor_unittest.cc
PowerMonitor.createForTests(); PowerMonitor.createForTests();
// Configure ubsan to print stack traces in the format understood by "stack" so that they // Configure ubsan using $UBSAN_OPTIONS. This needs to happen here because ubsan reads its
// will be symbolized. This needs to happen here because ubsan reads its configuration from // configuration from $UBSAN_OPTIONS when the native library is loaded.
// $UBSAN_OPTIONS when the native library is loaded.
// //
// The setenv API was added in L. On older versions of Android, we should still see ubsan // The setenv API was added in L. On older versions of Android, we should still see ubsan
// reports, but they will not have stack traces. // reports, but they will not have stack traces.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { String ubsanOptions = activity.getIntent().getStringExtra(EXTRA_UBSAN_OPTIONS);
if (ubsanOptions != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try { try {
Os.setenv("UBSAN_OPTIONS", "print_stacktrace=1:stack_trace_format='#%n pc %o %m'", Os.setenv("UBSAN_OPTIONS", ubsanOptions, true);
true);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "failed to set UBSAN_OPTIONS", e); Log.w(TAG, "failed to set UBSAN_OPTIONS", e);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment