source: XIOS/dev/dev_trunk_omp/GENERIC_TESTCASE/check.py @ 1734

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

GENERIC_TESTCASE : check all .nc files by default. Generate Cmake files from python scripts (user_config.py, setup.py). Add scripts for copy to/from compressed reference stored in /gpfswork/rech/psl/rpsl954 (Jean-Zay and Irene).

File size: 10.3 KB
Line 
1import os
2import sys
3import subprocess
4
5
6from user_param import *
7
8
9def OSinfo(runthis):
10        osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
11        theInfo = osstdout.communicate()[0].strip()
12        # print(theInfo)
13        # print(osstdout.returncode)
14        # return (osstdout.returncode)
15
16        if osstdout.returncode!=0:
17                print >> sys.stderr, osstdout.returncode
18                sys.exit()
19        else:
20                print(runthis+" OK")
21
22
23def main():
24
25        black = lambda text: '\033[0;30m' + text + '\033[0m'
26        red = lambda text: '\033[0;31m' + text + '\033[0m'
27        green = lambda text: '\033[0;32m' + text + '\033[0m'
28        yellow = lambda text: '\033[0;33m' + text + '\033[0m'
29        blue = lambda text: '\033[0;34m' + text + '\033[0m'
30        magenta = lambda text: '\033[0;35m' + text + '\033[0m'
31        cyan = lambda text: '\033[0;36m' + text + '\033[0m'
32        lgray = lambda text: '\033[0;37m' + text + '\033[0m'
33        dgray = lambda text: '\033[1;30m' + text + '\033[0m'
34        lred = lambda text: '\033[1;32m' + text + '\033[0m'
35        lgreen = lambda text: '\033[1;32m' + text + '\033[0m'
36        lyellow = lambda text: '\033[1;33m' + text + '\033[0m'
37        lblue = lambda text: '\033[1;34m' + text + '\033[0m'
38        lpurple = lambda text: '\033[1;35m' + text + '\033[0m'
39        lcyan = lambda text: '\033[1;36m' + text + '\033[0m'
40        white = lambda text: '\033[1;37m' + text + '\033[0m'
41       
42        configNamePattern=[0]*7
43
44        f=open("user_param.py", "r")
45        for line in f:
46                line = line.strip()
47                if line.startswith("UsingServer2"):
48                        configNamePattern[0] = '_UsingSrv2=' + UsingServer2
49                elif line.startswith("RatioServer2"):
50                        configNamePattern[1] = '_RatioSrv2=' + repr(RatioServer2)
51                elif line.startswith("NumberPoolsServer2"):
52                        configNamePattern[2] = '_NbPoolsSrv2=' + repr(NumberPoolsServer2)
53                elif line.startswith("NumberClients"):
54                        configNamePattern[3] = '_NbClients=' + repr(NumberClients)
55                elif line.startswith("NumberServers"):
56                        configNamePattern[4] = '_NbServers=' + repr(NumberServers)
57                elif line.startswith("Duration"):
58                        configNamePattern[5] = '_Duration=' + Duration
59                elif line.startswith("ATMdomain"):
60                        configNamePattern[5] = '_ATMdomain=' + ATMdomain
61        f.close()
62               
63       
64        configName = "config"
65        defaultConfig = True
66
67        for i in range(len(configNamePattern)):
68                if configNamePattern[i] != 0:
69                        configName = configName + configNamePattern[i]
70                        defaultConfig = False
71
72        if defaultConfig:
73                configName = "config_default"
74
75        check_result=False
76
77
78        if not os.path.exists(configName):
79                os.mkdir(configName)
80                print blue("\n    ****************************************************************")
81                print blue("    * Directory " + repr(configName) + " Created ")
82                print blue("    * Copy results to \'not_validated_reference\' folder")
83                print blue("    ****************************************************************\n")
84
85                # os.mkdir(configName+'/setup')
86                os.system("mkdir "+configName+'/setup')
87                os.mkdir(configName+'/tmp_reference')
88                os.mkdir(configName+'/xios_output')
89               
90                os.system('mv param.def '+configName+'/setup/')
91                os.system('mv all_param.def '+configName+'/setup/')
92                os.system('mv user_param.py '+configName+'/setup/')
93                os.system('mv iodef.xml '+configName+'/setup/')
94                os.system('cp context_atm.xml '+configName+'/setup/')
95                os.system('cp context_grid_dynamico.xml '+configName+'/setup/')
96                os.system('cp dynamico_grid.nc '+configName+'/setup/')
97                os.system('mv xios_*.out '+configName+'/xios_output/')
98                os.system('mv xios_*.err '+configName+'/xios_output/')
99               
100
101                f=open("checkfile.def", "r")
102                h=open("report.txt", "a+")
103                l=open("report.html", "a+")
104                h.write("Config : "+configName+"\n")           
105                l.write("<p>Config : "+configName+"</p>")       
106                endloop=False
107                for line in f:
108                        line=line.strip()
109                        line=line.rstrip()
110
111                        if line.startswith("all"):
112                                allfiles = os.listdir(os.getcwd())
113                                for thisfile in allfiles:
114                                        if thisfile.endswith(".nc") and thisfile!="dynamico_grid.nc":
115                                                cmd = 'mv '+thisfile + ' '+configName+'/tmp_reference/'
116                                                os.system(cmd) 
117                               
118                                h.write("test for "+lpurple("all NC files")+"     \t"+yellow('INITIALIZED')+"\n")               
119                                l.write("<p>test for <font color=\"purple\">"+"all NC files"+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"darkorange\">INITIALIZED</font></p>")
120                                print yellow("\n        ****************************************")
121                                print yellow("        ** "+"all NC files"+" is stored as temporal reference !!! **")
122                                print yellow("\n        ****************************************")
123
124                                break
125
126                        if not line.startswith("#") and len(line) != 0:
127                                cmd = 'mv '+line + ' '+configName+'/tmp_reference/'
128                                os.system(cmd)
129
130                                h.write("test for "+lpurple(line)+"     \t"+yellow('INITIALIZED')+"\n")         
131                                l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"darkorange\">INITIALIZED</font></p>")
132                                print yellow("\n        ****************************************")
133                                print yellow("        ** "+line+" is stored as temporal reference !!! **")
134                                print yellow("\n        ****************************************")
135                               
136                f.close()
137                h.write("\n")
138                l.write("<br>")
139                h.close()
140
141
142        else:   
143                print blue("\n    ********************************************************")
144                print blue("    * Directory " + repr(configName) + " already exists")
145                print blue("    * Start comparing results with references")
146                print blue("    ********************************************************\n")
147
148                tmp_ref = os.path.isdir(configName+'/tmp_reference')
149                ref = os.path.isdir(configName+'/reference') and not tmp_ref
150
151                if ref:
152                        print blue("\n    =====================================")
153                        print blue("    | Comparing results with references |")
154                        print blue("    =====================================\n")
155                        path = configName+'/reference/'
156                elif tmp_ref:
157                        print blue("\n    ===================================================")
158                        print blue("    | Comparing results with NON-Validated references |")
159                        print blue("    ===================================================\n")
160                        path = configName+'/tmp_reference/'
161               
162                f=open("checkfile.def", "r")
163                h=open("report.txt", "a+")
164                l=open("report.html", "a+")
165
166
167                h.write("Config : "+configName+"\n")   
168                l.write("<p>Config : "+configName+"</p>")       
169                for line in f:
170
171                        line=line.strip()
172                        line=line.rstrip()
173                       
174                        if line.startswith("all") :
175                                for thisfile in os.listdir(path):
176                                        if thisfile.endswith(".nc"):
177                                                cmd = 'cdo -W diffn '+ thisfile +' '+ path + thisfile + ' | tail -1 > diff.txt'
178                                               
179                                                OSinfo(cmd)
180                                               
181                                                if os.stat("diff.txt").st_size==0:
182                                                        h.write("test for "+lpurple(thisfile)+"     \t"+green('PASSED')+"\n")           
183                                                        l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"green\">PASSED</font></p>")         
184                                                        print green("\n        ****************************************")
185                                                        print green("        ** "+thisfile+" is valid !!! **")
186                                                        print green("\n        ****************************************")
187
188                                                else:   
189                                                        g=open("diff.txt", "r")
190                                                        for gline in g:
191                                                                if gline.strip().startswith("0") or ":" in gline :
192                                                                        h.write("test for "+lpurple(thisfile)+"      \t"+green('PASSED')+"\n")         
193                                                                        l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"green\">PASSED</font></p>")         
194                                                                        print green("\n        ****************************************")
195                                                                        print green("        ** "+thisfile+" is valid !!! **")
196                                                                        print green("\n        ****************************************")
197                                                                else:
198                                                                        h.write("test for "+lpurple(thisfile)+"     \t"+red('FAILED')+"\n")             
199                                                                        l.write("<p>test for <font color=\"purple\">"+thisfile+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"red\">FAILED</font></p>")           
200                                                                        print red("\n        **************************************************")
201                                                                        print red("        ** "+thisfile+" is NOT valid. Please debugging.. **")
202                                                                        print red("\n        **************************************************")
203                                                        g.close()
204                                break
205
206
207                        elif not line.startswith("#") and len(line) != 0:
208                                cmd = 'cdo -W diffn '+ line +' '+ path + line + ' | tail -1 > diff.txt'
209                               
210                                OSinfo(cmd)
211
212                                if os.stat("diff.txt").st_size==0:
213                                        h.write("test for "+lpurple(line)+"     \t"+green('PASSED')+"\n")               
214                                        l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"green\">PASSED</font></p>")             
215                                        print green("\n        ****************************************")
216                                        print green("        ** "+line+" is valid !!! **")
217                                        print green("\n        ****************************************")
218
219                                else:   
220                                        g=open("diff.txt", "r")
221                                        for gline in g:
222                                                if gline.strip().startswith("0") or ":" in gline :
223                                                        h.write("test for "+lpurple(line)+"      \t"+green('PASSED')+"\n")             
224                                                        l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"green\">PASSED</font></p>")             
225                                                        print green("\n        ****************************************")
226                                                        print green("        ** "+line+" is valid !!! **")
227                                                        print green("\n        ****************************************")
228                                                else:
229                                                        h.write("test for "+lpurple(line)+"     \t"+red('FAILED')+"\n")         
230                                                        l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"red\">FAILED</font></p>")               
231                                                        print red("\n        **************************************************")
232                                                        print red("        ** "+line+" is NOT valid. Please debugging.. **")
233                                                        print red("\n        **************************************************")
234                                        g.close()
235                f.close()
236                h.write("\n")
237                l.write("<br>")
238                h.close()
239
240                if not os.path.exists('current_run'):
241                        os.mkdir('current_run')
242
243                if not os.path.exists('current_run/'+configName):
244                        os.mkdir('current_run/'+configName)
245                os.system('mv -f param.def current_run/'+configName)
246                os.system('mv -f all_param.def current_run/'+configName)
247                os.system('mv -f user_param.py current_run/'+configName)
248                os.system('mv -f iodef.xml current_run/'+configName)
249                os.system('rm -f current_run/'+configName+'/context_atm.xml')
250                os.system('cp -n context_atm.xml current_run/'+configName)
251                os.system('cp -f context_grid_dynamico.xml current_run/'+configName)
252                os.system('cp -f dynamico_grid.nc current_run/'+configName)
253                os.system('mv -f xios_*.out current_run/'+configName)
254                os.system('mv -f xios_*.err current_run/'+configName)
255
256
257
258
259if __name__== "__main__":
260  main()
Note: See TracBrowser for help on using the repository browser.