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