blob: a8c8670812d861c783c52084d8d866dea1845fd8 [file] [log] [blame]
lpromerodf93a882017-05-04 09:42:201// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import <Foundation/Foundation.h>
6
7#import "testing/gtest/ios_enable_coverage.h"
8
9#if !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE)
10extern "C" void __llvm_profile_set_filename(const char* name);
11#endif
12
13namespace coverage_util {
14
15void ConfigureCoverageReportPath() {
16#if !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE)
17 static dispatch_once_t once_token;
18 dispatch_once(&once_token, ^{
19 // Writes the profraw file to the Documents directory, where the app has
20 // write rights.
21 NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
22 NSUserDomainMask, YES);
23 NSString* documents_directory = [paths firstObject];
24 NSString* file_name = [documents_directory
25 stringByAppendingPathComponent:@"coverage.profraw"];
26
27 // For documentation, see:
28 // http://clang.llvm.org/docs/SourceBasedCodeCoverage.html
29 __llvm_profile_set_filename(
30 [file_name cStringUsingEncoding:NSUTF8StringEncoding]);
31
32 // Print the path for easier retrieval.
33 NSLog(@"Coverage data at %@.", file_name);
34 });
35#endif // !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE)
36}
37
38} // namespace coverage_util