15 if os.path.exists(
"output.txt") ==
True:
16 os.remove(
"output.txt")
17 f = open(
"output.txt",
'w+')
20 if os.path.exists(
"main") ==
True:
22 if os.path.exists(
"CMakeCache.txt") ==
True:
23 os.remove(
"CMakeCache.txt")
24 if os.path.exists(
"unit_test_results.txt") ==
True:
25 os.remove(
"unit_test_results.txt")
28 subprocess.call([
"cmake",
"."],stdout=f,stderr=f)
29 subprocess.call([
"make",
"release"],stdout=f)
30 subprocess.call([
"mpirun",
"-n",
"2",
"main"],stdout=f)
33 result_file = open(
"unit_test_results.txt",
"r") 34 test_results = result_file.read().splitlines() 43 def run_simulation(run_name,dir_path):
45 if os.path.exists(run_name) ==
True:
46 shutil.rmtree(run_name)
49 if os.path.exists(
"output.txt") ==
True:
50 os.remove(
"output.txt")
51 f = open(
"output.txt",
'w+')
54 if os.path.exists(
"main") ==
True:
56 if os.path.exists(
"CMakeCache.txt") ==
True:
57 os.remove(
"CMakeCache.txt")
59 subprocess.call([
"rm",
"*vtu"],stdout=f,stderr=f)
62 subprocess.call([
"cmake",
"."])
63 subprocess.call([
"make",
"release",
"-j9"],stdout=f)
64 print(
"Compiling complete, running the regression test...")
67 subprocess.call([
"mpirun",
"-n",
"1",
"main"],stdout=f)
72 subprocess.call([
"mkdir",run_name])
73 for output_files
in glob.glob(
'*vtu'):
74 shutil.move(output_files,run_name)
75 if os.path.exists(
"integratedFields.txt") ==
True:
76 shutil.move(
"integratedFields.txt",run_name)
84 def run_regression_test(applicationName,getNewGoldStandard,dir_path):
86 if (getNewGoldStandard ==
False):
87 testName =
"test_"+applicationName
90 testName =
"gold_"+applicationName
92 if os.path.exists(testName) ==
True:
93 shutil.rmtree(testName)
97 os.chdir(
"../../applications/"+applicationName)
100 test_time = run_simulation(testName,dir_path)
102 shutil.move(testName,r_test_dir)
107 if (getNewGoldStandard ==
False):
109 os.chdir(
"gold_"+applicationName)
110 gold_standard_file = open(
"integratedFields.txt",
"r") 111 gold_energy = gold_standard_file.readlines() 112 gold_standard_file.close() 114 last_energy_index = len(gold_energy)-1 115 split_last_line = gold_energy[-1].split() 116 for index, entry
in enumerate(split_last_line):
118 gold_last_energy = split_last_line[index+1]
121 os.chdir(
"../"+testName)
122 test_file = open(
"integratedFields.txt",
"r") 123 test_energy = test_file.readlines() 126 last_energy_index = len(test_energy)-1 127 split_last_line = test_energy[-1].split() 128 for index, entry
in enumerate(split_last_line):
130 last_energy = split_last_line[index+1]
132 rel_diff = (float(gold_last_energy)-float(last_energy))/float(gold_last_energy)
133 rel_diff = abs(rel_diff)
135 if (rel_diff < 1.0e-9):
144 print(
"Regression Test: ", applicationName)
147 if getNewGoldStandard ==
False:
148 print(
"Result: Pass")
150 print(
"Result: New Gold Standard")
152 print(
"Result: Fail")
154 print(
"Time taken:", test_time)
160 text_file = open(
"test_results.txt",
"a")
161 now = datetime.datetime.now()
162 text_file.write(
"Application: " + applicationName +
" \n")
164 if getNewGoldStandard ==
False:
165 text_file.write(
"Result: Pass \n")
167 text_file.write(
"Result: New Gold Standard \n")
169 text_file.write(
"Result: Fail \n")
170 text_file.write(
"Time: "+str(test_time)+
" \n \n")
173 return (test_passed,test_time)
180 dir_path = os.path.dirname(os.path.realpath(__file__))
183 text_file = open(
"test_results.txt",
"a")
184 now = datetime.datetime.now()
191 os.chdir(
"../unit_tests/")
192 unit_test_results = run_unit_tests()
193 unit_tests_passed = unit_test_results[0]
194 unit_test_counter = unit_test_results[1]
197 print(
"Unit Tests Passed: "+str(unit_tests_passed)+
"/"+str(unit_test_counter)+
"\n")
201 text_file.write(
"--------------------------------------------------------- \n")
202 text_file.write(
"Unit test on " + now.strftime(
"%Y-%m-%d %H:%M") +
"\n")
203 text_file.write(
"--------------------------------------------------------- \n")
204 text_file.write(
"Unit Tests Passed: "+str(unit_tests_passed)+
"/"+str(unit_test_counter)+
"\n")
212 regression_test_counter = 0
213 regression_tests_passed = 0
215 text_file.write(
"--------------------------------------------------------- \n")
216 text_file.write(
"Regression test on " + now.strftime(
"%Y-%m-%d %H:%M") +
"\n")
217 text_file.write(
"--------------------------------------------------------- \n")
224 applicationList = [
"allenCahn",
"cahnHilliard",
"CHAC_anisotropyRegularized",
"coupledCahnHilliardAllenCahn",
"precipitateEvolution"]
225 getNewGoldStandardList = [
False,
False,
False,
False,
False]
231 for applicationName
in applicationList:
232 test_result = run_regression_test(applicationName,getNewGoldStandardList[regression_test_counter],dir_path)
234 regression_test_counter += 1
235 regression_tests_passed += int(test_result[0])
238 print(
"Regression Tests Passed: "+str(regression_tests_passed)+
"/"+str(regression_test_counter)+
"\n")
242 text_file = open(
"test_results.txt",
"a")
243 text_file.write(
"Tests Passed: "+str(regression_tests_passed)+
"/"+str(regression_test_counter)+
"\n")
244 text_file.write(
"--------------------------------------------------------- \n")
248 if ((regression_tests_passed < regression_test_counter)
or (unit_tests_passed < unit_test_counter)):