Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8a22bc1 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge "Make memunreachable_binder_test suitable for VTS"

parents d24c8484 51e6c252
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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",
    ],
}
+14 −2
Original line number Diff line number Diff line
@@ -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());