Commit 64179ab0 authored by zhaoyangli's avatar zhaoyangli Committed by Commit Bot

[iOS][code coverage] Change ios raw coverage data file path and name.

- Changed the path to the simulator shared resources directory, where
the app also write rights, and won't be deleted after app is killed.
- Added "%m" to the file name, so that on-line profile merging is
enabled.
- Added a generated UUID to the file name, so that there won't be a
conflict when multiple apps are launched in one test suite.

Please see ios code coverage design doc for rationales of those changes:
go/bling-code-coverage-doc.

Bug: 1043273
Change-Id: I21b2c8f4018036fdd13eecbe7e1362c926886eca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2031673
Commit-Queue: Zhaoyang Li <zhaoyangli@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarYuke Liao <liaoyuke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738365}
parent d534b729
...@@ -6,33 +6,43 @@ ...@@ -6,33 +6,43 @@
#import "testing/gtest/ios_enable_coverage.h" #import "testing/gtest/ios_enable_coverage.h"
#if !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE) #if !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE) && \
TARGET_IPHONE_SIMULATOR
extern "C" void __llvm_profile_set_filename(const char* name); extern "C" void __llvm_profile_set_filename(const char* name);
#endif #endif
namespace coverage_util { namespace coverage_util {
void ConfigureCoverageReportPath() { void ConfigureCoverageReportPath() {
#if !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE) // Targets won't build on real devices with BUILDFLAG(IOS_ENABLE_COVERAGE)
// because of llvm library linking issue for arm64 architecture.
#if !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE) && \
TARGET_IPHONE_SIMULATOR
static dispatch_once_t once_token; static dispatch_once_t once_token;
dispatch_once(&once_token, ^{ dispatch_once(&once_token, ^{
// Writes the profraw file to the Documents directory, where the app has // Writes the profraw file to the simulator shared resources directory,
// write rights. // where the app has write rights, and will be preserved after app is
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, // killed.
NSUserDomainMask, YES); NSString* shared_resources_path =
NSString* documents_directory = [paths firstObject]; NSProcessInfo.processInfo
NSString* file_name = [documents_directory .environment[@"SIMULATOR_SHARED_RESOURCES_DIRECTORY"];
stringByAppendingPathComponent:@"coverage.profraw"]; // UUID ensures that there won't be a conflict when multiple apps are
// launched in one test suite in EG2. %m enables on-line profile merging.
NSString* file_name =
[NSString stringWithFormat:@"%@-%%m.profraw", NSUUID.UUID.UUIDString];
NSString* file_path =
[shared_resources_path stringByAppendingPathComponent:file_name];
// For documentation, see: // For documentation, see:
// http://clang.llvm.org/docs/SourceBasedCodeCoverage.html // http://clang.llvm.org/docs/SourceBasedCodeCoverage.html
__llvm_profile_set_filename( __llvm_profile_set_filename(
[file_name cStringUsingEncoding:NSUTF8StringEncoding]); [file_path cStringUsingEncoding:NSUTF8StringEncoding]);
// Print the path for easier retrieval. // Print the path for easier retrieval.
NSLog(@"Coverage data at %@.", file_name); NSLog(@"Coverage data at %@.", file_path);
}); });
#endif // !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE) #endif // !defined(NDEBUG) && BUILDFLAG(IOS_ENABLE_COVERAGE) &&
// TARGET_IPHONE_SIMULATOR
} }
} // namespace coverage_util } // namespace coverage_util
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment