Commit bdcdbd4b authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[logging] Fix expected death message in official builds

The tests were failing in official release builds, because those drop
the fatal error message and always print "ignored" instead.

R=ecmziegler@chromium.org

Bug: v8:11251
Change-Id: I40512ca308337cf070ecb6a206dc4a5323d67415
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2595445Reviewed-by: 's avatarEmanuel Ziegler <ecmziegler@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71914}
parent d0ebe06b
......@@ -86,20 +86,30 @@ std::string SanitizeRegexp(std::string msg) {
}
std::string FailureMessage(const char* msg, const char* lhs, const char* rhs) {
std::string full_msg(msg);
#ifdef DEBUG
full_msg.append(" (").append(lhs).append(" vs. ").append(rhs);
return SanitizeRegexp(
std::string{msg}.append(" (").append(lhs).append(" vs. ").append(rhs));
#elif defined(OFFICIAL_BUILD)
// Official release builds strip all fatal messages for saving binary size,
// see src/base/logging.h.
USE(SanitizeRegexp);
return "ignored";
#else
return SanitizeRegexp(msg);
#endif
return SanitizeRegexp(std::move(full_msg));
}
std::string LongFailureMessage(const char* msg, const char* lhs,
const char* rhs) {
std::string full_msg(msg);
#ifdef DEBUG
full_msg.append("\n ").append(lhs).append("\n vs.\n ").append(rhs);
return SanitizeRegexp(std::string{msg}
.append("\n ")
.append(lhs)
.append("\n vs.\n ")
.append(rhs));
#else
return FailureMessage(msg, lhs, rhs);
#endif
return SanitizeRegexp(std::move(full_msg));
}
} // namespace
......
......@@ -74,27 +74,36 @@ TEST_P(RandomNumberGeneratorTest, NextDoubleReturnsValueBetween0And1) {
}
}
#if GTEST_HAS_DEATH_TEST
#if !defined(DEBUG) && defined(OFFICIAL_BUILD)
// Official release builds strip all fatal messages for saving binary size,
// see src/base/logging.h.
#define FATAL_MSG(msg) "ignored"
#else
#define FATAL_MSG(msg) "Check failed: " msg
#endif
TEST(RandomNumberGenerator, NextSampleInvalidParam) {
RandomNumberGenerator rng(123);
std::vector<uint64_t> sample;
EXPECT_DEATH(sample = rng.NextSample(10, 11), ".*Check failed: n <= max.*");
ASSERT_DEATH_IF_SUPPORTED(sample = rng.NextSample(10, 11),
FATAL_MSG("n <= max"));
}
TEST(RandomNumberGenerator, NextSampleSlowInvalidParam1) {
RandomNumberGenerator rng(123);
std::vector<uint64_t> sample;
EXPECT_DEATH(sample = rng.NextSampleSlow(10, 11),
".*Check failed: max - excluded.size*");
ASSERT_DEATH_IF_SUPPORTED(sample = rng.NextSampleSlow(10, 11),
FATAL_MSG("max - excluded.size"));
}
TEST(RandomNumberGenerator, NextSampleSlowInvalidParam2) {
RandomNumberGenerator rng(123);
std::vector<uint64_t> sample;
EXPECT_DEATH(sample = rng.NextSampleSlow(5, 3, {0, 2, 3}),
".*Check failed: max - excluded.size*");
ASSERT_DEATH_IF_SUPPORTED(sample = rng.NextSampleSlow(5, 3, {0, 2, 3}),
FATAL_MSG("max - excluded.size"));
}
#endif
#undef FATAL_MSG
TEST_P(RandomNumberGeneratorTest, NextSample0) {
size_t m = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment