Skip to content

Commit c6ec0d3

Browse files
Added unit tests
1 parent 9f176f7 commit c6ec0d3

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

src/Sentry.Android.AssemblyReader/V2/AssemblyStoreReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected AssemblyStoreReader(Stream store, string path, DebugLogger? logger)
4545

4646
protected BinaryReader CreateReader() => new BinaryReader(StoreStream, ReaderEncoding, leaveOpen: true);
4747

48-
protected abstract bool IsSupported();
48+
protected internal abstract bool IsSupported();
4949
protected abstract void Prepare();
5050
protected abstract ulong GetStoreStartDataOffset();
5151

src/Sentry.Android.AssemblyReader/V2/StoreReader.Classes.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Header(uint magic, uint version, uint entry_count, uint index_entry_count
3131
}
3232
}
3333

34-
private sealed class IndexEntry
34+
internal sealed class IndexEntry
3535
{
3636
public readonly ulong name_hash;
3737
public readonly uint descriptor_index;
@@ -45,7 +45,7 @@ public IndexEntry(ulong name_hash, uint descriptor_index, bool ignore)
4545
}
4646
}
4747

48-
private sealed class EntryDescriptor
48+
internal sealed class EntryDescriptor
4949
{
5050
public uint mapping_index;
5151

@@ -59,7 +59,7 @@ private sealed class EntryDescriptor
5959
public uint config_data_size;
6060
}
6161

62-
private sealed class StoreItemV2 : AssemblyStoreItem
62+
internal sealed class StoreItemV2 : AssemblyStoreItem
6363
{
6464
public StoreItemV2(AndroidTargetArch targetArch, string name, bool is64Bit, List<IndexEntry> indexEntries,
6565
EntryDescriptor descriptor, bool ignore)

src/Sentry.Android.AssemblyReader/V2/StoreReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public StoreReader(Stream store, string path, DebugLogger? logger)
9191

9292
protected override ulong GetStoreStartDataOffset() => elfOffset;
9393

94-
protected override bool IsSupported()
94+
protected internal override bool IsSupported()
9595
{
9696
lock (StreamLock)
9797
{
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Sentry.Android.AssemblyReader.V2;
2+
3+
namespace Sentry.Android.AssemblyReader.Tests;
4+
5+
public class StoreReaderTests
6+
{
7+
[Fact]
8+
public void IsSupported_Concurrent_IsThreadSafe()
9+
{
10+
// Arrange
11+
var buffer = new byte[1024*1024];
12+
var memoryStream = new MemoryStream(buffer);
13+
var storeReader = new StoreReader(memoryStream, "testStore", null);
14+
15+
// Act
16+
Parallel.For(0, 10, _ => storeReader.IsSupported());
17+
18+
// No Assert - test passes if no exceptions are thrown
19+
}
20+
21+
[Fact]
22+
public void ReadEntryImageData_Concurrent_IsThreadSafe()
23+
{
24+
// Arrange
25+
var buffer = new byte[1024*1024];
26+
var memoryStream = new MemoryStream(buffer);
27+
var storeReader = new StoreReader(memoryStream, "testStore", null);
28+
var entry = new StoreReader.StoreItemV2(
29+
AndroidTargetArch.Arm64,
30+
"testAssembly.dll",
31+
is64Bit: true,
32+
new List<StoreReader.IndexEntry>(),
33+
new StoreReader.EntryDescriptor
34+
{
35+
data_offset = 0,
36+
data_size = 0,
37+
debug_data_offset = 0,
38+
debug_data_size = 0,
39+
config_data_offset = 0,
40+
config_data_size = 0,
41+
mapping_index = 0
42+
},
43+
ignore: false);
44+
45+
// Act
46+
Parallel.For(0, 10, _ => storeReader.ReadEntryImageData(entry));
47+
48+
// No Assert - test passes if no exceptions are thrown
49+
}
50+
}

0 commit comments

Comments
 (0)