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.
6 """Script for a testing an existing SDK.
8 This script is normally run immediately after build_sdk.py.
16 import buildbot_common
22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
23 SDK_SRC_DIR = os.path.dirname(SCRIPT_DIR)
24 SDK_LIBRARY_DIR = os.path.join(SDK_SRC_DIR, 'libraries')
25 SDK_DIR = os.path.dirname(SDK_SRC_DIR)
26 SRC_DIR = os.path.dirname(SDK_DIR)
27 OUT_DIR = os.path.join(SRC_DIR, 'out')
29 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
32 def StepBuildExamples(pepperdir):
33 for config in ('Debug', 'Release'):
34 build_sdk.BuildStepMakeAll(pepperdir, 'getting_started',
35 'Build Getting Started (%s)' % config,
36 deps=False, config=config)
38 build_sdk.BuildStepMakeAll(pepperdir, 'examples',
39 'Build Examples (%s)' % config,
40 deps=False, config=config)
43 def StepCopyTests(pepperdir, toolchains, build_experimental):
44 buildbot_common.BuildStep('Copy Tests')
46 # Update test libraries and test apps
50 if not build_experimental:
51 filters['EXPERIMENTAL'] = False
53 tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
54 build_projects.UpdateHelpers(pepperdir, clobber=False)
55 build_projects.UpdateProjects(pepperdir, tree, clobber=False,
56 toolchains=toolchains)
59 def StepBuildTests(pepperdir):
60 for config in ('Debug', 'Release'):
61 build_sdk.BuildStepMakeAll(pepperdir, 'tests',
62 'Build Tests (%s)' % config,
63 deps=False, config=config)
66 def StepRunSelLdrTests(pepperdir):
71 tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
73 def RunTest(test, toolchain, arch, config):
74 args = ['TOOLCHAIN=%s' % toolchain, 'NACL_ARCH=%s' % arch]
75 args += ['SEL_LDR=1', 'run']
76 build_projects.BuildProjectsBranch(pepperdir, test, clean=False,
77 deps=False, config=config,
80 if getos.GetPlatform() == 'win':
81 # On win32 we only support running on the system
83 archs = (getos.GetSystemArch('win'),)
84 elif getos.GetPlatform() == 'mac':
85 # We only ship 32-bit version of sel_ldr on mac.
88 # On linux we can run both 32 and 64-bit
89 archs = ('x86_64', 'x86_32')
91 for root, projects in tree.iteritems():
92 for project in projects:
93 title = 'sel_ldr tests: %s' % os.path.basename(project['NAME'])
94 location = os.path.join(root, project['NAME'])
95 buildbot_common.BuildStep(title)
96 for toolchain in ('newlib', 'glibc'):
98 for config in ('Debug', 'Release'):
99 RunTest(location, toolchain, arch, config)
102 def StepRunBrowserTests(toolchains, experimental):
103 buildbot_common.BuildStep('Run Tests')
107 os.path.join(SCRIPT_DIR, 'test_projects.py'),
113 for toolchain in toolchains:
114 args.extend(['-t', toolchain])
117 subprocess.check_call(args)
118 except subprocess.CalledProcessError:
119 buildbot_common.ErrorExit('Error running tests.')
123 usage = '%prog [<options>] [<phase...>]'
124 parser = optparse.OptionParser(description=__doc__, usage=usage)
125 parser.add_option('--experimental', help='build experimental tests',
127 parser.add_option('--verbose', '-v', help='Verbose output',
130 if 'NACL_SDK_ROOT' in os.environ:
131 # We don't want the currently configured NACL_SDK_ROOT to have any effect
133 del os.environ['NACL_SDK_ROOT']
135 # To setup bash completion for this command first install optcomplete
136 # and then add this line to your .bashrc:
137 # complete -F _optcomplete test_sdk.py
140 optcomplete.autocomplete(parser)
144 options, args = parser.parse_args(args[1:])
146 pepper_ver = str(int(build_version.ChromeMajorVersion()))
147 pepperdir = os.path.join(OUT_DIR, 'pepper_' + pepper_ver)
148 toolchains = ['newlib', 'glibc', 'pnacl']
149 toolchains.append(getos.GetPlatform())
152 build_projects.verbose = True
155 ('build_examples', StepBuildExamples, pepperdir),
156 ('copy_tests', StepCopyTests, pepperdir, toolchains, options.experimental),
157 ('build_tests', StepBuildTests, pepperdir),
158 ('sel_ldr_tests', StepRunSelLdrTests, pepperdir),
159 ('browser_tests', StepRunBrowserTests, toolchains, options.experimental),
163 phase_names = [p[0] for p in phases]
165 if arg not in phase_names:
166 msg = 'Invalid argument: %s\n' % arg
167 msg += 'Possible arguments:\n'
168 for name in phase_names:
169 msg += ' %s\n' % name
170 parser.error(msg.strip())
173 phase_name = phase[0]
174 if args and phase_name not in args:
176 phase_func = phase[1]
177 phase_args = phase[2:]
178 phase_func(*phase_args)
183 if __name__ == '__main__':
185 sys.exit(main(sys.argv))
186 except KeyboardInterrupt:
187 buildbot_common.ErrorExit('test_sdk: interrupted')