[compiler-rt] [rtsan] Decouple assertions from error actions (PR #109535)

Chris Apple via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 09:51:04 PDT 2024


================
@@ -24,30 +23,33 @@ class TestRtsanAssertions : public ::testing::Test {
   void SetUp() override { __rtsan_ensure_initialized(); }
 };
 
-DiagnosticsInfo FakeDiagnosticsInfo() {
-  DiagnosticsInfo info;
-  info.pc = 0;
-  info.bp = 0;
-  info.call_info = InterceptedCallInfo{"fake_function_name"};
-  return info;
+static void testExpectNotRealtime(__rtsan::Context &context,
+                                  bool expect_violation_callback) {
+  ::testing::MockFunction<void()> mock_on_violation;
+  EXPECT_CALL(mock_on_violation, Call).Times(expect_violation_callback ? 1 : 0);
+  ExpectNotRealtime(context, mock_on_violation.AsStdFunction());
 }
 
-TEST_F(TestRtsanAssertions, ExpectNotRealtimeDoesNotDieIfNotInRealtimeContext) {
+TEST_F(TestRtsanAssertions,
+       ExpectNotRealtimeDoesNotCallViolationActionIfNotInRealtimeContext) {
   __rtsan::Context context{};
   ASSERT_FALSE(context.InRealtimeContext());
-  ExpectNotRealtime(context, FakeDiagnosticsInfo());
+  testExpectNotRealtime(context, false);
----------------
cjappl wrote:

This name could be improved, hard to reason about what it is doing.

perhaps:

```
expectRealtime(context, true)
```

has less double negatives. also `test` and `expect` is unnecessary duplication, would rather have "assertion style" leading with `expect` or `assert`

https://github.com/llvm/llvm-project/pull/109535


More information about the llvm-commits mailing list