From 5c8563d1420514e6ef41ce69d87b4061a539880c Mon Sep 17 00:00:00 2001 From: Andrew Bachmann Date: Wed, 18 May 2005 19:38:10 +0000 Subject: [PATCH] add some math tests git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12718 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kernel/libroot/posix/Jamfile | 1 + src/tests/kernel/libroot/posix/math/Jamfile | 27 +++++++++++ .../kernel/libroot/posix/math/math_test.cpp | 47 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/tests/kernel/libroot/posix/math/Jamfile create mode 100644 src/tests/kernel/libroot/posix/math/math_test.cpp diff --git a/src/tests/kernel/libroot/posix/Jamfile b/src/tests/kernel/libroot/posix/Jamfile index 647592dfbb..91b77b9eae 100644 --- a/src/tests/kernel/libroot/posix/Jamfile +++ b/src/tests/kernel/libroot/posix/Jamfile @@ -18,3 +18,4 @@ SEARCH on [ FGristFiles ] = [ FDirName $(OBOS_TOP) src system libroot posix ] ; SubInclude OBOS_TOP src tests kernel libroot posix bonnie ; +SubInclude OBOS_TOP src tests kernel libroot posix math ; diff --git a/src/tests/kernel/libroot/posix/math/Jamfile b/src/tests/kernel/libroot/posix/math/Jamfile new file mode 100644 index 0000000000..cb1e0b3363 --- /dev/null +++ b/src/tests/kernel/libroot/posix/math/Jamfile @@ -0,0 +1,27 @@ +SubDir OBOS_TOP src tests kernel libroot posix math ; + +UsePrivateHeaders libroot ; +SubDirHdrs [ FDirName $(OBOS_TOP) src system libroot posix glibc ] ; +SubDirC++Flags -mieee-fp ; + +MATH_SOURCES = + acosh.c asincos.c asinh.c atan.c + atan2.c atanh.c cabs.c cbrt.c + ceilf.c cosh.c erf.c exp.c + exp__E.c expm1.c floatmath.c floor.c + floorf.c fmod.c gamma.c ieee.c + j0.c j1.c jn.c lgamma.c + log.c log10.c log1p.c log__L.c + math_globals.c pow.c + sincos.c sinh.c tan.c tanh.c + ; + +SimpleTest math_test + : math_test.cpp $(MATH_SOURCES) + ; + + +# Tell Jam where to find these sources +SEARCH on [ FGristFiles + $(MATH_SOURCES) + ] = [ FDirName $(OBOS_TOP) src system libroot posix math ] ; diff --git a/src/tests/kernel/libroot/posix/math/math_test.cpp b/src/tests/kernel/libroot/posix/math/math_test.cpp new file mode 100644 index 0000000000..1c22112a9f --- /dev/null +++ b/src/tests/kernel/libroot/posix/math/math_test.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2005, Andrew Bachmann, andrewbachmann@myrealbox.com + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +static double (*be_sin)(double); +static double (*be_cos)(double); + +static image_id +get_libroot_id() +{ + image_info info; + int32 cookie = 0; + while (get_next_image_info(0, &cookie, &info) == B_OK) { + if (strcmp(info.name, "/boot/beos/system/lib/libroot.so") == 0) { + return info.id; + } + } + return B_BAD_VALUE; +} + + +int +main(int argc, char **argv) +{ + image_id libroot = get_libroot_id(); + assert(get_image_symbol(libroot, "sin", B_SYMBOL_TYPE_TEXT, (void**)&be_sin) == B_OK); + assert(get_image_symbol(libroot, "cos", B_SYMBOL_TYPE_TEXT, (void**)&be_cos) == B_OK); + + fprintf(stdout, "value\t\tsin(value)\tbe_sin(value)\tcos(value)\tbe_cos(value)\n"); + status_t result = B_OK; + for (int i = -10 ; i < 10 ; i++) { + double f = (double)i; + fprintf(stdout, "%0.10f\t%0.10f\t%0.10f\t%0.10f\t%0.10f\n", + f, sin(f), be_sin(f), cos(f), be_cos(f)); + if ((sin(f) != be_sin(f)) || (cos(f) != be_cos(f))) { + result = B_ERROR; + } + } + return result; +}