| 63 | } |
| 64 | |
| 65 | TEST(MemmappedFileSystemTest, SimpleTest) { |
| 66 | const TensorShape test_tensor_shape = {10, 200}; |
| 67 | Tensor test_tensor(DT_FLOAT, test_tensor_shape); |
| 68 | const string dir = testing::TmpDir(); |
| 69 | const string filename = io::JoinPath(dir, "memmapped_env_test"); |
| 70 | TF_ASSERT_OK(CreateMemmappedFileSystemFile(filename, false, &test_tensor)); |
| 71 | |
| 72 | // Check that we can memmap the created file. |
| 73 | MemmappedEnv memmapped_env(Env::Default()); |
| 74 | TF_ASSERT_OK(memmapped_env.InitializeFromFile(filename)); |
| 75 | // Try to load a proto from the file. |
| 76 | GraphDef test_graph_def; |
| 77 | TF_EXPECT_OK( |
| 78 | ReadBinaryProto(&memmapped_env, kProtoFileName, &test_graph_def)); |
| 79 | EXPECT_EQ(kTestGraphDefVersion, test_graph_def.versions().producer()); |
| 80 | EXPECT_EQ(kTestGraphDefVersion, test_graph_def.versions().min_consumer()); |
| 81 | // Check that we can correctly get a tensor memory. |
| 82 | std::unique_ptr<ReadOnlyMemoryRegion> memory_region; |
| 83 | TF_ASSERT_OK(memmapped_env.NewReadOnlyMemoryRegionFromFile(kTensor2FileName, |
| 84 | &memory_region)); |
| 85 | |
| 86 | // The memory region can be bigger but not less than Tensor size. |
| 87 | ASSERT_GE(memory_region->length(), test_tensor.TotalBytes()); |
| 88 | EXPECT_EQ(test_tensor.tensor_data(), |
| 89 | StringPiece(static_cast<const char*>(memory_region->data()), |
| 90 | test_tensor.TotalBytes())); |
| 91 | // Check that GetFileSize works. |
| 92 | uint64 file_size = 0; |
| 93 | TF_ASSERT_OK(memmapped_env.GetFileSize(kTensor2FileName, &file_size)); |
| 94 | EXPECT_EQ(test_tensor.TotalBytes(), file_size); |
| 95 | |
| 96 | // Check that Stat works. |
| 97 | FileStatistics stat; |
| 98 | TF_ASSERT_OK(memmapped_env.Stat(kTensor2FileName, &stat)); |
| 99 | EXPECT_EQ(test_tensor.TotalBytes(), stat.length); |
| 100 | |
| 101 | // Check that if file not found correct error message returned. |
| 102 | EXPECT_EQ( |
| 103 | error::NOT_FOUND, |
| 104 | memmapped_env.NewReadOnlyMemoryRegionFromFile("bla-bla", &memory_region) |
| 105 | .code()); |
| 106 | |
| 107 | // Check FileExists. |
| 108 | TF_EXPECT_OK(memmapped_env.FileExists(kTensor2FileName)); |
| 109 | EXPECT_EQ(error::Code::NOT_FOUND, |
| 110 | memmapped_env.FileExists("bla-bla-bla").code()); |
| 111 | } |
| 112 | |
| 113 | TEST(MemmappedFileSystemTest, NotInitialized) { |
| 114 | MemmappedEnv memmapped_env(Env::Default()); |
nothing calls this directly
no test coverage detected