59
59
"testapp_dir" , None ,
60
60
"Testapps in this directory will be tested." )
61
61
flags .DEFINE_string (
62
- "gameloop_zip " , "integration_testing/gameloop.zip " ,
62
+ "gameloop_project " , "integration_testing/gameloop" ,
63
63
"An zipped UI Test app that helps doing game-loop test."
64
64
" The source code can be found here: integration_testing/gameloop" )
65
65
flags .DEFINE_string (
@@ -78,8 +78,11 @@ def main(argv):
78
78
79
79
current_dir = pathlib .Path (__file__ ).parent .absolute ()
80
80
testapp_dir = os .path .abspath (os .path .expanduser (FLAGS .testapp_dir ))
81
- gameloop_zip = os .path .join (current_dir , FLAGS .gameloop_zip )
81
+ gameloop_project = os .path .join (current_dir , FLAGS .gameloop_project )
82
82
ios_device = FLAGS .ios_device
83
+ device_info = ios_device .split ("-" )
84
+ device_name = device_info [0 ]
85
+ device_os = device_info [1 ]
83
86
84
87
config_path = os .path .join (current_dir , "integration_testing" , "build_testapps.json" )
85
88
with open (config_path , "r" ) as config :
@@ -105,12 +108,12 @@ def main(argv):
105
108
106
109
logging .info ("Testapps found: %s" , "\n " .join (path for _ , path in testapps ))
107
110
108
- gameloop_app = _unzip_gameloop ( gameloop_zip )
111
+ gameloop_app = _build_gameloop ( gameloop_project , device_name , device_os )
109
112
if not gameloop_app :
110
113
logging .info ("gameloop app not found" )
111
114
return 2
112
115
113
- device_id = _boot_simulator (ios_device )
116
+ device_id = _boot_simulator (device_name , device_os )
114
117
if not device_id :
115
118
logging .info ("simulator created fail" )
116
119
return 3
@@ -125,28 +128,59 @@ def main(argv):
125
128
tests , test_validation .CPP , testapp_dir )
126
129
127
130
128
- def _unzip_gameloop (gameloop_zip ):
129
- """Unzip gameloop UI Test app.
131
+ def _get_bundle_id (app_path , config ):
132
+ """Get app bundle id from build_testapps.json file."""
133
+ for api in config ["apis" ]:
134
+ if api ["name" ] != "app" and (api ["name" ] in app_path or api ["full_name" ] in app_path ):
135
+ return api ["bundle_id" ]
136
+
137
+
138
+ def _build_gameloop (gameloop_project , device_name , device_os ):
139
+ """Build gameloop UI Test app.
130
140
131
141
This gameloop app can run integration_test app automatically.
132
142
"""
133
-
134
- directory = os .path .dirname (gameloop_zip )
135
- with zipfile .ZipFile (gameloop_zip ,"r" ) as zip_ref :
136
- zip_ref .extractall (directory )
143
+ project_path = os .path .join (gameloop_project , "gameloop.xcodeproj" )
144
+ output_path = os .path .join (gameloop_project , "Build" )
145
+
146
+ """Build the gameloop app for test."""
147
+ args = ["xcodebuild" , "-project" , project_path ,
148
+ "-scheme" , "gameloop" ,
149
+ "-sdk" , "iphonesimulator" ,
150
+ "build-for-testing" ,
151
+ "-destination" , "platform=iOS Simulator,name=%s,OS=%s" % (device_name , device_os ),
152
+ "SYMROOT=%s" % output_path ]
153
+ logging .info ("Running game-loop test: %s" , " " .join (args ))
154
+ subprocess .run (args = args , check = True )
137
155
138
- for file_dir , _ , file_names in os .walk (directory ):
156
+ for file_dir , _ , file_names in os .walk (output_path ):
139
157
for file_name in file_names :
140
158
if file_name .endswith (".xctestrun" ):
141
159
return os .path .join (file_dir , file_name )
142
160
143
161
144
- def _boot_simulator (ios_device ):
145
- """Create a simulator locally. Will wait until this simulator botted."""
146
- device_info = ios_device .split ("-" )
147
- device_name = device_info [0 ]
148
- device_os = device_info [1 ]
162
+ def _run_xctest (gameloop_app , device_id ):
163
+ """Run the gameloop UI Test app.
164
+ This gameloop app can run integration_test app automatically.
165
+ """
166
+ args = ["xcodebuild" , "test-without-building" ,
167
+ "-xctestrun" , gameloop_app ,
168
+ "-destination" , "id=%s" % device_id ]
169
+ logging .info ("Running game-loop test: %s" , " " .join (args ))
170
+ result = subprocess .run (args = args , capture_output = True , text = True , check = False )
149
171
172
+ if not result .stdout :
173
+ logging .info ("No xctest result" )
174
+ return
175
+
176
+ result = result .stdout .splitlines ()
177
+ log_path = next ((line for line in result if ".xcresult" in line ), None )
178
+ logging .info ("game-loop xctest result: %s" , log_path )
179
+ return log_path
180
+
181
+
182
+ def _boot_simulator (device_name , device_os ):
183
+ """Create a simulator locally. Will wait until this simulator botted."""
150
184
args = ["xcrun" , "simctl" , "shutdown" , "all" ]
151
185
logging .info ("Shutdown all simulators: %s" , " " .join (args ))
152
186
subprocess .run (args = args , check = True )
@@ -172,20 +206,13 @@ def _delete_simulator(device_id):
172
206
subprocess .run (args = args , check = True )
173
207
174
208
175
- def _get_bundle_id (app_path , config ):
176
- """Get app bundle id from build_testapps.json file."""
177
- for api in config ["apis" ]:
178
- if api ["name" ] != "app" and (api ["name" ] in app_path or api ["full_name" ] in app_path ):
179
- return api ["bundle_id" ]
180
-
181
-
182
209
def _run_gameloop_test (bundle_id , app_path , gameloop_app , device_id ):
183
210
"""Run gameloop test and collect test result."""
184
211
logging .info ("Running test: %s, %s, %s, %s" , bundle_id , app_path , gameloop_app , device_id )
185
212
_install_app (app_path , device_id )
186
213
_run_xctest (gameloop_app , device_id )
187
214
logs = _get_test_log (bundle_id , app_path , device_id )
188
- # _uninstall_app(bundle_id, device_id)
215
+ _uninstall_app (bundle_id , device_id )
189
216
return logs
190
217
191
218
@@ -219,24 +246,6 @@ def _get_test_log(bundle_id, app_path, device_id):
219
246
return _read_file (log_path )
220
247
221
248
222
- def _run_xctest (gameloop_app , device_id ):
223
- """Run the gamelop test."""
224
- args = ["xcodebuild" , "test-without-building" ,
225
- "-xctestrun" , gameloop_app ,
226
- "-destination" , "id=%s" % device_id ]
227
- logging .info ("Running game-loop test: %s" , " " .join (args ))
228
- result = subprocess .run (args = args , capture_output = True , text = True , check = False )
229
-
230
- if not result .stdout :
231
- logging .info ("No xctest result" )
232
- return
233
-
234
- result = result .stdout .splitlines ()
235
- log_path = next ((line for line in result if ".xcresult" in line ), None )
236
- logging .info ("game-loop xctest result: %s" , log_path )
237
- return log_path
238
-
239
-
240
249
def _read_file (path ):
241
250
"""Extracts the contents of a file."""
242
251
with open (path , "r" ) as f :
0 commit comments