[test] Trigger failures via USR1/USR2

USR1: abort the program
USR2: send buggy free event, to trigger an instrumentation failure
This commit is contained in:
Grégoire Roussel 2024-07-17 16:42:54 +02:00
parent 1458a6ab23
commit 82fd4075f9

View File

@ -1,4 +1,6 @@
#include <atomic>
#include <chrono> #include <chrono>
#include <csignal>
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -18,6 +20,19 @@ struct static_init_test_t
} }
}; };
static std::atomic<bool> s_triggerCrash{false};
static std::atomic<bool> 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; static const static_init_test_t static_init_test;
void* operator new( std::size_t count ) void* operator new( std::size_t count )
@ -301,6 +316,20 @@ void DeadlockTest2()
int main() 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 t1 = std::thread( TestFunction );
auto t2 = std::thread( TestFunction ); auto t2 = std::thread( TestFunction );
auto t3 = std::thread( ResolutionCheck ); auto t3 = std::thread( ResolutionCheck );
@ -338,6 +367,19 @@ int main()
std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) );
{ {
ZoneScoped; 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 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 2 ) );
} }
if(image != nullptr) if(image != nullptr)