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']
87 args
+= ['CC=clang', 'CXX=clang++',
88 'LDFLAGS=-pie -fsanitize=' + sanitizer
,
89 'CFLAGS=-fPIC -fsanitize=' + sanitizer
]
90 build_projects
.BuildProjectsBranch(pepperdir
, 'src', clean
=False,
91 deps
=deps
, config
=config
,
92 args
=args
+ ['clean'])
93 build_projects
.BuildProjectsBranch(pepperdir
, 'tests', clean
=False,
94 deps
=deps
, config
=config
,
95 args
=args
+ ['clean'])
97 build_projects
.BuildProjectsBranch(pepperdir
, test
, clean
=False,
98 deps
=deps
, config
=config
,
101 if getos
.GetPlatform() == 'win':
102 # On win32 we only support running on the system
104 archs
= (getos
.GetSystemArch('win'),)
105 elif getos
.GetPlatform() == 'mac':
106 # We only ship 32-bit version of sel_ldr on mac.
109 # On linux we can run both 32 and 64-bit
110 archs
= ('x86_64', 'x86_32')
112 for root
, projects
in tree
.iteritems():
113 for project
in projects
:
115 sanitizer_name
= '[sanitizer=%s]' % sanitizer
118 title
= 'standalone test%s: %s' % (sanitizer_name
,
119 os
.path
.basename(project
['NAME']))
120 location
= os
.path
.join(root
, project
['NAME'])
121 buildbot_common
.BuildStep(title
)
122 configs
= ('Debug', 'Release')
124 # On linux we can run the standalone tests natively using the host
126 if getos
.GetPlatform() == 'linux':
129 for config
in configs
:
130 RunTest(location
, 'linux', config
)
135 for toolchain
in ('newlib', 'glibc', 'pnacl'):
137 for config
in configs
:
138 RunTest(location
, toolchain
, config
, arch
)
141 def StepRunBrowserTests(toolchains
, experimental
):
142 buildbot_common
.BuildStep('Run Tests')
146 os
.path
.join(SCRIPT_DIR
, 'test_projects.py'),
152 for toolchain
in toolchains
:
153 args
.extend(['-t', toolchain
])
156 subprocess
.check_call(args
)
157 except subprocess
.CalledProcessError
:
158 buildbot_common
.ErrorExit('Error running tests.')
162 usage
= '%prog [<options>] [<phase...>]'
163 parser
= optparse
.OptionParser(description
=__doc__
, usage
=usage
)
164 parser
.add_option('--experimental', help='build experimental tests',
166 parser
.add_option('--sanitizer',
167 help='Run sanitizer (asan/tsan/valgrind) tests',
169 parser
.add_option('--verbose', '-v', help='Verbose output',
172 if 'NACL_SDK_ROOT' in os
.environ
:
173 # We don't want the currently configured NACL_SDK_ROOT to have any effect
175 del os
.environ
['NACL_SDK_ROOT']
177 # To setup bash completion for this command first install optcomplete
178 # and then add this line to your .bashrc:
179 # complete -F _optcomplete test_sdk.py
182 optcomplete
.autocomplete(parser
)
186 options
, args
= parser
.parse_args(args
[1:])
188 pepper_ver
= str(int(build_version
.ChromeMajorVersion()))
189 pepperdir
= os
.path
.join(OUT_DIR
, 'pepper_' + pepper_ver
)
190 toolchains
= ['newlib', 'glibc', 'pnacl']
191 toolchains
.append(getos
.GetPlatform())
194 build_projects
.verbose
= True
197 ('build_examples', StepBuildExamples
, pepperdir
),
198 ('copy_tests', StepCopyTests
, pepperdir
, toolchains
, options
.experimental
),
199 ('build_tests', StepBuildTests
, pepperdir
),
200 ('sel_ldr_tests', StepRunSelLdrTests
, pepperdir
, None),
201 ('browser_tests', StepRunBrowserTests
, toolchains
, options
.experimental
),
204 if options
.sanitizer
:
205 if getos
.GetPlatform() != 'linux':
206 buildbot_common
.ErrorExit('sanitizer tests only run on linux.')
208 ('sel_ldr_tests_asan', StepRunSelLdrTests
, pepperdir
, 'address'),
209 ('sel_ldr_tests_tsan', StepRunSelLdrTests
, pepperdir
, 'thread'),
210 ('sel_ldr_tests_valgrind', StepRunSelLdrTests
, pepperdir
, 'valgrind')
214 phase_names
= [p
[0] for p
in phases
]
216 if arg
not in phase_names
:
217 msg
= 'Invalid argument: %s\n' % arg
218 msg
+= 'Possible arguments:\n'
219 for name
in phase_names
:
220 msg
+= ' %s\n' % name
221 parser
.error(msg
.strip())
224 phase_name
= phase
[0]
225 if args
and phase_name
not in args
:
227 phase_func
= phase
[1]
228 phase_args
= phase
[2:]
229 phase_func(*phase_args
)
234 if __name__
== '__main__':
236 sys
.exit(main(sys
.argv
))
237 except KeyboardInterrupt:
238 buildbot_common
.ErrorExit('test_sdk: interrupted')