brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · f0cf90e Raw
49 lines · c
1//===--- rtsan_test_utilities.h - Realtime Sanitizer ------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9//===----------------------------------------------------------------------===//10 11#pragma once12 13#include "rtsan.h"14#include "gmock/gmock.h"15#include <string>16 17namespace rtsan_testing {18 19template <typename Function> void RealtimeInvoke(Function &&Func) {20  __rtsan_realtime_enter();21  std::forward<Function>(Func)();22  __rtsan_realtime_exit();23}24 25template <typename Function>26void ExpectRealtimeDeath(Function &&Func,27                         const char *intercepted_method_name = nullptr) {28 29  using namespace testing;30 31  auto GetExpectedErrorSubstring = [&]() -> std::string {32    return intercepted_method_name != nullptr33               ? ".*==ERROR: RealtimeSanitizer: unsafe-library-call.*"34                 "Intercepted call to real-time unsafe function `" +35                     std::string(intercepted_method_name) +36                     "` in real-time context!"37               : "";38  };39 40  EXPECT_EXIT(RealtimeInvoke(std::forward<Function>(Func)), ExitedWithCode(43),41              GetExpectedErrorSubstring());42}43 44template <typename Function> void ExpectNonRealtimeSurvival(Function &&Func) {45  std::forward<Function>(Func)();46}47 48} // namespace rtsan_testing49