From 918cc4da7cbc9377d529f075c89a8d9421e1e8be Mon Sep 17 00:00:00 2001 From: Shanqing Cai Date: Sun, 2 Feb 2020 19:10:34 -0800 Subject: [PATCH] [tfdbg] Remove use of dirent.h in debug_ops_test.cc - Replace it with the platform-independent GetChildren() - Re-enable the test on Windows PiperOrigin-RevId: 292835929 Change-Id: Ibc9c5402f61da50c784b068691d1bf3bbd8001d1 --- tensorflow/core/kernels/BUILD | 1 - tensorflow/core/kernels/debug_ops_test.cc | 59 +++++++++++------------ 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD index 00d9615311a..c5932cc9616 100644 --- a/tensorflow/core/kernels/BUILD +++ b/tensorflow/core/kernels/BUILD @@ -2117,7 +2117,6 @@ tf_cc_test( name = "debug_ops_test", size = "small", srcs = ["debug_ops_test.cc"], - tags = ["no_windows"], deps = [ ":debug_ops", ":ops_testutil", diff --git a/tensorflow/core/kernels/debug_ops_test.cc b/tensorflow/core/kernels/debug_ops_test.cc index bdf9e09f2a2..496271a7226 100644 --- a/tensorflow/core/kernels/debug_ops_test.cc +++ b/tensorflow/core/kernels/debug_ops_test.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include #include #include @@ -99,51 +98,51 @@ TEST_F(DebugIdentityOpTest, Int32Success_6_FileURLs) { ASSERT_TRUE(env_->IsDirectory(dump_roots[i]).ok()); std::vector device_roots; - DIR* dir0 = opendir(dump_roots[i].c_str()); - struct dirent* ent0; + FileSystem* fs = nullptr; + TF_ASSERT_OK(Env::Default()->GetFileSystemForFile(dump_roots[i], &fs)); + std::vector children; + TF_ASSERT_OK(fs->GetChildren(dump_roots[i], &children)); + const string kDeviceDirPrefix = strings::StrCat( DebugNodeKey::kMetadataFilePrefix, DebugNodeKey::kDeviceTag); - while ((ent0 = readdir(dir0)) != nullptr) { - if (!strncmp(ent0->d_name, kDeviceDirPrefix.c_str(), + for (const string child : children) { + if (!strncmp(child.c_str(), kDeviceDirPrefix.c_str(), kDeviceDirPrefix.size())) { - device_roots.push_back(io::JoinPath(dump_roots[i], ent0->d_name)); + device_roots.push_back(io::JoinPath(dump_roots[i], child)); } } ASSERT_EQ(1, device_roots.size()); - closedir(dir0); const string& device_root = device_roots[0]; - DIR* dir = opendir(device_root.c_str()); - struct dirent* ent; + TF_ASSERT_OK(Env::Default()->GetFileSystemForFile(device_root, &fs)); + TF_ASSERT_OK(fs->GetChildren(device_root, &children)); + int dump_files_found = 0; - while ((ent = readdir(dir)) != nullptr) { - if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..")) { - dump_files_found++; + for (const string child : children) { + dump_files_found++; - // Try reading the file into a Event proto. - const string dump_file_path = io::JoinPath(device_root, ent->d_name); - std::fstream ifs(dump_file_path, std::ios::in | std::ios::binary); - Event event; - event.ParseFromIstream(&ifs); - ifs.close(); + // Try reading the file into a Event proto. + const string dump_file_path = io::JoinPath(device_root, child); + std::fstream ifs(dump_file_path, std::ios::in | std::ios::binary); + Event event; + event.ParseFromIstream(&ifs); + ifs.close(); - ASSERT_GE(event.wall_time(), wall_time); - ASSERT_EQ(1, event.summary().value().size()); - ASSERT_EQ(strings::StrCat("FakeTensor", ":", 0, ":", "DebugIdentity"), - event.summary().value(0).node_name()); + ASSERT_GE(event.wall_time(), wall_time); + ASSERT_EQ(1, event.summary().value().size()); + ASSERT_EQ(strings::StrCat("FakeTensor", ":", 0, ":", "DebugIdentity"), + event.summary().value(0).node_name()); - Tensor tensor_prime(DT_INT32); - ASSERT_TRUE(tensor_prime.FromProto(event.summary().value(0).tensor())); + Tensor tensor_prime(DT_INT32); + ASSERT_TRUE(tensor_prime.FromProto(event.summary().value(0).tensor())); - // Verify tensor shape and value from the dump file. - ASSERT_EQ(TensorShape({6}), tensor_prime.shape()); + // Verify tensor shape and value from the dump file. + ASSERT_EQ(TensorShape({6}), tensor_prime.shape()); - for (int j = 0; j < 6; ++j) { - ASSERT_EQ(j + 1, tensor_prime.flat()(j)); - } + for (int j = 0; j < 6; ++j) { + ASSERT_EQ(j + 1, tensor_prime.flat()(j)); } } - closedir(dir); ASSERT_EQ(1, dump_files_found);