Skip to content

Commit edc6bc5

Browse files
authored
Merge pull request #489 from christoph-conrads/python2-in-hashbang
lapack_testing.py: python2 explicit in hashbang
2 parents 47a4a75 + a51f8ba commit edc6bc5

File tree

4 files changed

+61
-56
lines changed

4 files changed

+61
-56
lines changed

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,14 @@ option(BUILD_TESTING "Build tests" ${_is_coverage_build})
179179
include(CTest)
180180
message(STATUS "Build tests: ${BUILD_TESTING}")
181181

182-
# lapack_testing.py uses features from python 2.7 and greater
183182
if(BUILD_TESTING)
184-
set(_msg "Looking for Python >= 2.7 needed for summary tests")
183+
set(_msg "Looking for Python3 needed for summary tests")
185184
message(STATUS "${_msg}")
186-
find_package(PythonInterp 2.7 QUIET)
187-
if(PYTHONINTERP_FOUND)
188-
message(STATUS "${_msg} - found (${PYTHON_VERSION_STRING})")
185+
# find_package(PythonInterp 3) cannot be used because /usr/bin/python may be
186+
# a Python2 interpreter.
187+
find_program(PYTHON_EXECUTABLE python3)
188+
if(PYTHON_EXECUTABLE)
189+
message(STATUS "${_msg} - found")
189190
else()
190191
message(STATUS "${_msg} - not found (skipping summary tests)")
191192
endif()

CTestCustom.cmake.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION
4646
"Warning: File .* has modification time .* in the future"
4747
)
4848

49-
# Only rung post test if suitable python interpreter was found
50-
set(PYTHONINTERP_FOUND @PYTHONINTERP_FOUND@)
49+
# Only run post test if suitable python interpreter was found
5150
set(PYTHON_EXECUTABLE @PYTHON_EXECUTABLE@)
52-
if(PYTHONINTERP_FOUND)
51+
if(PYTHON_EXECUTABLE)
5352
set(CTEST_CUSTOM_POST_TEST "${PYTHON_EXECUTABLE} ./lapack_testing.py -s -d TESTING")
5453
endif()
5554

TESTING/CMakeLists.txt

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ if(MSVC_VERSION)
66
endif()
77
add_subdirectory(LIN)
88
add_subdirectory(EIG)
9-
macro(add_lapack_test output input target)
9+
10+
11+
# Only run this test if python 3 is found
12+
if(PYTHON_EXECUTABLE)
13+
message(STATUS "Running Summary")
14+
file(COPY ${LAPACK_SOURCE_DIR}/lapack_testing.py DESTINATION ${LAPACK_BINARY_DIR})
15+
add_test(
16+
NAME LAPACK_Test_Summary
17+
WORKING_DIRECTORY ${LAPACK_BINARY_DIR}
18+
COMMAND ${PYTHON_EXECUTABLE} "lapack_testing.py"
19+
)
20+
endif()
21+
22+
function(add_lapack_test output input target)
1023
set(TEST_INPUT "${LAPACK_SOURCE_DIR}/TESTING/${input}")
1124
set(TEST_OUTPUT "${LAPACK_BINARY_DIR}/TESTING/${output}")
1225
string(REPLACE "." "_" input_name ${input})
@@ -18,8 +31,15 @@ macro(add_lapack_test output input target)
1831
-DOUTPUT=${TEST_OUTPUT}
1932
-DINTDIR=${CMAKE_CFG_INTDIR}
2033
-P "${LAPACK_SOURCE_DIR}/TESTING/runtest.cmake")
34+
35+
if(PYTHONINTERP_FOUND)
36+
set_property(
37+
TEST LAPACK_Test_Summary
38+
APPEND PROPERTY DEPENDS LAPACK-${testName}
39+
)
40+
endif()
2141
endif()
22-
endmacro()
42+
endfunction()
2343

2444
if(BUILD_SINGLE)
2545
add_lapack_test(stest.out stest.in xlintsts)
@@ -156,15 +176,3 @@ if(BUILD_COMPLEX AND BUILD_COMPLEX16)
156176
# ======== COMPLEX-COMPLEX16 LIN TESTS ========================
157177
add_lapack_test(zctest.out zctest.in xlintstzc)
158178
endif()
159-
160-
# ==============================================================================
161-
# Only run this test if python 2.7 or greater is found
162-
if(PYTHONINTERP_FOUND)
163-
message(STATUS "Running Summary")
164-
file(COPY ${LAPACK_SOURCE_DIR}/lapack_testing.py DESTINATION ${LAPACK_BINARY_DIR})
165-
add_test(
166-
NAME LAPACK_Test_Summary
167-
WORKING_DIRECTORY ${LAPACK_BINARY_DIR}
168-
COMMAND ${PYTHON_EXECUTABLE} "lapack_testing.py"
169-
)
170-
endif()

lapack_testing.py

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
#! /usr/bin/env python
2-
# -*- coding: utf-8 -*-
1+
#!/usr/bin/env python3
32

43

54
###############################################################################
65
# lapack_testing.py
76
###############################################################################
87

9-
from __future__ import print_function
108
from subprocess import Popen, STDOUT, PIPE
119
import os, sys, math
1210
import getopt
1311
# Arguments
1412
try:
1513
opts, args = getopt.getopt(sys.argv[1:], "hd:b:srep:t:n",
16-
["help", "dir", "bin", "short", "run", "error","prec=","test=","number"])
14+
["help", "dir=", "bin=", "short", "run", "error","prec=","test=","number"])
1715

1816
except getopt.error as msg:
1917
print(msg)
2018
print("for help use --help")
2119
sys.exit(2)
2220

23-
short_summary=0
24-
with_file=1
25-
just_errors = 0
21+
short_summary = False
22+
with_file = True
23+
just_errors = False
2624
prec='x'
2725
test='all'
28-
only_numbers=0
26+
only_numbers = False
2927
test_dir='TESTING'
3028
bin_dir='bin/Release'
3129

@@ -34,10 +32,9 @@
3432
print(sys.argv[0]+" [-h|--help] [-d dir |--dir dir] [-s |--short] [-r |--run] [-e |--error] [-p p |--prec p] [-t test |--test test] [-n | --number]")
3533
print(" - h is to print this message")
3634
print(" - r is to use to run the LAPACK tests then analyse the output (.out files). By default, the script will not run all the LAPACK tests")
37-
print(" - d [dir] is to indicate where is the LAPACK testing directory (.out files). By default, the script will use .")
38-
print(" - b [bin] is to indicate where is the LAPACK binary files are located. By default, the script will use .")
35+
print(" - d [dir] indicates the location of the LAPACK testing directory (.out files). By default, the script will use {:s}.".format(test_dir))
36+
print(" - b [bin] indicates the location of the LAPACK binary files. By default, the script will use {:s}.".format(bin_dir))
3937
print(" LEVEL OF OUTPUT")
40-
print(" - x is to print a detailed summary")
4138
print(" - e is to print only the error summary")
4239
print(" - s is to print a short summary")
4340
print(" - n is to print the numbers of failing tests (turn on summary mode)")
@@ -67,11 +64,11 @@
6764
sys.exit(0)
6865
else:
6966
if o in ("-s", "--short"):
70-
short_summary = 1
67+
short_summary = True
7168
if o in ("-r", "--run"):
72-
with_file = 0
69+
with_file = False
7370
if o in ("-e", "--error"):
74-
just_errors = 1
71+
just_errors = True
7572
if o in ( '-p', '--prec' ):
7673
prec = a
7774
if o in ( '-b', '--bin' ):
@@ -81,12 +78,12 @@
8178
if o in ( '-t', '--test' ):
8279
test = a
8380
if o in ( '-n', '--number' ):
84-
only_numbers = 1
85-
short_summary = 1
81+
only_numbers = True
82+
short_summary = True
8683

8784
# process options
8885

89-
abs_bin_dir=os.path.normpath(os.path.join(os.getcwd(),bin_dir))
86+
abs_bin_dir=os.path.abspath(bin_dir)
9087

9188
os.chdir(test_dir)
9289

@@ -108,7 +105,7 @@ def run_summary_test( f, cmdline, short_summary):
108105
nb_test_illegal=0
109106
nb_test_info=0
110107

111-
if (with_file):
108+
if with_file:
112109
if not os.path.exists(cmdline):
113110
error_message=cmdline+" file not found"
114111
r=1
@@ -145,16 +142,16 @@ def run_summary_test( f, cmdline, short_summary):
145142
whereisrun=words_in_line.index("run)")
146143
nb_test_run+=int(words_in_line[whereisrun-2])
147144
if (line.find("out of")!=-1):
148-
if (short_summary==0): print(line, end=' ')
145+
if not short_summary: print(line, end=' ')
149146
whereisout= words_in_line.index("out")
150147
nb_test_fail+=int(words_in_line[whereisout-1])
151148
if ((line.find("illegal")!=-1) or (line.find("Illegal")!=-1)):
152-
if (short_summary==0):print(line, end=' ')
149+
if not short_summary: print(line, end=' ')
153150
nb_test_illegal+=1
154151
if (line.find(" INFO")!=-1):
155-
if (short_summary==0):print(line, end=' ')
152+
if not short_summary: print(line, end=' ')
156153
nb_test_info+=1
157-
if (with_file==1):
154+
if with_file:
158155
pipe.close()
159156

160157
f.flush();
@@ -169,7 +166,7 @@ def run_summary_test( f, cmdline, short_summary):
169166
except IOError:
170167
f = sys.stdout
171168

172-
if (short_summary==0):
169+
if not short_summary:
173170
print(" ")
174171
print("---------------- Testing LAPACK Routines ----------------")
175172
print(" ")
@@ -219,7 +216,7 @@ def run_summary_test( f, cmdline, short_summary):
219216
letter = dtypes[0][dtype]
220217
name = dtypes[1][dtype]
221218

222-
if (short_summary==0):
219+
if not short_summary:
223220
print(" ")
224221
print("------------------------- %s ------------------------" % name)
225222
print(" ")
@@ -252,7 +249,7 @@ def run_summary_test( f, cmdline, short_summary):
252249
# NEED TO SKIP SOME PRECISION (namely s and c) FOR PROTO MIXED PRECISION TESTING
253250
if dtest==17 and (letter=="s" or letter=="c"):
254251
continue
255-
if (with_file==1):
252+
if with_file:
256253
cmdbase=dtests[2][dtest]+".out"
257254
else:
258255
if dtest==16:
@@ -267,7 +264,7 @@ def run_summary_test( f, cmdline, short_summary):
267264
else:
268265
# EIG TESTS
269266
cmdbase="xeigtst"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
270-
if (not just_errors and not short_summary):
267+
if not just_errors and not short_summary:
271268
print("Testing "+name+" "+dtests[1][dtest]+"-"+cmdbase, end=' ')
272269
# Run the process: either to read the file or run the LAPACK testing
273270
nb_test = run_summary_test(f, cmdbase, short_summary)
@@ -277,19 +274,19 @@ def run_summary_test( f, cmdline, short_summary):
277274
list_results[3][dtype]+=nb_test[3]
278275
got_error=nb_test[1]+nb_test[2]+nb_test[3]
279276

280-
if (not short_summary):
281-
if (nb_test[0]>0 and just_errors==0):
277+
if not short_summary:
278+
if nb_test[0] > 0 and not just_errors:
282279
print("passed: "+str(nb_test[0]))
283-
if (nb_test[1]>0):
280+
if nb_test[1] > 0:
284281
print("failing to pass the threshold: "+str(nb_test[1]))
285-
if (nb_test[2]>0):
282+
if nb_test[2] > 0:
286283
print("Illegal Error: "+str(nb_test[2]))
287-
if (nb_test[3]>0):
284+
if nb_test[3] > 0:
288285
print("Info Error: "+str(nb_test[3]))
289-
if (got_error>0 and just_errors==1):
286+
if got_error > 0 and just_errors:
290287
print("ERROR IS LOCATED IN "+name+" "+dtests[1][dtest]+" [ "+cmdbase+" ]")
291288
print("")
292-
if (just_errors==0):
289+
if not just_errors:
293290
print("")
294291
# elif (got_error>0):
295292
# print dtests[2][dtest]+".out \t"+str(nb_test[1])+"\t"+str(nb_test[2])+"\t"+str(nb_test[3])
@@ -307,7 +304,7 @@ def run_summary_test( f, cmdline, short_summary):
307304
list_results[2][4]+=list_results[2][dtype]
308305
list_results[3][4]+=list_results[3][dtype]
309306

310-
if only_numbers==1:
307+
if only_numbers:
311308
print(str(list_results[1][4])+"\n"+str(list_results[2][4]+list_results[3][4]))
312309
else:
313310
print(summary)

0 commit comments

Comments
 (0)