tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_helpers.cc (2715B)


      1 // Copyright 2022 The Abseil Authors.
      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 //      https://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 #include "absl/log/internal/test_helpers.h"
     16 
     17 #ifdef __Fuchsia__
     18 #include <zircon/syscalls.h>
     19 #endif
     20 
     21 #include "gtest/gtest.h"
     22 #include "absl/base/config.h"
     23 #include "absl/base/log_severity.h"
     24 #include "absl/log/globals.h"
     25 #include "absl/log/initialize.h"
     26 #include "absl/log/internal/globals.h"
     27 
     28 namespace absl {
     29 ABSL_NAMESPACE_BEGIN
     30 namespace log_internal {
     31 
     32 // Returns false if the specified severity level is disabled by
     33 // `ABSL_MIN_LOG_LEVEL` or `absl::MinLogLevel()`.
     34 bool LoggingEnabledAt(absl::LogSeverity severity) {
     35  return severity >= kAbslMinLogLevel && severity >= absl::MinLogLevel();
     36 }
     37 
     38 // -----------------------------------------------------------------------------
     39 // Googletest Death Test Predicates
     40 // -----------------------------------------------------------------------------
     41 
     42 #if GTEST_HAS_DEATH_TEST
     43 
     44 bool DiedOfFatal(int exit_status) {
     45 #if defined(_WIN32)
     46  // Depending on NDEBUG and (configuration?) MSVC's abort either results
     47  // in error code 3 (SIGABRT) or error code 0x80000003 (breakpoint
     48  // triggered).
     49  return ::testing::ExitedWithCode(3)(exit_status & 0x7fffffff);
     50 #elif defined(__Fuchsia__)
     51  // The Fuchsia death test implementation kill()'s the process when it detects
     52  // an exception, so it should exit with the corresponding code. See
     53  // FuchsiaDeathTest::Wait().
     54  return ::testing::ExitedWithCode(ZX_TASK_RETCODE_SYSCALL_KILL)(exit_status);
     55 #elif defined(__ANDROID__) && defined(__aarch64__)
     56  // These are all run under a qemu config that eats died-due-to-signal exit
     57  // statuses.
     58  return true;
     59 #else
     60  return ::testing::KilledBySignal(SIGABRT)(exit_status);
     61 #endif
     62 }
     63 
     64 bool DiedOfQFatal(int exit_status) {
     65  return ::testing::ExitedWithCode(1)(exit_status);
     66 }
     67 
     68 #endif
     69 
     70 // -----------------------------------------------------------------------------
     71 // Helper for Log initialization in test
     72 // -----------------------------------------------------------------------------
     73 
     74 void LogTestEnvironment::SetUp() {
     75  if (!absl::log_internal::IsInitialized()) {
     76    absl::InitializeLog();
     77  }
     78 }
     79 
     80 }  // namespace log_internal
     81 ABSL_NAMESPACE_END
     82 }  // namespace absl