chromium/third_party/fuzztest/src/fuzztest/internal/logging.cc

// Copyright 2022 Google LLC
//
// 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 "./fuzztest/internal/logging.h"

#include <errno.h>
#include <string.h>

#include "absl/base/attributes.h"
#include "absl/base/const_init.h"
#include "absl/base/thread_annotations.h"
#include "absl/synchronization/mutex.h"

#if defined(__linux__)
#include <unistd.h>
#endif

#include <cstdio>
#include <cstdlib>
#include <string>

namespace fuzztest::internal {

namespace {

ABSL_CONST_INIT absl::Mutex stderr_file_guard_(absl::kConstInit);
FILE* stderr_file_ ABSL_GUARDED_BY();  // Zero-initialized.

}  // namespace

#if defined(__linux__)

namespace {

FILE* stdout_file_ =;  // Never accessed concurrently.

void Silence(int fd) {}

// Only accepts 1 or 2 (stdout or stderr).
// If it's stdout, silence it after duping it as a global temporary, which
// will be used when restoring the stdout.
// If it's a stderr, silence it after duping it as the global stderr, which
// will be used internally to log and be used when restoring the stderr.
void DupAndSilence(int fd) {}
}  // namespace

void SilenceTargetStdoutAndStderr() {}

void RestoreTargetStdoutAndStderr() {}

bool IsSilenceTargetEnabled() {}

#else

void SilenceTargetStdoutAndStderr() { return; }

void RestoreTargetStdoutAndStderr() { return; }

bool IsSilenceTargetEnabled() { return false; }

#endif  // defined(__linux__)

FILE* GetStderr() {}

void Abort(const char* file, int line, const std::string& message) {}

const std::string* volatile test_abort_message =;
void AbortInTest(const std::string& message) {}

}  // namespace fuzztest::internal