source: XIOS/trunk/xios_test_suite/TEST_SUITE/generate_test.py @ 1819

Last change on this file since 1819 was 1819, checked in by ymipsl, 4 years ago

XIOS test suite : adapt script for jean-zay
YM

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