Skip to content

Commit f53db0e

Browse files
committed
[rth] Add resilience test helper utility
1 parent 64185c7 commit f53db0e

22 files changed

+165
-420
lines changed

test/lit.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ config.llvm_link = inferSwiftBinary('llvm-link')
277277
config.swift_llvm_opt = inferSwiftBinary('swift-llvm-opt')
278278

279279
config.gyb = os.path.join(config.swift_src_root, 'utils', 'gyb')
280+
config.rth = os.path.join(config.swift_src_root, 'utils', 'rth') # Resilience test helper
280281
config.swift_lib_dir = os.path.join(os.path.dirname(os.path.dirname(config.swift)), 'lib')
281282

282283
# Find the resource directory. Assume it's near the swift compiler if not set.
@@ -750,6 +751,15 @@ config.target_sil_extract = (
750751
'%s -target %s %s'
751752
% (config.sil_extract, config.variant_triple, mcp_opt))
752753

754+
config.target_resilience_test_wmo = (
755+
("%s --target-build-swift '%s' --target-run '%s' --t %%t --S %%S --s %%s "
756+
"--additional-compile-flags-library '-whole-module-optimization -parse-as-library'")
757+
% (config.rth, config.target_build_swift, config.target_run))
758+
759+
config.target_resilience_test = (
760+
"%s --target-build-swift '%s' --target-run '%s' --t %%t --S %%S --s %%s"
761+
% (config.rth, config.target_build_swift, config.target_run))
762+
753763
#
754764
# When changing substitutions, update docs/Testing.rst.
755765
#
@@ -778,6 +788,7 @@ if hasattr(config, 'target_cc_options'):
778788
config.substitutions.append(('%target-cc-options', config.target_cc_options))
779789

780790
config.substitutions.append(('%gyb', config.gyb))
791+
config.substitutions.append(('%rth', config.rth))
781792

782793
config.substitutions.append(('%target-sil-opt', config.target_sil_opt))
783794
config.substitutions.append(('%target-sil-extract', config.target_sil_extract))
@@ -812,3 +823,6 @@ config.substitutions.append(('%target-swiftmodule-name', config.target_swiftmodu
812823
config.substitutions.append(('%target-swiftdoc-name', config.target_swiftdoc_name))
813824

814825
config.substitutions.append(('%target-object-format', config.target_object_format))
826+
827+
config.substitutions.append(('%target-resilience-test-wmo', config.target_resilience_test_wmo))
828+
config.substitutions.append(('%target-resilience-test', config.target_resilience_test))

utils/rth

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env python
2+
# utils/rth - Resilience test helper
3+
#
4+
# This source file is part of the Swift.org open source project
5+
#
6+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
7+
# Licensed under Apache License v2.0 with Runtime Library Exception
8+
#
9+
# See http://swift.org/LICENSE.txt for license information
10+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
12+
import subprocess
13+
import argparse
14+
import shutil
15+
import os
16+
import shlex
17+
import pipes
18+
19+
VERBOSE = True
20+
21+
def verbose_print_command(command):
22+
if VERBOSE:
23+
print " ".join(pipes.quote(c) for c in command)
24+
25+
class ResilienceTest(object):
26+
def __init__(self, target_build_swift, target_run, tmp_dir, test_dir,
27+
test_src, additional_compile_flags_library):
28+
self.target_build_swift = shlex.split(target_build_swift)
29+
self.target_run = shlex.split(target_run)
30+
self.tmp_dir = tmp_dir
31+
self.test_dir = test_dir
32+
self.test_src = test_src
33+
self.additional_compile_flags_library = \
34+
shlex.split(additional_compile_flags_library)
35+
36+
self.before_dir = os.path.join(self.tmp_dir, 'before')
37+
self.after_dir = os.path.join(self.tmp_dir, 'after')
38+
self.config_dir_map = {'BEFORE': self.before_dir,
39+
'AFTER': self.after_dir}
40+
41+
self.lib_src_name = os.path.basename(self.test_src)[5:]
42+
self.lib_obj_name = self.lib_src_name[:-6] + '.o'
43+
self.lib_src = os.path.join(self.test_dir, 'Inputs', self.lib_src_name)
44+
45+
def run(self):
46+
self.set_up()
47+
self.compile_library()
48+
self.compile_main()
49+
self.link()
50+
self.execute()
51+
return 0
52+
53+
def set_up(self):
54+
shutil.rmtree(self.tmp_dir)
55+
os.makedirs(self.after_dir)
56+
os.makedirs(self.before_dir)
57+
58+
def compile_library(self):
59+
for config in self.config_dir_map:
60+
for emit_flag in ['-emit-library', '-emit-module']:
61+
output_obj = os.path.join(self.config_dir_map[config],
62+
self.lib_obj_name)
63+
compiler_flags = [emit_flag, '-Xfrontend',
64+
'-enable-resilience', '-D', config, '-c',
65+
self.lib_src, '-o', output_obj]
66+
command = self.target_build_swift + \
67+
self.additional_compile_flags_library + compiler_flags
68+
verbose_print_command(command)
69+
returncode = subprocess.call(command)
70+
assert returncode == 0, str(command)
71+
72+
def compile_main(self):
73+
for config in self.config_dir_map:
74+
output_obj = os.path.join(self.config_dir_map[config], 'main.o')
75+
compiler_flags = ['-D', config, '-c', self.test_src, '-I',
76+
self.config_dir_map[config], '-o', output_obj]
77+
command = self.target_build_swift + compiler_flags
78+
verbose_print_command(command)
79+
returncode = subprocess.call(command)
80+
assert returncode == 0, str(command)
81+
82+
def link(self):
83+
for config1 in self.config_dir_map:
84+
for config2 in self.config_dir_map:
85+
config1_lower = config1.lower()
86+
config2_lower = config2.lower()
87+
output_obj = os.path.join(self.tmp_dir,
88+
config1_lower + '_' + config2_lower)
89+
compiler_flags = [
90+
os.path.join(self.config_dir_map[config1],
91+
self.lib_obj_name),
92+
os.path.join(self.config_dir_map[config2],
93+
'main.o'),
94+
'-o', output_obj
95+
]
96+
command = self.target_build_swift + compiler_flags
97+
verbose_print_command(command)
98+
returncode = subprocess.call(command)
99+
assert returncode == 0, str(command)
100+
101+
def execute(self):
102+
for config1 in self.config_dir_map:
103+
for config2 in self.config_dir_map:
104+
config1_lower = config1.lower()
105+
config2_lower = config2.lower()
106+
output_obj = os.path.join(self.tmp_dir,
107+
config1_lower + '_' + config2_lower)
108+
command = self.target_run + [output_obj]
109+
verbose_print_command(command)
110+
returncode = subprocess.call(command)
111+
assert returncode == 0, str(command)
112+
113+
def main():
114+
parser = argparse.ArgumentParser(description='Resilience test helper')
115+
parser.add_argument('--target-build-swift', required=True)
116+
parser.add_argument('--target-run', required=True)
117+
parser.add_argument('--t', required=True)
118+
parser.add_argument('--S', required=True)
119+
parser.add_argument('--s', required=True)
120+
parser.add_argument('--additional-compile-flags-library', default='')
121+
122+
args = parser.parse_args()
123+
124+
resilience_test = ResilienceTest(args.target_build_swift, args.target_run,
125+
args.t, args.S, args.s,
126+
args.additional_compile_flags_library)
127+
128+
return resilience_test.run()
129+
130+
if __name__ == '__main__':
131+
exit(main())

validation-test/Evolution/test_class_add_property.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_add_property.swift -o %t/before/class_add_property.o
4-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_add_property.swift -o %t/before/class_add_property.o
5-
6-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_add_property.swift -o %t/after/class_add_property.o
7-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_add_property.swift -o %t/after/class_add_property.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/class_add_property.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/class_add_property.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/class_add_property.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/class_add_property.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test
222
// REQUIRES: executable_test
233
// REQUIRES: no_asan
244

validation-test/Evolution/test_class_change_size.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_change_size.swift -o %t/before/class_change_size.o
4-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_change_size.swift -o %t/before/class_change_size.o
5-
6-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_change_size.swift -o %t/after/class_change_size.o
7-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_change_size.swift -o %t/after/class_change_size.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/class_change_size.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/class_change_size.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/class_change_size.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/class_change_size.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test
222
// REQUIRES: executable_test
233
// REQUIRES: no_asan
244

validation-test/Evolution/test_class_change_stored_to_computed.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_change_stored_to_computed.swift -o %t/before/class_change_stored_to_computed.o
4-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_change_stored_to_computed.swift -o %t/before/class_change_stored_to_computed.o
5-
6-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_change_stored_to_computed.swift -o %t/after/class_change_stored_to_computed.o
7-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_change_stored_to_computed.swift -o %t/after/class_change_stored_to_computed.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/class_change_stored_to_computed.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/class_change_stored_to_computed.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/class_change_stored_to_computed.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/class_change_stored_to_computed.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test
222
// REQUIRES: executable_test
233

244
import StdlibUnittest

validation-test/Evolution/test_class_remove_property.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_remove_property.swift -o %t/before/class_remove_property.o
4-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/class_remove_property.swift -o %t/before/class_remove_property.o
5-
6-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_remove_property.swift -o %t/after/class_remove_property.o
7-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/class_remove_property.swift -o %t/after/class_remove_property.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/class_remove_property.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/class_remove_property.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/class_remove_property.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/class_remove_property.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test
222
// REQUIRES: executable_test
233

244
import StdlibUnittest

validation-test/Evolution/test_enum_add_cases.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/enum_add_cases.swift -o %t/before/enum_add_cases.o
4-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/enum_add_cases.swift -o %t/before/enum_add_cases.o
5-
6-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/enum_add_cases.swift -o %t/after/enum_add_cases.o
7-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/enum_add_cases.swift -o %t/after/enum_add_cases.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/enum_add_cases.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/enum_add_cases.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/enum_add_cases.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/enum_add_cases.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test
222
// REQUIRES: executable_test
233

244
import StdlibUnittest

validation-test/Evolution/test_enum_change_size.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/enum_change_size.swift -o %t/before/enum_change_size.o
4-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/enum_change_size.swift -o %t/before/enum_change_size.o
5-
6-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/enum_change_size.swift -o %t/after/enum_change_size.o
7-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/enum_change_size.swift -o %t/after/enum_change_size.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/enum_change_size.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/enum_change_size.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/enum_change_size.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/enum_change_size.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test
222
// REQUIRES: executable_test
233

244
import StdlibUnittest

validation-test/Evolution/test_function_change_transparent_body.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -whole-module-optimization -parse-as-library -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/function_change_transparent_body.swift -o %t/before/function_change_transparent_body.o
4-
// RUN: %target-build-swift -whole-module-optimization -parse-as-library -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/function_change_transparent_body.swift -o %t/before/function_change_transparent_body.o
5-
6-
// RUN: %target-build-swift -whole-module-optimization -parse-as-library -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/function_change_transparent_body.swift -o %t/after/function_change_transparent_body.o
7-
// RUN: %target-build-swift -whole-module-optimization -parse-as-library -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/function_change_transparent_body.swift -o %t/after/function_change_transparent_body.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/function_change_transparent_body.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/function_change_transparent_body.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/function_change_transparent_body.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/function_change_transparent_body.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test-wmo
222
// REQUIRES: executable_test
233

244
// FIXME: shouldn't need -whole-module-optimization here; we need to fix the

validation-test/Evolution/test_global_change_size.swift

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
1-
// RUN: rm -rf %t && mkdir -p %t/before && mkdir -p %t/after
2-
3-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/global_change_size.swift -o %t/before/global_change_size.o
4-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D BEFORE -c %S/Inputs/global_change_size.swift -o %t/before/global_change_size.o
5-
6-
// RUN: %target-build-swift -emit-library -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/global_change_size.swift -o %t/after/global_change_size.o
7-
// RUN: %target-build-swift -emit-module -Xfrontend -enable-resilience -D AFTER -c %S/Inputs/global_change_size.swift -o %t/after/global_change_size.o
8-
9-
// RUN: %target-build-swift -D BEFORE -c %s -I %t/before -o %t/before/main.o
10-
// RUN: %target-build-swift -D AFTER -c %s -I %t/after -o %t/after/main.o
11-
12-
// RUN: %target-build-swift %t/before/global_change_size.o %t/before/main.o -o %t/before_before
13-
// RUN: %target-build-swift %t/before/global_change_size.o %t/after/main.o -o %t/before_after
14-
// RUN: %target-build-swift %t/after/global_change_size.o %t/before/main.o -o %t/after_before
15-
// RUN: %target-build-swift %t/after/global_change_size.o %t/after/main.o -o %t/after_after
16-
17-
// RUN: %target-run %t/before_before
18-
// RUN: %target-run %t/before_after
19-
// RUN: %target-run %t/after_before
20-
// RUN: %target-run %t/after_after
21-
1+
// RUN: %target-resilience-test
222
// REQUIRES: executable_test
233

244
import StdlibUnittest

0 commit comments

Comments
 (0)