11 #include <gtest/gtest.h> 23 fprintf(stderr,
"Type=%s, size=%ld, atomic_size=%ld, lockfree=%d\n",
24 typeid(T).name(), (
long)
sizeof(n), (
long)
sizeof(i), i.
is_lock_free());
26 ASSERT_TRUE(
sizeof(i)>=
sizeof(n));
70 ASSERT_TRUE(!success);
81 fprintf(stderr,
"Type=%s, size=%ld, atomic_size=%ld, lockfree=%d\n",
82 typeid(T).name(), (
long)
sizeof(n), (
long)
sizeof(i), i.
is_lock_free());
84 ASSERT_TRUE(
sizeof(i)>=
sizeof(n));
91 ASSERT_TRUE(!success);
93 ASSERT_TRUE(i.
load()==(T)0);
99 ASSERT_TRUE(i.
load()==(T)44);
103 ASSERT_TRUE(i.
load()==(T)20);
109 test_atomic_base<T *>();
117 ASSERT_TRUE(p==&array[0]);
118 ASSERT_TRUE(ptr==&array[1]);
120 ASSERT_TRUE(p==&array[2]);
121 ASSERT_TRUE(ptr==&array[2]);
124 ASSERT_TRUE(p==&array[2]);
125 ASSERT_TRUE(ptr==&array[6]);
128 ASSERT_TRUE(p==&array[6]);
129 ASSERT_TRUE(ptr==&array[2]);
132 ASSERT_TRUE(p==&array[2]);
133 ASSERT_TRUE(ptr==&array[1]);
135 ASSERT_TRUE(p==&array[0]);
136 ASSERT_TRUE(ptr==&array[0]);
145 fprintf(stderr,
"Type=bool, size=%ld, atomic_size=%ld, lockfree=%d\n",
148 ASSERT_TRUE(
sizeof(i)>=
sizeof(n));
154 ASSERT_TRUE(!success);
155 ASSERT_TRUE(n==
false);
156 ASSERT_TRUE(i==
false);
160 ASSERT_TRUE(success);
161 ASSERT_TRUE(n==
false);
162 ASSERT_TRUE(i==
true);
165 ASSERT_TRUE(n==
true);
166 ASSERT_TRUE(i==
false);
190 Compound zero={0}, one={1}, two={2};
192 ASSERT_TRUE(
sizeof(i)>=
sizeof(n));
199 ASSERT_TRUE(!success);
200 ASSERT_TRUE(n==zero);
201 ASSERT_TRUE(i.
load()==zero);
205 ASSERT_TRUE(success);
206 ASSERT_TRUE(n==zero);
207 ASSERT_TRUE(i.
load()==two);
211 ASSERT_TRUE(i.
load()==one);
225 test_atomic_arithmetic<char>();
226 test_atomic_arithmetic<signed char>();
227 test_atomic_arithmetic<unsigned char>();
228 test_atomic_arithmetic<uint8_t>();
229 test_atomic_arithmetic<int8_t>();
230 test_atomic_arithmetic<short>();
231 test_atomic_arithmetic<unsigned short>();
232 test_atomic_arithmetic<uint16_t>();
233 test_atomic_arithmetic<int16_t>();
234 test_atomic_arithmetic<int>();
235 test_atomic_arithmetic<unsigned int>();
236 test_atomic_arithmetic<uint32_t>();
237 test_atomic_arithmetic<int32_t>();
238 test_atomic_arithmetic<long>();
239 test_atomic_arithmetic<unsigned long>();
240 test_atomic_arithmetic<uint64_t>();
241 test_atomic_arithmetic<int64_t>();
242 test_atomic_arithmetic<long long>();
243 test_atomic_arithmetic<unsigned long long>();
247 test_atomic_base<void *>();
248 test_atomic_ptr<int>();
250 test_atomic_base<TestEnum>();
259 int main(
int argc,
char** argv)
261 testing::InitGoogleTest(&argc, argv);
262 return RUN_ALL_TESTS();
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order, memory_order) volatile
static void atomic_thread_fence(memory_order order)
bool operator==(const Compound &c) const
bool test_and_set(memory_order order=memory_order_seq_cst)
void test_atomic_arithmetic(void)
void test_atomic_base(void)
value_type load(memory_order=memory_order_seq_cst) volatileconst
int main(int argc, char **argv)
void test_atomic_ptr(void)
void store(value_type v, memory_order=memory_order_seq_cst) volatile
void test_atomic_struct(void)
void test_atomic_base< bool >(void)
void clear(memory_order order=memory_order_seq_cst) volatile
value_type exchange(value_type v, memory_order=memory_order_seq_cst) volatile
bool is_lock_free(void) const volatile