Align TESTING/{LIN,MATGEN}/*lahilb.f
[platform/upstream/lapack.git] / lapack_testing.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4
5 ###############################################################################
6 # lapack_testing.py
7 ###############################################################################
8
9 from __future__ import print_function
10 from subprocess import Popen, STDOUT, PIPE
11 import os, sys, math
12 import getopt
13 # Arguments
14 try:
15     opts, args = getopt.getopt(sys.argv[1:], "hd:srep:t:n",
16                                ["help", "dir", "short", "run", "error","prec=","test=","number"])
17
18 except getopt.error as msg:
19     print(msg)
20     print("for help use --help")
21     sys.exit(2)
22
23 short_summary=0
24 with_file=1
25 just_errors = 0
26 prec='x'
27 test='all'
28 only_numbers=0
29 test_dir='TESTING'
30 bin_dir='bin/Release'
31
32 abs_bin_dir=os.path.normpath(os.path.join(os.getcwd(),bin_dir))
33
34 for o, a in opts:
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:")
47         print("            s=single")
48         print("            d=double")
49         print("            sd=single/double")
50         print("            c=complex")
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]")
60         print(" EXAMPLES:")
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) ")
68         sys.exit(0)
69     else:
70         if o in ("-s", "--short"):
71             short_summary = 1
72         if o in ("-r", "--run"):
73             with_file = 0
74         if o in ("-e", "--error"):
75             just_errors = 1
76         if o in ( '-p', '--prec' ):
77             prec = a
78         if o in ( '-d', '--dir' ):
79             test_dir = a
80         if o in ( '-t', '--test' ):
81             test = a
82         if o in ( '-n', '--number' ):
83             only_numbers = 1
84             short_summary = 1
85
86 # process options
87
88 os.chdir(test_dir)
89
90 execution=1
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";
95 nb_of_test=0
96
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"]+":."
100
101 # Define a function to open the executable (different filenames on unix and Windows)
102 def run_summary_test( f, cmdline, short_summary):
103     nb_test_run=0
104     nb_test_fail=0
105     nb_test_illegal=0
106     nb_test_info=0
107
108     if (with_file):
109         if not os.path.exists(cmdline):
110             error_message=cmdline+" file not found"
111             r=1
112             if short_summary: return [nb_test_run,nb_test_fail,nb_test_illegal,nb_test_info]
113         else:
114             pipe = open(cmdline,'r')
115             r=0
116     else:
117         if os.name != 'nt':
118             cmdline='./' + cmdline
119         else :
120             cmdline=abs_bin_dir+os.path.sep+cmdline
121
122         outfile=cmdline.split()[4]
123         #pipe = open(outfile,'w')
124         p = Popen(cmdline, shell=True)#, stdout=pipe)
125         p.wait()
126         #pipe.close()
127         r=p.returncode
128         pipe = open(outfile,'r')
129         error_message=cmdline+" did not work"
130
131     if r != 0 and not with_file:
132         print("---- TESTING " + cmdline.split()[0] + "... FAILED(" + error_message +") !")
133         for line in pipe.readlines():
134             f.write(str(line))
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
139     else:
140         for line in pipe.readlines():
141             f.write(str(line))
142             words_in_line=line.split()
143             if (line.find("run")!=-1):
144 #                  print line
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=' ')
153                 nb_test_illegal+=1
154             if (line.find(" INFO")!=-1):
155                 if (short_summary==0):print(line, end=' ')
156                 nb_test_info+=1
157             if (with_file==1):
158                 pipe.close()
159
160     f.flush();
161
162     return [nb_test_run,nb_test_fail,nb_test_illegal,nb_test_info]
163
164
165 # If filename cannot be opened, send output to sys.stderr
166 filename = "testing_results.txt"
167 try:
168     f = open(filename, 'w')
169 except IOError:
170     f = sys.stdout
171
172 if (short_summary==0):
173     print(" ")
174     print("---------------- Testing LAPACK Routines ----------------")
175     print(" ")
176     print("-- Detailed results are stored in", filename)
177
178 dtypes = (
179 ("s", "d", "c", "z"),
180 ("REAL             ", "DOUBLE PRECISION", "COMPLEX          ", "COMPLEX16         "),
181 )
182
183 if prec=='s':
184     range_prec=[0]
185 elif prec=='d':
186     range_prec=[1]
187 elif prec=='sd':
188     range_prec=[0,1]
189 elif prec=='c':
190     range_prec=[2]
191 elif prec=='z':
192     range_prec=[3]
193 elif prec=='cz':
194     range_prec=[2,3]
195 else:
196     prec='x';
197     range_prec=list(range(4))
198
199 if test=='lin':
200     range_test=[16]
201 elif test=='mixed':
202     range_test=[17]
203     range_prec=[1,3]
204 elif test=='rfp':
205     range_test=[18]
206 elif test=='eig':
207     range_test=list(range(16))
208 else:
209     range_test=list(range(19))
210
211 list_results = [
212 [0, 0, 0, 0, 0],
213 [0, 0, 0, 0, 0],
214 [0, 0, 0, 0, 0],
215 [0, 0, 0, 0, 0],
216 ]
217
218 for dtype in range_prec:
219     letter = dtypes[0][dtype]
220     name = dtypes[1][dtype]
221
222     if (short_summary==0):
223         print(" ")
224         print("------------------------- %s ------------------------" % name)
225         print(" ")
226         sys.stdout.flush()
227
228     dtests = (
229     ("nep", "sep", "se2", "svd",
230     letter+"ec",letter+"ed",letter+"gg",
231     letter+"gd",letter+"sb",letter+"sg",
232     letter+"bb","glm","gqr",
233     "gsv","csd","lse",
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"),
247     )
248
249
250     for dtest in range_test:
251         nb_of_test=0
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"):
254             continue
255         if (with_file==1):
256             cmdbase=dtests[2][dtest]+".out"
257         else:
258             if dtest==16:
259                 # LIN TESTS
260                 cmdbase="xlintst"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
261             elif dtest==17:
262                 # PROTO LIN TESTS
263                 cmdbase="xlintst"+letter+dtypes[0][dtype-1]+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
264             elif dtest==18:
265                 # PROTO LIN TESTS
266                 cmdbase="xlintstrf"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
267             else:
268                 # EIG TESTS
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+" ]")
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]
279
280         if (not short_summary):
281             if (nb_test[0]>0 and just_errors==0):
282                 print("-->  Tests passed: "+str(nb_test[0]))
283             if (nb_test[1]>0):
284                 print("-->  Tests failing to pass the threshold: "+str(nb_test[1]))
285             if (nb_test[2]>0):
286                 print("-->  Illegal Error: "+str(nb_test[2]))
287             if (nb_test[3]>0):
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+" ]")
291                 print("")
292             if (just_errors==0):
293                 print("")
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])
296
297         sys.stdout.flush()
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
301     else:
302         percent_num_error=0
303         percent_error=0
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]
309
310 if only_numbers==1:
311     print(str(list_results[1][4])+"\n"+str(list_results[2][4]+list_results[3][4]))
312 else:
313     print(summary)
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
317     else:
318         percent_num_error=0
319         percent_error=0
320     if (prec=='x'):
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")
324
325 # This may close the sys.stdout stream, so make it the last statement
326 f.close()