test_main.cpp 942 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
  3. */
  4. #include <gtest/gtest.h>
  5. #include <uavcan/build_config.hpp>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <execinfo.h>
  9. #include <signal.h>
  10. #include <unistd.h>
  11. static void sigsegv_handler(int sig)
  12. {
  13. const int BacktraceSize = 32;
  14. void* array[BacktraceSize];
  15. const int size = backtrace(array, BacktraceSize);
  16. std::fprintf(stderr, "SIGNAL %d RECEIVED; STACKTRACE:\n", sig);
  17. backtrace_symbols_fd(array, size, STDERR_FILENO);
  18. std::exit(1);
  19. }
  20. int main(int argc, char **argv)
  21. {
  22. signal(SIGSEGV, sigsegv_handler);
  23. #ifndef UAVCAN_CPP_VERSION
  24. # error UAVCAN_CPP_VERSION
  25. #endif
  26. #if UAVCAN_CPP_VERSION == UAVCAN_CPP11
  27. std::cout << "C++11" << std::endl;
  28. #elif UAVCAN_CPP_VERSION == UAVCAN_CPP03
  29. std::cout << "C++03" << std::endl;
  30. #else
  31. # error UAVCAN_CPP_VERSION
  32. #endif
  33. ::testing::InitGoogleTest(&argc, argv);
  34. return RUN_ALL_TESTS();
  35. }