Skip to content

Commit

Permalink
Update Crash Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SMickelsn committed Dec 16, 2024
1 parent 7170d21 commit a429b26
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -14,6 +14,7 @@
86461EFC269729C0007C6DC0 /* CrashReporter in Frameworks */ = {isa = PBXBuildFile; productRef = 86461EFB269729C0007C6DC0 /* CrashReporter */; };
86461F0526972A11007C6DC0 /* sample_v1.plcrash in Resources */ = {isa = PBXBuildFile; fileRef = 86461F0426972A11007C6DC0 /* sample_v1.plcrash */; };
86D3180A271655B300B43379 /* SplunkOtel in Frameworks */ = {isa = PBXBuildFile; productRef = 86D31809271655B300B43379 /* SplunkOtel */; };
BA5DB5512D10A99F0090298A /* sample_v3.plcrash in Resources */ = {isa = PBXBuildFile; fileRef = BA5DB5502D10A99F0090298A /* sample_v3.plcrash */; };
D774545D28E38CF40056159F /* DeviceStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = D774545C28E38CF40056159F /* DeviceStats.swift */; };
D7C64D1228E494C50086368D /* DeviceStatsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C64D1128E494C50086368D /* DeviceStatsTests.swift */; };
D7D14290293804A200CAD87E /* sample_v2.plcrash in Resources */ = {isa = PBXBuildFile; fileRef = D7D1428F293804A200CAD87E /* sample_v2.plcrash */; };
Expand All @@ -38,6 +39,7 @@
86461EEA26972906007C6DC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
86461EF626972964007C6DC0 /* CrashReporting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CrashReporting.swift; sourceTree = "<group>"; };
86461F0426972A11007C6DC0 /* sample_v1.plcrash */ = {isa = PBXFileReference; lastKnownFileType = file.plcrash; path = sample_v1.plcrash; sourceTree = "<group>"; };
BA5DB5502D10A99F0090298A /* sample_v3.plcrash */ = {isa = PBXFileReference; lastKnownFileType = file; path = sample_v3.plcrash; sourceTree = "<group>"; };
D774545C28E38CF40056159F /* DeviceStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceStats.swift; sourceTree = "<group>"; };
D7C64D1128E494C50086368D /* DeviceStatsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceStatsTests.swift; sourceTree = "<group>"; };
D7D1428F293804A200CAD87E /* sample_v2.plcrash */ = {isa = PBXFileReference; lastKnownFileType = file; path = sample_v2.plcrash; sourceTree = "<group>"; };
Expand Down Expand Up @@ -96,6 +98,7 @@
86461EE726972906007C6DC0 /* SplunkRumCrashReportingTests */ = {
isa = PBXGroup;
children = (
BA5DB5502D10A99F0090298A /* sample_v3.plcrash */,
D7D1428F293804A200CAD87E /* sample_v2.plcrash */,
86461F0426972A11007C6DC0 /* sample_v1.plcrash */,
86461EE826972906007C6DC0 /* CrashTests.swift */,
Expand Down Expand Up @@ -213,6 +216,7 @@
buildActionMask = 2147483647;
files = (
86461F0526972A11007C6DC0 /* sample_v1.plcrash in Resources */,
BA5DB5512D10A99F0090298A /* sample_v3.plcrash in Resources */,
D7D14290293804A200CAD87E /* sample_v2.plcrash in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,59 @@ class CrashTests: XCTestCase {
XCTAssertEqual(startup!.attributes["component"]?.description, "appstart")

}
func testBasics_v3() throws {
let crashPath = Bundle(for: CrashTests.self).url(forResource: "sample_v3", withExtension: "plcrash")!
let crashData = try Data(contentsOf: crashPath)

SplunkRumBuilder(beaconUrl: "http://127.0.0.1:8989/v1/traces", rumAuth: "FAKE")
.allowInsecureBeacon(enabled: true)
.debug(enabled: true)
.build()
let tracerProvider = TracerProviderBuilder()
.add(spanProcessor: SimpleSpanProcessor(spanExporter: TestSpanExporter()))
.build()
OpenTelemetry.registerTracerProvider(tracerProvider: tracerProvider)
localSpans.removeAll()

SplunkRumCrashReporting.start()
try loadPendingCrashReport(crashData)

XCTAssertEqual(localSpans.count, 2)
let crashReport = localSpans.first(where: { (span) -> Bool in
return span.name == "SIGTRAP"
})
let startup = localSpans.first(where: { (span) -> Bool in
return span.name == "SplunkRumCrashReporting"
})

XCTAssertNotNil(crashReport)
XCTAssertNotEqual(crashReport!.attributes["splunk.rumSessionId"], crashReport!.attributes["crash.rumSessionId"])
XCTAssertEqual(crashReport!.attributes["crash.rumSessionId"]?.description, "a9ef9e0a7683eaf973ec8fa4b31df3f9")
XCTAssertEqual(crashReport!.attributes["crash.address"]?.description, "6786470812")
XCTAssertEqual(crashReport!.attributes["component"]?.description, "crash")
XCTAssertEqual(crashReport!.attributes["error"]?.description, "true")
XCTAssertEqual(crashReport!.attributes["exception.type"]?.description, "SIGTRAP")
XCTAssertTrue(crashReport!.attributes["exception.stacktrace"]?.description.contains("UIKitCore") ?? false)
XCTAssertEqual(crashReport!.attributes["crash.batteryLevel"]?.description, "100.0%")
XCTAssertEqual(crashReport!.attributes["crash.freeDiskSpace"]?.description, "628.03 GB")
XCTAssertEqual(crashReport!.attributes["crash.freeMemory"]?.description, "31.88 GB")
XCTAssertEqual(crashReport!.attributes["crash.app.version"]?.description, "1.0")
XCTAssertNotNil(crashReport!.attributes["exception.stackFrames"])
XCTAssertTrue(crashReport!.attributes["exception.stackFrames"]?.description.contains("threadNumber") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.stackFrames"]?.description.contains("crashed") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.stackFrames"]?.description.contains("instructionPointer") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.stackFrames"]?.description.contains("baseAddress") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.stackFrames"]?.description.contains("imageName") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.stackFrames"]?.description.contains("offset") ?? false)
XCTAssertNotNil(crashReport!.attributes["exception.images"])
XCTAssertTrue(crashReport!.attributes["exception.images"]?.description.contains("imageUUID") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.images"]?.description.contains("imageSize") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.images"]?.description.contains("imagePath") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.images"]?.description.contains("codeType") ?? false)
XCTAssertTrue(crashReport!.attributes["exception.images"]?.description.contains("baseAddress") ?? false)

XCTAssertNotNil(startup)
XCTAssertEqual(startup!.attributes["component"]?.description, "appstart")

}
}
Binary file not shown.

0 comments on commit a429b26

Please sign in to comment.