summaryrefslogtreecommitdiff
path: root/build/scripts/slave/recipes/boringssl.py
blob: 5cf45957633842cdb53950ab9be5f6d33bb24c5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from recipe_engine.recipe_api import Property

DEPS = [
  'bot_update',
  'file',
  'gclient',
  'path',
  'platform',
  'properties',
  'python',
  'step',
  'test_utils',
]


def _GetHostToolSuffix(platform):
  if platform.is_linux:
    if platform.bits == 64:
      return 'linux64'
  elif platform.is_mac:
    return 'mac'
  elif platform.is_win:
    return 'win32'
  # TODO(davidben): Add other host platforms as needed.


def _GetHostExeSuffix(platform):
  if platform.is_win:
    return '.exe'
  return ''


def _GetHostCMakeArgs(platform, bot_utils):
  args = {}
  if platform.is_win:
    # CMake does not allow backslashes in this variable. It writes the string
    # out to a cmake file with configure_file() and fails to escape it
    # correctly.
    # TODO(davidben): Fix the bug in CMake upstream and remove this workaround.
    args['CMAKE_ASM_NASM_COMPILER'] = \
        str(bot_utils.join('yasm-win32.exe')).replace('\\', '/')
    args['PERL_EXECUTABLE'] = bot_utils.join('perl-win32', 'perl', 'bin',
                                             'perl.exe')
  return args


def _HasToken(buildername, token):
  # Builder names are a sequence of tokens separated by underscores.
  return '_' + token + '_' in '_' + buildername + '_'


def _AppendFlags(args, key, flags):
  if key in args:
    args[key] += ' ' + flags
  else:
    args[key] = flags


def _GetTargetCMakeArgs(buildername, bot_utils):
  args = {}
  if _HasToken(buildername, 'shared'):
    args['BUILD_SHARED_LIBS'] = '1'
  if _HasToken(buildername, 'linux32'):
    # 32-bit Linux is cross-compiled on the 64-bit Linux bot.
    args['CMAKE_SYSTEM_NAME'] = 'Linux'
    args['CMAKE_SYSTEM_PROCESSOR'] = 'x86'
    _AppendFlags(args, 'CMAKE_CXX_FLAGS', '-m32 -msse2')
    _AppendFlags(args, 'CMAKE_C_FLAGS', '-m32 -msse2')
    _AppendFlags(args, 'CMAKE_ASM_FLAGS', '-m32 -msse2')
  if _HasToken(buildername, 'noasm'):
    args['OPENSSL_NO_ASM'] = '1'
  if _HasToken(buildername, 'asan'):
    args['CMAKE_C_COMPILER'] = bot_utils.join('llvm-build', 'bin', 'clang')
    args['CMAKE_CXX_COMPILER'] = bot_utils.join('llvm-build', 'bin', 'clang++')
    _AppendFlags(args, 'CMAKE_CXX_FLAGS', '-fsanitize=address')
    _AppendFlags(args, 'CMAKE_C_FLAGS', '-fsanitize=address')
  return args


def _GetTargetMSVCPrefix(buildername, bot_utils):
  if _HasToken(buildername, 'win32'):
    return ['python', bot_utils.join('vs_env.py'), 'x86']
  if _HasToken(buildername, 'win64'):
    return ['python', bot_utils.join('vs_env.py'), 'x64']
  return []


def _GetTargetEnv(buildername, bot_utils):
  env = {}
  if _HasToken(buildername, 'asan'):
    env['ASAN_SYMBOLIZER_PATH'] = bot_utils.join('llvm-build', 'bin',
                                                 'llvm-symbolizer')
  return env


def _LogFailingTests(api, deferred):
  if not deferred.is_ok:
    error = deferred.get_error()
    if hasattr(error.result, 'test_utils'):
      r = error.result.test_utils.test_results
      p = error.result.presentation
      p.step_text += api.test_utils.format_step_text([
        ['unexpected_failures:', r.unexpected_failures.keys()],
      ])


PROPERTIES = {
  'buildername': Property(),
}


def RunSteps(api, buildername):
  # Sync and pull in everything.
  api.gclient.set_config('boringssl')
  api.bot_update.ensure_checkout(force=True)
  api.gclient.runhooks()

  # Set up paths.
  bot_utils = api.path['checkout'].join('util', 'bot')
  go_env = bot_utils.join('go', 'env.py')
  build_dir = api.path['checkout'].join('build')
  api.file.makedirs('mkdir', build_dir)
  runner_dir = api.path['checkout'].join('ssl', 'test', 'runner')

  # If building with MSVC, all commands must run with an environment wrapper.
  # This is necessary both to find the toolchain and the runtime dlls. Rather
  # than copy the runtime to every directory where a binary is installed, just
  # run the tests with the toolchain prefix as well.
  msvc_prefix = _GetTargetMSVCPrefix(buildername, bot_utils)

  # Build BoringSSL itself.
  cmake = bot_utils.join('cmake-' + _GetHostToolSuffix(api.platform), 'bin',
                         'cmake' + _GetHostExeSuffix(api.platform))
  cmake_args = _GetHostCMakeArgs(api.platform, bot_utils)
  cmake_args.update(_GetTargetCMakeArgs(buildername, bot_utils))
  api.python('cmake', go_env,
             msvc_prefix + [cmake, '-GNinja'] +
             ['-D%s=%s' % (k, v) for (k, v) in sorted(cmake_args.items())] +
             [api.path['checkout']],
             cwd=build_dir)
  api.python('ninja', go_env, msvc_prefix + ['ninja', '-C', build_dir])

  with api.step.defer_results():
    env = _GetTargetEnv(buildername, bot_utils)

    # Run the unit tests.
    deferred = api.python('unit tests', go_env,
                          msvc_prefix + ['go', 'run',
                                         api.path.join('util', 'all_tests.go'),
                                         '-json-output',
                                         api.test_utils.test_results()],
                          cwd=api.path['checkout'], env=env)
    _LogFailingTests(api, deferred)

    # Run the SSL tests.
    deferred = api.python('ssl tests', go_env,
                          msvc_prefix + ['go', 'test', '-pipe', '-json-output',
                                         api.test_utils.test_results()],
                          cwd=runner_dir, env=env)
    _LogFailingTests(api, deferred)


def GenTests(api):
  tests = [
    ('linux', api.platform('linux', 64)),
    ('linux_shared', api.platform('linux', 64)),
    ('linux32', api.platform('linux', 64)),
    ('linux_noasm_asan', api.platform('linux', 64)),
    ('linux32_noasm_asan', api.platform('linux', 64)),
    ('mac', api.platform('mac', 64)),
    ('win32', api.platform('win', 64)),
    ('win64', api.platform('win', 64)),
  ]
  for (buildername, host_platform) in tests:
    yield (
      api.test(buildername) +
      host_platform +
      api.properties.generic(mastername='client.boringssl',
                             buildername=buildername, slavename='slavename') +
      api.override_step_data('unit tests',
                             api.test_utils.canned_test_output(True)) +
      api.override_step_data('ssl tests',
                             api.test_utils.canned_test_output(True))
    )

  yield (
    api.test('failed_unit_tests') +
    api.platform('linux', 64) +
    api.properties.generic(mastername='client.boringssl', buildername='linux',
                           slavename='slavename') +
    api.override_step_data('unit tests',
                           api.test_utils.canned_test_output(False)) +
    api.override_step_data('ssl tests',
                           api.test_utils.canned_test_output(True))
  )

  yield (
    api.test('failed_ssl_tests') +
    api.platform('linux', 64) +
    api.properties.generic(mastername='client.boringssl', buildername='linux',
                           slavename='slavename') +
    api.override_step_data('unit tests',
                           api.test_utils.canned_test_output(True)) +
    api.override_step_data('ssl tests',
                           api.test_utils.canned_test_output(False))
  )