-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsystem_testing.py
84 lines (69 loc) · 2.99 KB
/
system_testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Script for system testing preCICE with docker and comparing output.
This script builds a docker image for an system test of preCICE.
It starts a container of the builded image and copys the output generated by the
simulation within the test to the host.
The output is compared to a reference.
It passes if files are equal, else it raises an exception.
Example:
System test of-of and use local preCICE image
$ python system_testing.py -s of-of -l
"""
import sys
import os
import subprocess
import filecmp
import argparse
# Parsing flags
parser = argparse.ArgumentParser(description='Build local.')
parser.add_argument('-l', '--local', action='store_true', help="use local preCICE image (default: use remote image)")
parser.add_argument('-s', '--systemtest', help="choose system tests you want to use")
parser.add_argument('-b', '--branch', help="preCICE branch to use", default = "develop")
args = parser.parse_args()
def build(systest):
"""Building docker image.
This function builds a docker image with the respectively system test,
runs a container in background to copy the output generated by the
simulation to the host:
Args:
systest (str): Name of the system test.
"""
dirname = "/SystemTest_" + systest
print(os.getcwd() + dirname)
os.chdir(os.getcwd() + dirname)
print(os.getcwd())
if args.local:
subprocess.call("docker build -t {systest} -f Dockerfile.{systest} --build-arg from=precice-{branch}:latest .".format(systest = systest, branch = args.branch),
shell=True)
else:
subprocess.call("docker build -t "+ systest +" -f Dockerfile."+ systest +" .", shell=True)
subprocess.call("docker run -it -d --name "+ systest +"_container "+ systest, shell=True)
subprocess.call("docker cp "+ systest +"_container:Output_"+ systest +" .", shell=True)
def comparison(pathToRef, pathToOutput):
"""Building docker image.
This function builds a docker image with the respectively system test,
runs a container in background to copy the output generated by the
simulation to the host:
Args:
pathToRef (str): Path to the reference files.
pathToOutput (str): Path to the output files.
Raises:
Exception: Raises exception then output differs from reference.
"""
fileListRef = os.listdir(pathToRef)
fileListOutput = os.listdir(pathToOutput)
fileListRef.sort()
fileListOutput.sort()
for x, y in zip(fileListRef, fileListOutput):
if os.path.isdir(pathToRef+x):
comparison(pathToRef+x+'/', pathToOutput+y+'/')
else:
if not filecmp.cmp(pathToRef + x, pathToOutput + y):
raise Exception('Output differs from reference')
if __name__ == "__main__":
# Build
build(args.systemtest)
# Preparing string for path
pathToRef = os.getcwd() + "/referenceOutput_" + args.systemtest + "/"
pathToOutput = os.getcwd() + "/Output_" + args.systemtest + "/"
# Comparing
comparison(pathToRef, pathToOutput)