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

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

Generic_testcase : add colored output for easier reading

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