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
, sanitizer
):
71 tree
= parse_dsc
.LoadProjectTree(SDK_SRC_DIR
, include
=filters
)
73 def RunTest(test
, toolchain
, config
, arch
=None):
74 args
= ['STANDALONE=1', 'TOOLCHAIN=%s' % toolchain
]
76 args
.append('NACL_ARCH=%s' % arch
)
79 if sanitizer
is not None:
80 # For sanitizer builds we pass extra argument for make, and do
81 # full clean build to make sure everything is rebuilt with the
84 if sanitizer
== 'valgrind':
85 args
+= ['RUN_UNDER=valgrind']
86 elif sanitizer
== 'address':
88 elif sanitizer
== 'thread':
91 build_projects
.BuildProjectsBranch(pepperdir
, test
, clean
=False,
92 deps
=deps
, config
=config
,
95 if getos
.GetPlatform() == 'win':
96 # On win32 we only support running on the system
98 archs
= (getos
.GetSystemArch('win'),)
99 elif getos
.GetPlatform() == 'mac':
100 # We only ship 32-bit version of sel_ldr on mac.
103 # On linux we can run both 32 and 64-bit, and arm (via qemu)
104 archs
= ('x86_64', 'x86_32', 'arm')
106 for root
, projects
in tree
.iteritems():
107 for project
in projects
:
109 sanitizer_name
= '[sanitizer=%s]' % sanitizer
112 title
= 'standalone test%s: %s' % (sanitizer_name
,
113 os
.path
.basename(project
['NAME']))
114 location
= os
.path
.join(root
, project
['NAME'])
115 buildbot_common
.BuildStep(title
)
116 configs
= ('Debug', 'Release')
118 # On linux we can run the standalone tests natively using the host
120 if getos
.GetPlatform() == 'linux':
123 for config
in configs
:
124 RunTest(location
, 'linux', config
)
129 for toolchain
in ('clang-newlib', 'newlib', 'glibc', 'pnacl'):
131 # TODO(sbc): Remove this once we get elf_loader.nexe added to the SDK
132 if toolchain
== 'glibc' and arch
== 'arm':
134 for config
in configs
:
135 RunTest(location
, toolchain
, config
, arch
)
138 def StepRunBrowserTests(toolchains
, experimental
):
139 buildbot_common
.BuildStep('Run Tests')
143 os
.path
.join(SCRIPT_DIR
, 'test_projects.py'),
149 for toolchain
in toolchains
:
150 args
.extend(['-t', toolchain
])
153 subprocess
.check_call(args
)
154 except subprocess
.CalledProcessError
:
155 buildbot_common
.ErrorExit('Error running tests.')
159 parser
= argparse
.ArgumentParser(description
=__doc__
)
160 parser
.add_argument('--experimental', help='build experimental tests',
162 parser
.add_argument('--sanitizer',
163 help='Run sanitizer (asan/tsan/valgrind) tests',
165 parser
.add_argument('--verbose', '-v', help='Verbose output',
167 parser
.add_argument('phases', nargs
="*")
169 if 'NACL_SDK_ROOT' in os
.environ
:
170 # We don't want the currently configured NACL_SDK_ROOT to have any effect
172 del os
.environ
['NACL_SDK_ROOT']
174 # To setup bash completion for this command first install optcomplete
175 # and then add this line to your .bashrc:
176 # complete -F _optcomplete test_sdk.py
179 optcomplete
.autocomplete(parser
)
183 options
= parser
.parse_args(args
)
185 pepper_ver
= str(int(build_version
.ChromeMajorVersion()))
186 pepperdir
= os
.path
.join(OUT_DIR
, 'pepper_' + pepper_ver
)
187 toolchains
= ['clang-newlib', 'newlib', 'glibc', 'pnacl']
188 toolchains
.append(getos
.GetPlatform())
191 build_projects
.verbose
= True
194 ('build_examples', StepBuildExamples
, pepperdir
),
195 ('copy_tests', StepCopyTests
, pepperdir
, toolchains
, options
.experimental
),
196 ('build_tests', StepBuildTests
, pepperdir
),
197 ('sel_ldr_tests', StepRunSelLdrTests
, pepperdir
, None),
198 ('browser_tests', StepRunBrowserTests
, toolchains
, options
.experimental
),
201 if options
.sanitizer
:
202 if getos
.GetPlatform() != 'linux':
203 buildbot_common
.ErrorExit('sanitizer tests only run on linux.')
205 ('sel_ldr_tests_asan', StepRunSelLdrTests
, pepperdir
, 'address'),
206 ('sel_ldr_tests_tsan', StepRunSelLdrTests
, pepperdir
, 'thread'),
207 ('sel_ldr_tests_valgrind', StepRunSelLdrTests
, pepperdir
, 'valgrind')
211 phase_names
= [p
[0] for p
in phases
]
212 for arg
in options
.phases
:
213 if arg
not in phase_names
:
214 msg
= 'Invalid argument: %s\n' % arg
215 msg
+= 'Possible arguments:\n'
216 for name
in phase_names
:
217 msg
+= ' %s\n' % name
218 parser
.error(msg
.strip())
221 phase_name
= phase
[0]
222 if options
.phases
and phase_name
not in options
.phases
:
224 phase_func
= phase
[1]
225 phase_args
= phase
[2:]
226 phase_func(*phase_args
)
231 if __name__
== '__main__':
233 sys
.exit(main(sys
.argv
[1:]))
234 except KeyboardInterrupt:
235 buildbot_common
.ErrorExit('test_sdk: interrupted')