From 554f16e9701a34399f45617ea90675f30d30e0d0 Mon Sep 17 00:00:00 2001 From: Brian Atkinson Date: Thu, 20 Feb 2020 14:19:06 -0800 Subject: [PATCH] Make use of GetDataDependencyFilepath and JoinPath to build paths which will work across operating systems. The previous implementation doesn't work correctly on Windows. PiperOrigin-RevId: 296295721 Change-Id: I1d4d067a5c938cfd6c1ce8724bb9f49ea89a4bda --- tensorflow/cc/saved_model/BUILD | 1 + tensorflow/cc/saved_model/reader_test.cc | 30 +++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tensorflow/cc/saved_model/BUILD b/tensorflow/cc/saved_model/BUILD index e680cc72b3b..882b4032f76 100644 --- a/tensorflow/cc/saved_model/BUILD +++ b/tensorflow/cc/saved_model/BUILD @@ -68,6 +68,7 @@ tf_cc_test( "//tensorflow/core:test", "//tensorflow/core:test_main", "//tensorflow/core:testlib", + "//tensorflow/core/platform:resource_loader", ], ) diff --git a/tensorflow/cc/saved_model/reader_test.cc b/tensorflow/cc/saved_model/reader_test.cc index e898664c221..bc630bcaede 100644 --- a/tensorflow/cc/saved_model/reader_test.cc +++ b/tensorflow/cc/saved_model/reader_test.cc @@ -21,15 +21,22 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/str_util.h" +#include "tensorflow/core/platform/path.h" +#include "tensorflow/core/platform/resource_loader.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { namespace { -constexpr char kTestDataPbTxt[] = - "cc/saved_model/testdata/half_plus_two_pbtxt/00000123"; -constexpr char kTestDataSharded[] = - "cc/saved_model/testdata/half_plus_two/00000123"; +string TestDataPbTxt() { + return io::JoinPath("tensorflow", "cc", "saved_model", "testdata", + "half_plus_two_pbtxt", "00000123"); +} + +string TestDataSharded() { + return io::JoinPath("tensorflow", "cc", "saved_model", "testdata", + "half_plus_two", "00000123"); +} class ReaderTest : public ::testing::Test { protected: @@ -49,8 +56,7 @@ class ReaderTest : public ::testing::Test { TEST_F(ReaderTest, TagMatch) { MetaGraphDef meta_graph_def; - const string export_dir = - io::JoinPath(testing::TensorFlowSrcRoot(), kTestDataSharded); + const string export_dir = GetDataDependencyFilepath(TestDataSharded()); TF_ASSERT_OK(ReadMetaGraphDefFromSavedModel(export_dir, {kSavedModelTagServe}, &meta_graph_def)); CheckMetaGraphDef(meta_graph_def); @@ -59,8 +65,7 @@ TEST_F(ReaderTest, TagMatch) { TEST_F(ReaderTest, NoTagMatch) { MetaGraphDef meta_graph_def; - const string export_dir = - io::JoinPath(testing::TensorFlowSrcRoot(), kTestDataSharded); + const string export_dir = GetDataDependencyFilepath(TestDataSharded()); Status st = ReadMetaGraphDefFromSavedModel(export_dir, {"missing-tag"}, &meta_graph_def); EXPECT_FALSE(st.ok()); @@ -73,8 +78,7 @@ TEST_F(ReaderTest, NoTagMatch) { TEST_F(ReaderTest, NoTagMatchMultiple) { MetaGraphDef meta_graph_def; - const string export_dir = - io::JoinPath(testing::TensorFlowSrcRoot(), kTestDataSharded); + const string export_dir = GetDataDependencyFilepath(TestDataSharded()); Status st = ReadMetaGraphDefFromSavedModel( export_dir, {kSavedModelTagServe, "missing-tag"}, &meta_graph_def); EXPECT_FALSE(st.ok()); @@ -87,8 +91,7 @@ TEST_F(ReaderTest, NoTagMatchMultiple) { TEST_F(ReaderTest, PbtxtFormat) { MetaGraphDef meta_graph_def; - const string export_dir = - io::JoinPath(testing::TensorFlowSrcRoot(), kTestDataPbTxt); + const string export_dir = GetDataDependencyFilepath(TestDataPbTxt()); TF_ASSERT_OK(ReadMetaGraphDefFromSavedModel(export_dir, {kSavedModelTagServe}, &meta_graph_def)); CheckMetaGraphDef(meta_graph_def); @@ -97,8 +100,7 @@ TEST_F(ReaderTest, PbtxtFormat) { TEST_F(ReaderTest, InvalidExportPath) { MetaGraphDef meta_graph_def; - const string export_dir = - io::JoinPath(testing::TensorFlowSrcRoot(), "missing-path"); + const string export_dir = GetDataDependencyFilepath("missing-path"); Status st = ReadMetaGraphDefFromSavedModel(export_dir, {kSavedModelTagServe}, &meta_graph_def); EXPECT_FALSE(st.ok());