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

Last change on this file since 1833 was 1821, checked in by yushan, 4 years ago

XIOS test suite : unit tests will not run if build failed. Catch the make_xios exit value as build status.

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