blob: c21a16def24746a8ffd0fd22d9ac72b2d2484ae0 [file] [log] [blame]
Artem Titarenko34fc3462018-11-06 12:29:29 +01001/*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#import <Foundation/Foundation.h>
12
13#ifdef WEBRTC_IOS_ENABLE_COVERAGE
14extern "C" void __llvm_profile_set_filename(const char* name);
15#endif
16
17namespace rtc {
18namespace test {
19
20void ConfigureCoverageReportPath() {
21#ifdef WEBRTC_IOS_ENABLE_COVERAGE
22 static dispatch_once_t once_token;
23 dispatch_once(&once_token, ^{
24 // Writes the profraw file to the Documents directory, where the app has
25 // write rights.
26 NSArray* paths =
27 NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
28 NSString* documents_directory = [paths firstObject];
29 NSString* file_name = [documents_directory stringByAppendingPathComponent:@"coverage.profraw"];
30
31 // For documentation, see:
32 // http://clang.llvm.org/docs/SourceBasedCodeCoverage.html
33 __llvm_profile_set_filename([file_name cStringUsingEncoding:NSUTF8StringEncoding]);
34
35 // Print the path for easier retrieval.
36 NSLog(@"Coverage data at %@.", file_name);
37 });
38#endif // ifdef WEBRTC_IOS_ENABLE_COVERAGE
39}
40
41} // namespace test
42} // namespace rtc