/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
library/cpp/yt/backtrace/unittests/backtrace_ut.cpp
61 строка
2 KB
Anton Myagkov
Update ydb version to 24.4 (#4579)
07 фев 2026, 11:59
Не верифицирован
07 фев 2026, 11:59
2c21cae
Код
Авторство
О чём код?
#include <gtest/gtest.h> #include <gmock/gmock.h> #include <library/cpp/yt/memory/safe_memory_reader.h> #include <library/cpp/yt/backtrace/cursors/frame_pointer/frame_pointer_cursor.h> #include <library/cpp/yt/backtrace/cursors/interop/interop.h> #include <util/system/compiler.h> #include <contrib/libs/libunwind/include/libunwind.h> namespace NYT::NBacktrace { namespace { //////////////////////////////////////////////////////////////////////////////// template <int Depth, class TFn> Y_NO_INLINE void RunInDeepStack(TFn cb) { if constexpr (Depth == 0) { cb(); } else { std::vector<int> touchMem; touchMem.push_back(0); RunInDeepStack<Depth-1>(cb); DoNotOptimizeAway(touchMem); } } TEST(TFramePointerCursor, FramePointerCursor) { std::vector<const void*> backtrace; RunInDeepStack<64>([&] { unw_context_t unwContext; ASSERT_TRUE(unw_getcontext(&unwContext) == 0); unw_cursor_t unwCursor; ASSERT_TRUE(unw_init_local(&unwCursor, &unwContext) == 0); TSafeMemoryReader reader; auto fpCursorContext = NBacktrace::FramePointerCursorContextFromLibunwindCursor(unwCursor); NBacktrace::TFramePointerCursor fpCursor(&reader, fpCursorContext); while (!fpCursor.IsFinished()) { backtrace.push_back(fpCursor.GetCurrentIP()); fpCursor.MoveNext(); } }); ASSERT_THAT(backtrace, testing::SizeIs(testing::Ge(64u))); } //////////////////////////////////////////////////////////////////////////////// } // namespace } // namespace NYT::NBacktrace