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

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

Generic_testcase : Update for Jean-Zay

File size: 6.6 KB
Line 
1import os
2import sys
3
4
5from user_param import *
6
7def main():
8
9        black = lambda text: '\033[0;30m' + text + '\033[0m'
10        red = lambda text: '\033[0;31m' + text + '\033[0m'
11        green = lambda text: '\033[0;32m' + text + '\033[0m'
12        yellow = lambda text: '\033[0;33m' + text + '\033[0m'
13        blue = lambda text: '\033[0;34m' + text + '\033[0m'
14        magenta = lambda text: '\033[0;35m' + text + '\033[0m'
15        cyan = lambda text: '\033[0;36m' + text + '\033[0m'
16        lgray = lambda text: '\033[0;37m' + text + '\033[0m'
17        dgray = lambda text: '\033[1;30m' + text + '\033[0m'
18        lred = lambda text: '\033[1;32m' + text + '\033[0m'
19        lgreen = lambda text: '\033[1;32m' + text + '\033[0m'
20        lyellow = lambda text: '\033[1;33m' + text + '\033[0m'
21        lblue = lambda text: '\033[1;34m' + text + '\033[0m'
22        lpurple = lambda text: '\033[1;35m' + text + '\033[0m'
23        lcyan = lambda text: '\033[1;36m' + text + '\033[0m'
24        white = lambda text: '\033[1;37m' + text + '\033[0m'
25       
26        configNamePattern=[0]*7
27
28        f=open("user_param.py", "r")
29        for line in f:
30                line = line.strip()
31                if line.startswith("UsingServer2"):
32                        configNamePattern[0] = '_UsingSrv2=' + UsingServer2
33                elif line.startswith("RatioServer2"):
34                        configNamePattern[1] = '_RatioSrv2=' + repr(RatioServer2)
35                elif line.startswith("NumberPoolsServer2"):
36                        configNamePattern[2] = '_NbPoolsSrv2=' + repr(NumberPoolsServer2)
37                elif line.startswith("NumberClients"):
38                        configNamePattern[3] = '_NbClients=' + repr(NumberClients)
39                elif line.startswith("NumberServers"):
40                        configNamePattern[4] = '_NbServers=' + repr(NumberServers)
41                elif line.startswith("Duration"):
42                        configNamePattern[5] = '_Duration=' + Duration
43                elif line.startswith("ATMdomain"):
44                        configNamePattern[5] = '_ATMdomain=' + ATMdomain
45        f.close()
46               
47       
48        configName = "config"
49        defaultConfig = True
50
51        for i in range(len(configNamePattern)):
52                if configNamePattern[i] != 0:
53                        configName = configName + configNamePattern[i]
54                        defaultConfig = False
55
56        if defaultConfig:
57                configName = "config_default"
58
59
60        if not os.path.exists(configName):
61                os.mkdir(configName)
62                print blue("\n    ****************************************************************")
63                print blue("    * Directory " + repr(configName) + " Created ")
64                print blue("    * Copy results to \'not_validated_reference\' folder")
65                print blue("    ****************************************************************\n")
66
67                os.mkdir(configName+'/setup')
68                os.mkdir(configName+'/tmp_reference')
69                os.mkdir(configName+'/xios_output')
70               
71                os.system('cp param.def '+configName+'/setup/')
72                os.system('cp all_param.def '+configName+'/setup/')
73                os.system('cp iodef.xml '+configName+'/setup/')
74                os.system('cp context_atm.xml '+configName+'/setup/')
75                os.system('cp context_grid_dynamico.xml '+configName+'/setup/')
76                os.system('cp dynamico_grid.nc '+configName+'/setup/')
77                os.system('mv xios_*.out '+configName+'/xios_output/')
78                os.system('mv xios_*.err '+configName+'/xios_output/')
79               
80
81                f=open("checkfile.def", "r")
82                h=open("report.txt", "a+")
83                l=open("report.html", "a+")
84                h.write("Config : "+configName+"\n")           
85                l.write("<p>Config : "+configName+"</p>")       
86                for line in f:
87                        line=line.strip()
88                        line=line.rstrip()
89                        if not line.startswith("#") and len(line) != 0:
90                                cmd = 'cp -n '+line + ' '+configName+'/tmp_reference/'
91                                os.system(cmd)
92
93                                h.write("test for "+lpurple(line)+"     \t"+yellow('INITIALIZED')+"\n")         
94                                l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"darkorange\">INITIALIZED</font></p>")
95                                print yellow("\n        ****************************************")
96                                print yellow("        ** "+line+" is stored as temporal reference !!! **")
97                                print yellow("\n        ****************************************")
98                               
99                f.close()
100                h.write("\n")
101                l.write("<br>")
102                h.close()
103
104
105        else:   
106                print blue("\n    ********************************************************")
107                print blue("    * Directory " + repr(configName) + " already exists")
108                print blue("    * Start comparing results with (tmp) references")
109                print blue("    ********************************************************\n")
110
111                tmp_ref = os.path.isdir(configName+'/tmp_reference')
112                ref = os.path.isdir(configName+'/reference')
113
114                if ref:
115                        print blue("\n    =====================================")
116                        print blue("    | Comparing results with references |")
117                        print blue("    =====================================\n")
118                        os.system('rm -rf '+configName+'/tmp_reference/')
119                        tmp_ref = False
120                        path = configName+'/reference/'
121                elif tmp_ref:
122                        print blue("\n    ===================================================")
123                        print blue("    | Comparing results with NON-Validated references |")
124                        print blue("    ===================================================\n")
125                        path = ' '+configName+'/tmp_reference/'
126               
127                f=open("checkfile.def", "r")
128                h=open("report.txt", "a+")
129                l=open("report.html", "a+")
130
131
132                h.write("Config : "+configName+"\n")   
133                l.write("<p>Config : "+configName+"</p>")       
134                for line in f:
135
136                        line=line.strip()
137                        line=line.rstrip()
138                       
139                        if not line.startswith("#") and len(line) != 0:
140                                cmd = 'cdo diffn '+ line + path + line + ' | tail -1 > diff.txt'
141                                os.system(cmd)
142
143                                if os.stat("diff.txt").st_size==0:
144                                        h.write("test for "+lpurple(line)+"     \t"+green('PASSED')+"\n")               
145                                        l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"green\">PASSED</font></p>")             
146                                        print green("\n        ****************************************")
147                                        print green("        ** "+line+" is valid !!! **")
148                                        print green("\n        ****************************************")
149
150                                else:   
151                                        g=open("diff.txt", "r")
152                                        for gline in g:
153                                                if gline.strip().startswith("0") or ":" in gline :
154                                                        h.write("test for "+lpurple(line)+"      \t"+green('PASSED')+"\n")             
155                                                        l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"green\">PASSED</font></p>")             
156                                                        print green("\n        ****************************************")
157                                                        print green("        ** "+line+" is valid !!! **")
158                                                        print green("\n        ****************************************")
159                                                else:
160                                                        h.write("test for "+lpurple(line)+"     \t"+red('FAILED')+"\n")         
161                                                        l.write("<p>test for <font color=\"purple\">"+line+"</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color=\"red\">FAILED</font></p>")               
162                                                        print red("\n        **************************************************")
163                                                        print red("        ** "+line+" is NOT valid. Please debugging.. **")
164                                                        print red("\n        **************************************************")
165                                        g.close()
166                f.close()
167                h.write("\n")
168                l.write("<br>")
169                h.close()
170
171
172
173
174if __name__== "__main__":
175  main()
Note: See TracBrowser for help on using the repository browser.