mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-12 10:23:50 +01:00
removed comments. improved death test
This commit is contained in:
parent
671fd01aa1
commit
a068575595
@ -114,22 +114,24 @@ namespace
|
||||
f2.wait();
|
||||
}
|
||||
|
||||
void AccessViolation_x10000() {
|
||||
|
||||
using deathfunc = void (*) (void);
|
||||
void Death_x10000(deathfunc func, std::string funcname) {
|
||||
LOG(DEBUG) << " trigger exit";
|
||||
std::vector<std::future<void>> asyncs;
|
||||
asyncs.reserve(1000);
|
||||
for (auto idx = 0; idx < 1000; ++idx) {
|
||||
asyncs.push_back(std::async(std::launch::async, &AccessViolation));
|
||||
asyncs.reserve(10000);
|
||||
for (auto idx = 0; idx < 10000; ++idx) {
|
||||
asyncs.push_back(std::async(std::launch::async, func));
|
||||
}
|
||||
|
||||
for (const auto& a: asyncs) {
|
||||
for (const auto& a : asyncs) {
|
||||
a.wait();
|
||||
}
|
||||
|
||||
std::cout << __FUNCTION__ << " unexpected result. AccessViolation x many did not crash and exit the system" << std::endl;
|
||||
|
||||
std::cout << __FUNCTION__ << " unexpected result. Death by " << funcname << " did not crash and exit the system" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Throw() {
|
||||
LOG(DEBUG) << " trigger exit";
|
||||
std::future<int> empty;
|
||||
@ -138,6 +140,15 @@ namespace
|
||||
// example of std::exceptions can be found here: http://en.cppreference.com/w/cpp/error/exception
|
||||
}
|
||||
|
||||
|
||||
void SegFaultAttempt_x10000() {
|
||||
Death_x10000(&Throw, "throw uncaught exception");
|
||||
}
|
||||
|
||||
void AccessViolation_x10000() {
|
||||
Death_x10000(&AccessViolation, "AccessViolation");
|
||||
}
|
||||
|
||||
void FailedCHECK() {
|
||||
LOG(DEBUG) << " trigger exit";
|
||||
CHECK(false) << "This is fatal";
|
||||
@ -171,6 +182,7 @@ namespace
|
||||
case 11: exitFunction = &Throw; break;
|
||||
case 12: exitFunction = &FailedCHECK; break;
|
||||
case 13: exitFunction = &AccessViolation_x10000; break;
|
||||
case 14: exitFunction = &SegFaultAttempt_x10000; break;
|
||||
default: break;
|
||||
}
|
||||
if (runInNewThread) {
|
||||
@ -228,15 +240,15 @@ namespace
|
||||
std::cout << "[10] Rasing SIGABRT + Access Violation in two separate threads" << std::endl;
|
||||
std::cout << "[11] Throw a std::future_error" << std::endl;
|
||||
std::cout << "[12] Just CHECK(false) (in this thread)" << std::endl;
|
||||
std::cout << "[13] 1000 Continious crashes with out of counds array indexing" << std::endl;
|
||||
|
||||
std::cout << "[13] 10,000 Continious crashes with out of bounds array indexing" << std::endl;
|
||||
std::cout << "[14] 10,000 Continious crashes with segmentation fault attempts" << std::endl;
|
||||
|
||||
std::cout << std::flush;
|
||||
|
||||
try {
|
||||
std::getline(std::cin, option);
|
||||
choice = std::stoi(option);
|
||||
if (choice <= 0 || choice > 13) {
|
||||
if (choice <= 0 || choice > 14) {
|
||||
std::cout << "Invalid choice: [" << option << "\n\n";
|
||||
} else {
|
||||
return choice;
|
||||
@ -260,7 +272,7 @@ namespace
|
||||
|
||||
void breakHere() {
|
||||
std::ostringstream oss;
|
||||
oss << "Fatal hook function: " << __FUNCTION__ << ":" << __LINE__ " was called";
|
||||
oss << "Fatal hook function: " << __FUNCTION__ << ":" << __LINE__ << " was called";
|
||||
oss << " through g3::setFatalPreLoggingHook(). setFatalPreLoggingHook should be called AFTER g3::initializeLogging()" << std::endl;
|
||||
LOG(DEBUG) << oss.str();
|
||||
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
|
||||
|
@ -63,22 +63,6 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Kjell
|
||||
// Does this make a difference?
|
||||
// http://man7.org/linux/man-pages/man2/sigaltstack.2.html
|
||||
stack_t ss;
|
||||
ss.ss_sp = malloc(SIGSTKSZ);
|
||||
if (ss.ss_sp == NULL) {
|
||||
// Handle error -- no error handling at this moment
|
||||
}
|
||||
ss.ss_size = SIGSTKSZ;
|
||||
ss.ss_flags = 0;
|
||||
if (sigaltstack(&ss, NULL) == -1) {
|
||||
std::cerr << "\n\n\n\n\nFAILED\n\n\n\n\n" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
using namespace g3::internal;
|
||||
{
|
||||
const auto dump = stackdump();
|
||||
@ -227,15 +211,11 @@ namespace g3 {
|
||||
restoreSignalHandler(signal_number);
|
||||
std::cerr << "\n\n" << __FUNCTION__ << ":" << __LINE__ << ". Exiting due to " << level.text << ", " << signal_number << " \n\n" << std::flush;
|
||||
|
||||
TODO kjell ---
|
||||
what is the difference between kill and exit?
|
||||
does it have any significance for stack trace
|
||||
exit(signal_number); //kill(getpid(), signal_number);
|
||||
|
||||
}
|
||||
} // end g3::internal
|
||||
|
||||
|
||||
//
|
||||
// Installs FATAL signal handler that is enough to handle most fatal events
|
||||
// on *NIX systems
|
||||
|
Loading…
Reference in New Issue
Block a user