1 //  Copyright (c) 2011 Helge Bahmann
2 //  Copyright (c) 2020 Andrey Semashev
3 //
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)
7 
8 #include <boost/atomic.hpp>
9 
10 #include <boost/config.hpp>
11 #include <boost/cstdint.hpp>
12 
13 #include "api_test_helpers.hpp"
14 
main(int,char * [])15 int main(int, char *[])
16 {
17     test_flag_api< boost::atomic_flag >();
18 
19     test_integral_api< atomic_wrapper, char >();
20     test_integral_api< atomic_wrapper, signed char >();
21     test_integral_api< atomic_wrapper, unsigned char >();
22     test_integral_api< atomic_wrapper, boost::uint8_t >();
23     test_integral_api< atomic_wrapper, boost::int8_t >();
24     test_integral_api< atomic_wrapper, short >();
25     test_integral_api< atomic_wrapper, unsigned short >();
26     test_integral_api< atomic_wrapper, boost::uint16_t >();
27     test_integral_api< atomic_wrapper, boost::int16_t >();
28     test_integral_api< atomic_wrapper, int >();
29     test_integral_api< atomic_wrapper, unsigned int >();
30     test_integral_api< atomic_wrapper, boost::uint32_t >();
31     test_integral_api< atomic_wrapper, boost::int32_t >();
32     test_integral_api< atomic_wrapper, long >();
33     test_integral_api< atomic_wrapper, unsigned long >();
34     test_integral_api< atomic_wrapper, boost::uint64_t >();
35     test_integral_api< atomic_wrapper, boost::int64_t >();
36     test_integral_api< atomic_wrapper, long long >();
37     test_integral_api< atomic_wrapper, unsigned long long >();
38 #if defined(BOOST_HAS_INT128) && !defined(BOOST_ATOMIC_TESTS_NO_INT128)
39     test_integral_api< atomic_wrapper, boost::int128_type >();
40     test_integral_api< atomic_wrapper, boost::uint128_type >();
41 #endif
42 
43     test_constexpr_ctor< char >();
44     test_constexpr_ctor< short >();
45     test_constexpr_ctor< int >();
46     test_constexpr_ctor< long >();
47     // test_constexpr_ctor< int* >(); // for pointers we're not offering a constexpr constructor because of bitwise_cast
48 
49 #if !defined(BOOST_ATOMIC_NO_FLOATING_POINT)
50     test_floating_point_api< atomic_wrapper, float >();
51     test_floating_point_api< atomic_wrapper, double >();
52     test_floating_point_api< atomic_wrapper, long double >();
53 #if defined(BOOST_HAS_FLOAT128) && !defined(BOOST_ATOMIC_TESTS_NO_FLOAT128)
54     test_floating_point_api< atomic_wrapper, boost::float128_type >();
55 #endif
56 #endif
57 
58     test_pointer_api< atomic_wrapper, int >();
59 
60     test_enum_api< atomic_wrapper >();
61 
62     test_struct_api< atomic_wrapper, test_struct< boost::uint8_t > >();
63     test_struct_api< atomic_wrapper, test_struct< boost::uint16_t > >();
64     test_struct_api< atomic_wrapper, test_struct< boost::uint32_t > >();
65     test_struct_api< atomic_wrapper, test_struct< boost::uint64_t > >();
66 #if defined(BOOST_HAS_INT128)
67     test_struct_api< atomic_wrapper, test_struct< boost::uint128_type > >();
68 #endif
69 
70     // https://svn.boost.org/trac/boost/ticket/10994
71     test_struct_x2_api< atomic_wrapper, test_struct_x2< boost::uint64_t > >();
72 
73     // https://svn.boost.org/trac/boost/ticket/9985
74     test_struct_api< atomic_wrapper, test_struct< double > >();
75 
76     test_large_struct_api< atomic_wrapper >();
77 
78     // Test that boost::atomic<T> only requires T to be trivially copyable.
79     // Other non-trivial constructors are allowed.
80     test_struct_with_ctor_api< atomic_wrapper >();
81 
82     // Test that fences at least compile
83     boost::atomic_thread_fence(boost::memory_order_seq_cst);
84     boost::atomic_signal_fence(boost::memory_order_seq_cst);
85 
86     return boost::report_errors();
87 }
88