Path: blob/main/contrib/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_utilities.h
35269 views
//===--- rtsan_test_utilities.h - Realtime Sanitizer ------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8//===----------------------------------------------------------------------===//910#pragma once1112#include "rtsan.h"13#include "gmock/gmock.h"14#include <string>1516namespace rtsan_testing {1718template <typename Function> void RealtimeInvoke(Function &&Func) {19__rtsan_realtime_enter();20std::forward<Function>(Func)();21__rtsan_realtime_exit();22}2324template <typename Function>25void ExpectRealtimeDeath(Function &&Func,26const char *intercepted_method_name = nullptr) {2728using namespace testing;2930auto GetExpectedErrorSubstring = [&]() -> std::string {31return intercepted_method_name != nullptr32? "Real-time violation: intercepted call to real-time unsafe "33"function `" +34std::string(intercepted_method_name) + "`"35: "";36};3738EXPECT_EXIT(RealtimeInvoke(std::forward<Function>(Func)),39ExitedWithCode(EXIT_FAILURE), GetExpectedErrorSubstring());40}4142template <typename Function> void ExpectNonRealtimeSurvival(Function &&Func) {43std::forward<Function>(Func)();44}4546} // namespace rtsan_testing474849