1 // Copyright (c) 2011 Helge Bahmann
2 // Copyright (c) 2020 Andrey Semashev
4 // Distributed under the Boost Software License, Version 1.0.
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 #include <boost/atomic.hpp>
10 #include <boost/config.hpp>
11 #include <boost/cstdint.hpp>
13 #include "atomic_wrapper.hpp"
14 #include "api_test_helpers.hpp"
16 int main(int, char *[])
18 test_flag_api
< boost::atomic_flag
>();
20 test_integral_api
< atomic_wrapper
, char >();
21 test_integral_api
< atomic_wrapper
, signed char >();
22 test_integral_api
< atomic_wrapper
, unsigned char >();
23 test_integral_api
< atomic_wrapper
, boost::uint8_t >();
24 test_integral_api
< atomic_wrapper
, boost::int8_t >();
25 test_integral_api
< atomic_wrapper
, short >();
26 test_integral_api
< atomic_wrapper
, unsigned short >();
27 test_integral_api
< atomic_wrapper
, boost::uint16_t >();
28 test_integral_api
< atomic_wrapper
, boost::int16_t >();
29 test_integral_api
< atomic_wrapper
, int >();
30 test_integral_api
< atomic_wrapper
, unsigned int >();
31 test_integral_api
< atomic_wrapper
, boost::uint32_t >();
32 test_integral_api
< atomic_wrapper
, boost::int32_t >();
33 test_integral_api
< atomic_wrapper
, long >();
34 test_integral_api
< atomic_wrapper
, unsigned long >();
35 test_integral_api
< atomic_wrapper
, boost::uint64_t >();
36 test_integral_api
< atomic_wrapper
, boost::int64_t >();
37 test_integral_api
< atomic_wrapper
, long long >();
38 test_integral_api
< atomic_wrapper
, unsigned long long >();
39 #if defined(BOOST_HAS_INT128) && !defined(BOOST_ATOMIC_TESTS_NO_INT128)
40 test_integral_api
< atomic_wrapper
, boost::int128_type
>();
41 test_integral_api
< atomic_wrapper
, boost::uint128_type
>();
44 test_constexpr_ctor
< bool >();
45 test_constexpr_ctor
< char >();
46 test_constexpr_ctor
< short >();
47 test_constexpr_ctor
< int >();
48 test_constexpr_ctor
< long >();
49 test_constexpr_ctor
< long long >();
50 test_constexpr_ctor
< test_enum
>();
51 #if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_CONSTEXPR_BITWISE_CAST)
52 // As of gcc 11, clang 12 and MSVC 19.27, compilers don't support __builtin_bit_cast from pointers in constant expressions.
53 // test_constexpr_ctor< int* >();
54 test_constexpr_ctor
< test_struct
< int > >();
55 #if !defined(BOOST_ATOMIC_NO_FLOATING_POINT)
56 test_constexpr_ctor
< float >();
57 test_constexpr_ctor
< double >();
58 // We don't test long double as it may include padding bits, which will make the constructor non-constexpr
62 #if !defined(BOOST_ATOMIC_NO_FLOATING_POINT)
63 test_floating_point_api
< atomic_wrapper
, float >();
64 test_floating_point_api
< atomic_wrapper
, double >();
65 test_floating_point_api
< atomic_wrapper
, long double >();
66 #if defined(BOOST_HAS_FLOAT128) && !defined(BOOST_ATOMIC_TESTS_NO_FLOAT128)
67 test_floating_point_api
< atomic_wrapper
, boost::float128_type
>();
71 test_pointer_api
< atomic_wrapper
, int >();
73 test_enum_api
< atomic_wrapper
>();
75 test_struct_api
< atomic_wrapper
, test_struct
< boost::uint8_t > >();
76 test_struct_api
< atomic_wrapper
, test_struct
< boost::uint16_t > >();
77 test_struct_api
< atomic_wrapper
, test_struct
< boost::uint32_t > >();
78 test_struct_api
< atomic_wrapper
, test_struct
< boost::uint64_t > >();
79 #if defined(BOOST_HAS_INT128)
80 test_struct_api
< atomic_wrapper
, test_struct
< boost::uint128_type
> >();
83 // https://svn.boost.org/trac/boost/ticket/10994
84 test_struct_x2_api
< atomic_wrapper
, test_struct_x2
< boost::uint64_t > >();
86 // https://svn.boost.org/trac/boost/ticket/9985
87 test_struct_api
< atomic_wrapper
, test_struct
< double > >();
89 test_large_struct_api
< atomic_wrapper
>();
91 // Test that boost::atomic<T> only requires T to be trivially copyable.
92 // Other non-trivial constructors are allowed.
93 test_struct_with_ctor_api
< atomic_wrapper
>();
95 #if !defined(BOOST_ATOMIC_NO_CLEAR_PADDING)
96 test_struct_with_padding_api
< atomic_wrapper
>();
99 // Test that fences at least compile
100 boost::atomic_thread_fence(boost::memory_order_seq_cst
);
101 boost::atomic_signal_fence(boost::memory_order_seq_cst
);
103 return boost::report_errors();