source: XIOS/dev/dev_trunk_omp/html/generate_test.py @ 1846

Last change on this file since 1846 was 1792, checked in by yushan, 5 years ago

dev_trunk_omp : update and cleanup of unit tests

File size: 8.2 KB
Line 
1import glob
2import sys
3import subprocess
4import os
5
6def OSinfo(runthis):
7        red = lambda text: '\033[0;31m' + text + '\033[0m'
8        osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
9        theInfo = osstdout.communicate()[0].strip()
10        if osstdout.returncode!=0:
11                print(red(runthis+" FAILED"))
12                print >> sys.stderr, osstdout.returncode
13                sys.exit()
14        # else:
15        #       print(runthis+" OK")
16
17def Sort(sub_li): 
18    l = len(sub_li) 
19    for i in range(0, l): 
20        for j in range(0, l-i-1): 
21            if (sub_li[j][0] < sub_li[j+1][0]): 
22                tempo = sub_li[j] 
23                sub_li[j]= sub_li[j+1] 
24                sub_li[j+1]= tempo
25            if (sub_li[j][0] == sub_li[j+1][0]):
26                if (sub_li[j][2] < sub_li[j+1][2]): 
27                    tempo = sub_li[j] 
28                    sub_li[j]= sub_li[j+1] 
29                    sub_li[j+1]= tempo
30                if (sub_li[j][1] == sub_li[j+1][1]): 
31                    if (sub_li[j][2] < sub_li[j+1][2]): 
32                        tempo = sub_li[j] 
33                        sub_li[j]= sub_li[j+1] 
34                        sub_li[j+1]= tempo
35    return sub_li
36
37def subgenerate(machine_choice):
38   
39    test_list = glob.glob(machine_choice+"/test_*.txt")
40    if len(test_list) == 0 :
41        return
42   
43    revision_list=[]
44    relurl_list=[]
45    machine_list=[]
46    build_dir_list=[]
47    arch_list=[]
48    mode_list=[]
49   
50    myTestList=[]   
51       
52    for test_log in test_list :
53        f=open(test_log, "r")
54        for line in f :
55            if line.startswith("#revision") :
56                revision = line.replace("\n","").split(" ")[1]
57                if not revision in revision_list :
58                    revision_list.append(revision)
59            elif line.startswith("#relurl") :
60                relurl = line.replace("\n","").split(" ")[1]
61                if not relurl in relurl_list :
62                    relurl_list.append(relurl)
63            elif line.startswith("#machine") :
64                machine = line.replace("\n","").split(" ")[1]
65                if not machine in machine_list :
66                    machine_list.append(machine)
67            elif line.startswith("#build_dir") :
68                build_dir = line.replace("\n","").split(" ")[1]
69                tmp_list = build_dir.split("/")
70                short_dir = tmp_list[len(tmp_list)-1]
71                if not build_dir in build_dir_list :
72                    build_dir_list.append(short_dir)
73            elif line.startswith("#arch") :
74                arch = line.replace("\n","").split(" ")[1]
75                if not arch in arch_list :
76                    arch_list.append(arch)
77            elif line.startswith("#mode") :
78                mode = line.replace("\n","").split(" ")[1]
79                if not mode in mode_list :
80                    mode_list.append(mode)
81       
82        myTestList.append([revision, machine, short_dir])
83        f.close()
84       
85    revision_list = sorted(revision_list, reverse=True)
86    print(revision_list)
87   
88    Sort(myTestList)
89    print(myTestList)
90   
91   
92    machine = machine_choice.replace("test_","") 
93    f=open("test_"+machine+"_info.js", "w")
94    f.write("var test_"+machine+"_revision_list = "+repr(revision_list)+"\n\n")
95    f.write("var test_"+machine+"_info_list = "+repr(myTestList)+"\n\n")
96
97    myReportDict=dict()
98    for i in range(len(myTestList)) :
99        myReportList=[] # algo, config, file, status
100        print(myTestList[i])
101        file_to_open = machine_choice+"/test_"+myTestList[i][0]+"_"+myTestList[i][1]+"_"+myTestList[i][2].replace("build_","")+".txt"
102        g=open(file_to_open, "r")
103        for line in g :
104            if not line.startswith("#") :
105                line = line.replace("\n","").split(" ")
106                algo = line[0]
107                config = line[1].split("@")[1]
108                file = line[2].split("@")[2]
109                status = line[3]
110                myReportList.append([algo, config, file, status])
111        g.close()
112        print(len(myReportList))
113        myReportDict.update({myTestList[i][0]+"_"+myTestList[i][2].replace("build_","") : myReportList})
114   
115    for i in range(len(myReportDict)) :
116        key = list(myReportDict.keys())[i]
117        f.write("var test_"+machine+"_"+key+" = [\n")
118        for j in range(len(myReportDict[key])) :
119            if j<len(myReportDict[key])-1 : 
120                f.write("         [\'"+myReportDict[key][j][0]+"\', \'"+myReportDict[key][j][1]+"\', \'"+myReportDict[key][j][2]+"\', "+myReportDict[key][j][3]+"],\n")
121            else :
122                f.write("         [\'"+myReportDict[key][j][0]+"\', \'"+myReportDict[key][j][1]+"\', \'"+myReportDict[key][j][2]+"\', "+myReportDict[key][j][3]+"]]\n")
123        f.write("\n\n")
124    f.close()
125
126
127    # machine_list=["Jean-Zay", "Irene", "Other"]
128    # plein_report_list=["test_*_jeanzay_", "test_*_irene_", "test_*_other_"]
129        # xios_table_src_list=["xios_table_src_Jean-Zay.js", "xios_table_src_Irene.js", "xios_table_src_Other.js"]
130
131
132        # all_revision_list=[]
133
134        # if os.path.exists("table_Jean-Zay_auto.js"):
135        #       OSinfo("rm -f table_Jean-Zay_auto.js")
136        # if os.path.exists("table_Irene_auto.js"):
137        #       OSinfo("rm -f table_Irene_auto.js")
138        # if os.path.exists("table_Other_auto.js"):
139        #       OSinfo("rm -f table_Other_auto.js")
140       
141
142
143        # for machine_index in range(len(machine_list)) :
144
145        #       this_machine_revision_list=[]
146               
147        #       revision_dir_list = glob.glob(plein_report_list[machine_index]+"*")
148        #       revision_list=[]
149        #       build_list=[]
150        #       if len(revision_dir_list) > 0 :
151        #               if machine_index==0:
152        #                       f=open("table_jz_main.js", "w")
153        #                       f.write("function generateJZ()\n")
154        #                       f.write("{\n")
155        #               elif machine_index==1:
156        #                       f=open("table_irene_main.js", "w")
157        #                       f.write("function generateIRENE()\n")
158        #                       f.write("{\n")
159        #               else :
160        #                       f=open("table_other_main.js", "w")
161        #                       f.write("function generateOTHER()\n")
162        #                       f.write("{\n")
163
164        #               OSinfo("rm -f "+xios_table_src_list[machine_index])
165        #               for i in range(len(revision_dir_list)) :
166        #                       tmp_str = (revision_dir_list[i].replace(plein_report_list[machine_index], "").replace(".txt", ""))
167        #                       tmp_int =(int)(tmp_str[len(tmp_str)-4: len(tmp_str)])
168        #                       tmp_build = tmp_str[0 : len(tmp_str)-5]
169        #                       if not tmp_int in revision_list:
170        #                               revision_list.append( tmp_int )
171        #                       if not tmp_build in build_list:
172        #                               build_list.append( tmp_build )
173        #               revision_list = sorted(revision_list, reverse = True)
174        #               build_list = sorted(build_list, reverse = True)
175
176
177        #               for revision_number in revision_list:
178        #                       print("python generate_table.py "+machine_list[machine_index] +" "+repr(revision_number) + " " + plein_report_list[machine_index])
179        #                       OSinfo("python generate_table.py "+machine_list[machine_index] +" "+repr(revision_number) + " " + plein_report_list[machine_index])
180        #                       if machine_index ==0 :
181        #                               f.write("  generateTable_JZ_"+repr(revision_number)+"();\n")
182        #                       elif machine_index ==1 :
183        #                               f.write("  generateTable_IRENE_"+repr(revision_number)+"();\n")
184        #                       else:
185        #                               f.write("  generateTable_OTHER_"+repr(revision_number)+"();\n")
186
187
188        #               f.write("}\n")
189        #               f.close()
190
191        #               f=open("select_src_"+machine_list[machine_index]+".js", "w")
192        #               if machine_index == 0:
193        #                       f.write("function generateForm_jz()\n")
194        #                       f.write("{\n")
195        #                       f.write("  var sel = document.getElementById(\"jz_revision\");\n")
196        #               elif machine_index == 1:
197        #                       f.write("function generateForm_irene()\n")
198        #                       f.write("{\n")
199        #                       f.write("  var sel = document.getElementById(\"irene_revision\");\n")
200        #               else :
201        #                       f.write("function generateForm_other()\n")
202        #                       f.write("{\n")
203        #                       f.write("  var sel = document.getElementById(\"other_revision\");\n")
204        #               for revision in revision_list:
205        #                       f.write("  var opt = document.createElement(\'option\');\n")
206        #                       f.write("  opt.appendChild( document.createTextNode(\'"+repr(revision)+"\') );\n")
207        #                       f.write("  opt.value = \'"+repr(revision)+"\'; \n")
208        #                       f.write("  sel.appendChild(opt); \n")
209        #               f.write("}\n\n")
210        #               f.close()
211
212
213        #       for revision in revision_list :
214        #               if not revision in all_revision_list :
215        #                       all_revision_list.append(revision)
216
217        # all_revision_list = sorted(all_revision_list, reverse = True)
218   
219def main():
220    subgenerate("test_jeanzay")
221    subgenerate("test_irene")
222
223if __name__== "__main__":
224  main()
Note: See TracBrowser for help on using the repository browser.