-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[rtsan] Prune rtsan context and assertions tests #109503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rtsan] Prune rtsan context and assertions tests #109503
Conversation
@cjappl for review |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: None (davidtrevelyan) ChangesDisentangles (and simplifies) integration-like tests for Full diff: https://github.com/llvm/llvm-project/pull/109503.diff 3 Files Affected:
diff --git a/compiler-rt/lib/rtsan/tests/CMakeLists.txt b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
index 0529917bc895ce..139eea785fcdca 100644
--- a/compiler-rt/lib/rtsan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
@@ -21,6 +21,7 @@ set(RTSAN_INST_TEST_SOURCES
set(RTSAN_NOINST_TEST_SOURCES
../rtsan_preinit.cpp
+ rtsan_test_assertions.cpp
rtsan_test_context.cpp
rtsan_test_main.cpp)
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_assertions.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_assertions.cpp
new file mode 100644
index 00000000000000..cdf2ac32170043
--- /dev/null
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_assertions.cpp
@@ -0,0 +1,42 @@
+//===--- rtsan_test_assertions.cpp - Realtime Sanitizer ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Part of the RealtimeSanitizer runtime library test suite
+//
+//===----------------------------------------------------------------------===//
+
+#include "rtsan_test_utilities.h"
+
+#include "rtsan/rtsan_assertions.h"
+
+#include <gtest/gtest.h>
+
+class TestRtsanAssertions : public ::testing::Test {
+protected:
+ void SetUp() override { __rtsan_ensure_initialized(); }
+};
+
+TEST_F(TestRtsanAssertions, ExpectNotRealtimeDoesNotDieIfNotInRealtimeContext) {
+ __rtsan::Context context{};
+ ASSERT_FALSE(context.InRealtimeContext());
+ ExpectNotRealtime(context, "fake_function_name");
+}
+
+TEST_F(TestRtsanAssertions, ExpectNotRealtimeDiesIfInRealtimeContext) {
+ __rtsan::Context context{};
+ context.RealtimePush();
+ ASSERT_TRUE(context.InRealtimeContext());
+ EXPECT_DEATH(ExpectNotRealtime(context, "fake_function_name"), "");
+}
+
+TEST_F(TestRtsanAssertions, ExpectNotRealtimeDoesNotDieIfRealtimeButBypassed) {
+ __rtsan::Context context{};
+ context.RealtimePush();
+ context.BypassPush();
+ ExpectNotRealtime(context, "fake_function_name");
+}
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_context.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_context.cpp
index a7a96161cf2b54..9ba33185bde28e 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_context.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_context.cpp
@@ -11,66 +11,87 @@
#include "rtsan_test_utilities.h"
#include "rtsan/rtsan.h"
-#include "rtsan/rtsan_assertions.h"
#include "rtsan/rtsan_context.h"
#include <gtest/gtest.h>
-class TestRtsanContext : public ::testing::Test {
+using namespace ::testing;
+
+class TestRtsanContext : public Test {
protected:
void SetUp() override { __rtsan_ensure_initialized(); }
};
-TEST_F(TestRtsanContext, ExpectNotRealtimeDoesNotDieBeforeRealtimePush) {
+TEST_F(TestRtsanContext, IsNotRealtimeAfterDefaultConstruction) {
__rtsan::Context context{};
- ExpectNotRealtime(context, "do_some_stuff");
+ EXPECT_THAT(context.InRealtimeContext(), Eq(false));
}
-TEST_F(TestRtsanContext, ExpectNotRealtimeDoesNotDieAfterPushAndPop) {
+TEST_F(TestRtsanContext, IsRealtimeAfterRealtimePush) {
__rtsan::Context context{};
context.RealtimePush();
- context.RealtimePop();
- ExpectNotRealtime(context, "do_some_stuff");
+ EXPECT_THAT(context.InRealtimeContext(), Eq(true));
}
-TEST_F(TestRtsanContext, ExpectNotRealtimeDiesAfterRealtimePush) {
+TEST_F(TestRtsanContext, IsNotRealtimeAfterRealtimePushAndPop) {
__rtsan::Context context{};
-
context.RealtimePush();
- EXPECT_DEATH(ExpectNotRealtime(context, "do_some_stuff"), "");
+ ASSERT_THAT(context.InRealtimeContext(), Eq(true));
+ context.RealtimePop();
+ EXPECT_THAT(context.InRealtimeContext(), Eq(false));
}
-TEST_F(TestRtsanContext,
- ExpectNotRealtimeDiesAfterRealtimeAfterMorePushesThanPops) {
+TEST_F(TestRtsanContext, RealtimeContextStateIsStatefullyTracked) {
__rtsan::Context context{};
-
- context.RealtimePush();
- context.RealtimePush();
- context.RealtimePush();
- context.RealtimePop();
- context.RealtimePop();
- EXPECT_DEATH(ExpectNotRealtime(context, "do_some_stuff"), "");
+ auto const expect_rt = [&context](bool is_rt) {
+ EXPECT_THAT(context.InRealtimeContext(), Eq(is_rt));
+ };
+ expect_rt(false);
+ context.RealtimePush(); // depth 1
+ expect_rt(true);
+ context.RealtimePush(); // depth 2
+ expect_rt(true);
+ context.RealtimePop(); // depth 1
+ expect_rt(true);
+ context.RealtimePush(); // depth 2
+ expect_rt(true);
+ context.RealtimePop(); // depth 1
+ expect_rt(true);
+ context.RealtimePop(); // depth 0
+ expect_rt(false);
+ context.RealtimePush(); // depth 1
+ expect_rt(true);
}
-TEST_F(TestRtsanContext, ExpectNotRealtimeDoesNotDieAfterBypassPush) {
+TEST_F(TestRtsanContext, IsNotBypassedAfterDefaultConstruction) {
__rtsan::Context context{};
+ EXPECT_THAT(context.IsBypassed(), Eq(false));
+}
- context.RealtimePush();
+TEST_F(TestRtsanContext, IsBypassedAfterBypassPush) {
+ __rtsan::Context context{};
context.BypassPush();
- ExpectNotRealtime(context, "do_some_stuff");
+ EXPECT_THAT(context.IsBypassed(), Eq(true));
}
-TEST_F(TestRtsanContext,
- ExpectNotRealtimeDoesNotDieIfBypassDepthIsGreaterThanZero) {
+TEST_F(TestRtsanContext, BypassedStateIsStatefullyTracked) {
__rtsan::Context context{};
-
- context.RealtimePush();
- context.BypassPush();
- context.BypassPush();
- context.BypassPush();
- context.BypassPop();
- context.BypassPop();
- ExpectNotRealtime(context, "do_some_stuff");
- context.BypassPop();
- EXPECT_DEATH(ExpectNotRealtime(context, "do_some_stuff"), "");
+ auto const expect_bypassed = [&context](bool is_bypassed) {
+ EXPECT_THAT(context.IsBypassed(), Eq(is_bypassed));
+ };
+ expect_bypassed(false);
+ context.BypassPush(); // depth 1
+ expect_bypassed(true);
+ context.BypassPush(); // depth 2
+ expect_bypassed(true);
+ context.BypassPop(); // depth 1
+ expect_bypassed(true);
+ context.BypassPush(); // depth 2
+ expect_bypassed(true);
+ context.BypassPop(); // depth 1
+ expect_bypassed(true);
+ context.BypassPop(); // depth 0
+ expect_bypassed(false);
+ context.BypassPush(); // depth 1
+ expect_bypassed(true);
}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/5890 Here is the relevant piece of the build log for the reference
|
Disentangles (and simplifies) integration-like tests for
__rtsan::ExpectNotRealtime
and__rtsan::Context
into simpler unit tests. None of the tests are new, but their assertions have changed to reflect the more direct testing strategy.