2 # -*- coding: utf-8 -*-
5 ###############################################################################
7 ###############################################################################
9 from __future__ import print_function
10 from subprocess import Popen, STDOUT, PIPE
15 opts, args = getopt.getopt(sys.argv[1:], "hd:srep:t:n",
16 ["help", "dir", "short", "run", "error","prec=","test=","number"])
18 except getopt.error as msg:
20 print("for help use --help")
32 abs_bin_dir=os.path.normpath(os.path.join(os.getcwd(),bin_dir))
35 if o in ("-h", "--help"):
36 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]")
37 print(" - h is to print this message")
38 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")
39 print(" - d [dir] is to indicate where is the LAPACK testing directory (.out files). By default, the script will use .")
40 print(" LEVEL OF OUTPUT")
41 print(" - x is to print a detailed summary")
42 print(" - e is to print only the error summary")
43 print(" - s is to print a short summary")
44 print(" - n is to print the numbers of failing tests (turn on summary mode)")
45 print(" SECLECTION OF TESTS:")
46 print(" - p [s/c/d/z/x] is to indicate the PRECISION to run:")
49 print(" sd=single/double")
51 print(" z=double complex")
52 print(" cz=complex/double complex")
53 print(" x=all [DEFAULT]")
54 print(" - t [lin/eig/mixed/rfp/all] is to indicate which TEST FAMILY to run:")
55 print(" lin=Linear Equation")
56 print(" eig=Eigen Problems")
57 print(" mixed=mixed-precision")
58 print(" rfp=rfp format")
59 print(" all=all tests [DEFAULT]")
61 print(" ./lapack_testing.py -n")
62 print(" Will return the numbers of failed tests by analyzing the LAPACK output")
63 print(" ./lapack_testing.py -n -r -p s")
64 print(" Will return the numbers of failed tests in REAL precision by running the LAPACK Tests then analyzing the output")
65 print(" ./lapack_testing.py -n -p s -t eig ")
66 print(" Will return the numbers of failed tests in REAL precision by analyzing only the LAPACK output of EIGEN testings")
67 print("Written by Julie Langou (June 2011) ")
70 if o in ("-s", "--short"):
72 if o in ("-r", "--run"):
74 if o in ("-e", "--error"):
76 if o in ( '-p', '--prec' ):
78 if o in ( '-d', '--dir' ):
80 if o in ( '-t', '--test' ):
82 if o in ( '-n', '--number' ):
91 summary="\n\t\t\t--> LAPACK TESTING SUMMARY <--\n";
92 if with_file: summary+= "\t\tProcessing LAPACK Testing output found in the "+test_dir+" directory\n";
93 summary+="SUMMARY \tnb test run \tnumerical error \tother error \n";
94 summary+="================ \t===========\t=================\t================ \n";
97 # Add current directory to the path for subshells of this shell
98 # Allows the popen to find local files in both windows and unixes
99 os.environ["PATH"] = os.environ["PATH"]+":."
101 # Define a function to open the executable (different filenames on unix and Windows)
102 def run_summary_test( f, cmdline, short_summary):
109 if not os.path.exists(cmdline):
110 error_message=cmdline+" file not found"
112 if short_summary: return [nb_test_run,nb_test_fail,nb_test_illegal,nb_test_info]
114 pipe = open(cmdline,'r')
118 cmdline='./' + cmdline
120 cmdline=abs_bin_dir+os.path.sep+cmdline
122 outfile=cmdline.split()[4]
123 #pipe = open(outfile,'w')
124 p = Popen(cmdline, shell=True)#, stdout=pipe)
128 pipe = open(outfile,'r')
129 error_message=cmdline+" did not work"
131 if r != 0 and not with_file:
132 print("---- TESTING " + cmdline.split()[0] + "... FAILED(" + error_message +") !")
133 for line in pipe.readlines():
135 elif r != 0 and with_file and not short_summary:
136 print("---- WARNING: please check that you have the LAPACK output : "+cmdline+"!")
137 print("---- WARNING: with the option -r, we can run the LAPACK testing for you")
138 # print "---- "+error_message
140 for line in pipe.readlines():
142 words_in_line=line.split()
143 if (line.find("run")!=-1):
145 whereisrun=words_in_line.index("run)")
146 nb_test_run+=int(words_in_line[whereisrun-2])
147 if (line.find("out of")!=-1):
148 if (short_summary==0): print(line, end=' ')
149 whereisout= words_in_line.index("out")
150 nb_test_fail+=int(words_in_line[whereisout-1])
151 if ((line.find("illegal")!=-1) or (line.find("Illegal")!=-1)):
152 if (short_summary==0):print(line, end=' ')
154 if (line.find(" INFO")!=-1):
155 if (short_summary==0):print(line, end=' ')
162 return [nb_test_run,nb_test_fail,nb_test_illegal,nb_test_info]
165 # If filename cannot be opened, send output to sys.stderr
166 filename = "testing_results.txt"
168 f = open(filename, 'w')
172 if (short_summary==0):
174 print("---------------- Testing LAPACK Routines ----------------")
176 print("-- Detailed results are stored in", filename)
179 ("s", "d", "c", "z"),
180 ("REAL ", "DOUBLE PRECISION", "COMPLEX ", "COMPLEX16 "),
197 range_prec=list(range(4))
207 range_test=list(range(16))
209 range_test=list(range(19))
218 for dtype in range_prec:
219 letter = dtypes[0][dtype]
220 name = dtypes[1][dtype]
222 if (short_summary==0):
224 print("------------------------- %s ------------------------" % name)
229 ("nep", "sep", "se2", "svd",
230 letter+"ec",letter+"ed",letter+"gg",
231 letter+"gd",letter+"sb",letter+"sg",
232 letter+"bb","glm","gqr",
234 letter+"test", letter+dtypes[0][dtype-1]+"test",letter+"test_rfp"),
235 ("Nonsymmetric-Eigenvalue-Problem", "Symmetric-Eigenvalue-Problem", "Symmetric-Eigenvalue-Problem-2-stage", "Singular-Value-Decomposition",
236 "Eigen-Condition","Nonsymmetric-Eigenvalue","Nonsymmetric-Generalized-Eigenvalue-Problem",
237 "Nonsymmetric-Generalized-Eigenvalue-Problem-driver", "Symmetric-Eigenvalue-Problem", "Symmetric-Eigenvalue-Generalized-Problem",
238 "Banded-Singular-Value-Decomposition-routines", "Generalized-Linear-Regression-Model-routines", "Generalized-QR-and-RQ-factorization-routines",
239 "Generalized-Singular-Value-Decomposition-routines", "CS-Decomposition-routines", "Constrained-Linear-Least-Squares-routines",
240 "Linear-Equation-routines", "Mixed-Precision-linear-equation-routines","RFP-linear-equation-routines"),
241 (letter+"nep", letter+"sep", letter+"se2", letter+"svd",
242 letter+"ec",letter+"ed",letter+"gg",
243 letter+"gd",letter+"sb",letter+"sg",
244 letter+"bb",letter+"glm",letter+"gqr",
245 letter+"gsv",letter+"csd",letter+"lse",
246 letter+"test", letter+dtypes[0][dtype-1]+"test",letter+"test_rfp"),
250 for dtest in range_test:
252 # NEED TO SKIP SOME PRECISION (namely s and c) FOR PROTO MIXED PRECISION TESTING
253 if dtest==17 and (letter=="s" or letter=="c"):
256 cmdbase=dtests[2][dtest]+".out"
260 cmdbase="xlintst"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
263 cmdbase="xlintst"+letter+dtypes[0][dtype-1]+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
266 cmdbase="xlintstrf"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
269 cmdbase="xeigtst"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
270 if (not just_errors and not short_summary):
271 print("Testing "+name+" "+dtests[1][dtest]+"-"+cmdbase, end=' ')
272 # Run the process: either to read the file or run the LAPACK testing
273 nb_test = run_summary_test(f, cmdbase, short_summary)
274 list_results[0][dtype]+=nb_test[0]
275 list_results[1][dtype]+=nb_test[1]
276 list_results[2][dtype]+=nb_test[2]
277 list_results[3][dtype]+=nb_test[3]
278 got_error=nb_test[1]+nb_test[2]+nb_test[3]
280 if (not short_summary):
281 if (nb_test[0]>0 and just_errors==0):
282 print("passed: "+str(nb_test[0]))
284 print("failing to pass the threshold: "+str(nb_test[1]))
286 print("Illegal Error: "+str(nb_test[2]))
288 print("Info Error: "+str(nb_test[3]))
289 if (got_error>0 and just_errors==1):
290 print("ERROR IS LOCATED IN "+name+" "+dtests[1][dtest]+" [ "+cmdbase+" ]")
294 # elif (got_error>0):
295 # print dtests[2][dtest]+".out \t"+str(nb_test[1])+"\t"+str(nb_test[2])+"\t"+str(nb_test[3])
298 if (list_results[0][dtype] > 0 ):
299 percent_num_error=float(list_results[1][dtype])/float(list_results[0][dtype])*100
300 percent_error=float(list_results[2][dtype]+list_results[3][dtype])/float(list_results[0][dtype])*100
304 summary+=name+"\t"+str(list_results[0][dtype])+"\t\t"+str(list_results[1][dtype])+"\t("+"%.3f" % percent_num_error+"%)\t"+str(list_results[2][dtype]+list_results[3][dtype])+"\t("+"%.3f" % percent_error+"%)\t""\n"
305 list_results[0][4]+=list_results[0][dtype]
306 list_results[1][4]+=list_results[1][dtype]
307 list_results[2][4]+=list_results[2][dtype]
308 list_results[3][4]+=list_results[3][dtype]
311 print(str(list_results[1][4])+"\n"+str(list_results[2][4]+list_results[3][4]))
314 if (list_results[0][4] > 0 ):
315 percent_num_error=float(list_results[1][4])/float(list_results[0][4])*100
316 percent_error=float(list_results[2][4]+list_results[3][4])/float(list_results[0][4])*100
321 print("--> ALL PRECISIONS\t"+str(list_results[0][4])+"\t\t"+str(list_results[1][4])+"\t("+"%.3f" % percent_num_error+"%)\t"+str(list_results[2][4]+list_results[3][4])+"\t("+"%.3f" % percent_error+"%)\t""\n")
322 if list_results[0][4] == 0:
323 print("NO TESTS WERE ANALYZED, please use the -r option to run the LAPACK TESTING")
325 # This may close the sys.stdout stream, so make it the last statement