From edd65baa6d9f6b951f093a15b6fcb5771e3397e0 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Tue, 24 May 2011 02:07:55 -0400 Subject: [PATCH] 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(+) create mode 100644 glib/tests/atomic.c diff --git a/glib/tests/.gitignore b/glib/tests/.gitignore index 3c4a662e0..d05dbba4f 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 2dd37e5a7..29e706ef9 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 000000000..e16baf02e --- /dev/null +++ b/glib/tests/atomic.c @@ -0,0 +1,41 @@ +#include + +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; +}