[glib] Add a test case for atomic ops



commit edd65baa6d9f6b951f093a15b6fcb5771e3397e0
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue May 24 02:07:55 2011 -0400

    Add a test case for atomic ops
    
    Make sure that the macros work properly with the range of types that
    they are documented to work with and ensure that no strict aliasing
    warnings are issued (even at the highest warning level).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=650935

 glib/tests/.gitignore  |    1 +
 glib/tests/Makefile.am |    4 ++++
 glib/tests/atomic.c    |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/.gitignore b/glib/tests/.gitignore
index 3c4a662..d05dbba 100644
--- a/glib/tests/.gitignore
+++ b/glib/tests/.gitignore
@@ -1,4 +1,5 @@
 array-test
+atomic
 base64
 bookmarkfile
 checksum
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 2dd37e5..29e706e 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -177,6 +177,10 @@ TEST_PROGS    += unix-nothreads
 unix_nothreads_SOURCES = unix.c
 unix_nothreads_LDADD  = $(progs_ldadd)
 
+noinst_PROGRAMS += atomic
+atomic_CFLAGS = -Wstrict-aliasing=2 $(INCLUDES)
+atomic_LDADD = $(progs_ldadd)
+
 # some testing of gtester funcitonality
 XMLLINT=xmllint
 gtester-xmllint-check: # check testreport xml with xmllint if present
diff --git a/glib/tests/atomic.c b/glib/tests/atomic.c
new file mode 100644
index 0000000..e16baf0
--- /dev/null
+++ b/glib/tests/atomic.c
@@ -0,0 +1,41 @@
+#include <glib.h>
+
+int
+main (void)
+{
+  guint u;
+  gint s;
+  gpointer vp;
+  int *ip;
+  gsize gs;
+
+  g_atomic_int_set (&u, 5);
+  g_atomic_int_get (&u);
+  g_atomic_int_compare_and_exchange (&u, 6, 7);
+  g_atomic_int_exchange_and_add (&u, 1);
+  g_atomic_int_add (&u, 1);
+  g_atomic_int_inc (&u);
+  (void) g_atomic_int_dec_and_test (&u);
+
+  g_atomic_int_set (&s, 5);
+  g_atomic_int_get (&s);
+  g_atomic_int_compare_and_exchange (&s, 6, 7);
+  g_atomic_int_exchange_and_add (&s, 1);
+  g_atomic_int_add (&s, 1);
+  g_atomic_int_inc (&s);
+  (void) g_atomic_int_dec_and_test (&s);
+
+  g_atomic_pointer_set (&vp, 0);
+  g_atomic_pointer_get (&vp);
+  g_atomic_pointer_compare_and_exchange (&vp, 0, 0);
+
+  g_atomic_pointer_set (&ip, 0);
+  g_atomic_pointer_get (&ip);
+  g_atomic_pointer_compare_and_exchange (&ip, 0, 0);
+
+  g_atomic_pointer_set (&gs, 0);
+  g_atomic_pointer_get (&gs);
+  g_atomic_pointer_compare_and_exchange (&gs, 0, 0);
+
+  return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]