Home | History | Annotate | Download | only in framework
      1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include <memory>
     17 
     18 #include "tensorflow/core/framework/op.h"
     19 
     20 #include "tensorflow/core/lib/core/status_test_util.h"
     21 #include "tensorflow/core/platform/test.h"
     22 
     23 namespace tensorflow {
     24 
     25 namespace {
     26 
     27 void Register(const string& op_name, OpRegistry* registry) {
     28   registry->Register([op_name](OpRegistrationData* op_reg_data) -> Status {
     29     op_reg_data->op_def.set_name(op_name);
     30     return Status::OK();
     31   });
     32 }
     33 
     34 }  // namespace
     35 
     36 TEST(OpRegistrationTest, TestBasic) {
     37   std::unique_ptr<OpRegistry> registry(new OpRegistry);
     38   Register("Foo", registry.get());
     39   OpList op_list;
     40   registry->Export(true, &op_list);
     41   EXPECT_EQ(op_list.op().size(), 1);
     42   EXPECT_EQ(op_list.op(0).name(), "Foo");
     43 }
     44 
     45 TEST(OpRegistrationTest, TestDuplicate) {
     46   std::unique_ptr<OpRegistry> registry(new OpRegistry);
     47   Register("Foo", registry.get());
     48   Status s = registry->ProcessRegistrations();
     49   EXPECT_TRUE(s.ok());
     50 
     51   TF_EXPECT_OK(
     52       registry->SetWatcher([](const Status& s, const OpDef& op_def) -> Status {
     53         EXPECT_TRUE(errors::IsAlreadyExists(s));
     54         return Status::OK();
     55       }));
     56   Register("Foo", registry.get());
     57   s = registry->ProcessRegistrations();
     58   EXPECT_TRUE(s.ok());
     59 }
     60 
     61 }  // namespace tensorflow
     62