Skip to content

Commit

Permalink
RUMM-1492 isSystemImage logic is fixed
Browse files Browse the repository at this point in the history
In device, user images can be in /Bundle/Application/ only.
Otherwise, it is a system image.
In simulator, system image can be in Xcode.app/Contents/Developer/Platforms only.
Otherwise, it is a user image.
  • Loading branch information
buranmert committed Aug 12, 2021
1 parent 6aa4a2f commit d74d3a8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ extension BinaryImageInfo {

self.uuid = imageUUID
self.imageName = URL(string: imagePath)?.lastPathComponent
// NOTE: RUMM-1492 refer to JIRA ticket or `CrashReportTests.swift` to see imagePath examples
let isUserImage = imagePath.contains("/Bundle/Application/") || imagePath.contains("/Products/")
self.isSystemImage = !isUserImage

#if targetEnvironment(simulator)
self.isSystemImage = Self.isPathSystemImageInSimulator(imagePath)
#else
self.isSystemImage = Self.isPathSystemImageInDevice(imagePath)
#endif

if let codeType = imageInfo.codeType {
self.codeType = CodeType(from: codeType)
Expand All @@ -255,6 +258,17 @@ extension BinaryImageInfo {
self.imageBaseAddress = imageInfo.imageBaseAddress
self.imageSize = imageInfo.imageSize
}

static func isPathSystemImageInSimulator(_ path: String) -> Bool {
// in simulator, example system image path: ~/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/...
return path.contains("/Contents/Developer/Platforms/")
}

static func isPathSystemImageInDevice(_ path: String) -> Bool {
// in device, example user image path: .../containers/Bundle/Application/0000/Example.app/Frameworks/...
let isUserImage = path.contains("/Bundle/Application/")
return !isUserImage
}
}

extension BinaryImageInfo.CodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,37 @@ class CrashReportTests: XCTestCase {
XCTAssertEqual(threadInfo.stackFrames.count, mockStackFrames.count)
}

private let systemImagePaths_device = [
"/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
"/usr/lib/system/libdyld.dylib"
]
private let systemImagePaths_simulator = [
"/Users/john.appleseed/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
]
private let userImagePaths_device = [
"/private/var/containers/Bundle/Application/0000/Example.app/Example",
"/private/var/containers/Bundle/Application/0000/Example.app/Frameworks/DatadogCrashReporting.framework/DatadogCrashReporting"
]
private let userImagePaths_simulator = [
"/Users/john.appleseed/Library/Developer/CoreSimulator/Devices/0000/data/Containers/Bundle/Application/0000/Example.app/Example",
"/Users/john.appleseed/Library/Developer/Xcode/DerivedData/Datadog-abcd/Build/Products/Release-iphonesimulator/DatadogCrashReporting.framework/DatadogCrashReporting"
]

func testItDetectsSystemImages() throws {
for systemImagePath in systemImagePaths_device {
XCTAssertTrue(BinaryImageInfo.isPathSystemImageInDevice(systemImagePath), "\(systemImagePath) is a system image")
}
for systemImagePath in systemImagePaths_simulator {
XCTAssertTrue(BinaryImageInfo.isPathSystemImageInSimulator(systemImagePath), "\(systemImagePath) is a system image")
}
for userImagePath in userImagePaths_device {
XCTAssertFalse(BinaryImageInfo.isPathSystemImageInDevice(userImagePath), "\(userImagePath) is an user image")
}
for userImagePath in userImagePaths_simulator {
XCTAssertFalse(BinaryImageInfo.isPathSystemImageInSimulator(userImagePath), "\(userImagePath) is an user image")
}
}

func testItReadsBinaryImageInfo() throws {
func mock(with imagePath: URL) -> PLCrashReportMock.BinaryImageInfo {
let mock = PLCrashReportMock.BinaryImageInfo()
Expand All @@ -220,20 +251,13 @@ class CrashReportTests: XCTestCase {
}

// Given
let systemImagePathString = [
"/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
"/usr/lib/system/libdyld.dylib",
"/Users/john.appleseed/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
].randomElement()!
let systemImagePath = URL(string: systemImagePathString)!

let userImagePathString = [
"/private/var/containers/Bundle/Application/0000/Example.app/Example",
"/private/var/containers/Bundle/Application/0000/Example.app/Frameworks/DatadogCrashReporting.framework/DatadogCrashReporting",
"/Users/john.appleseed/Library/Developer/CoreSimulator/Devices/0000/data/Containers/Bundle/Application/0000/Example.app/Example",
"/Users/john.appleseed/Library/Developer/Xcode/DerivedData/Datadog-abcd/Build/Products/Release-iphonesimulator/DatadogCrashReporting.framework/DatadogCrashReporting"
].randomElement()!
let userImagePath = URL(string: userImagePathString)!
#if targetEnvironment(simulator)
let systemImagePath = URL(string: systemImagePaths_simulator.randomElement()!)!
let userImagePath = URL(string: userImagePaths_simulator.randomElement()!)!
#else
let systemImagePath = URL(string: systemImagePaths_device.randomElement()!)!
let userImagePath = URL(string: userImagePaths_device.randomElement()!)!
#endif

let mockSystemImage = mock(with: systemImagePath)
let mockUserImage = mock(with: userImagePath)
Expand Down

0 comments on commit d74d3a8

Please sign in to comment.