Phil Dubach | ec19a57 | 2009-08-21 15:20:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 2 | |
| 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 | |
| 19 | import glob |
| 20 | import os |
| 21 | import re |
Unsuk Jung | 2a692d1 | 2013-09-29 20:57:32 -0700 | [diff] [blame] | 22 | import shutil |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 23 | import subprocess |
| 24 | import sys |
| 25 | import xml.dom.minidom as dom |
| 26 | from cts import tools |
Brian Muramatsu | 9157e0a | 2011-04-05 18:06:15 -0700 | [diff] [blame] | 27 | from multiprocessing import Pool |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 28 | |
| 29 | def 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 | |
| 34 | def 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 | |
| 53 | class 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 Park | d93d0d1 | 2013-01-10 14:11:35 -0800 | [diff] [blame] | 58 | if len(argv) != 6: |
| 59 | print 'Usage: %s <testRoot> <ctsOutputDir> <tempDir> <androidRootDir> <docletPath>' % argv[0] |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 60 | 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 Jung | 2a692d1 | 2013-09-29 20:57:32 -0700 | [diff] [blame] | 75 | |
| 76 | #dirty hack to copy over prepopulated CTS test plans, stable vs flaky, for autoCTS |
Unsuk Jung | 08d97f9 | 2013-09-29 22:40:22 -0700 | [diff] [blame] | 77 | self.definedplans_repository = os.path.join(self.android_root, 'cts/tests/plans') |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 78 | |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 79 | def GenerateTestDescriptions(self): |
| 80 | """Generate test descriptions for all packages.""" |
Brian Muramatsu | 5df641c | 2011-12-28 15:46:57 -0800 | [diff] [blame] | 81 | pool = Pool(processes=2) |
Brian Muramatsu | 9157e0a | 2011-04-05 18:06:15 -0700 | [diff] [blame] | 82 | |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 83 | # individually generate descriptions not following conventions |
Brian Muramatsu | 9157e0a | 2011-04-05 18:06:15 -0700 | [diff] [blame] | 84 | pool.apply_async(GenerateSignatureCheckDescription, [self.test_repository]) |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 85 | |
| 86 | # generate test descriptions for android tests |
Brian Muramatsu | bdcfc7c | 2011-12-01 14:32:02 -0800 | [diff] [blame] | 87 | results = [] |
Brian Muramatsu | 9157e0a | 2011-04-05 18:06:15 -0700 | [diff] [blame] | 88 | pool.close() |
| 89 | pool.join() |
Brian Muramatsu | bdcfc7c | 2011-12-01 14:32:02 -0800 | [diff] [blame] | 90 | return sum(map(lambda result: result.get(), results)) |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 91 | |
| 92 | def __WritePlan(self, plan, plan_name): |
| 93 | print 'Generating test plan %s' % plan_name |
| 94 | plan.Write(os.path.join(self.plan_repository, plan_name + '.xml')) |
| 95 | |
| 96 | def GenerateTestPlans(self): |
| 97 | """Generate default test plans.""" |
| 98 | # TODO: Instead of hard-coding the plans here, use a configuration file, |
| 99 | # such as test_defs.xml |
| 100 | packages = [] |
Phil Dubach | 8dcedfe | 2009-08-20 16:10:39 -0700 | [diff] [blame] | 101 | descriptions = sorted(glob.glob(os.path.join(self.test_repository, '*.xml'))) |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 102 | for description in descriptions: |
| 103 | doc = tools.XmlFile(description) |
| 104 | packages.append(doc.GetAttr('TestPackage', 'appPackageName')) |
Keun young Park | 965d191 | 2013-02-08 11:37:16 -0800 | [diff] [blame] | 105 | # sort the list to give the same sequence based on name |
| 106 | packages.sort() |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 107 | |
| 108 | plan = tools.TestPlan(packages) |
Tsu Chiang Chuang | d4cce3b | 2011-05-12 12:19:54 -0700 | [diff] [blame] | 109 | plan.Exclude('android\.performance.*') |
Brian Muramatsu | 87ff4df | 2011-12-16 11:41:17 -0800 | [diff] [blame] | 110 | self.__WritePlan(plan, 'CTS') |
Brian Muramatsu | 89ae08c | 2012-01-03 10:55:02 -0800 | [diff] [blame] | 111 | self.__WritePlan(plan, 'CTS-TF') |
Tsu Chiang Chuang | d4cce3b | 2011-05-12 12:19:54 -0700 | [diff] [blame] | 112 | |
Keun young Park | d93d0d1 | 2013-01-10 14:11:35 -0800 | [diff] [blame] | 113 | plan = tools.TestPlan(packages) |
Keun young Park | d93d0d1 | 2013-01-10 14:11:35 -0800 | [diff] [blame] | 114 | plan.Exclude('android\.performance.*') |
Guru Nagarajan | 55f10db | 2013-06-03 13:50:37 -0700 | [diff] [blame] | 115 | plan.Exclude('android\.media\.cts\.StreamingMediaPlayerTest.*') |
| 116 | # Test plan to not include media streaming tests |
| 117 | self.__WritePlan(plan, 'CTS-No-Media-Stream') |
| 118 | |
| 119 | plan = tools.TestPlan(packages) |
| 120 | plan.Exclude('android\.performance.*') |
Keun young Park | d93d0d1 | 2013-01-10 14:11:35 -0800 | [diff] [blame] | 121 | self.__WritePlan(plan, 'SDK') |
| 122 | |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 123 | plan.Exclude(r'android\.tests\.sigtest') |
| 124 | plan.Exclude(r'android\.core.*') |
| 125 | self.__WritePlan(plan, 'Android') |
| 126 | |
| 127 | plan = tools.TestPlan(packages) |
| 128 | plan.Include(r'android\.core\.tests.*') |
Tsu Chiang Chuang | d192e6b | 2012-10-24 16:48:03 -0700 | [diff] [blame^] | 129 | plan.Exclude(r'android\.core\.tests\.libcore.\package.\harmony*') |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 130 | self.__WritePlan(plan, 'Java') |
| 131 | |
Tsu Chiang Chuang | d192e6b | 2012-10-24 16:48:03 -0700 | [diff] [blame^] | 132 | # TODO: remove this once the tests are fixed and merged into Java plan above. |
| 133 | plan = tools.TestPlan(packages) |
| 134 | plan.Include(r'android\.core\.tests\.libcore.\package.\harmony*') |
| 135 | self.__WritePlan(plan, 'Harmony') |
| 136 | |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 137 | plan = tools.TestPlan(packages) |
Tsu Chiang Chuang | 9a223d7 | 2011-04-27 17:19:46 -0700 | [diff] [blame] | 138 | plan.Include(r'android\.core\.vm-tests-tf') |
| 139 | self.__WritePlan(plan, 'VM-TF') |
| 140 | |
| 141 | plan = tools.TestPlan(packages) |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 142 | plan.Include(r'android\.tests\.sigtest') |
| 143 | self.__WritePlan(plan, 'Signature') |
| 144 | |
| 145 | plan = tools.TestPlan(packages) |
Phil Dubach | 6068048 | 2009-08-19 10:13:23 -0700 | [diff] [blame] | 146 | plan.Include(r'android\.tests\.appsecurity') |
| 147 | self.__WritePlan(plan, 'AppSecurity') |
| 148 | |
Keun young Park | ff19417 | 2012-08-14 17:56:11 -0700 | [diff] [blame] | 149 | # hard-coded white list for PDK plan |
| 150 | plan.Exclude('.*') |
keunyoung | c767cba | 2013-04-03 14:50:58 -0700 | [diff] [blame] | 151 | plan.Include('android\.aadb') |
Keun young Park | ff19417 | 2012-08-14 17:56:11 -0700 | [diff] [blame] | 152 | plan.Include('android\.bluetooth') |
| 153 | plan.Include('android\.graphics.*') |
| 154 | plan.Include('android\.hardware') |
keunyoung | de51946 | 2013-03-21 12:06:42 -0700 | [diff] [blame] | 155 | plan.Include('android\.media') |
| 156 | plan.Exclude('android\.mediastress') |
Keun young Park | ff19417 | 2012-08-14 17:56:11 -0700 | [diff] [blame] | 157 | plan.Include('android\.net') |
| 158 | plan.Include('android\.opengl.*') |
| 159 | plan.Include('android\.renderscript') |
| 160 | plan.Include('android\.telephony') |
| 161 | plan.Include('android\.nativemedia.*') |
Stuart Scott | a132af6 | 2013-11-07 10:30:32 -0800 | [diff] [blame] | 162 | plan.Include('com\.android\.cts\..*')#TODO(stuartscott): Should PDK have all these? |
| 163 | #TODO(stuartscott): Maybe move away from com.android.* to android.* - less typing |
Keun young Park | ff19417 | 2012-08-14 17:56:11 -0700 | [diff] [blame] | 164 | self.__WritePlan(plan, 'PDK') |
| 165 | |
Unsuk Jung | 2a692d1 | 2013-09-29 20:57:32 -0700 | [diff] [blame] | 166 | #dirty hack to copy over pre-populated CTS plans - flaky vs stable - to streamline autoCTS |
Unsuk Jung | 08d97f9 | 2013-09-29 22:40:22 -0700 | [diff] [blame] | 167 | shutil.copyfile(os.path.join(self.definedplans_repository, 'CTS-flaky.xml'), |
Unsuk Jung | 2a692d1 | 2013-09-29 20:57:32 -0700 | [diff] [blame] | 168 | os.path.join(self.plan_repository, 'CTS-flaky.xml')) |
Unsuk Jung | 08d97f9 | 2013-09-29 22:40:22 -0700 | [diff] [blame] | 169 | shutil.copyfile(os.path.join(self.definedplans_repository, 'CTS-stable.xml'), |
Unsuk Jung | 2a692d1 | 2013-09-29 20:57:32 -0700 | [diff] [blame] | 170 | os.path.join(self.plan_repository, 'CTS-stable.xml')) |
| 171 | |
Brian Muramatsu | 9157e0a | 2011-04-05 18:06:15 -0700 | [diff] [blame] | 172 | def LogGenerateDescription(name): |
| 173 | print 'Generating test description for package %s' % name |
| 174 | |
| 175 | def GenerateSignatureCheckDescription(test_repository): |
| 176 | """Generate the test description for the signature check.""" |
| 177 | LogGenerateDescription('android.tests.sigtest') |
| 178 | package = tools.TestPackage('SignatureTest', 'android.tests.sigtest') |
| 179 | package.AddAttribute('appNameSpace', 'android.tests.sigtest') |
| 180 | package.AddAttribute('signatureCheck', 'true') |
| 181 | package.AddAttribute('runner', '.InstrumentationRunner') |
Stuart Scott | c09a2e0 | 2013-11-15 13:03:29 -0800 | [diff] [blame] | 182 | package.AddTest('android.tests.sigtest.SignatureTest.testSignature') |
Brian Muramatsu | 9157e0a | 2011-04-05 18:06:15 -0700 | [diff] [blame] | 183 | description = open(os.path.join(test_repository, 'SignatureTest.xml'), 'w') |
| 184 | package.WriteDescription(description) |
| 185 | description.close() |
| 186 | |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 187 | if __name__ == '__main__': |
| 188 | builder = CtsBuilder(sys.argv) |
Keun young Park | d93d0d1 | 2013-01-10 14:11:35 -0800 | [diff] [blame] | 189 | result = builder.GenerateTestDescriptions() |
| 190 | if result != 0: |
| 191 | sys.exit(result) |
Phil Dubach | 0d6ef06 | 2009-08-12 18:13:16 -0700 | [diff] [blame] | 192 | builder.GenerateTestPlans() |
Keun young Park | 3769d33 | 2012-08-29 10:16:37 -0700 | [diff] [blame] | 193 | |