Skip to content

Commit 47f254f

Browse files
yoneymeta-codesync[bot]
authored andcommitted
Fix stack-walk tests in OSS builds
Summary: Keep frame pointers enabled for the stack-walk tests. Reviewed By: DinoV Differential Revision: D116998702 fbshipit-source-id: d75c5f0c9d21d48ca4bf98d928e2abcdf541ffbb
1 parent 4794388 commit 47f254f

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ if (BUILD_RUNTIME_TESTS)
509509
# sem_init() fails with ENOSYS.
510510
if (WINDOWS OR MACOS)
511511
list(REMOVE_ITEM RUNTIME_TESTS_SOURCES ${PROJECT_SOURCE_DIR}/RuntimeTests/stack_walk_test.cpp)
512+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
513+
# These tests walk native frame-pointer chains in their own fixture code.
514+
set_source_files_properties(
515+
${PROJECT_SOURCE_DIR}/RuntimeTests/stack_walk_test.cpp
516+
PROPERTIES COMPILE_OPTIONS -fno-omit-frame-pointer
517+
)
512518
endif()
513519

514520
add_executable(RuntimeTests ${RUNTIME_TESTS_SOURCES})

cinderx/RuntimeTests/stack_walk_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ TEST(StackWalkThreadTest, WalkOfOwnThreadStateWalksSelfRatherThanFailing) {
622622

623623
TEST(StackWalkThreadTest, WalksAnotherThreadThroughItsThreadState) {
624624
StackWalk sw;
625-
SpinningThread other;
625+
SpinningThread other{1};
626626
PyThreadState tstate = fakeThreadState(other.id());
627627

628628
std::vector<FramePair> frames;
@@ -633,7 +633,6 @@ TEST(StackWalkThreadTest, WalksAnotherThreadThroughItsThreadState) {
633633
});
634634

635635
EXPECT_EQ(walked, WalkResult::Completed);
636-
// A parked thread sits several frames deep inside libstdc++ and libc.
637636
EXPECT_GT(frames.size(), 1u);
638637
}
639638

@@ -642,7 +641,7 @@ TEST(StackWalkThreadTest, WalksAnotherThreadThroughItsThreadState) {
642641
// directly. Only whatever the chain ends on is off-stack.
643642
TEST(StackWalkThreadTest, ACrossThreadWalkCostsAFewSafeReadsNotOnePerFrame) {
644643
StackWalk sw;
645-
SpinningThread other;
644+
SpinningThread other{8};
646645
PyThreadState tstate = fakeThreadState(other.id());
647646

648647
const uint64_t before = StackWalk::safeReadCount();
@@ -657,11 +656,11 @@ TEST(StackWalkThreadTest, ACrossThreadWalkCostsAFewSafeReadsNotOnePerFrame) {
657656
WalkResult::Completed);
658657
const uint64_t reads = StackWalk::safeReadCount() - before;
659658

660-
// A parked thread sits several frames deep inside libstdc++ and libc.
661-
ASSERT_GT(frames, 3u);
662659
EXPECT_LE(reads, 2u) << "walked " << frames << " frames but spent " << reads
663660
<< " safe reads; the target's stack bounds are not "
664661
"reaching the walk";
662+
EXPECT_GT(frames, 8u) << "the walk did not reach every recursive fixture "
663+
"frame";
665664
}
666665

667666
// Walking our own stack takes the same fast path, via currentStackBounds().
@@ -676,9 +675,10 @@ TEST(StackWalkThreadTest, WalkingOurOwnStackCostsAFewSafeReadsNotOnePerFrame) {
676675
WalkResult::Completed);
677676
const uint64_t reads = StackWalk::safeReadCount() - before;
678677

679-
ASSERT_GT(frames, 3u);
680678
EXPECT_LE(reads, 2u) << "walked " << frames << " frames but spent " << reads
681679
<< " safe reads";
680+
EXPECT_GT(frames, reads)
681+
<< "the walk did not find more frames than it read through the fallback";
682682
}
683683

684684
TEST(StackWalkThreadTest, CallbackReturningFalseStopsACrossThreadWalk) {

0 commit comments

Comments
 (0)