Cleanup: doc/examples makefile
[urcu.git] / tests / test_uatomic.c
index c0f36fe5f90f5e346be54befc1f93b09b2050b50..804ce7bd8a79b1945f9fcd9ea5098d3f34a7a971 100644 (file)
@@ -1,19 +1,34 @@
+/*
+ * test_uatomic.c
+ *
+ * Userspace RCU library - test atomic operations
+ *
+ * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
 #include <stdio.h>
 #include <assert.h>
-
-#define UATOMIC_NO_LINK_ERROR
-#include <urcu/uatomic_arch.h>
-
-#if (defined(__i386__) || defined(__x86_64__))
-#define HAS_ATOMIC_BYTE
-#define HAS_ATOMIC_SHORT
-#endif
+#include <urcu/uatomic.h>
 
 struct testvals {
-#ifdef HAS_ATOMIC_BYTE
+#ifdef UATOMIC_HAS_ATOMIC_BYTE
        unsigned char c;
 #endif
-#ifdef HAS_ATOMIC_SHORT
+#ifdef UATOMIC_HAS_ATOMIC_SHORT
        unsigned short s;
 #endif
        unsigned int i;
@@ -44,20 +59,28 @@ do {                                                \
        assert(uatomic_read(ptr) == 23);                \
        uatomic_dec(ptr);                       \
        assert(uatomic_read(ptr) == 22);                \
-       v = uatomic_add_return(ptr, 100);       \
-       assert(v == 122);                       \
+       v = uatomic_add_return(ptr, 74);        \
+       assert(v == 96);                        \
+       assert(uatomic_read(ptr) == 96);        \
+       uatomic_or(ptr, 58);                    \
        assert(uatomic_read(ptr) == 122);       \
        v = uatomic_sub_return(ptr, 1);         \
        assert(v == 121);                       \
+       uatomic_sub(ptr, (unsigned int) 2);     \
+       assert(uatomic_read(ptr) == 119);       \
+       uatomic_inc(ptr);                       \
+       uatomic_inc(ptr);                       \
        assert(uatomic_read(ptr) == 121);       \
+       uatomic_and(ptr, 129);                  \
+       assert(uatomic_read(ptr) == 1);         \
 } while (0)
 
 int main(int argc, char **argv)
 {
-#ifdef HAS_ATOMIC_BYTE
+#ifdef UATOMIC_HAS_ATOMIC_BYTE
        do_test(&vals.c);
 #endif
-#ifdef HAS_ATOMIC_SHORT
+#ifdef UATOMIC_HAS_ATOMIC_SHORT
        do_test(&vals.s);
 #endif
        do_test(&vals.i);
This page took 0.02341 seconds and 4 git commands to generate.