Skip to content

Commit

Permalink
Update c_api_test.cc to load test_op1.so instead of test_op.so. If op…
Browse files Browse the repository at this point in the history
… has the same name as already

loaded op, then it won't be added to list returned by TF_GetOpList. So, we want to load a different op.

PiperOrigin-RevId: 220210246
  • Loading branch information
annarev authored and tensorflower-gardener committed Nov 6, 2018
1 parent be4dc89 commit dae1e7c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
6 changes: 3 additions & 3 deletions tensorflow/c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ tf_cuda_cc_test(
size = "small",
srcs = ["c_api_test.cc"],
data = [
":test_op.so",
":test_op1.so",
"//tensorflow/cc/saved_model:saved_model_half_plus_two",
],
kernels = [":test_op_kernel"],
Expand Down Expand Up @@ -284,8 +284,8 @@ tf_cc_test(
)

tf_custom_op_library(
name = "test_op.so",
srcs = ["test_op.cc"],
name = "test_op1.so",
srcs = ["test_op1.cc"],
)

tf_kernel_library(
Expand Down
40 changes: 19 additions & 21 deletions tensorflow/c/c_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,26 @@ TEST(CAPI, LibraryLoadFunctions) {
// tf_cuda_cc_test() bazel rule and remove the next line.
if (!GPUDeviceName().empty()) return;

// Load the library.
TF_Status* status = TF_NewStatus();
TF_Library* lib =
TF_LoadLibrary("tensorflow/c/test_op.so", status);
TF_Code code = TF_GetCode(status);
string status_msg(TF_Message(status));
TF_DeleteStatus(status);
ASSERT_EQ(TF_OK, code) << status_msg;
#if !defined(TENSORFLOW_NO_SHARED_OBJECTS)
{
// Load the library.
TF_Status* status = TF_NewStatus();
TF_Library* lib =
TF_LoadLibrary("tensorflow/c/test_op1.so", status);
TF_Code code = TF_GetCode(status);
string status_msg(TF_Message(status));
TF_DeleteStatus(status);
ASSERT_EQ(TF_OK, code) << status_msg;

// Test op list.
TF_Buffer op_list_buf = TF_GetOpList(lib);
tensorflow::OpList op_list;
EXPECT_TRUE(op_list.ParseFromArray(op_list_buf.data, op_list_buf.length));
ASSERT_EQ(op_list.op_size(), 1);
EXPECT_EQ("TestCApi1", op_list.op(0).name());
TF_DeleteLibraryHandle(lib);
}
#endif // !defined(TENSORFLOW_NO_SHARED_OBJECTS)
{
TF_Buffer* op_list_buffer = TF_GetAllOpList();
tensorflow::OpList op_list;
Expand All @@ -210,19 +221,6 @@ TEST(CAPI, LibraryLoadFunctions) {
EXPECT_TRUE(found);
TF_DeleteBuffer(op_list_buffer);
}

#if !defined(TENSORFLOW_NO_SHARED_OBJECTS)
{
// Test op list.
TF_Buffer op_list_buf = TF_GetOpList(lib);
tensorflow::OpList op_list;
EXPECT_TRUE(op_list.ParseFromArray(op_list_buf.data, op_list_buf.length));
ASSERT_EQ(op_list.op_size(), 1);
EXPECT_EQ("TestCApi", op_list.op(0).name());
}
#endif // !defined(TENSORFLOW_NO_SHARED_OBJECTS)

TF_DeleteLibraryHandle(lib);
}

void TestEncodeDecode(int line, const std::vector<string>& data) {
Expand Down
23 changes: 23 additions & 0 deletions tensorflow/c/test_op1.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"

namespace tensorflow {

REGISTER_OP("TestCApi1").Doc(R"doc(Used to test C API)doc");

} // namespace tensorflow

0 comments on commit dae1e7c

Please sign in to comment.