blob: f9228d791078f8792e6bbe67cbd3720600533a30 [file] [log] [blame]
Phil Dubachec19a572009-08-21 15:20:13 -07001#!/usr/bin/python
Phil Dubach0d6ef062009-08-12 18:13:16 -07002
3# Copyright (C) 2009 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Module for generating CTS test descriptions and test plans."""
18
19import glob
20import os
21import re
Unsuk Jung2a692d12013-09-29 20:57:32 -070022import shutil
Phil Dubach0d6ef062009-08-12 18:13:16 -070023import subprocess
24import sys
25import xml.dom.minidom as dom
26from cts import tools
Brian Muramatsu9157e0a2011-04-05 18:06:15 -070027from multiprocessing import Pool
Phil Dubach0d6ef062009-08-12 18:13:16 -070028
29def GetSubDirectories(root):
30 """Return all directories under the given root directory."""
31 return [x for x in os.listdir(root) if os.path.isdir(os.path.join(root, x))]
32
33
34def GetMakeFileVars(makefile_path):
35 """Extracts variable definitions from the given make file.
36
37 Args:
38 makefile_path: Path to the make file.
39
40 Returns:
41 A dictionary mapping variable names to their assigned value.
42 """
43 result = {}
44 pattern = re.compile(r'^\s*([^:#=\s]+)\s*:=\s*(.*?[^\\])$', re.MULTILINE + re.DOTALL)
45 stream = open(makefile_path, 'r')
46 content = stream.read()
47 for match in pattern.finditer(content):
48 result[match.group(1)] = match.group(2)
49 stream.close()
50 return result
51
52
53class CtsBuilder(object):
54 """Main class for generating test descriptions and test plans."""
55
56 def __init__(self, argv):
57 """Initialize the CtsBuilder from command line arguments."""
Keun young Parkd93d0d12013-01-10 14:11:35 -080058 if len(argv) != 6:
59 print 'Usage: %s <testRoot> <ctsOutputDir> <tempDir> <androidRootDir> <docletPath>' % argv[0]
Phil Dubach0d6ef062009-08-12 18:13:16 -070060 print ''
61 print 'testRoot: Directory under which to search for CTS tests.'
62 print 'ctsOutputDir: Directory in which the CTS repository should be created.'
63 print 'tempDir: Directory to use for storing temporary files.'
64 print 'androidRootDir: Root directory of the Android source tree.'
65 print 'docletPath: Class path where the DescriptionGenerator doclet can be found.'
66 sys.exit(1)
67 self.test_root = sys.argv[1]
68 self.out_dir = sys.argv[2]
69 self.temp_dir = sys.argv[3]
70 self.android_root = sys.argv[4]
71 self.doclet_path = sys.argv[5]
72
73 self.test_repository = os.path.join(self.out_dir, 'repository/testcases')
74 self.plan_repository = os.path.join(self.out_dir, 'repository/plans')
Unsuk Jung08d97f92013-09-29 22:40:22 -070075 self.definedplans_repository = os.path.join(self.android_root, 'cts/tests/plans')
Phil Dubach0d6ef062009-08-12 18:13:16 -070076
Phil Dubach0d6ef062009-08-12 18:13:16 -070077 def GenerateTestDescriptions(self):
78 """Generate test descriptions for all packages."""
Brian Muramatsu5df641c2011-12-28 15:46:57 -080079 pool = Pool(processes=2)
Brian Muramatsu9157e0a2011-04-05 18:06:15 -070080
Phil Dubach0d6ef062009-08-12 18:13:16 -070081 # individually generate descriptions not following conventions
Brian Muramatsu9157e0a2011-04-05 18:06:15 -070082 pool.apply_async(GenerateSignatureCheckDescription, [self.test_repository])
Phil Dubach0d6ef062009-08-12 18:13:16 -070083
84 # generate test descriptions for android tests
Brian Muramatsubdcfc7c2011-12-01 14:32:02 -080085 results = []
Brian Muramatsu9157e0a2011-04-05 18:06:15 -070086 pool.close()
87 pool.join()
Brian Muramatsubdcfc7c2011-12-01 14:32:02 -080088 return sum(map(lambda result: result.get(), results))
Phil Dubach0d6ef062009-08-12 18:13:16 -070089
90 def __WritePlan(self, plan, plan_name):
91 print 'Generating test plan %s' % plan_name
92 plan.Write(os.path.join(self.plan_repository, plan_name + '.xml'))
93
94 def GenerateTestPlans(self):
95 """Generate default test plans."""
96 # TODO: Instead of hard-coding the plans here, use a configuration file,
97 # such as test_defs.xml
98 packages = []
Phil Dubach8dcedfe2009-08-20 16:10:39 -070099 descriptions = sorted(glob.glob(os.path.join(self.test_repository, '*.xml')))
Phil Dubach0d6ef062009-08-12 18:13:16 -0700100 for description in descriptions:
101 doc = tools.XmlFile(description)
102 packages.append(doc.GetAttr('TestPackage', 'appPackageName'))
Keun young Park965d1912013-02-08 11:37:16 -0800103 # sort the list to give the same sequence based on name
104 packages.sort()
Phil Dubach0d6ef062009-08-12 18:13:16 -0700105
106 plan = tools.TestPlan(packages)
Tsu Chiang Chuangd4cce3b2011-05-12 12:19:54 -0700107 plan.Exclude('android\.performance.*')
Brian Muramatsu87ff4df2011-12-16 11:41:17 -0800108 self.__WritePlan(plan, 'CTS')
Brian Muramatsu89ae08c2012-01-03 10:55:02 -0800109 self.__WritePlan(plan, 'CTS-TF')
Tsu Chiang Chuangd4cce3b2011-05-12 12:19:54 -0700110
Keun young Parkd93d0d12013-01-10 14:11:35 -0800111 plan = tools.TestPlan(packages)
Keun young Parkd93d0d12013-01-10 14:11:35 -0800112 plan.Exclude('android\.performance.*')
Guru Nagarajan55f10db2013-06-03 13:50:37 -0700113 plan.Exclude('android\.media\.cts\.StreamingMediaPlayerTest.*')
114 # Test plan to not include media streaming tests
115 self.__WritePlan(plan, 'CTS-No-Media-Stream')
116
117 plan = tools.TestPlan(packages)
118 plan.Exclude('android\.performance.*')
Keun young Parkd93d0d12013-01-10 14:11:35 -0800119 self.__WritePlan(plan, 'SDK')
120
Phil Dubach0d6ef062009-08-12 18:13:16 -0700121 plan.Exclude(r'android\.tests\.sigtest')
122 plan.Exclude(r'android\.core.*')
123 self.__WritePlan(plan, 'Android')
124
125 plan = tools.TestPlan(packages)
126 plan.Include(r'android\.core\.tests.*')
Tsu Chiang Chuangcf7ceab2012-10-24 16:48:03 -0700127 plan.Exclude(r'android\.core\.tests\.libcore.\package.\harmony*')
Phil Dubach0d6ef062009-08-12 18:13:16 -0700128 self.__WritePlan(plan, 'Java')
129
Tsu Chiang Chuangcf7ceab2012-10-24 16:48:03 -0700130 # TODO: remove this once the tests are fixed and merged into Java plan above.
131 plan = tools.TestPlan(packages)
132 plan.Include(r'android\.core\.tests\.libcore.\package.\harmony*')
133 self.__WritePlan(plan, 'Harmony')
134
Phil Dubach0d6ef062009-08-12 18:13:16 -0700135 plan = tools.TestPlan(packages)
Tsu Chiang Chuang9a223d72011-04-27 17:19:46 -0700136 plan.Include(r'android\.core\.vm-tests-tf')
137 self.__WritePlan(plan, 'VM-TF')
138
139 plan = tools.TestPlan(packages)
Phil Dubach0d6ef062009-08-12 18:13:16 -0700140 plan.Include(r'android\.tests\.sigtest')
141 self.__WritePlan(plan, 'Signature')
142
143 plan = tools.TestPlan(packages)
Phil Dubach60680482009-08-19 10:13:23 -0700144 plan.Include(r'android\.tests\.appsecurity')
145 self.__WritePlan(plan, 'AppSecurity')
146
Keun young Parkff194172012-08-14 17:56:11 -0700147 # hard-coded white list for PDK plan
148 plan.Exclude('.*')
keunyoungc767cba2013-04-03 14:50:58 -0700149 plan.Include('android\.aadb')
Keun young Parkff194172012-08-14 17:56:11 -0700150 plan.Include('android\.bluetooth')
151 plan.Include('android\.graphics.*')
152 plan.Include('android\.hardware')
keunyoungde519462013-03-21 12:06:42 -0700153 plan.Include('android\.media')
154 plan.Exclude('android\.mediastress')
Keun young Parkff194172012-08-14 17:56:11 -0700155 plan.Include('android\.net')
156 plan.Include('android\.opengl.*')
157 plan.Include('android\.renderscript')
158 plan.Include('android\.telephony')
159 plan.Include('android\.nativemedia.*')
Stuart Scotta132af62013-11-07 10:30:32 -0800160 plan.Include('com\.android\.cts\..*')#TODO(stuartscott): Should PDK have all these?
Keun young Parkff194172012-08-14 17:56:11 -0700161 self.__WritePlan(plan, 'PDK')
162
Nicholas Sauer471c6012014-05-28 15:28:28 -0700163 flaky_tests = BuildCtsFlakyTestList()
164
165 # CTS Stable plan
166 plan = tools.TestPlan(packages)
Unsuk Jung7c7832b2014-09-06 20:31:08 -0700167 plan.Exclude(r'com\.android\.cts\.browserbench')
Nicholas Sauer471c6012014-05-28 15:28:28 -0700168 for package, test_list in flaky_tests.iteritems():
169 plan.ExcludeTests(package, test_list)
170 self.__WritePlan(plan, 'CTS-stable')
171
Unsuk Jung8398ab82014-09-19 03:26:39 -0700172 # CTS Flaky plan - list of tests known to be flaky in lab environment
Nicholas Sauer471c6012014-05-28 15:28:28 -0700173 plan = tools.TestPlan(packages)
174 plan.Exclude('.*')
Unsuk Jung7c7832b2014-09-06 20:31:08 -0700175 plan.Include(r'com\.android\.cts\.browserbench')
Nicholas Sauer471c6012014-05-28 15:28:28 -0700176 for package, test_list in flaky_tests.iteritems():
Unsuk Jungb5153c42014-09-19 02:12:50 -0700177 plan.Include(package+'$')
Nicholas Sauer471c6012014-05-28 15:28:28 -0700178 plan.IncludeTests(package, test_list)
179 self.__WritePlan(plan, 'CTS-flaky')
180
Unsuk Jung8398ab82014-09-19 03:26:39 -0700181 small_tests = BuildAospSmallSizeTestList()
182 medium_tests = BuildAospMediumSizeTestList()
183
184 # CTS - sub plan for public, small size tests
185 plan = tools.TestPlan(packages)
186 plan.Exclude('.*')
187 for package, test_list in small_tests.iteritems():
188 plan.Include(package+'$')
189 for package, test_list in flaky_tests.iteritems():
190 plan.ExcludeTests(package, test_list)
191 self.__WritePlan(plan, 'CTS-kitkat-small')
192
193 # CTS - sub plan for public, medium size tests
194 plan = tools.TestPlan(packages)
195 plan.Exclude('.*')
196 for package, test_list in medium_tests.iteritems():
197 plan.Include(package+'$')
198 for package, test_list in flaky_tests.iteritems():
199 plan.ExcludeTests(package, test_list)
200 self.__WritePlan(plan, 'CTS-kitkat-medium')
201
202 # CTS - sub plan for hardware tests which is public, large
203 plan = tools.TestPlan(packages)
204 plan.Exclude('.*')
205 plan.Include(r'android\.hardware$')
206 for package, test_list in flaky_tests.iteritems():
207 plan.ExcludeTests(package, test_list)
208 self.__WritePlan(plan, 'CTS-hardware')
209
210 # CTS - sub plan for media tests which is public, large
211 plan = tools.TestPlan(packages)
212 plan.Exclude('.*')
213 plan.Include(r'android\.media$')
214 for package, test_list in flaky_tests.iteritems():
215 plan.ExcludeTests(package, test_list)
216 self.__WritePlan(plan, 'CTS-media')
217
218 # CTS - sub plan for mediastress tests which is public, large
219 plan = tools.TestPlan(packages)
220 plan.Exclude('.*')
221 plan.Include(r'android\.mediastress$')
222 for package, test_list in flaky_tests.iteritems():
223 plan.ExcludeTests(package, test_list)
224 self.__WritePlan(plan, 'CTS-mediastress')
225
226 #CTS - sub plan for new test packages added for staging
227 plan = tools.TestPlan(packages)
228 for package, test_list in small_tests.iteritems():
229 plan.Exclude(package+'$')
230 for package, test_list in medium_tests.iteritems():
231 plan.Exclude(package+'$')
232 plan.Exclude(r'android\.hardware$')
233 plan.Exclude(r'android\.media$')
234 plan.Exclude(r'android\.mediastress$')
235 for package, test_list in flaky_tests.iteritems():
236 plan.ExcludeTests(package, test_list)
237 self.__WritePlan(plan, 'CTS-staging')
238
239def BuildAospMediumSizeTestList():
240 """ Construct a defaultdic that lists package names of medium tests
241 already published to aosp. """
242 return {
243 'android.app' : [],
244 'android.core.tests.libcore.package.libcore' : [],
245 'android.core.tests.libcore.package.org' : [],
246 'android.core.vm-tests-tf' : [],
247 'android.dpi' : [],
248 'android.host.security' : [],
249 'android.net' : [],
250 'android.os' : [],
251 'android.security' : [],
252 'android.telephony' : [],
253 'android.webkit' : [],
254 'android.widget' : [],
255 'com.android.cts.browserbench' : []}
256
257def BuildAospSmallSizeTestList():
258 """ Construct a defaultdict that lists packages names of small tests
259 already published to aosp. """
260 return {
261 'android.aadb' : [],
262 'android.acceleration' : [],
263 'android.accessibility' : [],
264 'android.accessibilityservice' : [],
265 'android.accounts' : [],
266 'android.admin' : [],
267 'android.animation' : [],
268 'android.bionic' : [],
269 'android.bluetooth' : [],
270 'android.calendarcommon' : [],
271 'android.content' : [],
272 'android.core.tests.libcore.package.com' : [],
273 'android.core.tests.libcore.package.conscrypt' : [],
274 'android.core.tests.libcore.package.dalvik' : [],
275 'android.core.tests.libcore.package.sun' : [],
276 'android.core.tests.libcore.package.tests' : [],
277 'android.database' : [],
278 'android.dreams' : [],
279 'android.drm' : [],
280 'android.effect' : [],
281 'android.gesture' : [],
282 'android.graphics' : [],
283 'android.graphics2' : [],
284 'android.jni' : [],
285 'android.keystore' : [],
286 'android.location' : [],
287 'android.nativemedia.sl' : [],
288 'android.nativemedia.xa' : [],
289 'android.nativeopengl' : [],
290 'android.ndef' : [],
291 'android.opengl' : [],
292 'android.openglperf' : [],
293 'android.permission' : [],
294 'android.permission2' : [],
295 'android.preference' : [],
296 'android.preference2' : [],
297 'android.provider' : [],
298 'android.renderscript' : [],
299 'android.rscpp' : [],
300 'android.rsg' : [],
301 'android.sax' : [],
302 'android.speech' : [],
303 'android.tests.appsecurity' : [],
304 'android.text' : [],
305 'android.textureview' : [],
306 'android.theme' : [],
307 'android.usb' : [],
308 'android.util' : [],
309 'android.view' : [],
310 'com.android.cts.dram' : [],
311 'com.android.cts.filesystemperf' : [],
312 'com.android.cts.jank' : [],
313 'com.android.cts.opengl' : [],
314 'com.android.cts.simplecpu' : [],
315 'com.android.cts.ui' : [],
316 'com.android.cts.uihost' : [],
317 'com.android.cts.videoperf' : [],
318 'zzz.android.monkey' : []}
Nicholas Sauer471c6012014-05-28 15:28:28 -0700319
320def BuildCtsFlakyTestList():
321 """ Construct a defaultdict that maps package name to a list of tests
322 that are known to be flaky. """
323 return {
324 'android.app' : [
325 'cts.ActivityManagerTest#testIsRunningInTestHarness',
326 'cts.AlertDialogTest#testAlertDialogCancelable',
327 'cts.ExpandableListActivityTest#testCallback',],
Unsuk Jung1d729242014-09-08 09:23:03 -0700328 'android.dpi' : [
329 'cts.DefaultManifestAttributesSdkTest#testPackageHasExpectedSdkVersion',],
Nicholas Sauer471c6012014-05-28 15:28:28 -0700330 'android.hardware' : [
331 'camera2.cts.CameraDeviceTest#testCameraDeviceRepeatingRequest',
332 'camera2.cts.ImageReaderTest#testImageReaderFromCameraJpeg',
333 'cts.CameraTest#testImmediateZoom',
334 'cts.CameraTest#testPreviewCallback',
335 'cts.CameraTest#testSmoothZoom',
336 'cts.CameraTest#testVideoSnapshot',
337 'cts.CameraGLTest#testCameraToSurfaceTextureMetadata',
338 'cts.CameraGLTest#testSetPreviewTextureBothCallbacks',
339 'cts.CameraGLTest#testSetPreviewTexturePreviewCallback',],
340 'android.media' : [
341 'cts.DecoderTest#testCodecResetsH264WithSurface',
342 'cts.StreamingMediaPlayerTest#testHLS',],
343 'android.mediastress' : [
344 'cts.NativeMediaTest#test480pPlay',],
345 'android.net' : [
346 'cts.ConnectivityManagerTest#testStartUsingNetworkFeature_enableHipri',
347 'cts.DnsTest#testDnsWorks',
348 'cts.SSLCertificateSocketFactoryTest#testCreateSocket',
349 'cts.SSLCertificateSocketFactoryTest#test_createSocket_bind',
350 'cts.SSLCertificateSocketFactoryTest#test_createSocket_simple',
351 'cts.SSLCertificateSocketFactoryTest#test_createSocket_wrapping',
352 'cts.TrafficStatsTest#testTrafficStatsForLocalhost',
353 'wifi.cts.NsdManagerTest#testAndroidTestCaseSetupProperly',
354 'wifi.cts.ScanResultTest#testAndroidTestCaseSetupProperly',
355 'wifi.cts.ScanResultTest#testScanResultTimeStamp',],
Unsuk Jung1d729242014-09-08 09:23:03 -0700356 'android.os' : [
357 'cts.BuildVersionTest#testReleaseVersion',
358 'cts.BuildTest#testIsSecureUserBuild',],
Nicholas Sauer471c6012014-05-28 15:28:28 -0700359 'android.security' : [
360 'cts.BannedFilesTest#testNoSu',
361 'cts.BannedFilesTest#testNoSuInPath',
362 'cts.ListeningPortsTest#testNoRemotelyAccessibleListeningUdp6Ports',
363 'cts.ListeningPortsTest#testNoRemotelyAccessibleListeningUdpPorts',
364 'cts.PackageSignatureTest#testPackageSignatures',],
365 'android.webkit' : [
366 'cts.WebViewClientTest#testDoUpdateVisitedHistory',
367 'cts.WebViewClientTest#testLoadPage',
368 'cts.WebViewClientTest#testOnFormResubmission',
369 'cts.WebViewClientTest#testOnReceivedError',
370 'cts.WebViewClientTest#testOnReceivedHttpAuthRequest',
371 'cts.WebViewClientTest#testOnScaleChanged',
372 'cts.WebViewClientTest#testOnUnhandledKeyEvent',
373 'cts.WebViewTest#testSetInitialScale',]}
Unsuk Jung2a692d12013-09-29 20:57:32 -0700374
Brian Muramatsu9157e0a2011-04-05 18:06:15 -0700375def LogGenerateDescription(name):
376 print 'Generating test description for package %s' % name
377
378def GenerateSignatureCheckDescription(test_repository):
379 """Generate the test description for the signature check."""
380 LogGenerateDescription('android.tests.sigtest')
381 package = tools.TestPackage('SignatureTest', 'android.tests.sigtest')
382 package.AddAttribute('appNameSpace', 'android.tests.sigtest')
383 package.AddAttribute('signatureCheck', 'true')
384 package.AddAttribute('runner', '.InstrumentationRunner')
Stuart Scottc09a2e02013-11-15 13:03:29 -0800385 package.AddTest('android.tests.sigtest.SignatureTest.testSignature')
Brian Muramatsu9157e0a2011-04-05 18:06:15 -0700386 description = open(os.path.join(test_repository, 'SignatureTest.xml'), 'w')
387 package.WriteDescription(description)
388 description.close()
389
Phil Dubach0d6ef062009-08-12 18:13:16 -0700390if __name__ == '__main__':
391 builder = CtsBuilder(sys.argv)
Keun young Parkd93d0d12013-01-10 14:11:35 -0800392 result = builder.GenerateTestDescriptions()
393 if result != 0:
394 sys.exit(result)
Phil Dubach0d6ef062009-08-12 18:13:16 -0700395 builder.GenerateTestPlans()
Keun young Park3769d332012-08-29 10:16:37 -0700396