This is an automated email from the ASF dual-hosted git repository.

gilbert pushed a commit to branch 1.5.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 5334e14ba10c76e3cb2da8407991f8ae9621049e
Author: Jie Yu <[email protected]>
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/
    (cherry picked from commit 3139e5137142b884ddae0b07b7bbbd8ad5319c6e)
---
 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 aa3bde0..6ac63e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2605,6 +2605,7 @@ mesos_tests_SOURCES +=                                    
        \
   tests/containerizer/cni_isolator_tests.cpp                   \
   tests/containerizer/docker_volume_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 2585b6c..89baa0a 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -218,6 +218,7 @@ if (LINUX)
     containerizer/fs_tests.cpp
     containerizer/linux_capabilities_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 {

Reply via email to