Skip to content

Commit

Permalink
Merge pull request #22 from rivosinc/dev/PingTakPeterTang/test_modifi…
Browse files Browse the repository at this point in the history
…cations

add EXPECT in a workhorse test function; modify number of test arguments
  • Loading branch information
PingTakPeterTang authored Mar 6, 2024
2 parents 06e7c15 + 19f92ef commit b5e524a
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 88 deletions.
122 changes: 61 additions & 61 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@

set(TEST_SOURCES
src/test_infra.cpp
src/test_acos.cpp
src/test_acosI.cpp
src/test_acospi.cpp
src/test_acospiI.cpp
src/test_asin.cpp
src/test_asinI.cpp
src/test_asinpi.cpp
src/test_asinpiI.cpp
src/test_atan.cpp
src/test_atanI.cpp
src/test_atanpi.cpp
src/test_atanpiI.cpp
src/test_atan2.cpp
src/test_atan2I.cpp
src/test_atan2pi.cpp
src/test_atan2piI.cpp
src/test_acosh.cpp
src/test_acoshI.cpp
src/test_asinh.cpp
src/test_asinhI.cpp
src/test_atanh.cpp
src/test_atanhI.cpp
src/test_cbrt.cpp
src/test_cbrtI.cpp
src/test_cdfnorm.cpp
src/test_cdfnormI.cpp
src/test_erf.cpp
src/test_erfI.cpp
src/test_erfc.cpp
src/test_erfcI.cpp
# src/test_acos.cpp
# src/test_acosI.cpp
# src/test_acospi.cpp
# src/test_acospiI.cpp
# src/test_asin.cpp
# src/test_asinI.cpp
# src/test_asinpi.cpp
# src/test_asinpiI.cpp
# src/test_atan.cpp
# src/test_atanI.cpp
# src/test_atanpi.cpp
# src/test_atanpiI.cpp
# src/test_atan2.cpp
# src/test_atan2I.cpp
# src/test_atan2pi.cpp
# src/test_atan2piI.cpp
# src/test_acosh.cpp
# src/test_acoshI.cpp
# src/test_asinh.cpp
# src/test_asinhI.cpp
# src/test_atanh.cpp
# src/test_atanhI.cpp
# src/test_cbrt.cpp
# src/test_cbrtI.cpp
# src/test_cdfnorm.cpp
# src/test_cdfnormI.cpp
# src/test_erf.cpp
# src/test_erfI.cpp
# src/test_erfc.cpp
# src/test_erfcI.cpp
src/test_exp.cpp
src/test_expI.cpp
src/test_exp2.cpp
Expand All @@ -42,37 +42,37 @@ set(TEST_SOURCES
src/test_exp10I.cpp
src/test_expm1.cpp
src/test_expm1I.cpp
src/test_log.cpp
src/test_logI.cpp
src/test_log2.cpp
src/test_log2I.cpp
src/test_log10.cpp
src/test_log10I.cpp
src/test_log1p.cpp
src/test_log1pI.cpp
src/test_pow.cpp
src/test_powI.cpp
src/test_cos.cpp
src/test_cosI.cpp
src/test_sin.cpp
src/test_sinI.cpp
src/test_cospi.cpp
src/test_cospiI.cpp
src/test_sinpi.cpp
src/test_sinpiI.cpp
src/test_sincos.cpp
src/test_sincosI.cpp
src/test_sincospi.cpp
src/test_sincospiI.cpp
src/test_tan.cpp
src/test_tanI.cpp
src/test_tanpi.cpp
src/test_cosh.cpp
src/test_coshI.cpp
src/test_sinh.cpp
src/test_sinhI.cpp
src/test_tanh.cpp
src/test_tanhI.cpp
# src/test_log.cpp
# src/test_logI.cpp
# src/test_log2.cpp
# src/test_log2I.cpp
# src/test_log10.cpp
# src/test_log10I.cpp
# src/test_log1p.cpp
# src/test_log1pI.cpp
# src/test_pow.cpp
# src/test_powI.cpp
# src/test_cos.cpp
# src/test_cosI.cpp
# src/test_sin.cpp
# src/test_sinI.cpp
# src/test_cospi.cpp
# src/test_cospiI.cpp
# src/test_sinpi.cpp
# src/test_sinpiI.cpp
# src/test_sincos.cpp
# src/test_sincosI.cpp
# src/test_sincospi.cpp
# src/test_sincospiI.cpp
# src/test_tan.cpp
# src/test_tanI.cpp
# src/test_tanpi.cpp
# src/test_cosh.cpp
# src/test_coshI.cpp
# src/test_sinh.cpp
# src/test_sinhI.cpp
# src/test_tanh.cpp
# src/test_tanhI.cpp
)

add_executable(test_veclibm ${TEST_SOURCES})
Expand Down
3 changes: 2 additions & 1 deletion test/include/test_infra.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
{ printf("\n=====\t" comment "\n"); }

void report_err_fp64(void (*test_func)(size_t, const double *, double *),
long double (*ref_func)(long double), double, double, int);
long double (*ref_func)(long double), double, double, int,
double = 1.0);

void report_err_fp64(void (*test_func)(size_t, const double *, double *,
double *),
Expand Down
35 changes: 27 additions & 8 deletions test/src/test_exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(exp, test) {
TEST(exp, small_args) {
unsigned long nb_tests;
double x_start, x_end;

Expand All @@ -18,26 +18,45 @@ TEST(exp, test) {

x_start = -0.34;
x_end = 0.34;
nb_tests = 3000000;
nb_tests = 100000;
report_err_fp64(rvvlm_exp, expl, x_start, x_end, nb_tests);

x_start = -3.0;
x_end = 3.0;
nb_tests = 4000000;
nb_tests = 100000;
report_err_fp64(rvvlm_exp, expl, x_start, x_end, nb_tests);
}

TEST(exp, medium_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp: current chosen algorithm; reduced argument in FP64 only")

x_start = -15.0;
x_end = -10.0;
nb_tests = 100000;
report_err_fp64(rvvlm_exp, expl, x_start, x_end, nb_tests);

x_start = 10.0;
x_end = 15.0;
nb_tests = 4000000;
x_start = 15.0;
x_end = 10.0;
nb_tests = 100000;
report_err_fp64(rvvlm_exp, expl, x_start, x_end, nb_tests);
}

TEST(exp, large_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp: current chosen algorithm; reduced argument in FP64 only")

x_start = 700.0;
x_end = 709.0;
nb_tests = 4000000;
nb_tests = 100000;
report_err_fp64(rvvlm_exp, expl, x_start, x_end, nb_tests);

x_start = -740.0;
x_end = -709.0;
nb_tests = 400000;
nb_tests = 100000;
report_err_fp64(rvvlm_exp, expl, x_start, x_end, nb_tests);
}
27 changes: 23 additions & 4 deletions test/src/test_exp10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(exp10, test) {
TEST(exp10, small_args) {
unsigned long nb_tests;
double x_start, x_end;

Expand All @@ -18,18 +18,37 @@ TEST(exp10, test) {

x_start = -0.34;
x_end = 0.34;
nb_tests = 3000000;
nb_tests = 300000;
report_err_fp64(rvvlm_exp10, exp10l, x_start, x_end, nb_tests);

x_start = -3.0;
x_end = 3.0;
nb_tests = 4000000;
nb_tests = 400000;
report_err_fp64(rvvlm_exp10, exp10l, x_start, x_end, nb_tests);
}

TEST(exp10, medium_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp10: current chosen algorithm; reduced argument in FP64 only")

x_start = -15.0;
x_end = -10.0;
nb_tests = 400000;
report_err_fp64(rvvlm_exp10, exp10l, x_start, x_end, nb_tests);

x_start = 10.0;
x_end = 15.0;
nb_tests = 4000000;
nb_tests = 400000;
report_err_fp64(rvvlm_exp10, exp10l, x_start, x_end, nb_tests);
}

TEST(exp10, large_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp10: current chosen algorithm; reduced argument in FP64 only")

x_start = 295.0;
x_end = 308.0;
Expand Down
31 changes: 25 additions & 6 deletions test/src/test_exp2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(exp2, test) {
TEST(exp2, small_args) {
unsigned long nb_tests;
double x_start, x_end;

Expand All @@ -18,26 +18,45 @@ TEST(exp2, test) {

x_start = -0.34;
x_end = 0.34;
nb_tests = 3000000;
nb_tests = 300000;
report_err_fp64(rvvlm_exp2, exp2l, x_start, x_end, nb_tests);

x_start = -3.0;
x_end = 3.0;
nb_tests = 4000000;
nb_tests = 400000;
report_err_fp64(rvvlm_exp2, exp2l, x_start, x_end, nb_tests);
}

TEST(exp2, medium_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp2: current chosen algorithm; reduced argument in FP64 only")

x_start = -14.0;
x_end = -10.0;
nb_tests = 400000;
report_err_fp64(rvvlm_exp2, exp2l, x_start, x_end, nb_tests);

x_start = 10.0;
x_end = 15.0;
nb_tests = 4000000;
nb_tests = 400000;
report_err_fp64(rvvlm_exp2, exp2l, x_start, x_end, nb_tests);
}

TEST(exp2, large_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp2: current chosen algorithm; reduced argument in FP64 only")

x_start = 1010.0;
x_end = 1023.0;
nb_tests = 400000;
nb_tests = 40000;
report_err_fp64(rvvlm_exp2, exp2l, x_start, x_end, nb_tests);

x_start = -1070.;
x_end = -1020.0;
nb_tests = 400000;
nb_tests = 40000;
report_err_fp64(rvvlm_exp2, exp2l, x_start, x_end, nb_tests);
}
28 changes: 21 additions & 7 deletions test/src/test_expm1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(expm1, test) {
TEST(expm1, small_args) {
unsigned long nb_tests;
double x_start, x_end;

Expand All @@ -18,33 +18,47 @@ TEST(expm1, test) {

x_start = -0.01;
x_end = 0.01;
nb_tests = 3000000;
nb_tests = 300000;
report_err_fp64(rvvlm_expm1, expm1l, x_start, x_end, nb_tests);

x_start = -.3;
x_end = 0.3;
nb_tests = 4000000;
nb_tests = 100000;
report_err_fp64(rvvlm_expm1, expm1l, x_start, x_end, nb_tests);
}

TEST(expm1, medium_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("expm1: current chosen algorithm; reduced argument in FP64 only")

x_start = 1.0;
x_end = 10.0;
nb_tests = 4000000;
nb_tests = 100000;
report_err_fp64(rvvlm_expm1, expm1l, x_start, x_end, nb_tests);

x_start = -10.0;
x_end = -1.0;
nb_tests = 4000000;
nb_tests = 100000;
report_err_fp64(rvvlm_expm1, expm1l, x_start, x_end, nb_tests);

x_start = -40.0;
x_end = -36.0;
nb_tests = 400000;
nb_tests = 10000;
report_err_fp64(rvvlm_expm1, expm1l, x_start, x_end, nb_tests);

x_start = 36.0;
x_end = 40.0;
nb_tests = 4000000;
nb_tests = 100000;
report_err_fp64(rvvlm_expm1, expm1l, x_start, x_end, nb_tests);
}

TEST(expm1, large_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("expm1: current chosen algorithm; reduced argument in FP64 only")

x_start = 700.0;
x_end = 709.0;
Expand Down
4 changes: 3 additions & 1 deletion test/src/test_infra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void report_err_fp64(void (*test_func)(size_t, const double *, double *),

void report_err_fp64(void (*test_func)(size_t, const double *, double *),
long double (*ref_func)(long double), double start,
double end, int nb_pts) {
double end, int nb_pts, double threshold) {

long double y_ref;
double *x, *y, delta;
Expand Down Expand Up @@ -208,6 +208,8 @@ void report_err_fp64(void (*test_func)(size_t, const double *, double *),
}
printf("Maximum observed ULP error is %3.3Lf\n", max_ulp_err);

EXPECT_LT((double)max_ulp_err, threshold);

free(x);
free(y);
}
Expand Down

0 comments on commit b5e524a

Please sign in to comment.