Repository: mesos
Updated Branches:
  refs/heads/master 4b15b9608 -> b74d07229


Simplified ROOT_CGROUPS_Listen test.

Review: https://reviews.apache.org/r/32955


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/dd9a4d5e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/dd9a4d5e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/dd9a4d5e

Branch: refs/heads/master
Commit: dd9a4d5ec2944fe12003bafb267f386a6e08cc15
Parents: 4b15b96
Author: Chi Zhang <[email protected]>
Authored: Fri Apr 10 15:09:35 2015 -0700
Committer: Jie Yu <[email protected]>
Committed: Fri Apr 10 15:17:31 2015 -0700

----------------------------------------------------------------------
 src/tests/cgroups_tests.cpp | 70 +++++++++-------------------------------
 1 file changed, 15 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dd9a4d5e/src/tests/cgroups_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cgroups_tests.cpp b/src/tests/cgroups_tests.cpp
index e18aed1..475f48a 100644
--- a/src/tests/cgroups_tests.cpp
+++ b/src/tests/cgroups_tests.cpp
@@ -536,17 +536,15 @@ TEST_F(CgroupsAnyHierarchyWithCpuMemoryTest, 
ROOT_CGROUPS_Listen)
     << "this test.\n"
     << "-------------------------------------------------------------";
 
-  // Disable oom killer.
-  ASSERT_SOME(cgroups::memory::oom::killer::disable(
-        hierarchy, TEST_CGROUPS_ROOT));
+  const Bytes limit =  Megabytes(64);
 
-  // Limit the memory usage of the test cgroup to 64MB.
   ASSERT_SOME(cgroups::memory::limit_in_bytes(
-      hierarchy, TEST_CGROUPS_ROOT, Megabytes(64)));
+      hierarchy, TEST_CGROUPS_ROOT, limit));
 
   // Listen on oom events for test cgroup.
   Future<Nothing> future =
     cgroups::memory::oom::listen(hierarchy, TEST_CGROUPS_ROOT);
+
   ASSERT_FALSE(future.isFailed());
 
   // Test the cancellation.
@@ -556,59 +554,21 @@ TEST_F(CgroupsAnyHierarchyWithCpuMemoryTest, 
ROOT_CGROUPS_Listen)
   future = cgroups::memory::oom::listen(hierarchy, TEST_CGROUPS_ROOT);
   ASSERT_FALSE(future.isFailed());
 
-  pid_t pid = ::fork();
-  ASSERT_NE(-1, pid);
-
-  if (pid > 0) {
-    // In parent process.
-    future.await(Seconds(5));
-
-    EXPECT_TRUE(future.isReady());
-
-    // Kill the child process.
-    EXPECT_NE(-1, ::kill(pid, SIGKILL));
-
-    // Wait for the child process.
-    int status;
-    EXPECT_NE(-1, ::waitpid((pid_t) -1, &status, 0));
-    ASSERT_TRUE(WIFSIGNALED(status));
-    EXPECT_EQ(SIGKILL, WTERMSIG(status));
-  } else {
-    // In child process. We try to trigger an oom here.
-    // Put self into the test cgroup.
-    Try<Nothing> assign =
-      cgroups::assign(hierarchy, TEST_CGROUPS_ROOT, ::getpid());
-
-    if (assign.isError()) {
-      std::cerr << "Failed to assign cgroup: " << assign.error() << std::endl;
-      abort();
-    }
-
-    // Blow up the memory.
-    size_t limit = 1024 * 1024 * 512;
-    void* buffer = NULL;
-
-    if (posix_memalign(&buffer, getpagesize(), limit) != 0) {
-      perror("Failed to allocate page-aligned memory, posix_memalign");
-      abort();
-    }
+  MemoryTestHelper helper;
+  ASSERT_SOME(helper.spawn());
+  ASSERT_SOME(helper.pid());
 
-    // We use mlock and memset here to make sure that the memory
-    // actually gets paged in and thus accounted for.
-    if (mlock(buffer, limit) != 0) {
-      perror("Failed to lock memory, mlock");
-      abort();
-    }
+  EXPECT_SOME(cgroups::assign(
+      hierarchy, TEST_CGROUPS_ROOT, helper.pid().get()));
 
-    if (memset(buffer, 1, limit) != buffer) {
-      perror("Failed to fill memory, memset");
-      abort();
-    }
+  // Request more RSS memory in the subprocess than the limit.
+  // NOTE: We enable the kernel oom killer in this test. If it were
+  // disabled, the subprocess might hang and the following call won't
+  // return. By enabling the oom killer, we let the subprocess get
+  // killed and expect that an error is returned.
+  EXPECT_ERROR(helper.increaseRSS(limit * 2));
 
-    // Should not reach here.
-    std::cerr << "OOM does not happen!" << std::endl;
-    abort();
-  }
+  AWAIT_READY(future);
 }
 
 

Reply via email to