Commit 96136783 by Abseil Team Committed by vslashg

- 60c1f40a5e0bc33f93392ff6827528072d749a29 Move ExceptionSafetyTester from the…

  - 60c1f40a5e0bc33f93392ff6827528072d749a29 Move ExceptionSafetyTester from the absl:: namespace to t... by Abseil Team <absl-team@google.com>
  - abd40a98f8ae746eb151e777ea8a8b5223d68a4b Splits the NoThrow flags into TypeSpec and AllocSpec flag... by Abseil Team <absl-team@google.com>
  - c16d0b5509b36679b384147b474135e7951afccf Change the abbreviation for the breakdowns of InfinitePas... by Abseil Team <absl-team@google.com>
  - 8ac104351764f23d666b52dce7536a34c05abf00 Use ABSL_CONST_INIT with std::atomic variables in static ... by Matt Armstrong <marmstrong@google.com>

GitOrigin-RevId: 60c1f40a5e0bc33f93392ff6827528072d749a29
Change-Id: I9d45a6ed30ed32ae57e9eff93f4205dbcd71feb2
parent 28f5b890
......@@ -17,7 +17,7 @@
#include "gtest/gtest.h"
#include "absl/meta/type_traits.h"
namespace absl {
namespace testing {
exceptions_internal::NoThrowTag no_throw_ctor;
exceptions_internal::StrongGuaranteeTagType strong_guarantee;
......@@ -37,5 +37,7 @@ testing::AssertionResult FailureMessage(const TestException& e,
int countdown) noexcept {
return testing::AssertionFailure() << "Exception thrown from " << e.what();
}
} // namespace exceptions_internal
} // namespace absl
} // namespace testing
......@@ -14,6 +14,7 @@
#include <cstdint>
#include <iostream>
#include "absl/base/attributes.h"
#include "absl/debugging/internal/address_is_readable.h"
#include "absl/debugging/internal/vdso_support.h" // a no-op on non-elf or non-glibc systems
#include "absl/debugging/stacktrace.h"
......@@ -24,7 +25,7 @@ static const uintptr_t kUnknownFrameSize = 0;
// Returns the address of the VDSO __kernel_rt_sigreturn function, if present.
static const unsigned char* GetKernelRtSigreturnAddress() {
constexpr uintptr_t kImpossibleAddress = 1;
static std::atomic<uintptr_t> memoized{kImpossibleAddress};
ABSL_CONST_INIT static std::atomic<uintptr_t> memoized{kImpossibleAddress};
uintptr_t address = memoized.load(std::memory_order_relaxed);
if (address != kImpossibleAddress) {
return reinterpret_cast<const unsigned char*>(address);
......
......@@ -41,6 +41,7 @@
#include <atomic>
#include "absl/base/attributes.h"
#include "absl/debugging/internal/elf_mem_image.h"
#ifdef ABSL_HAVE_ELF_MEM_IMAGE
......@@ -132,7 +133,7 @@ class VDSOSupport {
// This function pointer may point to InitAndGetCPU,
// GetCPUViaSyscall, or __vdso_getcpu at different stages of initialization.
static std::atomic<GetCpuFn> getcpu_fn_;
ABSL_CONST_INIT static std::atomic<GetCpuFn> getcpu_fn_;
friend int GetCPU(void); // Needs access to getcpu_fn_.
......
......@@ -51,6 +51,7 @@ cc_library(
cc_library(
name = "test_util",
testonly = 1,
srcs = [
"internal/test_util.cc",
"internal/zoneinfo.inc",
......@@ -64,6 +65,7 @@ cc_library(
":time",
"//absl/base",
"//absl/time/internal/cctz:time_zone",
"@com_google_googletest//:gtest",
],
)
......
......@@ -155,8 +155,7 @@ TEST(ParseTime, Basics) {
"2013-06-28 19:08:09 -0800", &t, &err))
<< err;
absl::Time::Breakdown bd = t.In(absl::FixedTimeZone(-8 * 60 * 60));
ABSL_INTERNAL_EXPECT_TIME(bd, 2013, 6, 28, 19, 8, 9, -8 * 60 * 60, false,
"UTC-8");
ABSL_INTERNAL_EXPECT_TIME(bd, 2013, 6, 28, 19, 8, 9, -8 * 60 * 60, false);
EXPECT_EQ(absl::ZeroDuration(), bd.subsecond);
}
......@@ -179,8 +178,7 @@ TEST(ParseTime, WithTimeZone) {
absl::ParseTime("%Y-%m-%d %H:%M:%S", "2013-06-28 19:08:09", tz, &t, &e))
<< e;
absl::Time::Breakdown bd = t.In(tz);
ABSL_INTERNAL_EXPECT_TIME(bd, 2013, 6, 28, 19, 8, 9, -7 * 60 * 60, true,
"PDT");
ABSL_INTERNAL_EXPECT_TIME(bd, 2013, 6, 28, 19, 8, 9, -7 * 60 * 60, true);
EXPECT_EQ(absl::ZeroDuration(), bd.subsecond);
// But the timezone is ignored when a UTC offset is present.
......@@ -188,8 +186,7 @@ TEST(ParseTime, WithTimeZone) {
"2013-06-28 19:08:09 +0800", tz, &t, &e))
<< e;
bd = t.In(absl::FixedTimeZone(8 * 60 * 60));
ABSL_INTERNAL_EXPECT_TIME(bd, 2013, 6, 28, 19, 8, 9, 8 * 60 * 60, false,
"UTC+8");
ABSL_INTERNAL_EXPECT_TIME(bd, 2013, 6, 28, 19, 8, 9, 8 * 60 * 60, false);
EXPECT_EQ(absl::ZeroDuration(), bd.subsecond);
}
......
......@@ -26,6 +26,13 @@ namespace cctz = absl::time_internal::cctz;
namespace absl {
namespace time_internal {
// TODO(bww): Reinstate when the FixedTimeZone() abbreviations are updated.
#if 1 || GTEST_USES_SIMPLE_RE
extern const char kZoneAbbrRE[] = ".*"; // just punt
#else
extern const char kZoneAbbrRE[] = "[A-Za-z]{3,4}|[-+][0-9]{2}([0-9]{2})?";
#endif
TimeZone LoadTimeZone(const std::string& name) {
TimeZone tz;
ABSL_RAW_CHECK(LoadTimeZone(name, &tz), name.c_str());
......
......@@ -17,6 +17,8 @@
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
// This helper is a macro so that failed expectations show up with the
......@@ -24,22 +26,26 @@
//
// This is for internal testing of the Base Time library itself. This is not
// part of a public API.
#define ABSL_INTERNAL_EXPECT_TIME(bd, y, m, d, h, min, s, off, isdst, zone) \
do { \
EXPECT_EQ(y, bd.year); \
EXPECT_EQ(m, bd.month); \
EXPECT_EQ(d, bd.day); \
EXPECT_EQ(h, bd.hour); \
EXPECT_EQ(min, bd.minute); \
EXPECT_EQ(s, bd.second); \
EXPECT_EQ(off, bd.offset); \
EXPECT_EQ(isdst, bd.is_dst); \
EXPECT_STREQ(zone, bd.zone_abbr); \
#define ABSL_INTERNAL_EXPECT_TIME(bd, y, m, d, h, min, s, off, isdst) \
do { \
EXPECT_EQ(y, bd.year); \
EXPECT_EQ(m, bd.month); \
EXPECT_EQ(d, bd.day); \
EXPECT_EQ(h, bd.hour); \
EXPECT_EQ(min, bd.minute); \
EXPECT_EQ(s, bd.second); \
EXPECT_EQ(off, bd.offset); \
EXPECT_EQ(isdst, bd.is_dst); \
EXPECT_THAT(bd.zone_abbr, \
testing::MatchesRegex(absl::time_internal::kZoneAbbrRE)); \
} while (0)
namespace absl {
namespace time_internal {
// A regular expression that matches all zone abbreviations (%Z).
extern const char kZoneAbbrRE[];
// Loads the named timezone, but dies on any failure.
absl::TimeZone LoadTimeZone(const std::string& name);
......
......@@ -71,7 +71,7 @@ inline absl::Time::Breakdown InfiniteFutureBreakdown() {
bd.yearday = 365;
bd.offset = 0;
bd.is_dst = false;
bd.zone_abbr = "-0000";
bd.zone_abbr = "-00";
return bd;
}
......@@ -88,7 +88,7 @@ inline Time::Breakdown InfinitePastBreakdown() {
bd.yearday = 1;
bd.offset = 0;
bd.is_dst = false;
bd.zone_abbr = "-0000";
bd.zone_abbr = "-00";
return bd;
}
......
......@@ -85,7 +85,7 @@ TEST(Time, ValueSemantics) {
TEST(Time, UnixEpoch) {
absl::Time::Breakdown bd = absl::UnixEpoch().In(absl::UTCTimeZone());
ABSL_INTERNAL_EXPECT_TIME(bd, 1970, 1, 1, 0, 0, 0, 0, false, "UTC");
ABSL_INTERNAL_EXPECT_TIME(bd, 1970, 1, 1, 0, 0, 0, 0, false);
EXPECT_EQ(absl::ZeroDuration(), bd.subsecond);
EXPECT_EQ(4, bd.weekday); // Thursday
}
......@@ -96,14 +96,14 @@ TEST(Time, Breakdown) {
// The Unix epoch as seen in NYC.
absl::Time::Breakdown bd = t.In(tz);
ABSL_INTERNAL_EXPECT_TIME(bd, 1969, 12, 31, 19, 0, 0, -18000, false, "EST");
ABSL_INTERNAL_EXPECT_TIME(bd, 1969, 12, 31, 19, 0, 0, -18000, false);
EXPECT_EQ(absl::ZeroDuration(), bd.subsecond);
EXPECT_EQ(3, bd.weekday); // Wednesday
// Just before the epoch.
t -= absl::Nanoseconds(1);
bd = t.In(tz);
ABSL_INTERNAL_EXPECT_TIME(bd, 1969, 12, 31, 18, 59, 59, -18000, false, "EST");
ABSL_INTERNAL_EXPECT_TIME(bd, 1969, 12, 31, 18, 59, 59, -18000, false);
EXPECT_EQ(absl::Nanoseconds(999999999), bd.subsecond);
EXPECT_EQ(3, bd.weekday); // Wednesday
......@@ -112,7 +112,7 @@ TEST(Time, Breakdown) {
t += absl::Hours(18) + absl::Minutes(30) + absl::Seconds(15) +
absl::Nanoseconds(9);
bd = t.In(tz);
ABSL_INTERNAL_EXPECT_TIME(bd, 1977, 6, 28, 14, 30, 15, -14400, true, "EDT");
ABSL_INTERNAL_EXPECT_TIME(bd, 1977, 6, 28, 14, 30, 15, -14400, true);
EXPECT_EQ(8, bd.subsecond / absl::Nanoseconds(1));
EXPECT_EQ(2, bd.weekday); // Tuesday
}
......@@ -983,16 +983,18 @@ TEST(Time, ConversionSaturation) {
// Checks how Time::In() saturates on infinities.
absl::Time::Breakdown bd = absl::InfiniteFuture().In(utc);
ABSL_INTERNAL_EXPECT_TIME(bd, std::numeric_limits<int64_t>::max(), 12, 31, 23,
59, 59, 0, false, "-0000");
59, 59, 0, false);
EXPECT_EQ(absl::InfiniteDuration(), bd.subsecond);
EXPECT_EQ(4, bd.weekday); // Thursday
EXPECT_EQ(365, bd.yearday);
EXPECT_STREQ("-00", bd.zone_abbr); // artifact of absl::Time::In()
bd = absl::InfinitePast().In(utc);
ABSL_INTERNAL_EXPECT_TIME(bd, std::numeric_limits<int64_t>::min(), 1, 1, 0, 0,
0, 0, false, "-0000");
0, 0, false);
EXPECT_EQ(-absl::InfiniteDuration(), bd.subsecond);
EXPECT_EQ(7, bd.weekday); // Sunday
EXPECT_EQ(1, bd.yearday);
EXPECT_STREQ("-00", bd.zone_abbr); // artifact of absl::Time::In()
// Approach the maximal Time value from below.
t = absl::FromDateTime(292277026596, 12, 4, 15, 30, 6, utc);
......@@ -1054,13 +1056,11 @@ TEST(Time, ExtendedConversionSaturation) {
// The maximal time converted in each zone.
bd = max.In(syd);
ABSL_INTERNAL_EXPECT_TIME(bd, 292277026596, 12, 5, 2, 30, 7, 39600, true,
"AEDT");
ABSL_INTERNAL_EXPECT_TIME(bd, 292277026596, 12, 5, 2, 30, 7, 39600, true);
t = absl::FromDateTime(292277026596, 12, 5, 2, 30, 7, syd);
EXPECT_EQ(max, t);
bd = max.In(nyc);
ABSL_INTERNAL_EXPECT_TIME(bd, 292277026596, 12, 4, 10, 30, 7, -18000, false,
"EST");
ABSL_INTERNAL_EXPECT_TIME(bd, 292277026596, 12, 4, 10, 30, 7, -18000, false);
t = absl::FromDateTime(292277026596, 12, 4, 10, 30, 7, nyc);
EXPECT_EQ(max, t);
......
......@@ -20,12 +20,12 @@
#include "gtest/gtest.h"
#include "absl/base/internal/exception_safety_testing.h"
using Thrower = absl::ThrowingValue<>;
using Thrower = testing::ThrowingValue<>;
using NoThrowMoveThrower =
absl::ThrowingValue<absl::NoThrow::kMoveCtor | absl::NoThrow::kMoveAssign>;
testing::ThrowingValue<testing::TypeSpec::kNoThrowMove>;
using ThrowerList = std::initializer_list<Thrower>;
using ThrowerVec = std::vector<Thrower>;
using ThrowingAlloc = absl::ThrowingAllocator<Thrower>;
using ThrowingAlloc = testing::ThrowingAllocator<Thrower>;
using ThrowingThrowerVec = std::vector<Thrower, ThrowingAlloc>;
namespace {
......@@ -81,30 +81,31 @@ testing::AssertionResult AnyIsEmpty(absl::any* a) {
TEST(AnyExceptionSafety, Ctors) {
Thrower val(1);
absl::TestThrowingCtor<absl::any>(val);
testing::TestThrowingCtor<absl::any>(val);
Thrower copy(val);
absl::TestThrowingCtor<absl::any>(copy);
testing::TestThrowingCtor<absl::any>(copy);
absl::TestThrowingCtor<absl::any>(absl::in_place_type_t<Thrower>(), 1);
testing::TestThrowingCtor<absl::any>(absl::in_place_type_t<Thrower>(), 1);
absl::TestThrowingCtor<absl::any>(absl::in_place_type_t<ThrowerVec>(),
ThrowerList{val});
testing::TestThrowingCtor<absl::any>(absl::in_place_type_t<ThrowerVec>(),
ThrowerList{val});
absl::TestThrowingCtor<absl::any, absl::in_place_type_t<ThrowingThrowerVec>,
ThrowerList, ThrowingAlloc>(
testing::TestThrowingCtor<absl::any,
absl::in_place_type_t<ThrowingThrowerVec>,
ThrowerList, ThrowingAlloc>(
absl::in_place_type_t<ThrowingThrowerVec>(), {val}, ThrowingAlloc());
}
TEST(AnyExceptionSafety, Assignment) {
auto original =
absl::any(absl::in_place_type_t<Thrower>(), 1, absl::no_throw_ctor);
absl::any(absl::in_place_type_t<Thrower>(), 1, testing::no_throw_ctor);
auto any_is_strong = [original](absl::any* ap) {
return testing::AssertionResult(ap->has_value() &&
absl::any_cast<Thrower>(original) ==
absl::any_cast<Thrower>(*ap));
};
auto any_strong_tester = absl::MakeExceptionSafetyTester()
auto any_strong_tester = testing::MakeExceptionSafetyTester()
.WithInitialValue(original)
.WithInvariants(AnyInvariants, any_is_strong);
......@@ -126,7 +127,7 @@ TEST(AnyExceptionSafety, Assignment) {
return testing::AssertionResult{!ap->has_value()};
};
auto strong_empty_any_tester =
absl::MakeExceptionSafetyTester()
testing::MakeExceptionSafetyTester()
.WithInitialValue(absl::any{})
.WithInvariants(AnyInvariants, empty_any_is_strong);
......@@ -138,14 +139,14 @@ TEST(AnyExceptionSafety, Assignment) {
#if !defined(ABSL_HAVE_STD_ANY)
TEST(AnyExceptionSafety, Emplace) {
auto initial_val =
absl::any{absl::in_place_type_t<Thrower>(), 1, absl::no_throw_ctor};
auto one_tester = absl::MakeExceptionSafetyTester()
absl::any{absl::in_place_type_t<Thrower>(), 1, testing::no_throw_ctor};
auto one_tester = testing::MakeExceptionSafetyTester()
.WithInitialValue(initial_val)
.WithInvariants(AnyInvariants, AnyIsEmpty);
auto emp_thrower = [](absl::any* ap) { ap->emplace<Thrower>(2); };
auto emp_throwervec = [](absl::any* ap) {
std::initializer_list<Thrower> il{Thrower(2, absl::no_throw_ctor)};
std::initializer_list<Thrower> il{Thrower(2, testing::no_throw_ctor)};
ap->emplace<ThrowerVec>(il);
};
auto emp_movethrower = [](absl::any* ap) {
......
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