source: XIOS/trunk/xios_test_suite/TEST_SUITE/step2.py @ 1972

Last change on this file since 1972 was 1915, checked in by yushan, 4 years ago

trunk : correct an error in reference match

File size: 2.6 KB
Line 
1import glob
2import sys
3import subprocess
4import os
5import json
6import itertools
7import copy
8
9
10mode=os.getenv("mode")
11arch=os.getenv("arch")
12svnr=os.getenv("svnR")
13ref_location=os.getenv("ref_location")
14ref_file=os.getenv("ref_file")
15
16
17
18def OSinfo(runthis):
19    red = lambda text: '\033[0;31m' + text + '\033[0m'
20    osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
21    theInfo = osstdout.communicate()[0].strip()
22    if osstdout.returncode!=0:
23        print(red(runthis+" FAILED"))
24        print(theInfo)
25        sys.exit()
26
27
28
29def nonblank_lines(f):
30    for l in f:
31        line = l.rstrip()
32        if line and not line.startswith("#"):
33            yield line
34
35def main():
36    ref_list = glob.glob(ref_location+"/*")
37    for i in range(len(ref_list)):
38        tmp = ref_list[i].split("/")
39        rev = tmp[len(tmp)-1]
40        ref_list[i] = int(rev)
41    ref_list.sort(reverse=True) #ref_list in descending order
42   
43    ref_rev = ""
44    for ref in ref_list:
45        if int(svnr) >= ref :
46            ref_rev = str(ref)
47            print("corresponding reference = ", ref)
48            break
49       
50    if not ref_rev:
51        print("no available reference found ... exit")
52        return
53   
54    OSinfo("cp "+ref_location+"/"+ref_rev+"/"+ref_file+" ./")
55    OSinfo("tar -zxvf "+ref_location+"/"+ref_rev+"/"+ref_file)
56    OSinfo("rm -f "+ref_file)
57   
58   
59    test_folder_list = glob.glob('test_*')
60
61    for test_folder in test_folder_list:
62        config_list = glob.glob(test_folder+"/CONFIG_*")
63       
64       
65        with open(test_folder+"/checkfile.def", "r") as fh:
66            checkfiles = list(nonblank_lines(fh))
67
68        with open("report_"+svnr+"_"+arch+"_"+mode+".txt", "a") as report:
69            for config in config_list:
70                folder_name = list(config.split("/"))[0]
71                config_name = list(config.split("/"))[1]
72                for checkfile in checkfiles:
73                    if os.path.exists(config+"/"+checkfile) and os.path.exists("reference/ref_"+config+"/"+checkfile):
74                        OSinfo("cdo -W diffn "+config+"/"+checkfile+" "+"reference/ref_"+config+"/"+checkfile+" | > diff.txt")
75                        if os.stat("diff.txt").st_size==0:
76                            report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(1)+"\n")
77                    elif os.path.exists(config+"/"+checkfile):
78                        report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(0)+"\n")
79                   
80
81if __name__== "__main__":
82  main()
Note: See TracBrowser for help on using the repository browser.