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

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

trunk : add reference generator and archievs for JZ

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(rev)
47            break
48       
49    if not ref_rev:
50        print("no available reference found ... exit")
51        return
52   
53    OSinfo("cp "+ref_location+"/"+ref_rev+"/"+ref_file+" ./")
54    OSinfo("tar -zxvf "+ref_location+"/"+ref_rev+"/"+ref_file)
55    OSinfo("rm -f "+ref_file)
56   
57   
58    test_folder_list = glob.glob('test_*')
59
60    for test_folder in test_folder_list:
61        config_list = glob.glob(test_folder+"/CONFIG_*")
62       
63       
64        with open(test_folder+"/checkfile.def", "r") as fh:
65            checkfiles = list(nonblank_lines(fh))
66
67        with open("report_"+svnr+"_"+arch+"_"+mode+".txt", "a") as report:
68            for config in config_list:
69                folder_name = list(config.split("/"))[0]
70                config_name = list(config.split("/"))[1]
71                for checkfile in checkfiles:
72                    if os.path.exists(config+"/"+checkfile) and os.path.exists("reference/ref_"+config+"/"+checkfile):
73                        OSinfo("cdo -W diffn "+config+"/"+checkfile+" "+"reference/ref_"+config+"/"+checkfile+" | > diff.txt")
74                        if os.stat("diff.txt").st_size==0:
75                            report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(1)+"\n")
76                    elif os.path.exists(config+"/"+checkfile):
77                        report.write(folder_name+" "+folder_name+"@"+config_name+" "+folder_name+"@"+config_name+"@"+checkfile+" "+str(0)+"\n")
78                   
79
80if __name__== "__main__":
81  main()
Note: See TracBrowser for help on using the repository browser.