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

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

Generic_testcase : Using CMake to generate tests

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