memgraph/tests/manual/antlr_sigsegv.cpp
antonio2368 28413fd626 Change log library to spdlog, expose log levels to user (#72)
* Change from glog to spdlog

* Remove HA tests

* Remove logrotate log configuration

* Define custom main for unit gtests
2021-01-21 16:30:55 +01:00

106 lines
4.9 KiB
C++

#include <atomic>
#include <chrono>
#include <thread>
#include <vector>
#include <gtest/gtest.h>
#include "query/frontend/opencypher/parser.hpp"
#include "utils/signals.hpp"
#include "utils/stacktrace.hpp"
using namespace std::chrono_literals;
TEST(Antlr, Sigsegv) {
// start clients
int N = 8;
std::vector<std::thread> threads;
std::atomic<bool> run{false};
for (int i = 0; i < N; ++i) {
threads.push_back(std::thread([&run]() {
while (!run)
;
while (run) {
query::frontend::opencypher::Parser parser(
"CREATE (:Label_T7 {x: 903}) CREATE (:Label_T7 {x: 720}) CREATE "
"(:Label_T7 {x: 13}) CREATE (:Label_T7 {x: 643}) CREATE (:Label_T7 "
"{x: 245}) CREATE (:Label_T7 {x: 441}) CREATE (:Label_T7 {x: 47}) "
"CREATE (:Label_T7 {x: 583}) CREATE (:Label_T7 {x: 262}) CREATE "
"(:Label_T7 {x: 472}) CREATE (:Label_T7 {x: 443}) CREATE "
"(:Label_T7 {x: 955}) CREATE (:Label_T7 {x: 197}) CREATE "
"(:Label_T7 {x: 524}) CREATE (:Label_T7 {x: 416}) CREATE "
"(:Label_T7 {x: 403}) CREATE (:Label_T7 {x: 100}) CREATE "
"(:Label_T7 {x: 524}) CREATE (:Label_T7 {x: 702}) CREATE "
"(:Label_T7 {x: 586}) CREATE (:Label_T7 {x: 459}) CREATE "
"(:Label_T7 {x: 844}) CREATE (:Label_T7 {x: 959}) CREATE "
"(:Label_T7 {x: 81}) CREATE (:Label_T7 {x: 423}) CREATE (:Label_T7 "
"{x: 553}) CREATE (:Label_T7 {x: 987}) CREATE (:Label_T7 {x: 579}) "
"CREATE (:Label_T7 {x: 980}) CREATE (:Label_T7 {x: 869}) CREATE "
"(:Label_T7 {x: 86}) CREATE (:Label_T7 {x: 521}) CREATE (:Label_T7 "
"{x: 171}) CREATE (:Label_T7 {x: 161}) CREATE (:Label_T7 {x: 260}) "
"CREATE (:Label_T7 {x: 857}) CREATE (:Label_T7 {x: 34}) CREATE "
"(:Label_T7 {x: 969}) CREATE (:Label_T7 {x: 948}) CREATE "
"(:Label_T7 {x: 519}) CREATE (:Label_T7 {x: 333}) CREATE "
"(:Label_T7 {x: 733}) CREATE (:Label_T7 {x: 870}) CREATE "
"(:Label_T7 {x: 129}) CREATE (:Label_T7 {x: 77}) CREATE (:Label_T7 "
"{x: 54}) CREATE (:Label_T7 {x: 109}) CREATE (:Label_T7 {x: 908}) "
"CREATE (:Label_T7 {x: 560}) CREATE (:Label_T7 {x: 928}) CREATE "
"(:Label_T7 {x: 934}) CREATE (:Label_T7 {x: 475}) CREATE "
"(:Label_T7 {x: 619}) CREATE (:Label_T7 {x: 787}) CREATE "
"(:Label_T7 {x: 739}) CREATE (:Label_T7 {x: 622}) CREATE "
"(:Label_T7 {x: 588}) CREATE (:Label_T7 {x: 917}) CREATE "
"(:Label_T7 {x: 45}) CREATE (:Label_T7 {x: 696}) CREATE (:Label_T7 "
"{x: 998}) CREATE (:Label_T7 {x: 232}) CREATE (:Label_T7 {x: 600}) "
"CREATE (:Label_T7 {x: 763}) CREATE (:Label_T7 {x: 511}) CREATE "
"(:Label_T7 {x: 501}) CREATE (:Label_T7 {x: 555}) CREATE "
"(:Label_T7 {x: 491}) CREATE (:Label_T7 {x: 896}) CREATE "
"(:Label_T7 {x: 95}) CREATE (:Label_T7 {x: 361}) CREATE (:Label_T7 "
"{x: 132}) CREATE (:Label_T7 {x: 637}) CREATE (:Label_T7 {x: 427}) "
"CREATE (:Label_T7 {x: 37}) CREATE (:Label_T7 {x: 78}) CREATE "
"(:Label_T7 {x: 405}) CREATE (:Label_T7 {x: 821}) CREATE "
"(:Label_T7 {x: 186}) CREATE (:Label_T7 {x: 66}) CREATE (:Label_T7 "
"{x: 450}) CREATE (:Label_T7 {x: 709}) CREATE (:Label_T7 {x: 424}) "
"CREATE (:Label_T7 {x: 698}) CREATE (:Label_T7 {x: 42}) CREATE "
"(:Label_T7 {x: 629}) CREATE (:Label_T7 {x: 121}) CREATE "
"(:Label_T7 {x: 891}) CREATE (:Label_T7 {x: 823}) CREATE "
"(:Label_T7 {x: 337}) CREATE (:Label_T7 {x: 139}) CREATE "
"(:Label_T7 {x: 704}) CREATE (:Label_T7 {x: 141}) CREATE "
"(:Label_T7 {x: 438}) CREATE (:Label_T7 {x: 793}) CREATE "
"(:Label_T7 {x: 42}) CREATE (:Label_T7 {x: 142}) CREATE (:Label_T7 "
"{x: 526}) CREATE (:Label_T7 {x: 732}) CREATE (:Label_T7 {x: "
"336})");
parser.tree();
}
}));
}
run = true;
std::this_thread::sleep_for(10ms);
run = false;
// cleanup threads
for (int i = 0; i < N; ++i) threads[i].join();
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
// Signal handling init.
utils::SignalHandler::RegisterHandler(utils::Signal::SegmentationFault, []() {
// Log that we got SIGSEGV and abort the program, because returning from
// SIGSEGV handler is undefined behaviour.
std::cerr << "SegmentationFault signal raised" << std::endl;
std::abort(); // This will continue into our SIGABRT handler.
});
utils::SignalHandler::RegisterHandler(utils::Signal::Abort, []() {
// Log the stacktrace and let the abort continue.
utils::Stacktrace stacktrace;
std::cerr << "Abort signal raised" << std::endl
<< stacktrace.dump() << std::endl;
});
return RUN_ALL_TESTS();
}