From: Jim Meyering Date: Fri, 17 Nov 2017 04:52:38 +0000 (-0800) Subject: folly/fibers/test/FibersTest.cpp: accommodate ASAN's detect_stack_use_after_return=1 X-Git-Tag: v2017.11.20.00~6 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a447cb9ebc32100b18c0e3fc75bf5882db4857e3;p=folly.git folly/fibers/test/FibersTest.cpp: accommodate ASAN's detect_stack_use_after_return=1 Summary: With ASAN enabled (actually, only with ASAN *and* its detect_stack_use_after_return=1 option), the addTaskFinally test would fail. This adapts to accommodate the larger stack offsets. Also, use EXPECT_GT and EXPECT_LT rather than EXPECT_TRUE. Reviewed By: yfeldblum Differential Revision: D6353666 fbshipit-source-id: 39e04caffa7b24cde97c749686c7e651a071dcec --- diff --git a/folly/fibers/test/FibersTest.cpp b/folly/fibers/test/FibersTest.cpp index 1dad237a..e12a78a9 100644 --- a/folly/fibers/test/FibersTest.cpp +++ b/folly/fibers/test/FibersTest.cpp @@ -903,12 +903,18 @@ namespace { void expectMainContext(bool& ran, int* mainLocation, int* fiberLocation) { int here; /* 2 pages is a good guess */ - constexpr ssize_t DISTANCE = 0x2000 / sizeof(int); + constexpr auto const kHereToFiberMaxDist = 0x2000 / sizeof(int); + + // With ASAN's detect_stack_use_after_return=1, this must be much larger + // I measured 410028 on x86_64, so allow for quadruple that, just in case. + constexpr auto const kHereToMainMaxDist = + folly::kIsSanitizeAddress ? 4 * 410028 : kHereToFiberMaxDist; + if (fiberLocation) { - EXPECT_TRUE(std::abs(&here - fiberLocation) > DISTANCE); + EXPECT_GT(std::abs(&here - fiberLocation), kHereToFiberMaxDist); } if (mainLocation) { - EXPECT_TRUE(std::abs(&here - mainLocation) < DISTANCE); + EXPECT_LT(std::abs(&here - mainLocation), kHereToMainMaxDist); } EXPECT_FALSE(ran);