Home | History | Annotate | Download | only in xla
      1 /* Copyright 2017 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 #ifndef TENSORFLOW_COMPILER_XLA_TEST_HELPERS_H_
     17 #define TENSORFLOW_COMPILER_XLA_TEST_HELPERS_H_
     18 
     19 #include <list>
     20 #include <vector>
     21 
     22 #include "tensorflow/compiler/xla/statusor.h"
     23 #include "tensorflow/compiler/xla/types.h"
     24 #include "tensorflow/core/lib/core/stringpiece.h"
     25 #include "tensorflow/core/platform/protobuf.h"
     26 #include "tensorflow/core/platform/regexp.h"
     27 #include "tensorflow/core/platform/test.h"
     28 
     29 // This module contains a minimal subset of gmock functionality just
     30 // sufficient to execute the currently existing tests.
     31 namespace util {
     32 class Status;
     33 }  // namespace util
     34 
     35 namespace xla {
     36 template <typename T>
     37 class Array2D;
     38 class Literal;
     39 
     40 namespace testing {
     41 
     42 namespace internal_status {
     43 inline const ::tensorflow::Status& GetStatus(
     44     const ::tensorflow::Status& status) {
     45   return status;
     46 }
     47 
     48 template <typename T>
     49 inline const ::tensorflow::Status& GetStatus(const StatusOr<T>& status) {
     50   return status.status();
     51 }
     52 }  // namespace internal_status
     53 
     54 }  // namespace testing
     55 }  // namespace xla
     56 
     57 // The following macros are similar to macros in gmock, but deliberately named
     58 // differently in order to avoid conflicts in files which include both.
     59 
     60 // Macros for testing the results of functions that return tensorflow::Status or
     61 // StatusOr<T> (for any type T).
     62 #define EXPECT_IS_OK(expression)      \
     63   EXPECT_EQ(tensorflow::Status::OK(), \
     64             xla::testing::internal_status::GetStatus(expression))
     65 #define EXPECT_IS_NOT_OK(expression)  \
     66   EXPECT_NE(tensorflow::Status::OK(), \
     67             xla::testing::internal_status::GetStatus(expression))
     68 #undef ASSERT_IS_OK
     69 #define ASSERT_IS_OK(expression)      \
     70   ASSERT_EQ(tensorflow::Status::OK(), \
     71             xla::testing::internal_status::GetStatus(expression))
     72 #undef ASSERT_IS_NOT_OK
     73 #define ASSERT_IS_NOT_OK(expression)  \
     74   ASSERT_NE(tensorflow::Status::OK(), \
     75             xla::testing::internal_status::GetStatus(expression))
     76 
     77 #endif  // TENSORFLOW_COMPILER_XLA_TEST_HELPERS_H_
     78