[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
This commit is contained in:
parent
de45c4b295
commit
918cc4da7c
@ -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",
|
||||
|
@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <fstream>
|
||||
@ -99,51 +98,51 @@ TEST_F(DebugIdentityOpTest, Int32Success_6_FileURLs) {
|
||||
ASSERT_TRUE(env_->IsDirectory(dump_roots[i]).ok());
|
||||
|
||||
std::vector<string> 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<string> 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<int32>()(j));
|
||||
}
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
ASSERT_EQ(j + 1, tensor_prime.flat<int32>()(j));
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
ASSERT_EQ(1, dump_files_found);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user