Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 445a43b

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ VM / Testing ] Add build flags to enable code coverage
Change-Id: I37e945f842932b1ac1d87444e4fec2eb752f312f Reviewed-on: https://dart-review.googlesource.com/c/79465 Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Zach Anderson <zra@google.com> Auto-Submit: Ben Konyi <bkonyi@google.com>
1 parent 6066ac8 commit 445a43b

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

runtime/BUILD.gn

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,20 @@ config("dart_config") {
165165
"-fno-exceptions",
166166
]
167167

168-
if (dart_debug) {
168+
ldflags = []
169+
if (is_clang && dart_vm_code_coverage) {
170+
cflags += [
171+
"-O0",
172+
"-fprofile-arcs",
173+
"-ftest-coverage",
174+
]
175+
ldflags += [ "--coverage" ]
176+
} else if (dart_debug) {
169177
cflags += [ "-O${dart_debug_optimization_level}" ]
170178
} else {
171179
cflags += [ "-O3" ]
172180
}
173181

174-
ldflags = []
175182
if (defined(is_asan) && is_asan) {
176183
ldflags += [ "-fsanitize=address" ]
177184
}

runtime/runtime_args.gni

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ declare_args() {
3131
# Available options are: arm, arm64, x64, ia32, and dbc.
3232
dart_target_arch = target_cpu
3333

34-
# The optimization level to use for debug builds.
34+
# The optimization level to use for debug builds. Defaults to 0 for builds with
35+
# code coverage enabled.
3536
dart_debug_optimization_level = "2"
3637

38+
# Whether to enable code coverage for the standalone VM.
39+
dart_vm_code_coverage = false
40+
3741
# Whether to fall back to built-in root certificates when they cannot be
3842
# verified at the operating system level.
3943
dart_use_fallback_root_certificates = false

tools/gn.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ def ToGnArgs(args, mode, arch, target_os):
230230
gn_args['target_cpu'])
231231
gn_args['is_clang'] = args.clang and not dont_use_clang
232232

233+
enable_code_coverage = args.code_coverage and gn_args['is_clang']
234+
gn_args['dart_vm_code_coverage'] = enable_code_coverage
235+
233236
gn_args['is_asan'] = args.asan and gn_args['is_clang']
234237
gn_args['is_msan'] = args.msan and gn_args['is_clang']
235238
gn_args['is_tsan'] = args.tsan and gn_args['is_clang']
@@ -262,7 +265,11 @@ def ToGnArgs(args, mode, arch, target_os):
262265
gn_args['use_goma'] = False
263266
gn_args['goma_dir'] = None
264267

265-
if args.debug_opt_level:
268+
# Code coverage requires -O0 to be set.
269+
if enable_code_coverage:
270+
gn_args['dart_debug_optimization_level'] = 0
271+
gn_args['debug_optimization_level'] = 0
272+
elif args.debug_opt_level:
266273
gn_args['dart_debug_optimization_level'] = args.debug_opt_level
267274
gn_args['debug_optimization_level'] = args.debug_opt_level
268275

@@ -384,6 +391,11 @@ def parse_args(args):
384391
help='Disable Clang',
385392
dest='clang',
386393
action='store_false')
394+
other_group.add_argument('--code-coverage',
395+
help='Enable code coverage for the standalone VM',
396+
default=False,
397+
dest="code_coverage",
398+
action='store_true')
387399
other_group.add_argument('--debug-opt-level',
388400
'-d',
389401
help='The optimization level to use for debug builds',

0 commit comments

Comments
 (0)