Chromium Code Reviews| Index: testing/coverage_util_ios.mm |
| diff --git a/testing/coverage_util_ios.mm b/testing/coverage_util_ios.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5e2878e7a174b97b3793cf65b59656406e2ec957 |
| --- /dev/null |
| +++ b/testing/coverage_util_ios.mm |
| @@ -0,0 +1,33 @@ |
| +// Copyright 2014 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. |
| + |
| +#import <Foundation/Foundation.h> |
| + |
| +extern "C" void __llvm_profile_set_filename(const char* name); |
| + |
| +namespace coverage_util { |
| + |
| +void SetupIfNecessary() { |
| +#if !defined(NDEBUG) // && defined(ENABLE_TEST_CODE_COVERAGE) |
|
baxley
2017/04/03 17:18:53
nit: do we want the commented out condition?
|
| + static dispatch_once_t once_token; |
| + dispatch_once(&once_token, ^{ |
| + // Writes the profraw file to the Documents directory, where the app has |
| + // write rights. |
| + NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, |
| + NSUserDomainMask, YES); |
| + NSString* documents_directory = [paths firstObject]; |
| + NSString* file_name = [documents_directory |
| + stringByAppendingPathComponent:@"coverage.profraw"]; |
| + |
| + // For documentation, see: |
| + // http://clang.llvm.org/docs/SourceBasedCodeCoverage.html |
| + __llvm_profile_set_filename([file_name UTF8String]); |
| + |
| + // Print the path for easier retrieval. |
| + NSLog(@"Coverage data at %@.", file_name); |
| + }); |
| +#endif |
| +} |
| + |
| +} // namespace coverage_util |