Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / build_tools / test_sdk.py
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
8 This script is normally run immediately after build_sdk.py.
9 """
10
11 import optparse
12 import os
13 import subprocess
14 import sys
15
16 import buildbot_common
17 import build_projects
18 import build_sdk
19 import build_version
20 import parse_dsc
21
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')
28
29 sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
30 import getos
31
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)
37
38     build_sdk.BuildStepMakeAll(pepperdir, 'examples',
39                                'Build Examples (%s)' % config,
40                                deps=False, config=config)
41
42
43 def StepCopyTests(pepperdir, toolchains, build_experimental):
44   buildbot_common.BuildStep('Copy Tests')
45
46   # Update test libraries and test apps
47   filters = {
48     'DEST': ['tests']
49   }
50   if not build_experimental:
51     filters['EXPERIMENTAL'] = False
52
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)
57
58
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)
64
65
66 def StepRunSelLdrTests(pepperdir):
67   filters = {
68     'SEL_LDR': True
69   }
70
71   tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
72
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,
78                                        args=args)
79
80   if getos.GetPlatform() == 'win':
81     # On win32 we only support running on the system
82     # arch
83     archs = (getos.GetSystemArch('win'),)
84   elif getos.GetPlatform() == 'mac':
85     # We only ship 32-bit version of sel_ldr on mac.
86     archs = ('x86_32',)
87   else:
88     # On linux we can run both 32 and 64-bit
89     archs = ('x86_64', 'x86_32')
90
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'):
97         for arch in archs:
98           for config in ('Debug', 'Release'):
99             RunTest(location, toolchain, arch, config)
100
101
102 def StepRunBrowserTests(toolchains, experimental):
103   buildbot_common.BuildStep('Run Tests')
104
105   args = [
106     sys.executable,
107     os.path.join(SCRIPT_DIR, 'test_projects.py'),
108     '--retry-times=3',
109   ]
110
111   if experimental:
112     args.append('-x')
113   for toolchain in toolchains:
114     args.extend(['-t', toolchain])
115
116   try:
117     subprocess.check_call(args)
118   except subprocess.CalledProcessError:
119     buildbot_common.ErrorExit('Error running tests.')
120
121
122 def main(args):
123   usage = '%prog [<options>] [<phase...>]'
124   parser = optparse.OptionParser(description=__doc__, usage=usage)
125   parser.add_option('--experimental', help='build experimental tests',
126                     action='store_true')
127   parser.add_option('--verbose', '-v', help='Verbose output',
128                     action='store_true')
129
130   if 'NACL_SDK_ROOT' in os.environ:
131     # We don't want the currently configured NACL_SDK_ROOT to have any effect
132     # of the build.
133     del os.environ['NACL_SDK_ROOT']
134
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
138   try:
139     import optcomplete
140     optcomplete.autocomplete(parser)
141   except ImportError:
142     pass
143
144   options, args = parser.parse_args(args[1:])
145
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())
150
151   if options.verbose:
152     build_projects.verbose = True
153
154   phases = [
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),
160   ]
161
162   if args:
163     phase_names = [p[0] for p in phases]
164     for arg in args:
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())
171
172   for phase in phases:
173     phase_name = phase[0]
174     if args and phase_name not in args:
175       continue
176     phase_func = phase[1]
177     phase_args = phase[2:]
178     phase_func(*phase_args)
179
180   return 0
181
182
183 if __name__ == '__main__':
184   try:
185     sys.exit(main(sys.argv))
186   except KeyboardInterrupt:
187     buildbot_common.ErrorExit('test_sdk: interrupted')