| 37 | |
| 38 | |
| 39 | TEST_F(MemfdTest, CloneSealedFile) |
| 40 | { |
| 41 | const string content = "hello world!"; |
| 42 | const string filePath = path::join(sandbox.get(), "file"); |
| 43 | ASSERT_SOME(os::write(filePath, content)); |
| 44 | |
| 45 | Try<int_fd> fd = memfd::cloneSealedFile(filePath); |
| 46 | ASSERT_SOME(fd); |
| 47 | |
| 48 | const string memFdFile = "/proc/self/fd/" + stringify(fd.get()); |
| 49 | |
| 50 | Try<string> actual = os::read(memFdFile); |
| 51 | EXPECT_SOME_EQ(content, actual); |
| 52 | |
| 53 | // Make sure we cannot write the cloned file. |
| 54 | EXPECT_ERROR(os::write(memFdFile, "xxx")); |
| 55 | |
| 56 | os::close(fd.get()); |
| 57 | } |
| 58 | |
| 59 | } // namespace tests { |
| 60 | } // namespace internal { |