source: XIOS/trunk/html/generate_test.py @ 1793

Last change on this file since 1793 was 1790, checked in by yushan, 4 years ago

trunk : add html scripts

File size: 6.8 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    machine_name_dict={"jeanzay":"Jean-Zay",
40                       "irene" : "Irene", 
41                       "other": "Other"}
42   
43    test_list = glob.glob(machine_choice+"/test_*.txt")
44    if len(test_list) == 0 :
45        return
46   
47    revision_list=[]
48    relurl_list=[]
49    machine_list=[]
50    build_dir_list=[]
51    arch_list=[]
52    mode_list=[]
53   
54    myTestList=[]   
55       
56    for test_log in test_list :
57        f=open(test_log, "r")
58        for line in f :
59            if line.startswith("#revision") :
60                revision = line.replace("\n","").split(" ")[1]
61                if not revision in revision_list :
62                    revision_list.append(revision)
63            elif line.startswith("#relurl") :
64                relurl = line.replace("\n","").split(" ")[1]
65                tmp_url = relurl.split("/")
66                branch = tmp_url[len(tmp_url)-1]
67                if not relurl in relurl_list :
68                    relurl_list.append(relurl)
69            elif line.startswith("#machine") :
70                machine = line.replace("\n","").split(" ")[1]
71                machine_name = machine_name_dict[machine]
72                if not machine in machine_list :
73                    machine_list.append(machine)
74            elif line.startswith("#build_dir") :
75                build_dir = line.replace("\n","").split(" ")[1]
76                tmp_list = build_dir.split("/")
77                short_dir = tmp_list[len(tmp_list)-1]
78                if not build_dir in build_dir_list :
79                    build_dir_list.append(short_dir)
80            elif line.startswith("#arch") :
81                arch = line.replace("\n","").split(" ")[1]
82                if not arch in arch_list :
83                    arch_list.append(arch)
84            elif line.startswith("#mode") :
85                mode = line.replace("\n","").split(" ")[1]
86                if not mode in mode_list :
87                    mode_list.append(mode)
88       
89        myTestList.append([revision, machine, short_dir, branch, machine_name, arch, mode, build_dir])
90        f.close()
91       
92    revision_list = sorted(revision_list, reverse=True)
93    print(revision_list)
94   
95    Sort(myTestList)
96    print(myTestList)
97   
98   
99    machine = machine_choice.replace("test_","") 
100    f=open("test_"+machine+"_info.js", "w")
101    f.write("var test_"+machine+"_revision_list = "+repr(revision_list)+"\n\n")
102    f.write("var test_"+machine+"_info_list = [\n")
103    for i in range(len(myTestList)) :
104        if i<len(myTestList)-1 :
105            f.write("        "+repr(myTestList[i])+",\n")
106        else :
107            f.write("        "+repr(myTestList[i])+"]\n\n")
108           
109    myReportDict=dict()
110    for i in range(len(myTestList)) :
111        myReportList=[] # algo, config, file, status
112        print(myTestList[i])
113        file_to_open = machine_choice+"/test_"+myTestList[i][0]+"_"+myTestList[i][1]+"_"+myTestList[i][2].replace("build_","")+".txt"
114        g=open(file_to_open, "r")
115        for line in g :
116            if not line.startswith("#") :
117                line = line.replace("\n","").split(" ")
118                algo = line[0]
119                config = line[1].split("@")[1]
120                file = line[2].split("@")[2]
121                status = line[3]
122                myReportList.append([algo, config, file, status])
123        g.close()
124        print(len(myReportList))
125        myReportDict.update({myTestList[i][0]+"_"+myTestList[i][2].replace("build_","") : myReportList})
126   
127    for i in range(len(myReportDict)) :
128        key = list(myReportDict.keys())[i]
129        f.write("var test_"+machine+"_"+key+" = [\n")
130        for j in range(len(myReportDict[key])) :
131            if j<len(myReportDict[key])-1 : 
132                f.write("        [\'"+myReportDict[key][j][0]+"\', \'"+myReportDict[key][j][1]+"\', \'"+myReportDict[key][j][2]+"\', "+myReportDict[key][j][3]+"],\n")
133            else :
134                f.write("        [\'"+myReportDict[key][j][0]+"\', \'"+myReportDict[key][j][1]+"\', \'"+myReportDict[key][j][2]+"\', "+myReportDict[key][j][3]+"]]\n")
135        f.write("\n\n")
136
137    for revision in revision_list :
138        algo_list = glob.glob("def_files/"+revision+"/test_*")
139   
140        for l in algo_list :
141            tmp_algo = l.split("/")
142            f.write("var test_"+machine+"_"+revision+"_"+tmp_algo[len(tmp_algo)-1]+"_user_params = [\n")
143            g=open(l+"/user_params.def","r")
144            for line in g:
145                if not line=="\n" and not line.startswith("#"):
146                    f.write("        \'"+line.replace("\n","").replace("'","\\\'")+"\',\n")
147            g.close()
148            f.write("        ]\n\n")
149
150    for revision in revision_list :
151        algo_list = glob.glob("def_files/"+revision+"/test_*")
152   
153        for algo in algo_list :
154            config_list = glob.glob(algo+"/config_*")
155            tmp_algo = algo.split("/") 
156            algo_name = tmp_algo[len(tmp_algo)-1]
157            for config in config_list :
158                tmp_config = config.split("/")
159                config_name = tmp_config[len(tmp_config)-1]
160                config_name_bis = config_name.replace("=","_")
161                f.write("var test_"+machine+"_"+revision+"_"+algo_name+"_"+config_name_bis+"_all_params = [\n")
162                g=open(config+"/all_param.def","r")
163                for line in g:
164                    line = line.replace("&", "& ")
165                    if not line=="\n" :
166                        f.write("        \'"+line.replace("\n","").replace("'","\\\'")+"\',\n")
167                g.close()
168                f.write("        ]\n\n")
169
170    f.close()
171
172   
173def main():
174    subgenerate("test_jeanzay")
175    subgenerate("test_irene")
176
177if __name__== "__main__":
178  main()
Note: See TracBrowser for help on using the repository browser.