mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-28 10:30:03 +01:00
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
This commit is contained in:
parent
c00ef0a17a
commit
edd65baa6d
1
glib/tests/.gitignore
vendored
1
glib/tests/.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
array-test
|
||||
atomic
|
||||
base64
|
||||
bookmarkfile
|
||||
checksum
|
||||
|
@ -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
|
||||
|
41
glib/tests/atomic.c
Normal file
41
glib/tests/atomic.c
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user