diff options
-rw-r--r-- | tensorflow/core/common_runtime/direct_session_test.cc | 25 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/function_test.cc | 9 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/function_threadpool_test.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/placer.cc | 4 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/placer_test.cc | 110 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/process_function_library_runtime_test.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/session_test.cc | 16 | ||||
-rw-r--r-- | tensorflow/core/common_runtime/shape_refiner_test.cc | 9 | ||||
-rw-r--r-- | tensorflow/core/graph/graph_constructor.cc | 15 | ||||
-rw-r--r-- | tensorflow/core/graph/graph_constructor_test.cc | 4 | ||||
-rw-r--r-- | tensorflow/core/graph/graph_partition.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/graph/graph_partition_test.cc | 5 | ||||
-rw-r--r-- | tensorflow/core/graph/graph_test.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/graph/quantize_training_test.cc | 5 | ||||
-rw-r--r-- | tensorflow/core/graph/subgraph_test.cc | 4 | ||||
-rw-r--r-- | tensorflow/core/graph/tensor_id.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/graph/validate_test.cc | 7 |
17 files changed, 122 insertions, 106 deletions
diff --git a/tensorflow/core/common_runtime/direct_session_test.cc b/tensorflow/core/common_runtime/direct_session_test.cc index ee38960618..f95cecfc66 100644 --- a/tensorflow/core/common_runtime/direct_session_test.cc +++ b/tensorflow/core/common_runtime/direct_session_test.cc @@ -39,6 +39,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" #include "tensorflow/core/protobuf/rewriter_config.pb.h" @@ -155,22 +156,22 @@ TEST_F(DirectSessionMinusAXTest, RunSimpleNetwork_Callable) { Status s = session->RunCallable(handle, {}, nullptr, nullptr); EXPECT_TRUE(errors::IsInvalidArgument(s)); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("`fetch_tensors` must be provided")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), + "`fetch_tensors` must be provided")); TF_ASSERT_OK(session->ReleaseCallable(handle)); std::vector<Tensor> outputs; s = session->RunCallable(handle, {}, &outputs, nullptr); EXPECT_TRUE(errors::IsInvalidArgument(s)); - EXPECT_TRUE( - StringPiece(s.error_message()) - .contains("Attempted to run callable after handle was released")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "Attempted to run callable after handle was released")); s = session->RunCallable(handle + 1, {}, &outputs, nullptr); EXPECT_TRUE(errors::IsInvalidArgument(s)); EXPECT_TRUE( - StringPiece(s.error_message()).contains("No such callable handle")); + str_util::StrContains(s.error_message(), "No such callable handle")); } } @@ -567,7 +568,7 @@ TEST(DirectSessionTest, MultipleFeedTest) { {first_identity->name() + ":0", second_identity->name() + ":0"}, {}, &outputs); EXPECT_TRUE(errors::IsInvalidArgument(s)); - EXPECT_TRUE(StringPiece(s.error_message()).contains("fed more than once")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "fed more than once")); } TEST(DirectSessionTest, MultipleFeedTest_Callable) { @@ -650,7 +651,7 @@ TEST(DirectSessionTest, MultipleFeedTest_Callable) { {first_identity->name() + ":0", second_identity->name() + ":0"}, {}), &handle); EXPECT_TRUE(errors::IsInvalidArgument(s)); - EXPECT_TRUE(StringPiece(s.error_message()).contains("fed more than once")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "fed more than once")); } TEST(DirectSessionTest, FetchMultipleTimes) { @@ -845,8 +846,8 @@ TEST(DirectSessionTest, PartialRunMissingFeed) { s = session->PRun(handle, {{first_const->name(), value_11}}, {third_identity->name() + ":0"}, &outputs); ASSERT_TRUE(errors::IsInvalidArgument(s)); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("can't be computed from the feeds")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), + "can't be computed from the feeds")); } TEST(DirectSessionTest, PartialRunMultiOutputFeed) { @@ -875,8 +876,8 @@ TEST(DirectSessionTest, PartialRunMultiOutputFeed) { // Fetch fourth_identity without feeds. s = session->PRun(handle, {}, {fourth_identity->name() + ":0"}, &outputs); ASSERT_TRUE(errors::IsInvalidArgument(s)); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("can't be computed from the feeds")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), + "can't be computed from the feeds")); // Feed switch_node:1 and fetch fourth_identity. s = session->PRun(handle, {{switch_node->name() + ":1", bool_value}}, diff --git a/tensorflow/core/common_runtime/function_test.cc b/tensorflow/core/common_runtime/function_test.cc index d17ef4d459..61b2f0e60f 100644 --- a/tensorflow/core/common_runtime/function_test.cc +++ b/tensorflow/core/common_runtime/function_test.cc @@ -39,6 +39,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session_options.h" #include "tensorflow/core/public/version.h" @@ -53,8 +54,8 @@ Status GetOpSig(const string& op, const OpDef** sig) { return OpRegistry::Global()->LookUpOpDef(op, sig); } -void HasError(const Status& s, const string& substr) { - EXPECT_TRUE(StringPiece(s.ToString()).contains(substr)) +void HasError(const Status& s, StringPiece substr) { + EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) << s << ", expected substring " << substr; } @@ -240,7 +241,7 @@ class FunctionLibraryRuntimeTest : public ::testing::Test { Status status2 = Run(flr, handle, opts, args, std::move(rets)); EXPECT_TRUE(errors::IsInvalidArgument(status2)); EXPECT_TRUE( - StringPiece(status2.error_message()).contains("remote execution.")); + str_util::StrContains(status2.error_message(), "remote execution.")); return status; } @@ -310,7 +311,7 @@ class FunctionLibraryRuntimeTest : public ::testing::Test { Status status2 = Run(flr, handle, opts, args, std::move(rets)); EXPECT_TRUE(errors::IsInvalidArgument(status2)); EXPECT_TRUE( - StringPiece(status2.error_message()).contains("remote execution.")); + str_util::StrContains(status2.error_message(), "remote execution.")); return status; } diff --git a/tensorflow/core/common_runtime/function_threadpool_test.cc b/tensorflow/core/common_runtime/function_threadpool_test.cc index 6223a4e648..2d09e83d01 100644 --- a/tensorflow/core/common_runtime/function_threadpool_test.cc +++ b/tensorflow/core/common_runtime/function_threadpool_test.cc @@ -39,6 +39,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session_options.h" #include "tensorflow/core/public/version.h" @@ -153,7 +154,7 @@ class FunctionLibraryRuntimeTest : public ::testing::Test { Status status2 = Run(flr, handle, opts, args, std::move(rets)); EXPECT_TRUE(errors::IsInvalidArgument(status2)); EXPECT_TRUE( - StringPiece(status2.error_message()).contains("remote execution.")); + str_util::StrContains(status2.error_message(), "remote execution.")); return status; } diff --git a/tensorflow/core/common_runtime/placer.cc b/tensorflow/core/common_runtime/placer.cc index e128b9257f..86851c2c07 100644 --- a/tensorflow/core/common_runtime/placer.cc +++ b/tensorflow/core/common_runtime/placer.cc @@ -29,6 +29,7 @@ limitations under the License. #include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/lib/strings/str_util.h" namespace tensorflow { @@ -151,7 +152,8 @@ class ColocationGraph { if (attr_value != nullptr && attr_value->has_list()) { for (const string& class_spec : attr_value->list().s()) { StringPiece spec(class_spec); - if (spec.Consume(kColocationGroupPrefixStringPiece)) { + if (str_util::ConsumePrefix(&spec, + kColocationGroupPrefixStringPiece)) { found_spec = true; TF_RETURN_IF_ERROR( ColocateNodeToGroup(&colocation_group_root, node, spec)); diff --git a/tensorflow/core/common_runtime/placer_test.cc b/tensorflow/core/common_runtime/placer_test.cc index 098024d219..5ad251c892 100644 --- a/tensorflow/core/common_runtime/placer_test.cc +++ b/tensorflow/core/common_runtime/placer_test.cc @@ -34,6 +34,7 @@ limitations under the License. #include "tensorflow/core/lib/core/error_codes.pb.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/test.h" @@ -262,9 +263,9 @@ class PlacerTest : public ::testing::Test { ->attributes() \ .device_type()) -#define EXPECT_DEVICE_CONTAINS(g, name, device_substr) \ - EXPECT_TRUE(StringPiece(GetNodeByName((g), (name))->assigned_device_name()) \ - .contains(device_substr)) +#define EXPECT_DEVICE_CONTAINS(g, name, device_substr) \ + EXPECT_TRUE(::tensorflow::str_util::StrContains( \ + GetNodeByName((g), (name))->assigned_device_name(), device_substr)) // Test that a graph with no constraints will successfully assign nodes to the // "best available" device (i.e. prefer GPU over CPU). @@ -488,11 +489,10 @@ TEST_F(PlacerTest, TestAssignedGpuDeviceToCpuDevice) { Status s = Place(&g); EXPECT_EQ(error::INTERNAL, s.code()); - EXPECT_TRUE( - StringPiece(s.error_message()) - .contains( - "Assigned device '/job:a/replica:0/task:0/device:fakegpu:0' " - "does not have registered OpKernel support for TestInput")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "Assigned device '/job:a/replica:0/task:0/device:fakegpu:0' " + "does not have registered OpKernel support for TestInput")); } // Test that graphs with reference connections are correctly placed. @@ -541,15 +541,15 @@ TEST_F(PlacerTest, TestReferenceConnection) { { Status s = ReferenceTestHelper("VariableCPU", "AssignGPU", "FakeCPU"); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("no device type supports both of those nodes")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), "no device type supports both of those nodes")); } TF_EXPECT_OK(ReferenceTestHelper("VariableGPU", "TestAssign", "FakeGPU")); { Status s = ReferenceTestHelper("VariableGPU", "AssignCPU", "FakeCPU"); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("no device type supports both of those nodes")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), "no device type supports both of those nodes")); } TF_EXPECT_OK(ReferenceTestHelper("VariableGPU", "AssignGPU", "FakeGPU")); } @@ -760,8 +760,9 @@ TEST_F(PlacerTest, TestInvalidMultipleColocationGroups) { } Status s = Place(&g); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("Cannot colocate nodes 'foo' and 'in' because no " + EXPECT_TRUE( + str_util::StrContains(s.error_message(), + "Cannot colocate nodes 'foo' and 'in' because no " "device type supports both of those nodes and the " "other nodes colocated with them")); } @@ -824,11 +825,11 @@ TEST_F(PlacerTest, TestColocationGroupWithUnsatisfiableReferenceConnections) { } Status s = Place(&g); - EXPECT_TRUE( - StringPiece(s.error_message()) - .contains("Cannot colocate nodes 'var3' and 'assign3' because no " - "device type supports both of those nodes and the other " - "nodes colocated with them.")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "Cannot colocate nodes 'var3' and 'assign3' because no " + "device type supports both of those nodes and the other " + "nodes colocated with them.")); } TEST_F(PlacerTest, TestColocationAndReferenceConnections) { @@ -888,7 +889,7 @@ TEST_F(PlacerTest, TestEmptyDeviceSet) { Status s = Place(&g, &empty); EXPECT_TRUE( - StringPiece(s.error_message()).contains("No devices are registered")); + str_util::StrContains(s.error_message(), "No devices are registered")); } // Test that placement fails when the requested device forces an @@ -913,16 +914,17 @@ TEST_F(PlacerTest, TestHeterogeneousDeviceSetFailure) { heterogeneous.AddDevice(cpu.get()); Status s = Place(&g, &heterogeneous); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("colocated with a group of nodes that required " + EXPECT_TRUE( + str_util::StrContains(s.error_message(), + "colocated with a group of nodes that required " "incompatible device")); // The error message should contain information that indicates which // op types have which registered device types. - EXPECT_TRUE(StringPiece(s.error_message()).contains("VariableGPU: FakeGPU")) + EXPECT_TRUE(str_util::StrContains(s.error_message(), "VariableGPU: FakeGPU")) << s; EXPECT_TRUE( - StringPiece(s.error_message()).contains("TestAssign: FakeGPU FakeCPU")) + str_util::StrContains(s.error_message(), "TestAssign: FakeGPU FakeCPU")) << s; } @@ -937,7 +939,7 @@ TEST_F(PlacerTest, TestUnknownDevice) { Status s = Place(&g); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()).contains("/job:foo")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "/job:foo")); } // Test that placement fails when the combination of partial @@ -952,7 +954,7 @@ TEST_F(PlacerTest, TestUnknownMergedDevice) { Status s = Place(&g); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()).contains("/job:foo")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "/job:foo")); } // Test that placement fails when the previously-assigned device for a @@ -969,9 +971,9 @@ TEST_F(PlacerTest, TestUnknownAssignedDevice) { Status s = Place(&g); EXPECT_EQ(error::INTERNAL, s.code()); - EXPECT_TRUE( - StringPiece(s.error_message()) - .contains("Assigned device '/job:foo' does not match any device")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "Assigned device '/job:foo' does not match any device")); } // Test that placement fails when an op with no registered kernels is @@ -986,12 +988,11 @@ TEST_F(PlacerTest, TestNoKernelsRegistered) { Status s = Place(&g); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "No OpKernel was registered to support Op 'VariableNoKernels'")); EXPECT_TRUE( - StringPiece(s.error_message()) - .contains( - "No OpKernel was registered to support Op 'VariableNoKernels'")); - EXPECT_TRUE( - StringPiece(s.error_message()).contains("<no registered kernels>")); + str_util::StrContains(s.error_message(), "<no registered kernels>")); } // Test that placement fails when a kernel is registered but no known @@ -1011,10 +1012,10 @@ TEST_F(PlacerTest, TestNoDevicesRegistered) { Status s = Place(&g, &cpu_only); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("No OpKernel was registered to support " - "Op 'VariableGPU'")); - EXPECT_TRUE(StringPiece(s.error_message()).contains("device='FakeGPU'")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "No OpKernel was registered to support Op 'VariableGPU'")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "device='FakeGPU'")); } // Test that placement fails when a requested device is malformed. @@ -1028,8 +1029,8 @@ TEST_F(PlacerTest, TestMalformedDeviceSpecification) { Status s = Place(&g); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("Malformed device specification '/foo:bar'")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), "Malformed device specification '/foo:bar'")); } // Test that placement fails when a previously-assigned device is malformed. @@ -1045,8 +1046,8 @@ TEST_F(PlacerTest, TestMalformedAssignedDevice) { Status s = Place(&g); EXPECT_EQ(error::INTERNAL, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("Malformed assigned device '/foo:bar'")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), + "Malformed assigned device '/foo:bar'")); } // Test that placement fails when a device was previously assigned to @@ -1063,9 +1064,8 @@ TEST_F(PlacerTest, TestNonUniqueAssignedDevice) { Status s = Place(&g); EXPECT_EQ(error::INTERNAL, s.code()); - EXPECT_TRUE( - StringPiece(s.error_message()) - .contains("Assigned device '/job:a' does not match any device")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), "Assigned device '/job:a' does not match any device")); } // Test that ops request to be placed on non-existent devices will be relocated @@ -1099,7 +1099,7 @@ TEST_F(PlacerTest, TestNonexistentGpuNoAllowSoftPlacement) { SessionOptions options; Status s = Place(&g, &options); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()).contains("/device:fakegpu:11")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "/device:fakegpu:11")); } // Test that placement fails when a node requests an explicit device that is not @@ -1116,10 +1116,10 @@ TEST_F(PlacerTest, TestUnsupportedDeviceNoAllowSoftPlacement) { SessionOptions options; Status s = Place(&g, &options); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()).contains("/device:fakecpu:0")); - EXPECT_TRUE( - StringPiece(s.error_message()) - .contains("no supported kernel for fakecpu devices is available")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "/device:fakecpu:0")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "no supported kernel for fakecpu devices is available")); } // Test that placement fails when a node requests an explicit device that is not @@ -1137,9 +1137,9 @@ TEST_F(PlacerTest, TestNonExistentDevice) { Status s = Place(&g, &options); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); LOG(WARNING) << s.error_message(); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("was explicitly assigned to /job:foo/replica:17 " - "but available devices")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "was explicitly assigned to /job:foo/replica:17 but available devices")); } TEST_F(PlacerTest, TestUnsupportedDeviceAllowSoftPlacement) { @@ -1205,8 +1205,8 @@ TEST_F(PlacerTest, TestUnsatisfiableConstraintWithReferenceConnections) { Status s = Place(&g); EXPECT_EQ(error::INVALID_ARGUMENT, s.code()); - EXPECT_TRUE(StringPiece(s.error_message()) - .contains("Cannot colocate nodes 'var' and 'assign'")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), "Cannot colocate nodes 'var' and 'assign'")); } // Test that a generator node follows its consumers (where there are several diff --git a/tensorflow/core/common_runtime/process_function_library_runtime_test.cc b/tensorflow/core/common_runtime/process_function_library_runtime_test.cc index 2da67b084a..4fbf2abc67 100644 --- a/tensorflow/core/common_runtime/process_function_library_runtime_test.cc +++ b/tensorflow/core/common_runtime/process_function_library_runtime_test.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor_testutil.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session_options.h" #include "tensorflow/core/public/version.h" @@ -132,7 +133,7 @@ class ProcessFunctionLibraryRuntimeTest : public ::testing::Test { }); done2.WaitForNotification(); EXPECT_TRUE(errors::IsNotFound(status)); - EXPECT_TRUE(StringPiece(status.error_message()).contains("not found.")); + EXPECT_TRUE(str_util::StrContains(status.error_message(), "not found.")); return Status::OK(); } diff --git a/tensorflow/core/common_runtime/session_test.cc b/tensorflow/core/common_runtime/session_test.cc index a074154450..feaf29c7bb 100644 --- a/tensorflow/core/common_runtime/session_test.cc +++ b/tensorflow/core/common_runtime/session_test.cc @@ -16,6 +16,7 @@ limitations under the License. #include "tensorflow/core/public/session.h" #include "tensorflow/core/common_runtime/session_factory.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session_options.h" @@ -31,10 +32,9 @@ TEST(SessionTest, InvalidTargetReturnsNull) { Session* session; Status s = tensorflow::NewSession(options, &session); EXPECT_EQ(s.code(), error::NOT_FOUND); - EXPECT_TRUE( - StringPiece(s.error_message()) - .contains( - "No session factory registered for the given session options")); + EXPECT_TRUE(str_util::StrContains( + s.error_message(), + "No session factory registered for the given session options")); } // Register a fake session factory to test error handling paths in @@ -44,7 +44,7 @@ class FakeSessionFactory : public SessionFactory { FakeSessionFactory() {} bool AcceptsOptions(const SessionOptions& options) override { - return StringPiece(options.target).starts_with("fake"); + return str_util::StartsWith(options.target, "fake"); } Session* NewSession(const SessionOptions& options) override { @@ -68,9 +68,9 @@ TEST(SessionTest, MultipleFactoriesForTarget) { Status s = tensorflow::NewSession(options, &session); EXPECT_EQ(s.code(), error::INTERNAL); EXPECT_TRUE( - StringPiece(s.error_message()).contains("Multiple session factories")); - EXPECT_TRUE(StringPiece(s.error_message()).contains("FAKE_SESSION_1")); - EXPECT_TRUE(StringPiece(s.error_message()).contains("FAKE_SESSION_2")); + str_util::StrContains(s.error_message(), "Multiple session factories")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "FAKE_SESSION_1")); + EXPECT_TRUE(str_util::StrContains(s.error_message(), "FAKE_SESSION_2")); } } // namespace diff --git a/tensorflow/core/common_runtime/shape_refiner_test.cc b/tensorflow/core/common_runtime/shape_refiner_test.cc index adf5a9afff..f48638afc0 100644 --- a/tensorflow/core/common_runtime/shape_refiner_test.cc +++ b/tensorflow/core/common_runtime/shape_refiner_test.cc @@ -26,6 +26,7 @@ limitations under the License. #include "tensorflow/core/graph/testlib.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/version.h" @@ -143,8 +144,8 @@ TEST_F(ShapeRefinerTest, BadShapes) { // an error. Status s = m.AddNode(mm.node()); ASSERT_FALSE(s.ok()); - ASSERT_TRUE(StringPiece(s.error_message()) - .contains("Dimensions must be equal, but are 1 and 2")); + ASSERT_TRUE(str_util::StrContains( + s.error_message(), "Dimensions must be equal, but are 1 and 2")); } TEST_F(ShapeRefinerTest, SetShape) { @@ -1032,8 +1033,8 @@ TEST_F(ShapeRefinerTest, ConstantValueAsShape_PackInvalidInput) { TF_ASSERT_OK(m.AddNode(input.node())); } TF_ASSERT_OK(m.AddNode(pack.node())); - EXPECT_TRUE( - StringPiece(m.AddNode(result).error_message()).contains("but is rank 2")); + EXPECT_TRUE(str_util::StrContains(m.AddNode(result).error_message(), + "but is rank 2")); } TEST_F(ShapeRefinerTest, ConstantValueAsShape_Concat) { diff --git a/tensorflow/core/graph/graph_constructor.cc b/tensorflow/core/graph/graph_constructor.cc index 76ee88e684..f15e2ce9fa 100644 --- a/tensorflow/core/graph/graph_constructor.cc +++ b/tensorflow/core/graph/graph_constructor.cc @@ -37,6 +37,7 @@ limitations under the License. #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/strings/scanner.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/public/version.h" @@ -73,7 +74,7 @@ class GraphConstructor { Options(const ImportGraphDefOptions& in) // NOLINT(runtime/explicit) : allow_internal_ops(false), expect_device_spec(false), - prefix(in.prefix.empty() || StringPiece(in.prefix).ends_with("/") + prefix(in.prefix.empty() || str_util::EndsWith(in.prefix, "/") ? in.prefix : in.prefix + "/"), uniquify_names(in.uniquify_names), @@ -436,7 +437,7 @@ Status GraphConstructor::BuildNodeIndex() { bool in_control_dependence = false; for (int i = 0; i < node_def.input_size(); ++i) { StringPiece input_name = node_def.input(i); - if (!input_name.empty() && input_name.starts_with("^")) { + if (!input_name.empty() && str_util::StartsWith(input_name, "^")) { in_control_dependence = true; } else if (in_control_dependence) { return errors::InvalidArgument( @@ -484,7 +485,7 @@ Status GraphConstructor::InitFromEdges() { bool has_loop_back_edge = false; for (int i = 0; i < node_def.input_size(); ++i) { StringPiece input_name(node_def.input(i)); - if (input_name.starts_with("^")) { + if (str_util::StartsWith(input_name, "^")) { num_control_edges++; } else { TensorId id(ParseTensorName(input_name)); @@ -534,7 +535,7 @@ Status GraphConstructor::ValidateColocationConstraints( if (iter == node_def.attr().end()) return Status::OK(); for (const string& c : iter->second.list().s()) { StringPiece s(c); - if (s.Consume(kColocationGroupPrefix) && + if (str_util::ConsumePrefix(&s, kColocationGroupPrefix) && gdef_nodes_.find(s) == gdef_nodes_.end()) { return errors::InvalidArgument( "Node '", node_def.name(), @@ -764,7 +765,7 @@ void GraphConstructor::AddPrefixToNodeDef( // Skip remapped inputs (which already exist in g_ and are not being // imported). if (input_already_exists[i]) continue; - if (input.Consume("^")) { + if (str_util::ConsumePrefix(&input, "^")) { node_def->set_input(i, strings::StrCat("^", prefix_, input)); } else { node_def->set_input(i, strings::StrCat(prefix_, input)); @@ -776,7 +777,7 @@ void GraphConstructor::AddPrefixToNodeDef( node_def->mutable_attr()->at(kColocationAttrName).mutable_list(); for (int i = 0; i < list->s_size(); ++i) { StringPiece v(list->s(i)); - if (v.Consume(kColocationGroupPrefix)) { + if (str_util::ConsumePrefix(&v, kColocationGroupPrefix)) { list->set_s(i, strings::StrCat(kColocationGroupPrefix, prefix_, v)); } } @@ -819,7 +820,7 @@ void GraphConstructor::UpdateUniquifiedColocationNames() { bool updated = false; for (int i = 0; i < coloc_values.size(); ++i) { StringPiece val(coloc_values[i]); - if (val.Consume(kColocationGroupPrefix)) { + if (str_util::ConsumePrefix(&val, kColocationGroupPrefix)) { const auto& name_pair = uniquified_names_.find(val.ToString()); if (name_pair == uniquified_names_.end()) continue; updated = true; diff --git a/tensorflow/core/graph/graph_constructor_test.cc b/tensorflow/core/graph/graph_constructor_test.cc index 963c1dc024..c18ccf6ce4 100644 --- a/tensorflow/core/graph/graph_constructor_test.cc +++ b/tensorflow/core/graph/graph_constructor_test.cc @@ -156,7 +156,9 @@ class GraphConstructorTest : public ::testing::Test { return ""; } StringPiece loc(value[0]); - return loc.Consume(kColocationGroupPrefix) ? loc.ToString() : ""; + return str_util::ConsumePrefix(&loc, kColocationGroupPrefix) + ? loc.ToString() + : ""; } string GraphDebugString() const { diff --git a/tensorflow/core/graph/graph_partition.cc b/tensorflow/core/graph/graph_partition.cc index 17a174101b..877e4f1b44 100644 --- a/tensorflow/core/graph/graph_partition.cc +++ b/tensorflow/core/graph/graph_partition.cc @@ -35,6 +35,7 @@ limitations under the License. #include "tensorflow/core/graph/tensor_id.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/hash/hash.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/util/device_name_utils.h" @@ -372,7 +373,7 @@ string ControlLoopName(const string& name) { bool IsControlLoop(const Node* node) { const string& name = node->name(); - return StringPiece(name).starts_with("_cloop"); + return str_util::StartsWith(name, "_cloop"); } // An enter node for control flow. diff --git a/tensorflow/core/graph/graph_partition_test.cc b/tensorflow/core/graph/graph_partition_test.cc index 6841f29149..83b24cafe2 100644 --- a/tensorflow/core/graph/graph_partition_test.cc +++ b/tensorflow/core/graph/graph_partition_test.cc @@ -35,6 +35,7 @@ limitations under the License. #include "tensorflow/core/graph/graph_def_builder.h" #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/test.h" @@ -120,7 +121,7 @@ void CheckLoopConstruction(const GraphDef& graph_def) { if (ndef.op() == "_Recv") { bool has_control = false; for (const string& input_name : ndef.input()) { - if (StringPiece(input_name).starts_with("^")) { + if (str_util::StartsWith(input_name, "^")) { has_control = true; break; } @@ -128,7 +129,7 @@ void CheckLoopConstruction(const GraphDef& graph_def) { EXPECT_TRUE(has_control); } // Must have a control loop - if (StringPiece(ndef.name()).starts_with("_cloop")) { + if (str_util::StartsWith(ndef.name(), "_cloop")) { if (ndef.op() == "Enter") { has_control_enter = true; } diff --git a/tensorflow/core/graph/graph_test.cc b/tensorflow/core/graph/graph_test.cc index e2ce0ba046..c8c2b225fe 100644 --- a/tensorflow/core/graph/graph_test.cc +++ b/tensorflow/core/graph/graph_test.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/protobuf.h" @@ -408,7 +409,7 @@ TEST_F(GraphTest, NewName) { EXPECT_NE(a1, a2); EXPECT_NE(a1, b1); EXPECT_NE(a2, b1); - EXPECT_TRUE(StringPiece(a1).starts_with("A")) << a1; + EXPECT_TRUE(str_util::StartsWith(a1, "A")) << a1; } TEST_F(GraphTest, IsValidNode) { diff --git a/tensorflow/core/graph/quantize_training_test.cc b/tensorflow/core/graph/quantize_training_test.cc index 2ad69dbd0c..e46f92bc24 100644 --- a/tensorflow/core/graph/quantize_training_test.cc +++ b/tensorflow/core/graph/quantize_training_test.cc @@ -32,6 +32,7 @@ limitations under the License. #include "tensorflow/core/graph/testlib.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session.h" @@ -215,7 +216,7 @@ TEST_F(QuantizeTrainingTest, WithBackwardNodes_QuantizeAndDequantize) { Node* found_node; Status s = FindNode(g, strings::StrCat(d->name(), "/QuantizeAndDequantizeV2"), &found_node); - EXPECT_TRUE(StringPiece(s.ToString()).contains("not found")) << s; + EXPECT_TRUE(str_util::StrContains(s.ToString(), "not found")) << s; // Ensure that m1 and m2's inputs were quantized. TF_ASSERT_OK( @@ -269,7 +270,7 @@ TEST_F(QuantizeTrainingTest, WithBackwardNodes_FakeQuant) { Node* found_node; Status s = FindNode(g, strings::StrCat(d->name(), "/FakeQuantWithMinMaxVars"), &found_node); - EXPECT_TRUE(StringPiece(s.ToString()).contains("not found")) << s; + EXPECT_TRUE(str_util::StrContains(s.ToString(), "not found")) << s; // Ensure that m1 and m2's inputs were quantized. TF_ASSERT_OK( diff --git a/tensorflow/core/graph/subgraph_test.cc b/tensorflow/core/graph/subgraph_test.cc index 7219d9812f..6c014a8d44 100644 --- a/tensorflow/core/graph/subgraph_test.cc +++ b/tensorflow/core/graph/subgraph_test.cc @@ -312,8 +312,8 @@ TEST_F(SubgraphTest, ChainOfFools) { EXPECT_TRUE(HasEdge("e", 0, "_send_e_0", 0)); } -static bool HasSubstr(const string& base, const string& substr) { - bool ok = StringPiece(base).contains(substr); +static bool HasSubstr(StringPiece base, StringPiece substr) { + bool ok = str_util::StrContains(base, substr); EXPECT_TRUE(ok) << base << ", expected substring " << substr; return ok; } diff --git a/tensorflow/core/graph/tensor_id.cc b/tensorflow/core/graph/tensor_id.cc index 089ea5e527..8af1936d64 100644 --- a/tensorflow/core/graph/tensor_id.cc +++ b/tensorflow/core/graph/tensor_id.cc @@ -18,6 +18,7 @@ limitations under the License. #include <string> #include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/lib/strings/str_util.h" namespace tensorflow { @@ -45,7 +46,7 @@ TensorId ParseTensorName(StringPiece name) { if (p > base && *p == ':' && mul > 1) { id.first = StringPiece(base, p - base); id.second = index; - } else if (name.starts_with("^")) { + } else if (str_util::StartsWith(name, "^")) { // Control edge id.first = StringPiece(base + 1); id.second = Graph::kControlSlot; diff --git a/tensorflow/core/graph/validate_test.cc b/tensorflow/core/graph/validate_test.cc index cb6d107cad..d58cdc3c5b 100644 --- a/tensorflow/core/graph/validate_test.cc +++ b/tensorflow/core/graph/validate_test.cc @@ -26,6 +26,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -60,7 +61,7 @@ TEST(ValidateGraphDefTest, GraphWithUnspecifiedDefaultAttr) { CHECK(parser.MergeFromString(graph_def_str, &graph_def)) << graph_def_str; Status s = graph::ValidateGraphDef(graph_def, *OpRegistry::Global()); EXPECT_FALSE(s.ok()); - EXPECT_TRUE(StringPiece(s.ToString()).contains("NodeDef missing attr")); + EXPECT_TRUE(str_util::StrContains(s.ToString(), "NodeDef missing attr")); // Add the defaults. TF_ASSERT_OK(AddDefaultAttrsToGraphDef(&graph_def, *OpRegistry::Global(), 0)); @@ -83,7 +84,7 @@ TEST(ValidateGraphDefTest, GraphWithUnspecifiedRequiredAttr) { CHECK(parser.MergeFromString(graph_def_str, &graph_def)) << graph_def_str; Status s = graph::ValidateGraphDef(graph_def, *OpRegistry::Global()); EXPECT_FALSE(s.ok()); - EXPECT_TRUE(StringPiece(s.ToString()).contains("NodeDef missing attr")); + EXPECT_TRUE(str_util::StrContains(s.ToString(), "NodeDef missing attr")); // Add the defaults. TF_ASSERT_OK(AddDefaultAttrsToGraphDef(&graph_def, *OpRegistry::Global(), 0)); @@ -91,7 +92,7 @@ TEST(ValidateGraphDefTest, GraphWithUnspecifiedRequiredAttr) { // Validation should still fail. s = graph::ValidateGraphDef(graph_def, *OpRegistry::Global()); EXPECT_FALSE(s.ok()); - EXPECT_TRUE(StringPiece(s.ToString()).contains("NodeDef missing attr")); + EXPECT_TRUE(str_util::StrContains(s.ToString(), "NodeDef missing attr")); } TEST(ValidateGraphDefAgainstOpListTest, GraphWithOpOnlyInOpList) { |