Merge pull request #3709 from nursik/develop
[platform/upstream/openblas.git] / test / CMakeLists.txt
1 include_directories(${PROJECT_SOURCE_DIR})
2 include_directories(${PROJECT_BINARY_DIR})
3
4 enable_language(Fortran)
5 if (CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
6         set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-tree-vectorize")
7 endif()
8 if (CMAKE_Fortran_COMPILER_ID STREQUAL Flang)
9         set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -O2")
10 endif()
11
12 if (BUILD_SINGLE)
13         list( APPEND OpenBLAS_Tests sblat1 sblat2 sblat3)
14 endif()
15 if (BUILD_DOUBLE)
16         list (APPEND OpenBLAS_Tests dblat1 dblat2 dblat3)
17 endif()
18 if (BUILD_COMPLEX)
19         list (APPEND OpenBLAS_Tests cblat1 cblat2 cblat3)
20 endif()
21 if (BUILD_COMPLEX16)
22         list (APPEND OpenBLAS_Tests zblat1 zblat2 zblat3)
23 endif()
24
25 foreach(test_bin ${OpenBLAS_Tests})
26         add_executable(${test_bin} ${test_bin}.f)
27 target_link_libraries(${test_bin} ${OpenBLAS_LIBNAME})
28 endforeach()
29
30 # $1 exec, $2 input, $3 output_result
31 if(WIN32)
32 FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test_helper.ps1
33 "[Console]::InputEncoding = New-Object Text.UTF8Encoding $false\n"
34 "if (Test-Path $args[2]) { Remove-Item -Force $args[2] } \n"
35 "$ErrorActionPreference = \"Stop\"\n"
36 "Get-Content $args[1] | & $args[0]\n" 
37 "If ((Get-Content $args[2] | %{$_ -match \"FATAL\"}) -contains $true) {\n"
38 "echo Error\n"
39 "exit 1\n"
40 "} else {\n"
41 "exit 0\n"
42 "}\n"
43 )
44 set(helper_prefix powershell -ExecutionPolicy Bypass "${CMAKE_CURRENT_BINARY_DIR}/test_helper.ps1")
45 else()
46 FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test_helper.sh
47 "rm -f $3\n"
48 "$1 < $2\n"
49 "grep -q FATAL $3\n"
50 "if [ $? -eq 0 ]; then\n"
51 "echo Error\n"
52 "exit 1\n"
53 "else\n"
54 "exit 0\n"
55 "fi\n"
56 )
57 set(helper_prefix sh "${CMAKE_CURRENT_BINARY_DIR}/test_helper.sh")
58 endif()
59
60 #set(float_types s d c z)
61 if (BUILD_SINGLE)
62         list (APPEND float_types s)
63 endif()
64 if (BUILD_DOUBLE)
65         list (APPEND float_types d)
66 endif()
67 if (BUILD_COMPLEX)
68         list (APPEND float_types c)
69 endif()
70 if (BUILD_COMPLEX16)
71         list (APPEND float_types z)
72 endif()
73 foreach(float_type ${float_types})
74 string(TOUPPER ${float_type} float_type_upper)
75 add_test(NAME "${float_type}blas1" 
76   COMMAND $<TARGET_FILE:${float_type}blat1>)
77 add_test(NAME "${float_type}blas2" 
78   COMMAND ${helper_prefix} $<TARGET_FILE:${float_type}blat2> "${PROJECT_SOURCE_DIR}/test/${float_type}blat2.dat" ${float_type_upper}BLAT2.SUMM)
79 add_test(NAME "${float_type}blas3" 
80   COMMAND ${helper_prefix} $<TARGET_FILE:${float_type}blat3> "${PROJECT_SOURCE_DIR}/test/${float_type}blat3.dat" ${float_type_upper}BLAT3.SUMM)
81 endforeach()