1*0fca6ea1SDimitry Andric //===--- rtsan_test_context.cpp - Realtime Sanitizer ------------*- C++ -*-===//
2*0fca6ea1SDimitry Andric //
3*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0fca6ea1SDimitry Andric //
7*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
8*0fca6ea1SDimitry Andric //
9*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
10*0fca6ea1SDimitry Andric
11*0fca6ea1SDimitry Andric #include "rtsan_test_utilities.h"
12*0fca6ea1SDimitry Andric
13*0fca6ea1SDimitry Andric #include "rtsan_context.h"
14*0fca6ea1SDimitry Andric
TEST(TestRtsanContext,CanCreateContext)15*0fca6ea1SDimitry Andric TEST(TestRtsanContext, CanCreateContext) { __rtsan::Context context{}; }
16*0fca6ea1SDimitry Andric
TEST(TestRtsanContext,ExpectNotRealtimeDoesNotDieBeforeRealtimePush)17*0fca6ea1SDimitry Andric TEST(TestRtsanContext, ExpectNotRealtimeDoesNotDieBeforeRealtimePush) {
18*0fca6ea1SDimitry Andric __rtsan::Context context{};
19*0fca6ea1SDimitry Andric context.ExpectNotRealtime("do_some_stuff");
20*0fca6ea1SDimitry Andric }
21*0fca6ea1SDimitry Andric
TEST(TestRtsanContext,ExpectNotRealtimeDoesNotDieAfterPushAndPop)22*0fca6ea1SDimitry Andric TEST(TestRtsanContext, ExpectNotRealtimeDoesNotDieAfterPushAndPop) {
23*0fca6ea1SDimitry Andric __rtsan::Context context{};
24*0fca6ea1SDimitry Andric context.RealtimePush();
25*0fca6ea1SDimitry Andric context.RealtimePop();
26*0fca6ea1SDimitry Andric context.ExpectNotRealtime("do_some_stuff");
27*0fca6ea1SDimitry Andric }
28*0fca6ea1SDimitry Andric
TEST(TestRtsanContext,ExpectNotRealtimeDiesAfterRealtimePush)29*0fca6ea1SDimitry Andric TEST(TestRtsanContext, ExpectNotRealtimeDiesAfterRealtimePush) {
30*0fca6ea1SDimitry Andric __rtsan::Context context{};
31*0fca6ea1SDimitry Andric
32*0fca6ea1SDimitry Andric context.RealtimePush();
33*0fca6ea1SDimitry Andric EXPECT_DEATH(context.ExpectNotRealtime("do_some_stuff"), "");
34*0fca6ea1SDimitry Andric }
35*0fca6ea1SDimitry Andric
TEST(TestRtsanContext,ExpectNotRealtimeDiesAfterRealtimeAfterMorePushesThanPops)36*0fca6ea1SDimitry Andric TEST(TestRtsanContext,
37*0fca6ea1SDimitry Andric ExpectNotRealtimeDiesAfterRealtimeAfterMorePushesThanPops) {
38*0fca6ea1SDimitry Andric __rtsan::Context context{};
39*0fca6ea1SDimitry Andric
40*0fca6ea1SDimitry Andric context.RealtimePush();
41*0fca6ea1SDimitry Andric context.RealtimePush();
42*0fca6ea1SDimitry Andric context.RealtimePush();
43*0fca6ea1SDimitry Andric context.RealtimePop();
44*0fca6ea1SDimitry Andric context.RealtimePop();
45*0fca6ea1SDimitry Andric EXPECT_DEATH(context.ExpectNotRealtime("do_some_stuff"), "");
46*0fca6ea1SDimitry Andric }
47*0fca6ea1SDimitry Andric
TEST(TestRtsanContext,ExpectNotRealtimeDoesNotDieAfterBypassPush)48*0fca6ea1SDimitry Andric TEST(TestRtsanContext, ExpectNotRealtimeDoesNotDieAfterBypassPush) {
49*0fca6ea1SDimitry Andric __rtsan::Context context{};
50*0fca6ea1SDimitry Andric
51*0fca6ea1SDimitry Andric context.RealtimePush();
52*0fca6ea1SDimitry Andric context.BypassPush();
53*0fca6ea1SDimitry Andric context.ExpectNotRealtime("do_some_stuff");
54*0fca6ea1SDimitry Andric }
55*0fca6ea1SDimitry Andric
TEST(TestRtsanContext,ExpectNotRealtimeDoesNotDieIfBypassDepthIsGreaterThanZero)56*0fca6ea1SDimitry Andric TEST(TestRtsanContext,
57*0fca6ea1SDimitry Andric ExpectNotRealtimeDoesNotDieIfBypassDepthIsGreaterThanZero) {
58*0fca6ea1SDimitry Andric __rtsan::Context context{};
59*0fca6ea1SDimitry Andric
60*0fca6ea1SDimitry Andric context.RealtimePush();
61*0fca6ea1SDimitry Andric context.BypassPush();
62*0fca6ea1SDimitry Andric context.BypassPush();
63*0fca6ea1SDimitry Andric context.BypassPush();
64*0fca6ea1SDimitry Andric context.BypassPop();
65*0fca6ea1SDimitry Andric context.BypassPop();
66*0fca6ea1SDimitry Andric context.ExpectNotRealtime("do_some_stuff");
67*0fca6ea1SDimitry Andric context.BypassPop();
68*0fca6ea1SDimitry Andric EXPECT_DEATH(context.ExpectNotRealtime("do_some_stuff"), "");
69*0fca6ea1SDimitry Andric }
70