1#!/usr/bin/env python 2# Copyright (c) 2012 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Script for a testing an existing SDK. 7 8This script is normally run immediately after build_sdk.py. 9""" 10 11import optparse 12import os 13import subprocess 14import sys 15 16import buildbot_common 17import build_projects 18import build_sdk 19import build_version 20import parse_dsc 21 22SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 23SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR) 24SDK_LIBRARY_DIR = os.path.join(SDK_SRC_DIR, 'libraries') 25SDK_DIR = os.path.dirname(SDK_SRC_DIR) 26SRC_DIR = os.path.dirname(SDK_DIR) 27OUT_DIR = os.path.join(SRC_DIR, 'out') 28 29sys.path.append(os.path.join(SDK_SRC_DIR, 'tools')) 30import getos 31 32def StepBuildExamples(pepperdir): 33 for config in ('Debug', 'Release'): 34 build_sdk.BuildStepMakeAll(pepperdir, 'examples', 35 'Build Examples (%s)' % config, 36 deps=False, config=config) 37 38 39def StepCopyTests(pepperdir, toolchains, build_experimental): 40 buildbot_common.BuildStep('Copy Tests') 41 42 # Update test libraries and test apps 43 filters = { 44 'DEST': ['tests'] 45 } 46 if not build_experimental: 47 filters['EXPERIMENTAL'] = False 48 49 tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) 50 build_projects.UpdateHelpers(pepperdir, clobber=False) 51 build_projects.UpdateProjects(pepperdir, tree, clobber=False, 52 toolchains=toolchains) 53 54 55def StepBuildTests(pepperdir): 56 for config in ('Debug', 'Release'): 57 build_sdk.BuildStepMakeAll(pepperdir, 'tests', 58 'Build Tests (%s)' % config, 59 deps=False, config=config) 60 61 62def StepRunSelLdrTests(pepperdir): 63 filters = { 64 'SEL_LDR': True 65 } 66 67 tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) 68 69 def RunTest(test, toolchain, arch, config): 70 args = ['TOOLCHAIN=%s' % toolchain, 'NACL_ARCH=%s' % arch] 71 args += ['SEL_LDR=1', 'run'] 72 build_projects.BuildProjectsBranch(pepperdir, test, clean=False, 73 deps=False, config=config, 74 args=args) 75 76 if getos.GetPlatform() == 'win': 77 # On win32 we only support running on the system 78 # arch 79 archs = (getos.GetSystemArch('win'),) 80 elif getos.GetPlatform() == 'mac': 81 # We only ship 32-bit version of sel_ldr on mac. 82 archs = ('x86_32',) 83 else: 84 # On linux we can run both 32 and 64-bit 85 archs = ('x86_64', 'x86_32') 86 87 for root, projects in tree.iteritems(): 88 for project in projects: 89 title = 'sel_ldr tests: %s' % os.path.basename(project['NAME']) 90 location = os.path.join(root, project['NAME']) 91 buildbot_common.BuildStep(title) 92 for toolchain in ('newlib', 'glibc'): 93 for arch in archs: 94 for config in ('Debug', 'Release'): 95 RunTest(location, toolchain, arch, config) 96 97 98def StepRunBrowserTests(toolchains, experimental): 99 buildbot_common.BuildStep('Run Tests') 100 101 args = [ 102 sys.executable, 103 os.path.join(SCRIPT_DIR, 'test_projects.py'), 104 ] 105 106 if experimental: 107 args.append('-x') 108 for toolchain in toolchains: 109 args.extend(['-t', toolchain]) 110 111 try: 112 subprocess.check_call(args) 113 except subprocess.CalledProcessError: 114 buildbot_common.ErrorExit('Error running tests.') 115 116 117def main(args): 118 usage = '%prog [<options>] [<phase...>]' 119 parser = optparse.OptionParser(description=__doc__, usage=usage) 120 parser.add_option('--experimental', help='build experimental tests', 121 action='store_true') 122 parser.add_option('--verbose', help='Verbose output', action='store_true') 123 124 if 'NACL_SDK_ROOT' in os.environ: 125 # We don't want the currently configured NACL_SDK_ROOT to have any effect 126 # of the build. 127 del os.environ['NACL_SDK_ROOT'] 128 129 options, args = parser.parse_args(args[1:]) 130 131 pepper_ver = str(int(build_version.ChromeMajorVersion())) 132 pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver) 133 toolchains = ['newlib', 'glibc', 'pnacl'] 134 toolchains.append(getos.GetPlatform()) 135 136 if options.verbose: 137 build_projects.verbose = True 138 139 phases = [ 140 ('build_examples', StepBuildExamples, pepperdir), 141 ('copy_tests', StepCopyTests, pepperdir, toolchains, options.experimental), 142 ('build_tests', StepBuildTests, pepperdir), 143 ('sel_ldr_tests', StepRunSelLdrTests, pepperdir), 144 ('browser_tests', StepRunBrowserTests, toolchains, options.experimental), 145 ] 146 147 if args: 148 phase_names = [p[0] for p in phases] 149 for arg in args: 150 if arg not in phase_names: 151 msg = 'Invalid argument: %s\n' % arg 152 msg += 'Possible arguments:\n' 153 for name in phase_names: 154 msg += ' %s\n' % name 155 parser.error(msg.strip()) 156 157 for phase in phases: 158 phase_name = phase[0] 159 if args and phase_name not in args: 160 continue 161 phase_func = phase[1] 162 phase_args = phase[2:] 163 phase_func(*phase_args) 164 165 return 0 166 167 168if __name__ == '__main__': 169 try: 170 sys.exit(main(sys.argv)) 171 except KeyboardInterrupt: 172 buildbot_common.ErrorExit('test_sdk: interrupted') 173