-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun_tests.py
executable file
·162 lines (123 loc) · 4.09 KB
/
run_tests.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
from utils import *
from resources import copy_resources
self_dir = os.path.dirname(__file__)
swift_build = os.path.join(self_dir, "swift-android-build")
def push(dst, name, skip_push_stdlib, skip_push_external, skip_push_resources, device=None):
from os.path import join
from glob import glob
ADB.makedirs(dst, device)
if not skip_push_resources:
copy_resources(device)
if not skip_push_stdlib:
ADB.push(dst, glob(join(SWIFT_ANDROID_HOME, "toolchain/usr/lib/swift-{}/android".format(BuildConfig.swift_abi()), "*.so*")), device)
if not skip_push_external:
ADB.push(dst, glob(join(Dirs.external_libs_dir(), "*.so")), device)
ADB.push(dst, glob(join(Dirs.build_dir(), "*.so")), device)
ADB.push(dst, [join(Dirs.build_dir(), name)], device)
def exec_tests(folder, name, args, device=None):
ld_path = "LD_LIBRARY_PATH=" + folder
test_path = folder + "/" + name
ADB.shell([ld_path, test_path] + args, device)
def run(args):
skip_build = args.skip_build or args.fast_mode
skip_push = args.skip_push or args.fast_mode
skip_push_stdlib = args.skip_push_stdlib
skip_push_external = args.skip_push_external
skip_push_resources = args.skip_push_resources
skip_testing = args.skip_testing
if not skip_build:
sh_checked(
[swift_build, "--build-tests"] + args.build_args
)
name = TestingApp.get_name()
folder = TestingApp.get_folder(name)
if not skip_push:
push(folder, name, skip_push_stdlib, skip_push_external, skip_push_resources, args.device)
if not skip_testing:
exec_tests(folder, name, args.test_args, args.device)
def main():
from arg_parser_ext import ArgumentParserOpt
parser = ArgumentParserOpt(description="Build and run swift tests on Android")
parser.add_argument(
"-s", "--serial", "--device",
dest="device",
action="store",
default=None,
help="use device with given serial (overrides $ANDROID_SERIAL)"
)
parser.add_argument(
"-f", "--fast", "--just-run",
dest="fast_mode",
action="store_true",
default=False,
help="Fast mode. Just run. Alias for --skip-build --skip-push"
)
parser.add_argument(
"-d", "--deploy",
dest="skip_testing",
action="store_true",
default=False,
help="Build and push. Alias for --skip-testing"
)
parser.add_argument(
"--skip-build",
dest="skip_build",
action="store_true",
help="Skip rebuilding. Only deploy and run.",
)
parser.add_argument(
"--skip-push",
dest="skip_push",
action="store_true",
default=False,
help="Skip rebuilding and redeploying. Just run."
)
parser.add_argument(
"--skip-push-stdlib",
dest="skip_push_stdlib",
action="store_true",
default=False,
help="Don't push externally built libraries"
)
parser.add_argument(
"--skip-push-external",
dest="skip_push_external",
action="store_true",
default=False,
help="Don't push toolchain libraries"
)
parser.add_argument(
"--skip-testing",
dest="skip_testing",
action="store_true",
default=False,
help="Don't execute tests on device.\n"
"Useful when you need build and deploy then run manually with different tool (simpleperf, lldb etc.)"
)
parser.add_argument(
"--skip-push-resources",
dest="skip_push_resources",
action="store_true",
default=False,
help="Skip pushing resources to the device."
)
parser.add_argument(
"-Xbuild",
dest="build_args",
action="append",
default=[],
help="Pass flag through to Swift PM"
)
parser.add_argument(
"-Xtest",
dest="test_args",
action="append",
default=[],
help="Pass flag through to XCTest"
)
args = parser.parse_args()
check_swift_home()
run(args)
if __name__ == "__main__":
main()