Skip to content

Commit

Permalink
Linux sandbox: Make the test run on Android as Native executable
Browse files Browse the repository at this point in the history
Make it possible to run the tests via run_tests.py --exe.

BUG=169416
NOTRY=true


Review URL: https://chromiumcodereview.appspot.com/12093055

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180236 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jln@chromium.org committed Feb 2, 2013
1 parent 99768ba commit 72a083f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build/all_android.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
'../ipc/ipc.gyp:ipc_tests_apk',
'../media/media.gyp:media_unittests_apk',
'../net/net.gyp:net_unittests_apk',
'../sandbox/sandbox.gyp:sandbox_linux_unittests_apk',
'../sandbox/sandbox.gyp:sandbox_linux_jni_unittests_apk',
'../sql/sql.gyp:sql_unittests_apk',
'../sync/sync.gyp:sync_unit_tests_apk',
'../ui/ui.gyp:ui_unittests_apk',
Expand Down
1 change: 1 addition & 0 deletions build/android/pylib/forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def Run(self, port_pairs, tool, host_name):
def KillHost(build_type):
logging.info('Killing host_forwarder.')
host_forwarder_path = _MakeBinaryPath(build_type, 'host_forwarder')
assert os.path.exists(host_forwarder_path), 'Please build forwarder2'
(exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
[host_forwarder_path, 'kill-server'])
if exit_code != 0:
Expand Down
4 changes: 3 additions & 1 deletion build/android/pylib/gtest/gtest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

# Add new suites here before upgrading them to the stable list below.
EXPERIMENTAL_TEST_SUITES = [
'sandbox_linux_unittests',
# The JNI version of the sandbox_linux_unittests. Should be changed to
# 'sandbox_linux_unittests' once it can be run with --exe.
'sandbox_linux_jni_unittests',
]

# Do not modify this list without approval of an android owner.
Expand Down
57 changes: 21 additions & 36 deletions sandbox/linux/sandbox_linux.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,26 @@
],
},
{
# The main sandboxing test target.
'target_name': 'sandbox_linux_unittests',
'type': '<(gtest_target_type)',
'dependencies': [
'sandbox',
'../testing/gtest.gyp:gtest',
],
'sources': [
'tests/main.cc',
'tests/unit_tests.cc',
'tests/unit_tests.h',
'services/broker_process_unittest.cc',
'includes': [
'sandbox_linux_test_sources.gypi',
],
'include_dirs': [
'../..',
'type': 'executable',
},
{
# This target is the shared library used by Android APK (i.e.
# JNI-friendly) tests.
'target_name': 'sandbox_linux_jni_unittests',
'includes': [
'sandbox_linux_test_sources.gypi',
],
'type': 'shared_library',
'conditions': [
[ 'compile_suid_client==1', {
'sources': [
'suid/client/setuid_sandbox_client_unittest.cc',
],
}],
[ 'compile_seccomp_bpf==1', {
'sources': [
'seccomp-bpf/bpf_tests.h',
'seccomp-bpf/codegen_unittest.cc',
'seccomp-bpf/errorcode_unittest.cc',
'seccomp-bpf/sandbox_bpf_unittest.cc',
'seccomp-bpf/syscall_iterator_unittest.cc',
'seccomp-bpf/syscall_unittest.cc',
],
}],
['OS == "android" and gtest_target_type == "shared_library"', {
[ 'OS == "android" and gtest_target_type == "shared_library"', {
'dependencies': [
'../testing/android/native_test.gyp:native_test_native_code',
]
],
}],
],
},
Expand Down Expand Up @@ -216,24 +201,24 @@
'..',
],
},

],
'conditions': [
# Strategy copied from base_unittests_apk in base/base.gyp.
[ 'OS=="android" and gtest_target_type == "shared_library"', {
'targets': [
{
'target_name': 'sandbox_linux_unittests_apk',
'target_name': 'sandbox_linux_jni_unittests_apk',
'type': 'none',
'dependencies': [
'sandbox_linux_unittests',
],
'variables': {
'test_suite_name': 'sandbox_linux_unittests',
'test_suite_name': 'sandbox_linux_jni_unittests',
'input_shlib_path':
'<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)sandbox_linux_unittests'
'<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)'
'sandbox_linux_jni_unittests'
'<(SHARED_LIB_SUFFIX)',
},
'dependencies': [
'sandbox_linux_jni_unittests',
],
'includes': [ '../../build/apk_test.gypi' ],
}
],
Expand Down
38 changes: 38 additions & 0 deletions sandbox/linux/sandbox_linux_test_sources.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Tests need to be compiled in the same link unit, so we have to list them
# in a separate .gypi file.
{
'dependencies': [
'sandbox',
'../testing/gtest.gyp:gtest',
],
'include_dirs': [
'../..',
],
'sources': [
'tests/main.cc',
'tests/unit_tests.cc',
'tests/unit_tests.h',
'services/broker_process_unittest.cc',
],
'conditions': [
[ 'compile_suid_client==1', {
'sources': [
'suid/client/setuid_sandbox_client_unittest.cc',
],
}],
[ 'compile_seccomp_bpf==1', {
'sources': [
'seccomp-bpf/bpf_tests.h',
'seccomp-bpf/codegen_unittest.cc',
'seccomp-bpf/errorcode_unittest.cc',
'seccomp-bpf/sandbox_bpf_unittest.cc',
'seccomp-bpf/syscall_iterator_unittest.cc',
'seccomp-bpf/syscall_unittest.cc',
],
}],
],
}
9 changes: 8 additions & 1 deletion sandbox/linux/services/broker_process_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

namespace sandbox {

#if defined(OS_ANDROID)
#define DISABLE_ON_ANDROID(function) DISABLED_##function
#else
#define DISABLE_ON_ANDROID(function) function
#endif

TEST(BrokerProcess, CreateAndDestroy) {
std::vector<std::string> read_whitelist;
read_whitelist.push_back("/proc/cpuinfo");
Expand Down Expand Up @@ -188,7 +194,8 @@ TEST(BrokerProcess, OpenCpuinfoNoClientCheck) {
// expected.
}

TEST(BrokerProcess, OpenFileRW) {
// Disabled until we implement a mkstemp that doesn't require JNI.
TEST(BrokerProcess, DISABLE_ON_ANDROID(OpenFileRW)) {
const char basename[] = "BrokerProcessXXXXXX";
char template_name[2048];
#if defined(OS_ANDROID)
Expand Down

0 comments on commit 72a083f

Please sign in to comment.