summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2015-03-29 04:50:56 -0500
committerWaldemar Brodkorb <wbx@openadk.org>2015-03-29 04:50:56 -0500
commitcd5f92704e1e17bbc0c15d197f3bc236c7dc9bf2 (patch)
tree1400302b543e4528aedea5d72731983559cfcf36 /test
parentad2bffbf1926051ef333f9899344f6bddf2c03cf (diff)
parent24946289317ea23bb0d1814cca0a499a905f7d6f (diff)
merge uClibc git master
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore3
-rw-r--r--test/README3
-rw-r--r--test/Test.mak5
-rw-r--r--test/math/compile_test.c20
-rw-r--r--test/math/libm-test.inc62
-rw-r--r--test/misc/Makefile.in8
-rw-r--r--test/misc/tst-scandir.c2
-rw-r--r--test/misc/tst-utmp.c15
-rw-r--r--test/misc/tst-utmpx.c2
-rw-r--r--test/silly/Makefile.in3
-rw-r--r--test/silly/hello.c2
-rw-r--r--test/silly/tst-atomic-long.c27
-rw-r--r--test/silly/tst-atomic.c573
-rw-r--r--test/stdlib/Makefile.in3
-rw-r--r--test/stdlib/testarc4random.c2
15 files changed, 678 insertions, 52 deletions
diff --git a/test/.gitignore b/test/.gitignore
index 5944f0a0f..0d19285e9 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -163,6 +163,7 @@ misc/tst-seekdir
misc/tst-statfs
misc/tst-statvfs
misc/tst-utmp
+misc/tst-utmpx
mmap/mmap
mmap/mmap2
mmap/mmap64
@@ -262,6 +263,8 @@ signal/tst-sigset
signal/tst-sigsimple
silly/hello
silly/tiny
+silly/tst-atomic
+silly/tst-atomic-long
stat/memcmp-stat
stat/stat
stat/stat64
diff --git a/test/README b/test/README
index 28225b063..723ce6e43 100644
--- a/test/README
+++ b/test/README
@@ -29,6 +29,9 @@ The following make variables may help you in testing:
So, to just run the uClibc tests, try this:
make check UCLIBC_ONLY=1
+You can pass the following 2 environment variables to "make run":
+ - make run SIMULATOR_uclibc=qemu-sh4 SIMULATOR_glibc=qemu-x86_64
+
If you need to test just a subset of all test, delete subdirectories
you do not need.
diff --git a/test/Test.mak b/test/Test.mak
index ee43a0fcd..a56a20165 100644
--- a/test/Test.mak
+++ b/test/Test.mak
@@ -69,7 +69,7 @@ endef
define exec_test
$(showtest)
$(Q)\
- $(WRAPPER) $(WRAPPER_$(tst_src_name)) \
+ $(SIMULATOR) $(WRAPPER) $(WRAPPER_$(tst_src_name)) \
./$(binary_name) $(OPTS) $(OPTS_$(tst_src_name)) > "$(binary_name).out" 2>&1 ; \
ret=$$? ; \
expected_ret="$(RET_$(tst_src_name))" ; \
@@ -85,6 +85,9 @@ endef
test check all: run
run: $(RUN_TARGETS)
+
+$(addsuffix .exe,$(U_TARGETS)): SIMULATOR:=$(SIMULATOR_uclibc)
+$(addsuffix .exe,$(G_TARGETS)): SIMULATOR:=$(SIMULATOR_glibc)
$(RUN_TARGETS):
$(exec_test)
$(diff_test)
diff --git a/test/math/compile_test.c b/test/math/compile_test.c
index ab8c40c48..aedfde601 100644
--- a/test/math/compile_test.c
+++ b/test/math/compile_test.c
@@ -22,11 +22,11 @@ r += exp2f(float_x);
r += expf(float_x);
r += expm1f(float_x);
r += fabsf(float_x);
-/*r += fdimf(float_x, float_x); - uclibc does not have it (yet?) */
+r += fdimf(float_x, float_x);
r += floorf(float_x);
-/*r += fmaf(float_x, float_x, float_x); - uclibc does not have it (yet?) */
-/*r += fmaxf(float_x, float_x); - uclibc does not have it (yet?) */
-/*r += fminf(float_x, float_x); - uclibc does not have it (yet?) */
+r += fmaf(float_x, float_x, float_x);
+r += fmaxf(float_x, float_x);
+r += fminf(float_x, float_x);
r += fmodf(float_x, float_x);
r += frexpf(float_x, &int_x);
r += gammaf(float_x);
@@ -44,17 +44,17 @@ r += logf(float_x);
r += lrintf(float_x);
r += lroundf(float_x);
r += modff(float_x, &float_x);
-/*r += nearbyintf(float_x); - uclibc does not have it (yet?) */
-/*r += nexttowardf(float_x, long_double_x); - uclibc does not have it (yet?) */
+r += nearbyintf(float_x);
+r += nexttowardf(float_x, long_double_x);
r += powf(float_x, float_x);
r += remainderf(float_x, float_x);
-/*r += remquof(float_x, float_x, &int_x); - uclibc does not have it (yet?) */
+r += remquof(float_x, float_x, &int_x);
r += rintf(float_x);
r += roundf(float_x);
#ifdef __UCLIBC_SUSV3_LEGACY__
r += scalbf(float_x, float_x);
#endif
-/*r += scalblnf(float_x, long_x); - uclibc does not have it (yet?) */
+r += scalblnf(float_x, long_x);
r += scalbnf(float_x, int_x);
r += significandf(float_x);
r += sinf(float_x);
@@ -62,7 +62,7 @@ r += sinhf(float_x);
r += sqrtf(float_x);
r += tanf(float_x);
r += tanhf(float_x);
-/*r += tgammaf(float_x); - uclibc does not have it (yet?) */
+r += tgammaf(float_x);
r += truncf(float_x);
return r;
}
@@ -116,7 +116,7 @@ r += lroundl(long_double_x);
r += modfl(long_double_x, &long_double_x);
r += nearbyintl(long_double_x);
r += nextafterl(long_double_x, long_double_x);
-/* r += nexttowardl(long_double_x, long_double_x); - uclibc doesn't provide this [yet?] */
+r += nexttowardl(long_double_x, long_double_x);
r += powl(long_double_x, long_double_x);
r += remainderl(long_double_x, long_double_x);
r += remquol(long_double_x, long_double_x, &int_x);
diff --git a/test/math/libm-test.inc b/test/math/libm-test.inc
index d0f0a0c30..f50b48b81 100644
--- a/test/math/libm-test.inc
+++ b/test/math/libm-test.inc
@@ -115,6 +115,9 @@
# define _GNU_SOURCE
#endif
+#undef __CHK_COMPLEX_STUFF
+#define __CHK_COMPLEX_STUFF 0
+
#include "libm-test-ulps.h"
#include <complex.h>
#include <math.h>
@@ -1120,8 +1123,10 @@ cacosh_test (void)
END (cacosh, complex);
}
+#endif
+#if __CHK_COMPLEX_STUFF
static void
carg_test (void)
{
@@ -1188,7 +1193,9 @@ carg_test (void)
END (carg);
}
+#endif /* __CHK_COMPLEX_STUFF */
+#if 0
static void
casin_test (void)
{
@@ -1683,7 +1690,7 @@ ceil_test (void)
}
-#if 0
+#if __CHK_COMPLEX_STUFF
static void
cexp_test (void)
{
@@ -1746,8 +1753,9 @@ cexp_test (void)
END (cexp, complex);
}
+#endif /* __CHK_COMPLEX_STUFF */
-
+#if 0
static void
cimag_test (void)
{
@@ -2588,7 +2596,6 @@ fabs_test (void)
}
-#if 0
static void
fdim_test (void)
{
@@ -2624,7 +2631,6 @@ fdim_test (void)
END (fdim);
}
-#endif
static void
@@ -2694,7 +2700,6 @@ floor_test (void)
}
-#if 0
static void
fma_test (void)
{
@@ -2797,7 +2802,6 @@ fmin_test (void)
END (fmin);
}
-#endif
static void
@@ -3002,7 +3006,7 @@ isnormal_test (void)
END (isnormal);
}
-#if defined __DO_XSI_MATH__
+#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT)
static void
j0_test (void)
{
@@ -3414,8 +3418,6 @@ log1p_test (void)
END (log1p);
}
-
-#if 0
static void
log2_test (void)
{
@@ -3445,8 +3447,6 @@ log2_test (void)
END (log2);
}
-#endif
-
static void
logb_test (void)
@@ -3629,7 +3629,6 @@ modf_test (void)
}
-#if 0
static void
nearbyint_test (void)
{
@@ -3710,7 +3709,6 @@ nexttoward_test (void)
END (nexttoward);
}
-#endif
static void
@@ -3950,7 +3948,6 @@ remainder_test (void)
END (remainder);
}
-#if 0
static void
remquo_test (void)
{
@@ -3981,7 +3978,6 @@ remquo_test (void)
END (remquo);
}
-#endif
static void
rint_test (void)
@@ -4229,12 +4225,12 @@ round_test (void)
#endif
+#ifdef __UCLIBC_SUSV3_LEGACY__
static void
scalb_test (void)
{
START (scalb);
#ifndef TEST_LDOUBLE /* uclibc doesn't have scalbl */
-#ifdef __UCLIBC_SUSV3_LEGACY__ /* scalbf is susv3 legacy */
TEST_ff_f (scalb, 2.0, 0.5, nan_value, INVALID_EXCEPTION);
TEST_ff_f (scalb, 3.0, -2.5, nan_value, INVALID_EXCEPTION);
@@ -4285,11 +4281,10 @@ scalb_test (void)
TEST_ff_f (scalb, 0.8L, 4, 12.8L);
TEST_ff_f (scalb, -0.854375L, 5, -27.34L);
-#endif /* __UCLIBC_SUSV3_LEGACY__ */
#endif /* TEST_LDOUBLE */
END (scalb);
}
-
+#endif
static void
scalbn_test (void)
@@ -4313,7 +4308,6 @@ scalbn_test (void)
}
-#if 0
static void
scalbln_test (void)
{
@@ -4334,7 +4328,6 @@ scalbln_test (void)
END (scalbn);
}
-#endif
static void
@@ -4539,7 +4532,6 @@ tanh_test (void)
END (tanh);
}
-#if 0
static void
tgamma_test (void)
{
@@ -4571,7 +4563,6 @@ tgamma_test (void)
END (tgamma);
}
-#endif
#if 0
@@ -4651,7 +4642,7 @@ trunc_test (void)
}
#endif
-#if defined __DO_XSI_MATH__
+#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT)
static void
y0_test (void)
{
@@ -4973,17 +4964,15 @@ main (int argc, char **argv)
log_test ();
log10_test ();
log1p_test ();
-#if 0
log2_test ();
-#endif
logb_test ();
modf_test ();
ilogb_test ();
+#ifdef __UCLIBC_SUSV3_LEGACY__
scalb_test ();
+#endif
scalbn_test ();
-#if 0
scalbln_test ();
-#endif
significand_test ();
/* Power and absolute value functions: */
@@ -4998,16 +4987,12 @@ main (int argc, char **argv)
erfc_test ();
gamma_test ();
lgamma_test ();
-#if 0
tgamma_test ();
-#endif
/* Nearest integer functions: */
ceil_test ();
floor_test ();
-#if 0
nearbyint_test ();
-#endif
rint_test ();
#if 0
rint_test_tonearest ();
@@ -5025,13 +5010,10 @@ main (int argc, char **argv)
/* Remainder functions: */
fmod_test ();
remainder_test ();
-#if 0
remquo_test ();
-#endif
/* Manipulation functions: */
copysign_test ();
-#if 0
nextafter_test ();
nexttoward_test ();
@@ -5043,24 +5025,29 @@ main (int argc, char **argv)
/* Multiply and add: */
fma_test ();
+
/* Complex functions: */
cabs_test ();
+#if __CHK_COMPLEX_STUFF
+#if 0
cacos_test ();
cacosh_test ();
+#endif
carg_test ();
+#if 0
casin_test ();
casinh_test ();
catan_test ();
catanh_test ();
ccos_test ();
ccosh_test ();
+#endif
cexp_test ();
+#if 0
cimag_test ();
clog10_test ();
clog_test ();
-#if 0
conj_test ();
-#endif
cpow_test ();
cproj_test ();
creal_test ();
@@ -5070,9 +5057,10 @@ main (int argc, char **argv)
ctan_test ();
ctanh_test ();
#endif
+#endif /* __CHK_COMPLEX_STUFF */
/* Bessel functions: */
-#if defined __DO_XSI_MATH__
+#if defined __DO_XSI_MATH__ && !(defined TEST_LDOUBLE || defined TEST_FLOAT)
j0_test ();
j1_test ();
jn_test ();
diff --git a/test/misc/Makefile.in b/test/misc/Makefile.in
index 345889e0f..d78b276c2 100644
--- a/test/misc/Makefile.in
+++ b/test/misc/Makefile.in
@@ -21,6 +21,14 @@ ifeq ($(UCLIBC_HAS_GLOB),)
TESTS_DISABLED += bug-glob2
endif
+ifeq ($(UCLIBC_HAS_UTMPX),)
+TESTS_DISABLED += tst-utmpx
+endif
+
+ifeq ($(UCLIBC_HAS_UTMP),)
+TESTS_DISABLED += tst-utmp
+endif
+
DODIFF_dirent := 1
DODIFF_dirent64 := 1
DODIFF_tst-statfs := 1
diff --git a/test/misc/tst-scandir.c b/test/misc/tst-scandir.c
index df62a40d4..e1c72e3c9 100644
--- a/test/misc/tst-scandir.c
+++ b/test/misc/tst-scandir.c
@@ -3,7 +3,7 @@
#include <stdio.h> /* perror() */
#include <stdlib.h>
-int skip_all(const struct dirent *dirbuf)
+static int skip_all(const struct dirent *dirbuf)
{
errno = EBADF;
return 0;
diff --git a/test/misc/tst-utmp.c b/test/misc/tst-utmp.c
index 08a6f8ea3..1b0333a32 100644
--- a/test/misc/tst-utmp.c
+++ b/test/misc/tst-utmp.c
@@ -37,6 +37,21 @@
# include <utmp.h>
#endif
+#ifndef _HAVE_UT_TYPE
+# define _HAVE_UT_TYPE 0
+#endif
+#ifndef _HAVE_UT_PID
+# define _HAVE_UT_PID 0
+#endif
+#ifndef _HAVE_UT_ID
+# define _HAVE_UT_ID 0
+#endif
+#ifndef _HAVE_UT_TV
+# define _HAVE_UT_TV 0
+#endif
+#ifndef _HAVE_UT_HOST
+# define _HAVE_UT_HOST 0
+#endif
#if _HAVE_UT_TYPE || defined UTMPX
diff --git a/test/misc/tst-utmpx.c b/test/misc/tst-utmpx.c
new file mode 100644
index 000000000..edb5551d7
--- /dev/null
+++ b/test/misc/tst-utmpx.c
@@ -0,0 +1,2 @@
+#define UTMPX
+#include "tst-utmp.c"
diff --git a/test/silly/Makefile.in b/test/silly/Makefile.in
index bb08e0db9..9bb4032b5 100644
--- a/test/silly/Makefile.in
+++ b/test/silly/Makefile.in
@@ -3,3 +3,6 @@
RET_hello := 42
RET_tiny := 42
+
+# missing internal headers, disable these
+GLIBC_TESTS_DISABLED := tst-atomic_glibc tst-atomic-long_glibc
diff --git a/test/silly/hello.c b/test/silly/hello.c
index 4aba926e6..d330597ab 100644
--- a/test/silly/hello.c
+++ b/test/silly/hello.c
@@ -1,4 +1,4 @@
-#include<stdio.h>
+#include <stdio.h>
#include <stdlib.h>
int main(void)
diff --git a/test/silly/tst-atomic-long.c b/test/silly/tst-atomic-long.c
new file mode 100644
index 000000000..d13fb074c
--- /dev/null
+++ b/test/silly/tst-atomic-long.c
@@ -0,0 +1,27 @@
+/* Tests for atomic.h macros.
+ Copyright (C) 2003-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <bits/wordsize.h>
+
+#define atomic_t long
+#if __WORDSIZE == 64
+# define TEST_ATOMIC64 1
+#endif
+
+#include "tst-atomic.c"
diff --git a/test/silly/tst-atomic.c b/test/silly/tst-atomic.c
new file mode 100644
index 000000000..fc773b231
--- /dev/null
+++ b/test/silly/tst-atomic.c
@@ -0,0 +1,573 @@
+/* Tests for atomic.h macros.
+ Copyright (C) 2003-2015 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <atomic.h>
+
+#ifndef atomic_t
+# define atomic_t int
+#endif
+
+#define CHK2(f,a1,a2,rv,new_mem) \
+ retval = f(&mem, a1, a2); \
+ if (retval != rv) { \
+ printf("%s(mem, %lu, %lu): retval %lu != expected %lu\n", \
+ #f, a1, a2, retval, rv); \
+ ret = 1; \
+ } \
+ if (mem != new_mem) { \
+ printf("%s(mem, %lu, %lu): mem %lu != expected %lu\n", \
+ #f, a1, a2, mem, new_mem); \
+ ret = 1; \
+ }
+#define CHK1(f,a1,rv,new_mem) \
+ retval = f(&mem, a1); \
+ if (retval != rv) { \
+ printf("%s(mem, %lu): retval %lu != expected %lu\n", \
+ #f, a1, retval, rv); \
+ ret = 1; \
+ } \
+ if (mem != new_mem) { \
+ printf("%s(mem, %lu): mem %lu != expected %lu\n", \
+ #f, a1, mem, new_mem); \
+ ret = 1; \
+ }
+#define CHK0(f,rv,new_mem) \
+ retval = f(&mem); \
+ if (retval != rv) { \
+ printf("%s(mem): retval %lu != expected %lu\n", \
+ #f, retval, rv); \
+ ret = 1; \
+ } \
+ if (mem != new_mem) { \
+ printf("%s(mem): mem %lu != expected %lu\n", \
+ #f, mem, new_mem); \
+ ret = 1; \
+ }
+
+/* Test various atomic.h macros. */
+static int
+do_test (void)
+{
+ atomic_t mem, expected, retval;
+ int ret = 0;
+
+#ifdef atomic_compare_and_exchange_val_acq
+ mem = 24;
+ CHK2(atomic_compare_and_exchange_val_acq, 35, 24, 24, 35);
+ mem = 12;
+ CHK2(atomic_compare_and_exchange_val_acq, 10, 15, 12, 12);
+ mem = -15;
+ CHK2(atomic_compare_and_exchange_val_acq, -56, -15, -15, -56);
+ mem = -1;
+ CHK2(atomic_compare_and_exchange_val_acq, 17, 0, -1, -1);
+#endif
+
+ mem = 24;
+ CHK2(atomic_compare_and_exchange_bool_acq, 35, 24, 0, 35);
+ mem = 12;
+ CHK2(atomic_compare_and_exchange_bool_acq, 10, 15, 1, 12);
+ mem = -15;
+ CHK2(atomic_compare_and_exchange_bool_acq, -56, -15, 0, -56);
+ mem = -1;
+ CHK2(atomic_compare_and_exchange_bool_acq, 17, 0, 1, -1);
+
+ mem = 64;
+ CHK1(atomic_exchange_acq, 31, 64, 31);
+ mem = 2;
+ CHK1(atomic_exchange_and_add, 11, 2, 13);
+ mem = 2;
+ CHK1(atomic_exchange_and_add_acq, 11, 2, 13);
+ mem = 2;
+ CHK1(atomic_exchange_and_add_rel, 11, 2, 13);
+
+ mem = -21;
+ atomic_add (&mem, 22);
+ if (mem != 1)
+ {
+ printf ("atomic_add(mem, 22): mem %lu != expected 1\n", mem);
+ ret = 1;
+ }
+
+ mem = -1;
+ atomic_increment (&mem);
+ if (mem != 0)
+ {
+ printf ("atomic_increment(mem): mem %lu != expected 0\n", mem);
+ ret = 1;
+ }
+
+ mem = 2;
+ if ((retval = atomic_increment_val (&mem)) != 3)
+ {
+ printf ("atomic_increment_val(mem): retval %lu != expected 3\n", retval);
+ ret = 1;
+ }
+
+ mem = 0;
+ CHK0(atomic_increment_and_test, 0, 1);
+ mem = 35;
+ CHK0(atomic_increment_and_test, 0, 36);
+ mem = -1;
+ CHK0(atomic_increment_and_test, 1, 0);
+ mem = 17;
+ atomic_decrement (&mem);
+ if (mem != 16)
+ {
+ printf ("atomic_increment(mem): mem %lu != expected 16\n", mem);
+ ret = 1;
+ }
+
+ if ((retval = atomic_decrement_val (&mem)) != 15)
+ {
+ printf ("atomic_decrement_val(mem): retval %lu != expected 15\n", retval);
+ ret = 1;
+ }
+
+ mem = 0;
+ CHK0(atomic_decrement_and_test, 0, -1);
+
+ mem = 15;
+ CHK0(atomic_decrement_and_test, 0, 14);
+ mem = 1;
+ CHK0(atomic_decrement_and_test, 1, 0);
+ mem = 1;
+ if (atomic_decrement_if_positive (&mem) != 1
+ || mem != 0)
+ {
+ puts ("atomic_decrement_if_positive test 1 failed");
+ ret = 1;
+ }
+
+ mem = 0;
+ if (atomic_decrement_if_positive (&mem) != 0
+ || mem != 0)
+ {
+ puts ("atomic_decrement_if_positive test 2 failed");
+ ret = 1;
+ }
+
+ mem = -1;
+ if (atomic_decrement_if_positive (&mem) != -1
+ || mem != -1)
+ {
+ puts ("atomic_decrement_if_positive test 3 failed");
+ ret = 1;
+ }
+
+ mem = -12;
+ if (! atomic_add_negative (&mem, 10)
+ || mem != -2)
+ {
+ puts ("atomic_add_negative test 1 failed");
+ ret = 1;
+ }
+
+ mem = 0;
+ if (atomic_add_negative (&mem, 100)
+ || mem != 100)
+ {
+ puts ("atomic_add_negative test 2 failed");
+ ret = 1;
+ }
+
+ mem = 15;
+ if (atomic_add_negative (&mem, -10)
+ || mem != 5)
+ {
+ puts ("atomic_add_negative test 3 failed");
+ ret = 1;
+ }
+
+ mem = -12;
+ if (atomic_add_negative (&mem, 14)
+ || mem != 2)
+ {
+ puts ("atomic_add_negative test 4 failed");
+ ret = 1;
+ }
+
+ mem = 0;
+ if (! atomic_add_negative (&mem, -1)
+ || mem != -1)
+ {
+ puts ("atomic_add_negative test 5 failed");
+ ret = 1;
+ }
+
+ mem = -31;
+ if (atomic_add_negative (&mem, 31)
+ || mem != 0)
+ {
+ puts ("atomic_add_negative test 6 failed");
+ ret = 1;
+ }
+
+ mem = -34;
+ if (atomic_add_zero (&mem, 31)
+ || mem != -3)
+ {
+ puts ("atomic_add_zero test 1 failed");
+ ret = 1;
+ }
+
+ mem = -36;
+ if (! atomic_add_zero (&mem, 36)
+ || mem != 0)
+ {
+ puts ("atomic_add_zero test 2 failed");
+ ret = 1;
+ }
+
+ mem = 113;
+ if (atomic_add_zero (&mem, -13)
+ || mem != 100)
+ {
+ puts ("atomic_add_zero test 3 failed");
+ ret = 1;
+ }
+
+ mem = -18;
+ if (atomic_add_zero (&mem, 20)
+ || mem != 2)
+ {
+ puts ("atomic_add_zero test 4 failed");
+ ret = 1;
+ }
+
+ mem = 10;
+ if (atomic_add_zero (&mem, -20)
+ || mem != -10)
+ {
+ puts ("atomic_add_zero test 5 failed");
+ ret = 1;
+ }
+
+ mem = 10;
+ if (! atomic_add_zero (&mem, -10)
+ || mem != 0)
+ {
+ puts ("atomic_add_zero test 6 failed");
+ ret = 1;
+ }
+
+ mem = 0;
+ atomic_bit_set (&mem, 1);
+ if (mem != 2)
+ {
+ puts ("atomic_bit_set test 1 failed");
+ ret = 1;
+ }
+
+ mem = 8;
+ atomic_bit_set (&mem, 3);
+ if (mem != 8)
+ {
+ puts ("atomic_bit_set test 2 failed");
+ ret = 1;
+ }
+
+#ifdef TEST_ATOMIC64
+ mem = 16;
+ atomic_bit_set (&mem, 35);
+ if (mem != 0x800000010LL)
+ {
+ puts ("atomic_bit_set test 3 failed");
+ ret = 1;
+ }
+#endif
+
+ mem = 0;
+ if (atomic_bit_test_set (&mem, 1)
+ || mem != 2)
+ {
+ puts ("atomic_bit_test_set test 1 failed");
+ ret = 1;
+ }
+
+ mem = 8;
+ if (! atomic_bit_test_set (&mem, 3)
+ || mem != 8)
+ {
+ puts ("atomic_bit_test_set test 2 failed");
+ ret = 1;
+ }
+
+#ifdef TEST_ATOMIC64
+ mem = 16;
+ if (atomic_bit_test_set (&mem, 35)
+ || mem != 0x800000010LL)
+ {
+ puts ("atomic_bit_test_set test 3 failed");
+ ret = 1;
+ }
+
+ mem = 0x100000000LL;
+ if (! atomic_bit_test_set (&mem, 32)
+ || mem != 0x100000000LL)
+ {
+ puts ("atomic_bit_test_set test 4 failed");
+ ret = 1;
+ }
+#endif
+
+#ifdef catomic_compare_and_exchange_val_acq
+ mem = 24;
+ if (catomic_compare_and_exchange_val_acq (&mem, 35, 24) != 24
+ || mem != 35)
+ {
+ puts ("catomic_compare_and_exchange_val_acq test 1 failed");
+ ret = 1;
+ }
+
+ mem = 12;
+ if (catomic_compare_and_exchange_val_acq (&mem, 10, 15) != 12
+ || mem != 12)
+ {
+ puts ("catomic_compare_and_exchange_val_acq test 2 failed");
+ ret = 1;
+ }
+
+ mem = -15;
+ if (catomic_compare_and_exchange_val_acq (&mem, -56, -15) != -15
+ || mem != -56)
+ {
+ puts ("catomic_compare_and_exchange_val_acq test 3 failed");
+ ret = 1;
+ }
+
+ mem = -1;
+ if (catomic_compare_and_exchange_val_acq (&mem, 17, 0) != -1
+ || mem != -1)
+ {
+ puts ("catomic_compare_and_exchange_val_acq test 4 failed");
+ ret = 1;
+ }
+#endif
+
+ mem = 24;
+ if (catomic_compare_and_exchange_bool_acq (&mem, 35, 24)
+ || mem != 35)
+ {
+ puts ("catomic_compare_and_exchange_bool_acq test 1 failed");
+ ret = 1;
+ }
+
+ mem = 12;
+ if (! catomic_compare_and_exchange_bool_acq (&mem, 10, 15)
+ || mem != 12)
+ {
+ puts ("catomic_compare_and_exchange_bool_acq test 2 failed");
+ ret = 1;
+ }
+
+ mem = -15;
+ if (catomic_compare_and_exchange_bool_acq (&mem, -56, -15)
+ || mem != -56)
+ {
+ puts ("catomic_compare_and_exchange_bool_acq test 3 failed");
+ ret = 1;
+ }
+
+ mem = -1;
+ if (! catomic_compare_and_exchange_bool_acq (&mem, 17, 0)
+ || mem != -1)
+ {
+ puts ("catomic_compare_and_exchange_bool_acq test 4 failed");
+ ret = 1;
+ }
+
+ mem = 2;
+ if (catomic_exchange_and_add (&mem, 11) != 2
+ || mem != 13)
+ {
+ puts ("catomic_exchange_and_add test failed");
+ ret = 1;
+ }
+
+ mem = -21;
+ catomic_add (&mem, 22);
+ if (mem != 1)
+ {
+ puts ("catomic_add test failed");
+ ret = 1;
+ }
+
+ mem = -1;
+ catomic_increment (&mem);
+ if (mem != 0)
+ {
+ puts ("catomic_increment test failed");
+ ret = 1;
+ }
+
+ mem = 2;
+ if (catomic_increment_val (&mem) != 3)
+ {
+ puts ("catomic_increment_val test failed");
+ ret = 1;
+ }
+
+ mem = 17;
+ catomic_decrement (&mem);
+ if (mem != 16)
+ {
+ puts ("catomic_decrement test failed");
+ ret = 1;
+ }
+
+ if (catomic_decrement_val (&mem) != 15)
+ {
+ puts ("catomic_decrement_val test failed");
+ ret = 1;
+ }
+
+ /* Tests for C11-like atomics. */
+ mem = 11;
+ if (atomic_load_relaxed (&mem) != 11 || atomic_load_acquire (&mem) != 11)
+ {
+ puts ("atomic_load_{relaxed,acquire} test failed");
+ ret = 1;
+ }
+
+ atomic_store_relaxed (&mem, 12);
+ if (mem != 12)
+ {
+ puts ("atomic_store_relaxed test failed");
+ ret = 1;
+ }
+ atomic_store_release (&mem, 13);
+ if (mem != 13)
+ {
+ puts ("atomic_store_release test failed");
+ ret = 1;
+ }
+
+ mem = 14;
+ expected = 14;
+ if (!atomic_compare_exchange_weak_relaxed (&mem, &expected, 25)
+ || mem != 25 || expected != 14)
+ {
+ puts ("atomic_compare_exchange_weak_relaxed test 1 failed");
+ ret = 1;
+ }
+ if (atomic_compare_exchange_weak_relaxed (&mem, &expected, 14)
+ || mem != 25 || expected != 25)
+ {
+ puts ("atomic_compare_exchange_weak_relaxed test 2 failed");
+ ret = 1;
+ }
+ mem = 14;
+ expected = 14;
+ if (!atomic_compare_exchange_weak_acquire (&mem, &expected, 25)
+ || mem != 25 || expected != 14)
+ {
+ puts ("atomic_compare_exchange_weak_acquire test 1 failed");
+ ret = 1;
+ }
+ if (atomic_compare_exchange_weak_acquire (&mem, &expected, 14)
+ || mem != 25 || expected != 25)
+ {
+ puts ("atomic_compare_exchange_weak_acquire test 2 failed");
+ ret = 1;
+ }
+ mem = 14;
+ expected = 14;
+ if (!atomic_compare_exchange_weak_release (&mem, &expected, 25)
+ || mem != 25 || expected != 14)
+ {
+ puts ("atomic_compare_exchange_weak_release test 1 failed");
+ ret = 1;
+ }
+ if (atomic_compare_exchange_weak_release (&mem, &expected, 14)
+ || mem != 25 || expected != 25)
+ {
+ puts ("atomic_compare_exchange_weak_release test 2 failed");
+ ret = 1;
+ }
+
+ mem = 23;
+ if (atomic_exchange_acquire (&mem, 42) != 23 || mem != 42)
+ {
+ puts ("atomic_exchange_acquire test failed");
+ ret = 1;
+ }
+ mem = 23;
+ if (atomic_exchange_release (&mem, 42) != 23 || mem != 42)
+ {
+ puts ("atomic_exchange_release test failed");
+ ret = 1;
+ }
+
+ mem = 23;
+ if (atomic_fetch_add_relaxed (&mem, 1) != 23 || mem != 24)
+ {
+ puts ("atomic_fetch_add_relaxed test failed");
+ ret = 1;
+ }
+ mem = 23;
+ if (atomic_fetch_add_acquire (&mem, 1) != 23 || mem != 24)
+ {
+ puts ("atomic_fetch_add_acquire test failed");
+ ret = 1;
+ }
+ mem = 23;
+ if (atomic_fetch_add_release (&mem, 1) != 23 || mem != 24)
+ {
+ puts ("atomic_fetch_add_release test failed");
+ ret = 1;
+ }
+ mem = 23;
+ if (atomic_fetch_add_acq_rel (&mem, 1) != 23 || mem != 24)
+ {
+ puts ("atomic_fetch_add_acq_rel test failed");
+ ret = 1;
+ }
+
+ mem = 3;
+ if (atomic_fetch_and_acquire (&mem, 2) != 3 || mem != 2)
+ {
+ puts ("atomic_fetch_and_acquire test failed");
+ ret = 1;
+ }
+
+ mem = 4;
+ if (atomic_fetch_or_relaxed (&mem, 2) != 4 || mem != 6)
+ {
+ puts ("atomic_fetch_or_relaxed test failed");
+ ret = 1;
+ }
+ mem = 4;
+ if (atomic_fetch_or_acquire (&mem, 2) != 4 || mem != 6)
+ {
+ puts ("atomic_fetch_or_acquire test failed");
+ ret = 1;
+ }
+
+ /* This is a single-threaded test, so we can't test the effects of the
+ fences. */
+ atomic_thread_fence_acquire ();
+ atomic_thread_fence_release ();
+ atomic_thread_fence_seq_cst ();
+
+ return ret;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in
index 38c3e19c4..91dfde412 100644
--- a/test/stdlib/Makefile.in
+++ b/test/stdlib/Makefile.in
@@ -10,6 +10,9 @@ TESTS_DISABLED :=
ifeq ($(UCLIBC_HAS_PTY),)
TESTS_DISABLED += ptytest
endif
+ifeq ($(UCLIBC_HAS_ARC4RANDOM),)
+TESTS_DISABLED += testarc4random
+endif
CFLAGS_test-canon = -fPIC
CFLAGS_test-canon2 = -fPIC
diff --git a/test/stdlib/testarc4random.c b/test/stdlib/testarc4random.c
index 4d773aa4b..14ff1cc36 100644
--- a/test/stdlib/testarc4random.c
+++ b/test/stdlib/testarc4random.c
@@ -3,10 +3,8 @@
int main(void)
{
-#ifdef __UCLIBC_HAS_ARC4RANDOM__
int random_number;
random_number = arc4random() % 65536;
printf("%d\n", random_number);
-#endif
return 0;
}