1 //===--- rtsan_test_context.cpp - 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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 //===----------------------------------------------------------------------===// 10 11 #include "rtsan_test_utilities.h" 12 13 #include "rtsan_context.h" 14 15 TEST(TestRtsanContext, CanCreateContext) { __rtsan::Context context{}; } 16 17 TEST(TestRtsanContext, ExpectNotRealtimeDoesNotDieBeforeRealtimePush) { 18 __rtsan::Context context{}; 19 context.ExpectNotRealtime("do_some_stuff"); 20 } 21 22 TEST(TestRtsanContext, ExpectNotRealtimeDoesNotDieAfterPushAndPop) { 23 __rtsan::Context context{}; 24 context.RealtimePush(); 25 context.RealtimePop(); 26 context.ExpectNotRealtime("do_some_stuff"); 27 } 28 29 TEST(TestRtsanContext, ExpectNotRealtimeDiesAfterRealtimePush) { 30 __rtsan::Context context{}; 31 32 context.RealtimePush(); 33 EXPECT_DEATH(context.ExpectNotRealtime("do_some_stuff"), ""); 34 } 35 36 TEST(TestRtsanContext, 37 ExpectNotRealtimeDiesAfterRealtimeAfterMorePushesThanPops) { 38 __rtsan::Context context{}; 39 40 context.RealtimePush(); 41 context.RealtimePush(); 42 context.RealtimePush(); 43 context.RealtimePop(); 44 context.RealtimePop(); 45 EXPECT_DEATH(context.ExpectNotRealtime("do_some_stuff"), ""); 46 } 47 48 TEST(TestRtsanContext, ExpectNotRealtimeDoesNotDieAfterBypassPush) { 49 __rtsan::Context context{}; 50 51 context.RealtimePush(); 52 context.BypassPush(); 53 context.ExpectNotRealtime("do_some_stuff"); 54 } 55 56 TEST(TestRtsanContext, 57 ExpectNotRealtimeDoesNotDieIfBypassDepthIsGreaterThanZero) { 58 __rtsan::Context context{}; 59 60 context.RealtimePush(); 61 context.BypassPush(); 62 context.BypassPush(); 63 context.BypassPush(); 64 context.BypassPop(); 65 context.BypassPop(); 66 context.ExpectNotRealtime("do_some_stuff"); 67 context.BypassPop(); 68 EXPECT_DEATH(context.ExpectNotRealtime("do_some_stuff"), ""); 69 } 70