mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 06:46:33 +00:00
[rtsan] Add statistics for suppression count (#112718)
This commit is contained in:
parent
6d7712a70c
commit
8f8d5f005a
@ -15,6 +15,7 @@
|
||||
#include "rtsan/rtsan.h"
|
||||
#include "rtsan/rtsan_context.h"
|
||||
#include "rtsan/rtsan_diagnostics.h"
|
||||
#include "rtsan/rtsan_stats.h"
|
||||
#include "rtsan/rtsan_suppressions.h"
|
||||
|
||||
#include "sanitizer_common/sanitizer_stacktrace.h"
|
||||
@ -28,8 +29,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
|
||||
if (context.InRealtimeContext() && !context.IsBypassed()) {
|
||||
ScopedBypass sb{context};
|
||||
|
||||
if (IsFunctionSuppressed(info.func_name))
|
||||
if (IsFunctionSuppressed(info.func_name)) {
|
||||
IncrementSuppressedCount();
|
||||
return;
|
||||
}
|
||||
|
||||
__sanitizer::BufferedStackTrace stack;
|
||||
|
||||
@ -38,8 +41,10 @@ void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
|
||||
stack.Unwind(info.pc, info.bp, nullptr,
|
||||
__sanitizer::common_flags()->fast_unwind_on_fatal);
|
||||
|
||||
if (IsStackTraceSuppressed(stack))
|
||||
if (IsStackTraceSuppressed(stack)) {
|
||||
IncrementSuppressedCount();
|
||||
return;
|
||||
}
|
||||
|
||||
OnViolation(stack, info);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ struct Flags {
|
||||
Type Name{DefaultValue};
|
||||
#include "rtsan_flags.inc"
|
||||
#undef RTSAN_FLAG
|
||||
|
||||
bool ContainsSuppresionFile() { return suppressions[0] != '\0'; }
|
||||
};
|
||||
|
||||
extern Flags flags_data;
|
||||
|
@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "rtsan/rtsan_stats.h"
|
||||
#include "rtsan/rtsan_flags.h"
|
||||
|
||||
#include "sanitizer_common/sanitizer_atomic.h"
|
||||
#include "sanitizer_common/sanitizer_common.h"
|
||||
@ -20,6 +21,7 @@ using namespace __rtsan;
|
||||
|
||||
static atomic_uint32_t rtsan_total_error_count{0};
|
||||
static atomic_uint32_t rtsan_unique_error_count{0};
|
||||
static atomic_uint32_t rtsan_suppressed_count{0};
|
||||
|
||||
void __rtsan::IncrementTotalErrorCount() {
|
||||
atomic_fetch_add(&rtsan_total_error_count, 1, memory_order_relaxed);
|
||||
@ -37,9 +39,20 @@ static u32 GetUniqueErrorCount() {
|
||||
return atomic_load(&rtsan_unique_error_count, memory_order_relaxed);
|
||||
}
|
||||
|
||||
void __rtsan::IncrementSuppressedCount() {
|
||||
atomic_fetch_add(&rtsan_suppressed_count, 1, memory_order_relaxed);
|
||||
}
|
||||
|
||||
static u32 GetSuppressedCount() {
|
||||
return atomic_load(&rtsan_suppressed_count, memory_order_relaxed);
|
||||
}
|
||||
|
||||
void __rtsan::PrintStatisticsSummary() {
|
||||
ScopedErrorReportLock l;
|
||||
Printf("RealtimeSanitizer exit stats:\n");
|
||||
Printf(" Total error count: %u\n", GetTotalErrorCount());
|
||||
Printf(" Unique error count: %u\n", GetUniqueErrorCount());
|
||||
|
||||
if (flags().ContainsSuppresionFile())
|
||||
Printf(" Suppression count: %u\n", GetSuppressedCount());
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ namespace __rtsan {
|
||||
|
||||
void IncrementTotalErrorCount();
|
||||
void IncrementUniqueErrorCount();
|
||||
void IncrementSuppressedCount();
|
||||
|
||||
void PrintStatisticsSummary();
|
||||
|
||||
|
@ -56,7 +56,7 @@ void __rtsan::InitializeSuppressions() {
|
||||
CHECK_EQ(nullptr, suppression_ctx);
|
||||
|
||||
// We will use suppression_ctx == nullptr as an early out
|
||||
if (flags().suppressions[0] == '\0')
|
||||
if (!flags().ContainsSuppresionFile())
|
||||
return;
|
||||
|
||||
suppression_ctx = new (suppression_placeholder)
|
||||
|
@ -1,6 +1,7 @@
|
||||
// RUN: %clangxx -fsanitize=realtime %s -o %t
|
||||
// RUN: %env_rtsan_opts="halt_on_error=false,print_stats_on_exit=true" %run %t 2>&1 | FileCheck %s
|
||||
// RUN: %env_rtsan_opts="halt_on_error=true,print_stats_on_exit=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HALT
|
||||
// RUN: %env_rtsan_opts="suppressions=%s.supp,print_stats_on_exit=true" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPPRESSIONS
|
||||
|
||||
// UNSUPPORTED: ios
|
||||
|
||||
@ -23,7 +24,17 @@ int main() {
|
||||
// CHECK: RealtimeSanitizer exit stats:
|
||||
// CHECK-NEXT: Total error count: 10
|
||||
// CHECK-NEXT: Unique error count: 1
|
||||
// CHECK-NOT: Suppression count
|
||||
|
||||
// CHECK-HALT: RealtimeSanitizer exit stats:
|
||||
// CHECK-HALT-NEXT: Total error count: 1
|
||||
// CHECK-HALT-NEXT: Unique error count: 1
|
||||
// CHECK-HALT-NOT: Suppression count
|
||||
|
||||
// We pass in intentionally_non_existant_function in the suppressions file
|
||||
// This is just to ensure we only get the "Suppression count" metric if this
|
||||
// file is passed at runtime, otherwise that statistic is omitted
|
||||
// CHECK-SUPPRESSIONS: RealtimeSanitizer exit stats:
|
||||
// CHECK-SUPPRESSIONS-NEXT: Total error count: 1
|
||||
// CHECK-SUPPRESSIONS-NEXT: Unique error count: 1
|
||||
// CHECK-SUPPRESSIONS-NEXT: Suppression count: 0
|
||||
|
1
compiler-rt/test/rtsan/exit_stats.cpp.supp
Normal file
1
compiler-rt/test/rtsan/exit_stats.cpp.supp
Normal file
@ -0,0 +1 @@
|
||||
function-name-matches:intentionally_non_existant_function
|
@ -1,6 +1,6 @@
|
||||
// RUN: %clangxx -fsanitize=realtime %s -o %t
|
||||
// RUN: %env_rtsan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPPRESSIONS
|
||||
// RUN: %env_rtsan_opts=suppressions='%s.supp' not %run %t 2>&1 | FileCheck %s
|
||||
// RUN: %env_rtsan_opts=suppressions='%s.supp':print_stats_on_exit=true not %run %t 2>&1 | FileCheck %s
|
||||
// UNSUPPORTED: ios
|
||||
|
||||
// Intent: Ensure that suppressions work as intended
|
||||
@ -61,6 +61,9 @@ int main() {
|
||||
// CHECK-NOT: free
|
||||
// CHECK-NOT: BlockFunc
|
||||
|
||||
// CHECK: RealtimeSanitizer exit stats:
|
||||
// CHECK: Suppression count: 7
|
||||
|
||||
// CHECK-NOSUPPRESSIONS: malloc
|
||||
// CHECK-NOSUPPRESSIONS: vector
|
||||
// CHECK-NOSUPPRESSIONS: free
|
||||
|
Loading…
x
Reference in New Issue
Block a user