ce29517998
Summary: Utils source files are now moved to a standalone mg-utils library. Unit and manual tests are no longer collected using glob recursion in cmake, but are explicitly listed. This allows us to set only required dependencies of those tests. Both of these changes should improve compilation and link times, as well as lower the disk usage. Additional improvement would be to cleanup utils header files to be split in .hpp and .cpp as well as merging threading into utils. Other potential library extractions that shouldn't be difficult are: * data_structures * io/network * communication Reviewers: buda, mferencevic, dgleich, ipaljak, mculinovic, mtomic, msantl Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1408
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#include "gtest/gtest.h"
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <utility>
|
|
|
|
#include "utils/signals.hpp"
|
|
#include "utils/stacktrace.hpp"
|
|
|
|
/**
|
|
* NOTE: The signals used in these tests must be unique because signal handlers
|
|
* installed in one test are preserved during the other tests and you might not
|
|
* get desired results.
|
|
*/
|
|
|
|
TEST(Signals, Handler) {
|
|
ASSERT_TRUE(utils::SignalHandler::RegisterHandler(
|
|
utils::Signal::SegmentationFault, []() {
|
|
std::cout << "Segmentation Fault" << std::endl;
|
|
utils::Stacktrace stacktrace;
|
|
std::cout << stacktrace.dump() << std::endl;
|
|
}));
|
|
|
|
std::raise(SIGSEGV);
|
|
}
|
|
|
|
TEST(Signals, Ignore) {
|
|
ASSERT_TRUE(utils::SignalIgnore(utils::Signal::Pipe));
|
|
std::raise(SIGPIPE);
|
|
}
|
|
|
|
/** In this test the signal is ignored from the main process and a signal is
|
|
* raised in a thread. We want to check that the signal really is ignored
|
|
* globally.
|
|
*/
|
|
TEST(SignalsMultithreaded, Ignore) {
|
|
ASSERT_TRUE(utils::SignalIgnore(utils::Signal::BusError));
|
|
std::thread thread([] { std::raise(SIGBUS); });
|
|
thread.join();
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|