Path: blob/main/contrib/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_assertions.cpp
213799 views
//===--- rtsan_test_assertions.cpp - 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// Part of the RealtimeSanitizer runtime library test suite9//10//===----------------------------------------------------------------------===//1112#include "rtsan_test_utilities.h"1314#include "rtsan/rtsan_assertions.h"1516#include "sanitizer_common/sanitizer_stacktrace.h"1718#include <gmock/gmock.h>1920using namespace __sanitizer;21using namespace __rtsan;2223class TestRtsanAssertions : public ::testing::Test {24protected:25void SetUp() override { __rtsan_ensure_initialized(); }26};2728static void ExpectViolationAction(Context &context,29bool expect_violation_callback) {30::testing::MockFunction<void(const BufferedStackTrace &stack,31const DiagnosticsInfo &info)>32mock_on_violation;33EXPECT_CALL(mock_on_violation, Call).Times(expect_violation_callback ? 1 : 0);34DiagnosticsInfo info{};35ExpectNotRealtime(context, info, mock_on_violation.AsStdFunction());36}3738TEST_F(TestRtsanAssertions,39ExpectNotRealtimeDoesNotCallViolationActionIfNotInRealtimeContext) {40Context context{};41ASSERT_FALSE(context.InRealtimeContext());42ExpectViolationAction(context, false);43}4445TEST_F(TestRtsanAssertions,46ExpectNotRealtimeCallsViolationActionIfInRealtimeContext) {47Context context{};48context.RealtimePush();49ASSERT_TRUE(context.InRealtimeContext());50ExpectViolationAction(context, true);51}5253TEST_F(TestRtsanAssertions,54ExpectNotRealtimeDoesNotCallViolationActionIfRealtimeButBypassed) {55Context context{};56context.RealtimePush();57context.BypassPush();58ASSERT_TRUE(context.IsBypassed());59ExpectViolationAction(context, false);60}616263