Merge "Make memunreachable_binder_test suitable for VTS" am: c8a22bc1af
am: ab9ca8beb5
Change-Id: I2c604c33974656144df772afdb7219ed39e1529a
This commit is contained in:
commit
ca18f082aa
2 changed files with 17 additions and 5 deletions
|
@ -20,7 +20,7 @@ cc_defaults {
|
|||
},
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
cc_library {
|
||||
name: "libmemunreachable",
|
||||
defaults: ["libmemunreachable_defaults"],
|
||||
srcs: [
|
||||
|
@ -88,14 +88,14 @@ cc_test {
|
|||
cc_test {
|
||||
name: "memunreachable_binder_test",
|
||||
defaults: ["libmemunreachable_defaults"],
|
||||
test_suites: ["vts"],
|
||||
srcs: [
|
||||
"tests/Binder_test.cpp",
|
||||
"tests/MemUnreachable_test.cpp",
|
||||
],
|
||||
static_libs: ["libmemunreachable"],
|
||||
shared_libs: [
|
||||
"libbinder",
|
||||
"libhwbinder",
|
||||
"libmemunreachable",
|
||||
"libutils",
|
||||
],
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ namespace android {
|
|||
|
||||
static const String16 service_name("test.libmemunreachable_binder");
|
||||
|
||||
// Provides a service that will hold a strong reference to any remote binder
|
||||
// object, so that the test can verify that a remote strong reference is
|
||||
// visible to libmemunreachable.
|
||||
class BinderService : public BBinder {
|
||||
public:
|
||||
BinderService() = default;
|
||||
|
@ -55,6 +58,8 @@ class BinderObject : public BBinder {
|
|||
~BinderObject() = default;
|
||||
};
|
||||
|
||||
// Forks a subprocess that registers a BinderService with the global binder
|
||||
// servicemanager. Requires root permissions.
|
||||
class ServiceProcess {
|
||||
public:
|
||||
ServiceProcess() : child_(0) {}
|
||||
|
@ -97,6 +102,7 @@ class ServiceProcess {
|
|||
fprintf(stderr, "Failed to get service manager\n");
|
||||
return 1;
|
||||
}
|
||||
// This step requires root permissions
|
||||
if (sm->addService(service_name, new BinderService()) != OK) {
|
||||
fprintf(stderr, "Failed to add test service\n");
|
||||
return 1;
|
||||
|
@ -110,12 +116,18 @@ class ServiceProcess {
|
|||
pid_t child_;
|
||||
};
|
||||
|
||||
class BinderTest : public ::testing::Test {
|
||||
class MemunreachableBinderTest : public ::testing::Test {
|
||||
protected:
|
||||
ServiceProcess service_process_;
|
||||
};
|
||||
|
||||
TEST_F(BinderTest, binder) {
|
||||
// Tests that a local binder object with a remote strong reference is visible
|
||||
// through the libmemunreachable BinderReferences interface, which uses the
|
||||
// getBinderKernelReferences method in libbinder. Starts a BinderService
|
||||
// through ServiceProcess as a remote service to hold the strong reference.
|
||||
TEST_F(MemunreachableBinderTest, binder) {
|
||||
ASSERT_EQ(static_cast<uid_t>(0), getuid()) << "This test must be run as root.";
|
||||
|
||||
ServiceProcess service_process;
|
||||
ASSERT_TRUE(service_process.Run());
|
||||
|
||||
|
|
Loading…
Reference in a new issue