Home | History | Annotate | Download | only in platform
      1 /* Copyright 2015 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 "tensorflow/core/platform/logging.h"
     17 #include "tensorflow/core/platform/test.h"
     18 
     19 namespace tensorflow {
     20 
     21 TEST(Logging, Log) {
     22   LOG(INFO) << "Hello";
     23   LOG(INFO) << "Another log message";
     24   LOG(ERROR) << "Error message";
     25   VLOG(1) << "A VLOG message";
     26   VLOG(2) << "A higher VLOG message";
     27 }
     28 
     29 TEST(Logging, CheckChecks) {
     30   CHECK(true);
     31   CHECK(7 > 5);
     32   string a("abc");
     33   string b("xyz");
     34   CHECK_EQ(a, a);
     35   CHECK_NE(a, b);
     36   CHECK_EQ(3, 3);
     37   CHECK_NE(4, 3);
     38   CHECK_GT(4, 3);
     39   CHECK_GE(3, 3);
     40   CHECK_LT(2, 3);
     41   CHECK_LE(2, 3);
     42 
     43   DCHECK(true);
     44   DCHECK(7 > 5);
     45   DCHECK_EQ(a, a);
     46   DCHECK_NE(a, b);
     47   DCHECK_EQ(3, 3);
     48   DCHECK_NE(4, 3);
     49   DCHECK_GT(4, 3);
     50   DCHECK_GE(3, 3);
     51   DCHECK_LT(2, 3);
     52   DCHECK_LE(2, 3);
     53 }
     54 
     55 TEST(LoggingDeathTest, FailedChecks) {
     56   string a("abc");
     57   string b("xyz");
     58   const char* p_const = "hello there";
     59   const char* p_null_const = nullptr;
     60   char mybuf[10];
     61   char* p_non_const = mybuf;
     62   char* p_null = nullptr;
     63   CHECK_NOTNULL(p_const);
     64   CHECK_NOTNULL(p_non_const);
     65 
     66   ASSERT_DEATH(CHECK(false), "false");
     67   ASSERT_DEATH(CHECK(9 < 7), "9 < 7");
     68   ASSERT_DEATH(CHECK_EQ(a, b), "a == b");
     69   ASSERT_DEATH(CHECK_EQ(3, 4), "3 == 4");
     70   ASSERT_DEATH(CHECK_NE(3, 3), "3 != 3");
     71   ASSERT_DEATH(CHECK_GT(2, 3), "2 > 3");
     72   ASSERT_DEATH(CHECK_GE(2, 3), "2 >= 3");
     73   ASSERT_DEATH(CHECK_LT(3, 2), "3 < 2");
     74   ASSERT_DEATH(CHECK_LE(3, 2), "3 <= 2");
     75   ASSERT_DEATH(CHECK(false), "false");
     76   ASSERT_DEATH(printf("%s", CHECK_NOTNULL(p_null)), "Must be non NULL");
     77   ASSERT_DEATH(printf("%s", CHECK_NOTNULL(p_null_const)), "Must be non NULL");
     78 #ifndef NDEBUG
     79   ASSERT_DEATH(DCHECK(9 < 7), "9 < 7");
     80   ASSERT_DEATH(DCHECK(9 < 7), "9 < 7");
     81   ASSERT_DEATH(DCHECK_EQ(a, b), "a == b");
     82   ASSERT_DEATH(DCHECK_EQ(3, 4), "3 == 4");
     83   ASSERT_DEATH(DCHECK_NE(3, 3), "3 != 3");
     84   ASSERT_DEATH(DCHECK_GT(2, 3), "2 > 3");
     85   ASSERT_DEATH(DCHECK_GE(2, 3), "2 >= 3");
     86   ASSERT_DEATH(DCHECK_LT(3, 2), "3 < 2");
     87   ASSERT_DEATH(DCHECK_LE(3, 2), "3 <= 2");
     88 #endif
     89 }
     90 
     91 TEST(InternalLogString, Basic) {
     92   // Just make sure that this code compiles (we don't actually verify
     93   // the output)
     94   internal::LogString(__FILE__, __LINE__, INFO, "Hello there");
     95 }
     96 
     97 }  // namespace tensorflow
     98