From f334556476cd9c33d3a9d8df9af0dfae798dc9ae Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Mar 2015 20:54:38 +0100 Subject: test: Tweak arc4random exclusion Signed-off-by: Bernhard Reutner-Fischer --- test/stdlib/Makefile.in | 4 +++- test/stdlib/testarc4random.c | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in index 53e5a7280..f39941dc2 100644 --- a/test/stdlib/Makefile.in +++ b/test/stdlib/Makefile.in @@ -10,4 +10,6 @@ TESTS_DISABLED := ifeq ($(UCLIBC_HAS_PTY),) TESTS_DISABLED += ptytest endif - +ifeq ($(UCLIBC_HAS_ARC4RANDOM),) +TESTS_DISABLED += testarc4random +endif 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; } -- cgit v1.2.3 From 78e6494c2cf677d170a5c4ce0f46d152d478abc0 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 22:32:13 +0100 Subject: test: skip arc4random on glibc Signed-off-by: Bernhard Reutner-Fischer --- test/stdlib/Makefile.in | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in index f39941dc2..df3440a39 100644 --- a/test/stdlib/Makefile.in +++ b/test/stdlib/Makefile.in @@ -7,9 +7,12 @@ DODIFF_teston_exit := 1 DODIFF_teststrtol := 1 TESTS_DISABLED := +GLIBC_TESTS_DISABLED := ifeq ($(UCLIBC_HAS_PTY),) TESTS_DISABLED += ptytest endif ifeq ($(UCLIBC_HAS_ARC4RANDOM),) TESTS_DISABLED += testarc4random +else +GLIBC_TESTS_DISABLED += testarc4random endif -- cgit v1.2.3 From 6c4538905e65ceb203f59aaa9a61728e81c6bc0a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 22:32:22 +0100 Subject: libm: Add missing C99 float/ld wrappers Signed-off-by: Bernhard Reutner-Fischer --- test/math/compile_test.c | 20 ++++++++--------- test/math/libm-test.inc | 56 +++++++++++++++++++++--------------------------- 2 files changed, 35 insertions(+), 41 deletions(-) (limited to '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..8f0db3c88 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 #include @@ -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) { @@ -3629,7 +3633,6 @@ modf_test (void) } -#if 0 static void nearbyint_test (void) { @@ -3710,7 +3713,6 @@ nexttoward_test (void) END (nexttoward); } -#endif static void @@ -3950,7 +3952,6 @@ remainder_test (void) END (remainder); } -#if 0 static void remquo_test (void) { @@ -3981,7 +3982,6 @@ remquo_test (void) END (remquo); } -#endif static void rint_test (void) @@ -4229,12 +4229,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 +4285,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 +4312,6 @@ scalbn_test (void) } -#if 0 static void scalbln_test (void) { @@ -4334,7 +4332,6 @@ scalbln_test (void) END (scalbn); } -#endif static void @@ -4539,7 +4536,6 @@ tanh_test (void) END (tanh); } -#if 0 static void tgamma_test (void) { @@ -4571,7 +4567,6 @@ tgamma_test (void) END (tgamma); } -#endif #if 0 @@ -4651,7 +4646,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) { @@ -4979,11 +4974,11 @@ main (int argc, char **argv) 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 +4993,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 +5016,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 +5031,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 +5063,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 (); -- cgit v1.2.3 From fdebbe2044653c5c84172524ed6e036d38716d88 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: test: enable libm test log2 Signed-off-by: Bernhard Reutner-Fischer --- test/math/libm-test.inc | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test') diff --git a/test/math/libm-test.inc b/test/math/libm-test.inc index 8f0db3c88..f50b48b81 100644 --- a/test/math/libm-test.inc +++ b/test/math/libm-test.inc @@ -3418,8 +3418,6 @@ log1p_test (void) END (log1p); } - -#if 0 static void log2_test (void) { @@ -3449,8 +3447,6 @@ log2_test (void) END (log2); } -#endif - static void logb_test (void) @@ -4968,9 +4964,7 @@ main (int argc, char **argv) log_test (); log10_test (); log1p_test (); -#if 0 log2_test (); -#endif logb_test (); modf_test (); ilogb_test (); -- cgit v1.2.3 From 63729418992d5f63965a88fa2ac3570e3d270479 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: test: add utmpx test Signed-off-by: Bernhard Reutner-Fischer --- test/.gitignore | 1 + test/misc/Makefile.in | 4 ++++ test/misc/tst-utmp.c | 15 +++++++++++++++ test/misc/tst-utmpx.c | 2 ++ 4 files changed, 22 insertions(+) create mode 100644 test/misc/tst-utmpx.c (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore index 5944f0a0f..beb50958d 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 diff --git a/test/misc/Makefile.in b/test/misc/Makefile.in index 1e0da6f43..2fb9652fd 100644 --- a/test/misc/Makefile.in +++ b/test/misc/Makefile.in @@ -16,6 +16,10 @@ ifeq ($(UCLIBC_HAS_GLOB),) TESTS_DISABLED += bug-glob2 endif +ifeq ($(UCLIBC_HAS_UTMPX),) +TESTS_DISABLED += tst-utmpx +endif + DODIFF_dirent := 1 DODIFF_dirent64 := 1 DODIFF_tst-statfs := 1 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 #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" -- cgit v1.2.3 From 6ff9c31abc14f207265ab214370982ecb3bfe428 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:45 +0100 Subject: utmp: favour POSIX utmpx over SVID utmp Note: _PATH_UTMPX == _PATH_UTMP and the utmp struct is identical to the utmpx struct so this only changes the external API entrypoints and NOT the underlying data source. This saves about 500b (~1300b from previously ~1950) while at it. Signed-off-by: Bernhard Reutner-Fischer --- test/misc/Makefile.in | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/misc/Makefile.in b/test/misc/Makefile.in index 2fb9652fd..09f631fe3 100644 --- a/test/misc/Makefile.in +++ b/test/misc/Makefile.in @@ -20,6 +20,10 @@ 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 -- cgit v1.2.3 From 9e552e6a2d836698834d2bf887dbf1806172729f Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:52 +0100 Subject: test: tweaks Fix arc4random exclusion for real. Silence warning about missing prototype for external helper-function in tst-scandir Signed-off-by: Bernhard Reutner-Fischer --- test/misc/tst-scandir.c | 2 +- test/stdlib/Makefile.in | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'test') 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 /* perror() */ #include -int skip_all(const struct dirent *dirbuf) +static int skip_all(const struct dirent *dirbuf) { errno = EBADF; return 0; diff --git a/test/stdlib/Makefile.in b/test/stdlib/Makefile.in index df3440a39..e1cbccfca 100644 --- a/test/stdlib/Makefile.in +++ b/test/stdlib/Makefile.in @@ -11,8 +11,9 @@ GLIBC_TESTS_DISABLED := ifeq ($(UCLIBC_HAS_PTY),) TESTS_DISABLED += ptytest endif + ifeq ($(UCLIBC_HAS_ARC4RANDOM),) TESTS_DISABLED += testarc4random else -GLIBC_TESTS_DISABLED += testarc4random +GLIBC_TESTS_DISABLED += testarc4random_glibc endif -- cgit v1.2.3 From 560f416794403be952e850756d7e8b23e8fa92ac Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 22:51:16 +0100 Subject: test: Add SIMULATOR_uclibc and SIMULATOR_glibc where SIMULATOR_glibc is an optional simulator to run host binaries and SIMULATOR_uclibc is an optional simulator to run target (uClibc) binaries. Signed-off-by: Bernhard Reutner-Fischer --- test/README | 3 +++ test/Test.mak | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'test') 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) -- cgit v1.2.3 From cc8d7d062e2db0a1ed3973e6af38cd1938ba74d7 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 23:12:38 +0100 Subject: include: update atomic.h from glibc Signed-off-by: Bernhard Reutner-Fischer --- test/.gitignore | 2 + test/silly/Makefile.in | 3 + test/silly/hello.c | 2 +- test/silly/tst-atomic-long.c | 27 ++ test/silly/tst-atomic.c | 573 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 606 insertions(+), 1 deletion(-) create mode 100644 test/silly/tst-atomic-long.c create mode 100644 test/silly/tst-atomic.c (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore index beb50958d..0d19285e9 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -263,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/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 +#include #include 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 , 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 + . */ + +#include + +#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 , 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 + . */ + +#include +#include + +#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" -- cgit v1.2.3