You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/08/25 21:58:01 UTC
[08/11] mesos git commit: Moved memory test helper to the common test
helper.
Moved memory test helper to the common test helper.
Review: https://reviews.apache.org/r/51215/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9b04b8df
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9b04b8df
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9b04b8df
Branch: refs/heads/master
Commit: 9b04b8df50cfdea6c3700ba031b7fdfd60a909a4
Parents: 7a1bdf3
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Aug 22 13:07:50 2016 +0200
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Aug 25 14:57:50 2016 -0700
----------------------------------------------------------------------
src/Makefile.am | 18 +-
src/tests/CMakeLists.txt | 3 +
src/tests/cmake/MesosTestsConfigure.cmake | 5 -
src/tests/containerizer/CMakeLists.txt | 15 --
src/tests/containerizer/memory_test_helper.cpp | 217 ++++++++++----------
src/tests/containerizer/memory_test_helper.hpp | 25 +--
src/tests/test_helper_main.cpp | 6 +-
7 files changed, 132 insertions(+), 157 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9b04b8df/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 11bd72a..f226b8f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1915,21 +1915,15 @@ setns_test_helper_CPPFLAGS = $(MESOS_CPPFLAGS)
setns_test_helper_LDADD = libmesos.la $(LDADD)
endif
-check_PROGRAMS += memory-test-helper
-memory_test_helper_SOURCES = \
- tests/flags.cpp \
- tests/utils.cpp \
- tests/containerizer/memory_test_helper_main.cpp \
- tests/containerizer/memory_test_helper.cpp
-memory_test_helper_CPPFLAGS = $(mesos_tests_CPPFLAGS)
-memory_test_helper_LDADD = $(mesos_tests_LDADD)
-
check_PROGRAMS += test-helper
test_helper_SOURCES = \
tests/active_user_test_helper.cpp \
- tests/test_helper_main.cpp
-test_helper_CPPFLAGS = $(MESOS_CPPFLAGS)
-test_helper_LDADD = libmesos.la $(LDADD)
+ tests/flags.cpp \
+ tests/test_helper_main.cpp \
+ tests/utils.cpp \
+ tests/containerizer/memory_test_helper.cpp
+test_helper_CPPFLAGS = $(mesos_tests_CPPFLAGS)
+test_helper_LDADD = libmesos.la $(mesos_tests_LDADD)
check_PROGRAMS += mesos-tests
http://git-wip-us.apache.org/repos/asf/mesos/blob/9b04b8df/src/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 45e3a55..2732a79 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -20,7 +20,10 @@ include(MesosTestsConfigure)
set(TEST_HELPER_SRC
${TEST_HELPER_SRC}
active_user_test_helper.cpp
+ flags.cpp
test_helper_main.cpp
+ utils.cpp
+ containerizer/memory_test_helper.cpp
)
add_subdirectory(containerizer/)
http://git-wip-us.apache.org/repos/asf/mesos/blob/9b04b8df/src/tests/cmake/MesosTestsConfigure.cmake
----------------------------------------------------------------------
diff --git a/src/tests/cmake/MesosTestsConfigure.cmake b/src/tests/cmake/MesosTestsConfigure.cmake
index 8ab4ca3..d593b54 100644
--- a/src/tests/cmake/MesosTestsConfigure.cmake
+++ b/src/tests/cmake/MesosTestsConfigure.cmake
@@ -15,11 +15,6 @@
# limitations under the License.
set(
- CONTAINERIZER_MEMORY_TESTS_TARGET mesos-containerizer-memory_test
- CACHE STRING "Target we use to refer to tests for mesos containerizer tests"
- )
-
-set(
TEST_HELPER_TARGET test-helper
CACHE STRING "Test helper target to run tests that require a subprocess."
)
http://git-wip-us.apache.org/repos/asf/mesos/blob/9b04b8df/src/tests/containerizer/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/CMakeLists.txt b/src/tests/containerizer/CMakeLists.txt
index 2c52e43..4f5461b 100644
--- a/src/tests/containerizer/CMakeLists.txt
+++ b/src/tests/containerizer/CMakeLists.txt
@@ -16,14 +16,6 @@
# CONTAINERIZER TESTS.
######################
-set(CONTAINERIZER_MEMORY_TESTS_SRC
- ${CONTAINERIZER_MEMORY_TESTS_SRC}
- ${MESOS_SRC_DIR}/tests/flags.cpp
- ${MESOS_SRC_DIR}/tests/utils.cpp
- memory_test_helper_main.cpp
- memory_test_helper.cpp
- )
-
if (LINUX)
set(SETNS_TEST_HELPER_SRC
${SETNS_TEST_HELPER_SRC}
@@ -44,28 +36,21 @@ link_directories(${CONTAINERIZER_TEST_LIB_DIRS})
# THE CONTAINERIZER TEST EXECUTABLE (generates, e.g., stout_tests, etc., on Linux).
###########################################################################
-add_executable(${CONTAINERIZER_MEMORY_TESTS_TARGET} ${CONTAINERIZER_MEMORY_TESTS_SRC})
-
if (LINUX)
add_executable(${SETNS_TEST_HELPER_TARGET} ${SETNS_TEST_HELPER_SRC})
endif (LINUX)
# ADD LINKER FLAGS (generates, e.g., -lglog on Linux).
######################################################
-target_link_libraries(${CONTAINERIZER_MEMORY_TESTS_TARGET} ${CONTAINERIZER_TEST_LIBS})
-
if (LINUX)
target_link_libraries(${SETNS_TEST_HELPER_TARGET} ${CONTAINERIZER_TEST_LIBS})
endif (LINUX)
# ADD BINARY DEPENDENCIES (tells CMake what to compile/build first).
####################################################################
-add_dependencies(${CONTAINERIZER_MEMORY_TESTS_TARGET} ${CONTAINERIZER_TEST_DEPENDENCIES})
-
if (LINUX)
add_dependencies(${SETNS_TEST_HELPER_TARGET} ${CONTAINERIZER_TEST_DEPENDENCIES})
endif (LINUX)
# ADD TEST TARGET (runs when you do, e.g., `make check`).
#########################################################
-add_test(NAME MesosContainerizerMemoryTests COMMAND ${CMAKE_BINARY_DIR}/src/${CONTAINERIZER_MEMORY_TESTS_TARGET})
http://git-wip-us.apache.org/repos/asf/mesos/blob/9b04b8df/src/tests/containerizer/memory_test_helper.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/memory_test_helper.cpp b/src/tests/containerizer/memory_test_helper.cpp
index e850b37..1a33b7b 100644
--- a/src/tests/containerizer/memory_test_helper.cpp
+++ b/src/tests/containerizer/memory_test_helper.cpp
@@ -73,6 +73,109 @@ const char INCREASE_RSS[] = "INCREASE_RSS";
const char INCREASE_PAGE_CACHE[] = "INCREASE_PAGE_CACHE";
+MemoryTestHelper::~MemoryTestHelper()
+{
+ cleanup();
+}
+
+
+Try<Nothing> MemoryTestHelper::spawn()
+{
+ if (s.isSome()) {
+ return Error("A subprocess has been spawned already");
+ }
+
+ vector<string> argv;
+ argv.push_back("test-helper");
+ argv.push_back(MemoryTestHelper::NAME);
+
+ Try<Subprocess> process = subprocess(
+ getTestHelperPath("test-helper"),
+ argv,
+ Subprocess::PIPE(),
+ Subprocess::PIPE(),
+ Subprocess::FD(STDERR_FILENO));
+
+ if (process.isError()) {
+ return Error("Failed to spawn a subprocess: " + process.error());
+ }
+
+ s = process.get();
+
+ // Wait for the child to inform it has started before returning.
+ // Otherwise, the user might set the memory limit too earlier, and
+ // cause the child oom-killed because 'ld' could use a lot of
+ // memory.
+ Result<string> read = os::read(s.get().out().get(), sizeof(STARTED));
+ if (!read.isSome() || read.get() != string(sizeof(STARTED), STARTED)) {
+ cleanup();
+ return Error("Failed to sync with the subprocess");
+ }
+
+ return Nothing();
+}
+
+
+void MemoryTestHelper::cleanup()
+{
+ if (s.isSome()) {
+ // We just want to make sure the subprocess is terminated in case
+ // it's stuck, but we don't care about its status. Any error
+ // should have been logged in the subprocess directly.
+ ::kill(s.get().pid(), SIGKILL);
+ ::waitpid(s.get().pid(), nullptr, 0);
+ s = None();
+ }
+}
+
+
+Try<pid_t> MemoryTestHelper::pid()
+{
+ if (s.isNone()) {
+ return Error("The subprocess has not been spawned yet");
+ }
+
+ return s.get().pid();
+}
+
+
+// Send a request to the subprocess and wait for its signal that the
+// work has been done.
+Try<Nothing> MemoryTestHelper::requestAndWait(const string& request)
+{
+ if (s.isNone()) {
+ return Error("The subprocess has not been spawned yet");
+ }
+
+ Try<Nothing> write = os::write(s.get().in().get(), request + "\n");
+ if (write.isError()) {
+ cleanup();
+ return Error("Fail to sync with the subprocess: " + write.error());
+ }
+
+ Result<string> read = os::read(s.get().out().get(), sizeof(DONE));
+ if (!read.isSome() || read.get() != string(sizeof(DONE), DONE)) {
+ cleanup();
+ return Error("Failed to sync with the subprocess");
+ }
+
+ return Nothing();
+}
+
+
+Try<Nothing> MemoryTestHelper::increaseRSS(const Bytes& size)
+{
+ return requestAndWait(string(INCREASE_RSS) + " " + stringify(size));
+}
+
+
+Try<Nothing> MemoryTestHelper::increasePageCache(const Bytes& size)
+{
+ return requestAndWait(string(INCREASE_PAGE_CACHE) + " " + stringify(size));
+}
+
+
+
// This helper allocates memory and prevents the compiler from
// optimizing that allocation away by locking the allocated pages.
static Try<void*> allocateRSS(const Bytes& size)
@@ -108,7 +211,7 @@ static Try<void*> allocateRSS(const Bytes& size)
}
-static Try<Nothing> increaseRSS(const vector<string>& tokens)
+static Try<Nothing> doIncreaseRSS(const vector<string>& tokens)
{
if (tokens.size() < 2) {
return Error("Expect at least one argument");
@@ -128,7 +231,7 @@ static Try<Nothing> increaseRSS(const vector<string>& tokens)
}
-static Try<Nothing> increasePageCache(const vector<string>& tokens)
+static Try<Nothing> doIncreasePageCache(const vector<string>& tokens)
{
const Bytes UNIT = Megabytes(1);
@@ -180,116 +283,14 @@ static Try<Nothing> increasePageCache(const vector<string>& tokens)
}
-MemoryTestHelper::~MemoryTestHelper()
-{
- cleanup();
-}
-
-
-Try<Nothing> MemoryTestHelper::spawn()
-{
- if (s.isSome()) {
- return Error("A subprocess has been spawned already");
- }
-
- vector<string> argv;
- argv.push_back("memory-test-helper");
- argv.push_back(MemoryTestHelperMain::NAME);
-
- Try<Subprocess> process = subprocess(
- getTestHelperPath("memory-test-helper"),
- argv,
- Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::FD(STDERR_FILENO));
-
- if (process.isError()) {
- return Error("Failed to spawn a subprocess: " + process.error());
- }
-
- s = process.get();
-
- // Wait for the child to inform it has started before returning.
- // Otherwise, the user might set the memory limit too earlier, and
- // cause the child oom-killed because 'ld' could use a lot of
- // memory.
- Result<string> read = os::read(s.get().out().get(), sizeof(STARTED));
- if (!read.isSome() || read.get() != string(sizeof(STARTED), STARTED)) {
- cleanup();
- return Error("Failed to sync with the subprocess");
- }
-
- return Nothing();
-}
-
-
-void MemoryTestHelper::cleanup()
-{
- if (s.isSome()) {
- // We just want to make sure the subprocess is terminated in case
- // it's stuck, but we don't care about its status. Any error
- // should have been logged in the subprocess directly.
- ::kill(s.get().pid(), SIGKILL);
- ::waitpid(s.get().pid(), nullptr, 0);
- s = None();
- }
-}
-
-
-Try<pid_t> MemoryTestHelper::pid()
-{
- if (s.isNone()) {
- return Error("The subprocess has not been spawned yet");
- }
-
- return s.get().pid();
-}
-
-
-// Send a request to the subprocess and wait for its signal that the
-// work has been done.
-Try<Nothing> MemoryTestHelper::requestAndWait(const string& request)
-{
- if (s.isNone()) {
- return Error("The subprocess has not been spawned yet");
- }
-
- Try<Nothing> write = os::write(s.get().in().get(), request + "\n");
- if (write.isError()) {
- cleanup();
- return Error("Fail to sync with the subprocess: " + write.error());
- }
-
- Result<string> read = os::read(s.get().out().get(), sizeof(DONE));
- if (!read.isSome() || read.get() != string(sizeof(DONE), DONE)) {
- cleanup();
- return Error("Failed to sync with the subprocess");
- }
-
- return Nothing();
-}
-
-
-Try<Nothing> MemoryTestHelper::increaseRSS(const Bytes& size)
-{
- return requestAndWait(string(INCREASE_RSS) + " " + stringify(size));
-}
-
-
-Try<Nothing> MemoryTestHelper::increasePageCache(const Bytes& size)
-{
- return requestAndWait(string(INCREASE_PAGE_CACHE) + " " + stringify(size));
-}
-
-
-const char MemoryTestHelperMain::NAME[] = "MemoryTestHelperMain";
+const char MemoryTestHelper::NAME[] = "Memory";
-int MemoryTestHelperMain::execute()
+int MemoryTestHelper::execute()
{
hashmap<string, Try<Nothing>(*)(const vector<string>&)> commands;
- commands[INCREASE_RSS] = &increaseRSS;
- commands[INCREASE_PAGE_CACHE] = &increasePageCache;
+ commands[INCREASE_RSS] = &doIncreaseRSS;
+ commands[INCREASE_PAGE_CACHE] = &doIncreasePageCache;
// Tell the parent that child has started.
cout << STARTED << flush;
http://git-wip-us.apache.org/repos/asf/mesos/blob/9b04b8df/src/tests/containerizer/memory_test_helper.hpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/memory_test_helper.hpp b/src/tests/containerizer/memory_test_helper.hpp
index 86a9b57..cddfbf1 100644
--- a/src/tests/containerizer/memory_test_helper.hpp
+++ b/src/tests/containerizer/memory_test_helper.hpp
@@ -31,10 +31,12 @@ namespace tests {
// The abstraction for controlling the memory usage of a subprocess.
// TODO(chzhcn): Currently, this helper is only supposed to be used by
// one thread. Consider making it thread safe.
-class MemoryTestHelper
+class MemoryTestHelper : public Subcommand
{
public:
- MemoryTestHelper() {}
+ static const char NAME[];
+
+ MemoryTestHelper() : Subcommand(NAME) {}
~MemoryTestHelper();
// Spawns a subprocess.
@@ -60,26 +62,17 @@ public:
// TODO(chzhcn): Consider returning a future instead of blocking.
Try<Nothing> increasePageCache(const Bytes& size = Megabytes(1));
+protected:
+ // The main function of the subprocess. It runs in a loop and
+ // executes commands passed from stdin.
+ virtual int execute();
+
private:
Try<Nothing> requestAndWait(const std::string& request);
Option<process::Subprocess> s;
};
-
-// The actual subprocess behind MemoryTestHelper. It runs in a loop
-// and executes commands passed from stdin.
-class MemoryTestHelperMain : public Subcommand
-{
-public:
- static const char NAME[];
-
- MemoryTestHelperMain() : Subcommand(NAME) {}
-
-protected:
- virtual int execute();
-};
-
} // namespace tests {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/9b04b8df/src/tests/test_helper_main.cpp
----------------------------------------------------------------------
diff --git a/src/tests/test_helper_main.cpp b/src/tests/test_helper_main.cpp
index de95682..dd1be67 100644
--- a/src/tests/test_helper_main.cpp
+++ b/src/tests/test_helper_main.cpp
@@ -19,7 +19,10 @@
#include "tests/active_user_test_helper.hpp"
+#include "tests/containerizer/memory_test_helper.hpp"
+
using mesos::internal::tests::ActiveUserTestHelper;
+using mesos::internal::tests::MemoryTestHelper;
int main(int argc, char** argv)
@@ -28,5 +31,6 @@ int main(int argc, char** argv)
None(),
argc,
argv,
- new ActiveUserTestHelper());
+ new ActiveUserTestHelper(),
+ new MemoryTestHelper());
}