You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2019/02/12 01:29:34 UTC
[mesos] 03/10: Added a test to test memfd file clone.
This is an automated email from the ASF dual-hosted git repository.
gilbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 3139e5137142b884ddae0b07b7bbbd8ad5319c6e
Author: Jie Yu <yu...@gmail.com>
AuthorDate: Mon Feb 11 12:51:21 2019 -0800
Added a test to test memfd file clone.
This patch added a test to test the memfd::cloneFile.
Review: https://reviews.apache.org/r/69945/
---
src/Makefile.am | 1 +
src/tests/CMakeLists.txt | 1 +
src/tests/containerizer/linux_memfd_tests.cpp | 61 +++++++++++++++++++++++++++
3 files changed, 63 insertions(+)
diff --git a/src/Makefile.am b/src/Makefile.am
index 8fe0325..9d45bb9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2703,6 +2703,7 @@ mesos_tests_SOURCES += \
tests/containerizer/docker_volume_isolator_tests.cpp \
tests/containerizer/linux_devices_isolator_tests.cpp \
tests/containerizer/linux_filesystem_isolator_tests.cpp \
+ tests/containerizer/linux_memfd_tests.cpp \
tests/containerizer/fs_tests.cpp \
tests/containerizer/memory_pressure_tests.cpp \
tests/containerizer/nested_mesos_containerizer_tests.cpp \
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 42f8207..d05824f 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -227,6 +227,7 @@ if (LINUX)
containerizer/linux_capabilities_isolator_tests.cpp
containerizer/linux_devices_isolator_tests.cpp
containerizer/linux_filesystem_isolator_tests.cpp
+ containerizer/linux_memfd_tests.cpp
containerizer/memory_pressure_tests.cpp
containerizer/nested_mesos_containerizer_tests.cpp
containerizer/ns_tests.cpp
diff --git a/src/tests/containerizer/linux_memfd_tests.cpp b/src/tests/containerizer/linux_memfd_tests.cpp
new file mode 100644
index 0000000..de54ac3
--- /dev/null
+++ b/src/tests/containerizer/linux_memfd_tests.cpp
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <string>
+
+#include <stout/gtest.hpp>
+#include <stout/path.hpp>
+
+#include <stout/os/close.hpp>
+#include <stout/os/read.hpp>
+#include <stout/os/write.hpp>
+
+#include <stout/tests/utils.hpp>
+
+#include "linux/memfd.hpp"
+
+using std::string;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class MemfdTest : public TemporaryDirectoryTest {};
+
+
+TEST_F(MemfdTest, CloneSealedFile)
+{
+ const string content = "hello world!";
+ const string filePath = path::join(sandbox.get(), "file");
+ ASSERT_SOME(os::write(filePath, content));
+
+ Try<int_fd> fd = memfd::cloneSealedFile(filePath);
+ ASSERT_SOME(fd);
+
+ const string memFdFile = "/proc/self/fd/" + stringify(fd.get());
+
+ Try<string> actual = os::read(memFdFile);
+ EXPECT_SOME_EQ(content, actual);
+
+ // Make sure we cannot write the cloned file.
+ EXPECT_ERROR(os::write(memFdFile, "xxx"));
+
+ os::close(fd.get());
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {