#include "u_atomic.h"
-/* Test operations that are supported for all types, including 8 bits types */
-#define test_atomic_8bits(type, ones) \
- static void test_atomic_8bits_##type (void) { \
+/* Test only assignment-like operations, which are supported on all types */
+#define test_atomic_assign(type, ones) \
+ static void test_atomic_assign_##type (void) { \
type v, r; \
\
p_atomic_set(&v, ones); \
assert(v == 0 && "p_atomic_cmpxchg"); \
assert(r == ones && "p_atomic_cmpxchg"); \
\
+ (void) r; \
+ }
+
+
+/* Test arithmetic operations that are supported on 8 bits integer types */
+#define test_atomic_8bits(type, ones) \
+ test_atomic_assign(type, ones) \
+ \
+ static void test_atomic_8bits_##type (void) { \
+ type v, r; \
+ \
+ test_atomic_assign_##type(); \
+ \
v = 23; \
p_atomic_add(&v, 42); \
r = p_atomic_read(&v); \
}
-/* Test operations that are not supported for 8 bits types */
+/* Test all operations */
#define test_atomic(type, ones) \
test_atomic_8bits(type, ones) \
\
test_atomic_8bits(int8_t, INT8_C(-1))
test_atomic_8bits(uint8_t, UINT8_C(0xff))
-test_atomic_8bits(bool, true)
+test_atomic_assign(bool, true)
int
main()
test_atomic_8bits_int8_t();
test_atomic_8bits_uint8_t();
- test_atomic_8bits_bool();
+ test_atomic_assign_bool();
return 0;
}