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

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

trunk : add reference generator and archievs

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