Skip to content

Commit d41f83e

Browse files
authored
Merge pull request #2436 from marxin/improve-utest-coverage
Improve test coverage for utests.
2 parents ee4ca7c + 7ca4ffd commit d41f83e

5 files changed

Lines changed: 199 additions & 3 deletions

File tree

utest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (MSVC AND "${CMAKE_C_COMPILER_ID}" MATCHES Clang)
66
else ()
77
set(OpenBLAS_utest_src
88
utest_main.c
9+
test_min.c
910
test_amax.c
1011
test_ismin.c
1112
test_rotmg.c

utest/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ UTESTBIN=openblas_utest
1111

1212
include $(TOPDIR)/Makefile.system
1313

14-
OBJS=utest_main.o test_amax.o test_ismin.o test_rotmg.o test_axpy.o test_dotu.o test_dsdot.o test_swap.o test_rot.o
14+
OBJS=utest_main.o test_min.o test_amax.o test_ismin.o test_rotmg.o test_axpy.o test_dotu.o test_dsdot.o test_swap.o test_rot.o
1515
#test_rot.o test_swap.o test_axpy.o test_dotu.o test_dsdot.o test_fork.o
1616

1717
ifneq ($(NO_LAPACK), 1)

utest/test_amax.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ CTEST(amax, samax){
4040

4141
te_max=BLASFUNC(samax)(&N, x, &inc);
4242
tr_max=3.3;
43-
43+
4444
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
4545
}
46+
47+
CTEST(amax, damax){
48+
blasint N=3, inc=1;
49+
double te_max=0.0, tr_max=0.0;
50+
double x[]={-1.1, 2.2, -3.3};
51+
52+
te_max=BLASFUNC(damax)(&N, x, &inc);
53+
tr_max=3.3;
54+
55+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
56+
}

utest/test_min.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2016, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
**********************************************************************************/
33+
34+
#include "openblas_utest.h"
35+
36+
CTEST(min, smin_negative){
37+
blasint N=3, inc=1;
38+
float te_min=0.0, tr_min=0.0;
39+
float x[]={-1.1, -2.2, -3.3};
40+
41+
te_min=BLASFUNC(smin)(&N, x, &inc);
42+
tr_min=-3.3;
43+
44+
ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
45+
}
46+
47+
CTEST(min, dmin_positive){
48+
blasint N=3, inc=1;
49+
double te_min=0.0, tr_min=0.0;
50+
double x[]={1.1, 0.0, 3.3};
51+
52+
te_min=BLASFUNC(dmin)(&N, x, &inc);
53+
tr_min=0.0;
54+
55+
ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), DOUBLE_EPS);
56+
}
57+
58+
CTEST(min, smin_zero){
59+
blasint N=3, inc=1;
60+
float te_min=0.0, tr_min=0.0;
61+
float x[]={1.1, 2.2, 0.0};
62+
63+
te_min=BLASFUNC(smin)(&N, x, &inc);
64+
tr_min=0.0;
65+
66+
ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
67+
}
68+
69+
CTEST(max, smax_negative){
70+
blasint N=3, inc=1;
71+
float te_max=0.0, tr_max=0.0;
72+
float x[]={-1.1, -2.2, -3.3};
73+
74+
te_max=BLASFUNC(smax)(&N, x, &inc);
75+
tr_max=-1.1;
76+
77+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
78+
}
79+
80+
CTEST(max, dmax_positive){
81+
blasint N=3, inc=1;
82+
double te_max=0.0, tr_max=0.0;
83+
double x[]={1.1, 0.0, 3.3};
84+
85+
te_max=BLASFUNC(dmax)(&N, x, &inc);
86+
tr_max=3.3;
87+
88+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
89+
}
90+
91+
CTEST(max, smax_zero){
92+
blasint N=3, inc=1;
93+
float te_max=0.0, tr_max=0.0;
94+
float x[]={-1.1, -2.2, 0.0};
95+
96+
te_max=BLASFUNC(smax)(&N, x, &inc);
97+
tr_max=0.0;
98+
99+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
100+
}

utest/utest_main2.c

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ CTEST(amax, samax){
5050
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
5151
}
5252

53+
CTEST(amax, damax){
54+
blasint N=3, inc=1;
55+
double te_max=0.0, tr_max=0.0;
56+
double x[]={-1.1, 2.2, -3.3};
57+
58+
te_max=BLASFUNC(damax)(&N, x, &inc);
59+
tr_max=3.3;
60+
61+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
62+
}
63+
5364
CTEST (drotmg,rotmg)
5465
{
5566
double te_d1, tr_d1;
@@ -508,9 +519,82 @@ CTEST(swap,cswap_inc_0)
508519
}
509520
}
510521

522+
CTEST(min, smin_negative){
523+
blasint N=3, inc=1;
524+
float te_min=0.0, tr_min=0.0;
525+
float x[]={-1.1, -2.2, -3.3};
526+
527+
te_min=BLASFUNC(smin)(&N, x, &inc);
528+
tr_min=-3.3;
529+
530+
ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
531+
}
532+
533+
CTEST(min, dmin_positive){
534+
blasint N=3, inc=1;
535+
double te_min=0.0, tr_min=0.0;
536+
double x[]={1.1, 0.0, 3.3};
537+
538+
te_min=BLASFUNC(dmin)(&N, x, &inc);
539+
tr_min=0.0;
540+
541+
ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), DOUBLE_EPS);
542+
}
543+
544+
CTEST(min, smin_zero){
545+
blasint N=3, inc=1;
546+
float te_min=0.0, tr_min=0.0;
547+
float x[]={1.1, 2.2, 0.0};
548+
549+
te_min=BLASFUNC(smin)(&N, x, &inc);
550+
tr_min=0.0;
551+
552+
ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
553+
}
554+
555+
CTEST(max, smax_negative){
556+
blasint N=3, inc=1;
557+
float te_max=0.0, tr_max=0.0;
558+
float x[]={-1.1, -2.2, -3.3};
559+
560+
te_max=BLASFUNC(smax)(&N, x, &inc);
561+
tr_max=-1.1;
562+
563+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
564+
}
565+
566+
CTEST(max, dmax_positive){
567+
blasint N=3, inc=1;
568+
double te_max=0.0, tr_max=0.0;
569+
double x[]={1.1, 0.0, 3.3};
570+
571+
te_max=BLASFUNC(dmax)(&N, x, &inc);
572+
tr_max=3.3;
573+
574+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
575+
}
576+
577+
CTEST(max, smax_zero){
578+
blasint N=3, inc=1;
579+
float te_max=0.0, tr_max=0.0;
580+
float x[]={-1.1, -2.2, 0.0};
581+
582+
te_max=BLASFUNC(smax)(&N, x, &inc);
583+
tr_max=0.0;
584+
585+
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
586+
}
587+
511588
int main(int argc, const char ** argv){
512589

513-
CTEST_ADD(amax, samax);
590+
CTEST_ADD (amax, samax);
591+
CTEST_ADD (amax, damax);
592+
CTEST_ADD (min, smin_negative);
593+
CTEST_ADD (min, dmin_positive);
594+
CTEST_ADD (min, smin_zero);
595+
CTEST_ADD (max, smax_negative);
596+
CTEST_ADD (max, dmax_positive);
597+
CTEST_ADD (max, smax_zero);
514598
CTEST_ADD (drotmg,rotmg);
515599
CTEST_ADD (drotmg,rotmg_issue1452);
516600
CTEST_ADD (drotmg,rotmg_D1eqD2_X1eqX2);

0 commit comments

Comments
 (0)