backtrace_ut.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <library/cpp/testing/gtest/gtest.h>
  2. #include <util/system/compiler.h>
  3. #include <util/system/backtrace.h>
  4. #include <util/stream/str.h>
  5. Y_FORCE_INLINE
  6. TString InlinedFunction_866a4407b28483588033f95add111d() {
  7. TStringStream out;
  8. FormatBackTrace(&out);
  9. return out.Str();
  10. }
  11. Y_NO_INLINE
  12. TString Function_3e15a2d04c8613ae64833c5407dd98() {
  13. return InlinedFunction_866a4407b28483588033f95add111d();
  14. }
  15. Y_NO_INLINE
  16. TString NotInlinedFunction_3c7dbf1e3b2b71819241cb5ad2b142() {
  17. return Function_3e15a2d04c8613ae64833c5407dd98();
  18. }
  19. namespace NTestNamespace {
  20. Y_NO_INLINE
  21. TString NamespacedFunction() {
  22. return InlinedFunction_866a4407b28483588033f95add111d();
  23. }
  24. }
  25. using namespace ::testing;
  26. TEST(dwarf_backtrace_should, handle_inlines) {
  27. const TString backtrace = NotInlinedFunction_3c7dbf1e3b2b71819241cb5ad2b142();
  28. EXPECT_THAT(
  29. backtrace,
  30. HasSubstr("InlinedFunction_866a4407b28483588033f95add111d")
  31. );
  32. EXPECT_THAT(
  33. backtrace,
  34. HasSubstr("backtrace_ut.cpp:9:0 in InlinedFunction")
  35. );
  36. EXPECT_THAT(
  37. backtrace,
  38. HasSubstr("Function_3e15a2d04c8613ae64833c5407dd98")
  39. );
  40. }
  41. TEST(dwarf_backtrace_should, handle_namespaces) {
  42. EXPECT_THAT(
  43. NTestNamespace::NamespacedFunction(),
  44. HasSubstr("NTestNamespace::NamespacedFunction")
  45. );
  46. }