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 @@
#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);
#endif
namespace coverage_util {
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;
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"];
// Writes the profraw file to the simulator shared resources directory,
// where the app has write rights, and will be preserved after app is
// killed.
NSString* shared_resources_path =
NSProcessInfo.processInfo
.environment[@"SIMULATOR_SHARED_RESOURCES_DIRECTORY"];
// 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:
// http://clang.llvm.org/docs/SourceBasedCodeCoverage.html
__llvm_profile_set_filename(
[file_name cStringUsingEncoding:NSUTF8StringEncoding]);
[file_path cStringUsingEncoding:NSUTF8StringEncoding]);
// 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
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