Skip to content

Commit

Permalink
Merge pull request #833 from Arpafaucon/trigger-failures-in-test
Browse files Browse the repository at this point in the history
[test] Trigger failures via USR1/USR2
  • Loading branch information
wolfpld authored Jul 17, 2024
2 parents a636950 + 7a74d38 commit 5634c15
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <atomic>
#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>
#include <signal.h>
#include <stdlib.h>
#include "tracy/Tracy.hpp"

Expand All @@ -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;

void* operator new( std::size_t count )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5634c15

Please sign in to comment.