]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/atomic/test/api_test_helpers.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / atomic / test / api_test_helpers.hpp
index 32e788d243957dbf05d4061f50ce5cfeacff24c1..dc4d60948be2a1d7540bdc20c6b6af91d8e2f718 100644 (file)
@@ -1,5 +1,5 @@
 //  Copyright (c) 2011 Helge Bahmann
-//  Copyright (c) 2017 - 2020 Andrey Semashev
+//  Copyright (c) 2017 - 2021 Andrey Semashev
 //
 //  Distributed under the Boost Software License, Version 1.0.
 //  See accompanying file LICENSE_1_0.txt or copy at
@@ -114,6 +114,14 @@ void test_base_operators(T value1, T value2, T value3)
 {
     test_atomic_type_traits(boost::type< typename Wrapper<T>::atomic_type >());
 
+    if (is_atomic< typename Wrapper<T>::atomic_type >::value)
+    {
+        // default constructor must value-initialize the contained object
+        Wrapper<T> wrapper;
+        typename Wrapper<T>::atomic_reference_type a = wrapper.a;
+        BOOST_TEST_EQ( a.load(), T() );
+    }
+
     // explicit load/store
     {
         Wrapper<T> wrapper(value1);
@@ -215,9 +223,13 @@ template< typename T >
 void test_constexpr_ctor()
 {
 #ifndef BOOST_ATOMIC_DETAIL_NO_CXX11_CONSTEXPR_UNION_INIT
-    constexpr T value(0);
-    constexpr boost::atomic<T> tester(value);
-    BOOST_TEST( tester == value );
+    static constexpr T value = T();
+
+    constexpr boost::atomic<T> tester_default;
+    BOOST_TEST_EQ(tester_default.load(boost::memory_order_relaxed), value);
+
+    constexpr boost::atomic<T> tester_init(value);
+    BOOST_TEST_EQ(tester_init.load(boost::memory_order_relaxed), value);
 #endif
 }
 
@@ -1506,14 +1518,6 @@ inline std::basic_ostream< Char, Traits >& operator<< (std::basic_ostream< Char,
 template< template< typename > class Wrapper >
 void test_struct_with_ctor_api(void)
 {
-    {
-        test_struct_with_ctor s;
-        Wrapper<test_struct_with_ctor> wrapper_sa;
-        typename Wrapper<test_struct_with_ctor>::atomic_reference_type sa = wrapper_sa.a;
-        // Check that the default constructor was called
-        BOOST_TEST( sa.load() == s );
-    }
-
     test_struct_with_ctor a, b, c;
     a.i = 1;
     b.i = 2;
@@ -1522,4 +1526,52 @@ void test_struct_with_ctor_api(void)
     test_base_operators< Wrapper >(a, b, c);
 }
 
-#endif
+#if !defined(BOOST_ATOMIC_NO_CLEAR_PADDING)
+
+struct test_struct_with_padding
+{
+    unsigned char c;
+    unsigned short n;
+
+    inline bool operator==(test_struct_with_padding const& s) const { return c == s.c && n == s.n; }
+    inline bool operator!=(test_struct_with_padding const& s) const { return !operator==(s); }
+};
+
+template< typename Char, typename Traits >
+inline std::basic_ostream< Char, Traits >& operator<< (std::basic_ostream< Char, Traits >& strm, test_struct_with_padding const& s)
+{
+    strm << "{" << static_cast< unsigned int >(s.c) << ", " << static_cast< unsigned int >(s.n) << "}";
+    return strm;
+}
+
+
+template< template< typename > class Wrapper >
+void test_struct_with_padding_api(void)
+{
+    union test_struct_with_padding_init
+    {
+        unsigned char as_bytes[sizeof(test_struct_with_padding)];
+        test_struct_with_padding as_struct;
+    }
+    a, b, c;
+
+    for (unsigned int i = 0u; i < sizeof(a.as_bytes) / sizeof(*a.as_bytes); ++i)
+    {
+        a.as_bytes[i] = static_cast< unsigned char >(i + 0xA0);
+        b.as_bytes[i] = static_cast< unsigned char >(i + 0xB0);
+        c.as_bytes[i] = static_cast< unsigned char >(i + 0xC0);
+    }
+
+    a.as_struct.c = 10u;
+    a.as_struct.n = 1000u;
+    b.as_struct.c = 11u;
+    b.as_struct.n = 1001u;
+    c.as_struct.c = 12u;
+    c.as_struct.n = 1002u;
+
+    test_base_operators< Wrapper >(a.as_struct, b.as_struct, c.as_struct);
+}
+
+#endif // !defined(BOOST_ATOMIC_NO_CLEAR_PADDING)
+
+#endif // BOOST_ATOMIC_API_TEST_HELPERS_HPP