update x86_64 cmpxchg
[urcu.git] / tests / test_atomic.c
index 47cc319f9164381a92c6bb1e0ee374d8378bcd48..3d2b64e434d3ef97eb0feec03a2c49968b96bc2e 100644 (file)
@@ -11,10 +11,32 @@ struct testvals {
 
 static struct testvals vals;
 
-int main(int argc, void **argv)
+#define do_test(ptr)                           \
+do {                                           \
+       __typeof__(*(ptr)) v;                   \
+                                               \
+       atomic_add(ptr, 10);                    \
+       assert(*(ptr) == 10);                   \
+       atomic_add(ptr, -11UL);                 \
+       assert(*(ptr) == (__typeof__(*(ptr)))-1UL);     \
+       v = cmpxchg(ptr, -1UL, 22);             \
+       assert(*(ptr) == 22);                   \
+       assert(v == (__typeof__(*(ptr)))-1UL);  \
+       v = cmpxchg(ptr, 33, 44);               \
+       assert(*(ptr) == 22);                   \
+       assert(v == 22);                        \
+       v = xchg(ptr, 55);                      \
+       assert(*(ptr) == 55);                   \
+       assert(v == 22);                        \
+} while (0)
+
+int main(int argc, char **argv)
 {
-       atomic_add(&vals.c, 10);
-       assert(vals.c == 10);
-       atomic_add(&vals.c, -11);
-       assert((char)vals.c == -1);
+       do_test(&vals.c);
+       do_test(&vals.s);
+       do_test(&vals.i);
+       do_test(&vals.l);
+       printf("Atomic ops test OK\n");
+
+       return 0;
 }
This page took 0.023856 seconds and 4 git commands to generate.