-
Notifications
You must be signed in to change notification settings - Fork 4
/
local_test.py
84 lines (72 loc) · 3.45 KB
/
local_test.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
#!/usr/bin/env python3
"""Script for testing on the local machine.
This script allows to build preCICE with a branch choosen by the user, execute
all or choosen system tests and allows to push the results to the output repository
of preCICE system test.
Example:
Example to use preCICE branch "master" and only system tests "of-of" and "su2-ccx":
$ python local_test.py --branch=master --systemtest of-of su2-ccx
"""
import argparse, os, subprocess
import docker, common
from common import call, ccall, determine_test_name, get_test_variants, filter_tests
from system_testing import build_run_compare
if __name__ == "__main__":
# Parsing flags
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Build local.')
parser.add_argument('-b', '--branch', help="Branch you want to use for preCICE", default = "develop")
parser.add_argument('-d', '--dockerfile', help="Dockerfile used to create preCICE base image", default = "Dockerfile.Ubuntu1804.home")
parser.add_argument('--keep', help="Keep containers and docker volumes upon finishing", action='store_true')
parser.add_argument('-s', '--systemtest', nargs='+', help="System tests you want to use",
default = common.get_tests(),
choices = common.get_tests())
parser.add_argument('-f', '--force_rebuild', nargs='+', help="Force rebuild of variable parts of docker image", default = [], choices = ["precice", "tests"])
parser.add_argument('-v', '--verbose', action='store_true', help="Verbose output of participant containers")
args = parser.parse_args()
test_names = args.systemtest
tests = []
for test_name in test_names:
tests += get_test_variants(test_name)
tests = filter_tests(tests, args.dockerfile)
# Checking for older docker containers
lst2 = docker.get_containers()
print (lst2)
if lst2:
print("Deleting following docker containers:", lst2)
answer = input("\nOk? (yes/no)\n")
if answer in ["yes", "y"]:
for x in lst2:
ccall("docker container rm -f " + x)
else:
print("BE CAREFUL!: Not deleting previous containers can later lead to problems.")
# Building preCICE
print("\n\nBuilding preCICE docker image with choosen branch\n\n")
with common.chdir(os.path.join(os.getcwd(), 'precice')):
docker.build_image("precice-" + args.dockerfile.lower() + "-" + args.branch, args.dockerfile,
build_args = {"branch" : args.branch},
force_rebuild = "precice" in args.force_rebuild)
# Starting system tests
failed = []
success = []
for test in tests:
test_basename = determine_test_name(test)
print("\n\nStarting system test %s\n\n" % test)
try:
build_run_compare(test, args.dockerfile.lower(),
args.branch.lower(), True, "tests" in args.force_rebuild,
not args.keep, args.verbose)
except subprocess.CalledProcessError:
failed.append(test_basename)
else:
success.append(test_basename)
# Results
print("\n\n\n\n\nLocal build finished.\n")
if success:
print("Following system tests succeeded: ")
print(", ".join(success))
print('\n')
if failed:
print("Following system tests failed: ")
print(", ".join(failed))
print('\n')