From 82fd4075f9951979e863d194134de45cd026f1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Roussel?= Date: Wed, 17 Jul 2024 16:42:54 +0200 Subject: [PATCH] [test] Trigger failures via USR1/USR2 USR1: abort the program USR2: send buggy free event, to trigger an instrumentation failure --- test/test.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/test.cpp b/test/test.cpp index fe678b53..60279dc1 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,4 +1,6 @@ +#include #include +#include #include #include #include @@ -18,6 +20,19 @@ struct static_init_test_t } }; +static std::atomic s_triggerCrash{false}; +static std::atomic s_triggerInstrumentationFailure{false}; + +void SignalHandler_TriggerCrash(int) +{ + s_triggerCrash.store(true, std::memory_order_relaxed); +} + +void SignalHandler_TriggerInstrumentationFailure(int) +{ + s_triggerInstrumentationFailure.store(true, std::memory_order_relaxed); +} + static const static_init_test_t static_init_test; void* operator new( std::size_t count ) @@ -301,6 +316,20 @@ void DeadlockTest2() int main() { +#ifdef _WIN32 + signal( SIGUSR1, SignalHandler_TriggerCrash ); + signal( SIGUSR2, SignalHandler_TriggerInstrumentationFailure ); +#else + struct sigaction sigusr1, oldsigusr1,sigusr2, oldsigusr2 ; + memset( &sigusr1, 0, sizeof( sigusr1 ) ); + sigusr1.sa_handler = SignalHandler_TriggerCrash; + sigaction( SIGUSR1, &sigusr1, &oldsigusr1 ); + + memset( &sigusr2, 0, sizeof( sigusr2 ) ); + sigusr2.sa_handler = SignalHandler_TriggerInstrumentationFailure; + sigaction( SIGUSR2, &sigusr2, &oldsigusr2 ); +#endif + auto t1 = std::thread( TestFunction ); auto t2 = std::thread( TestFunction ); auto t3 = std::thread( ResolutionCheck ); @@ -338,6 +367,19 @@ int main() std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) ); { ZoneScoped; + if(s_triggerCrash.load(std::memory_order_relaxed)) + { + std::cout << "Abort requested" << std::endl; + std::abort(); + } + if (s_triggerInstrumentationFailure.load(std::memory_order_relaxed)) + { + std::cout << "Triggering instrumentation failure" << std::endl; + char const* randomPtr = "Hello!"; + TracyFree(randomPtr); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + return 2; + } std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) ); } if(image != nullptr)