Skip to content

Commit ee3a362

Browse files
committed
add array instance test
1 parent 1ab4f08 commit ee3a362

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

src/native/managed/cdacreader/tests/MethodTableTests.cs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void MethodTableEEClassInvalidThrows(MockTarget.Architecture arch)
264264

265265
[Theory]
266266
[ClassData(typeof(MockTarget.StdArch))]
267-
public void MethodTableGenericInstValid(MockTarget.Architecture arch)
267+
public void ValidateGenericInstMethodTable(MockTarget.Architecture arch)
268268
{
269269
TargetTestHelpers targetTestHelpers = new(arch);
270270
const ulong SystemObjectMethodTableAddress = 0x00000000_7c000010;
@@ -315,4 +315,62 @@ public void MethodTableGenericInstValid(MockTarget.Architecture arch)
315315
Assert.Equal(numMethods, metadataContract.GetNumMethods(genericInstanceMethodTableHandle));
316316
});
317317
}
318+
319+
[Theory]
320+
[ClassData(typeof(MockTarget.StdArch))]
321+
public void ValidateArrayInstMethodTable(MockTarget.Architecture arch)
322+
{
323+
TargetTestHelpers targetTestHelpers = new(arch);
324+
const ulong SystemObjectMethodTableAddress = 0x00000000_7c000010;
325+
const ulong SystemObjectEEClassAddress = 0x00000000_7c0000d0;
326+
TargetPointer systemObjectMethodTablePtr = new TargetPointer(SystemObjectMethodTableAddress);
327+
TargetPointer systemObjectEEClassPtr = new TargetPointer(SystemObjectEEClassAddress);
328+
329+
const ulong SystemArrayMethodTableAddress = 0x00000000_7c00a010;
330+
const ulong SystemArrayEEClassAddress = 0x00000000_7c00a0d0;
331+
TargetPointer systemArrayMethodTablePtr = new TargetPointer(SystemArrayMethodTableAddress);
332+
TargetPointer systemArrayEEClassPtr = new TargetPointer(SystemArrayEEClassAddress);
333+
334+
const ulong arrayInstanceMethodTableAddress = 0x00000000_330000a0;
335+
const ulong arrayInstanceEEClassAddress = 0x00000000_330001d0;
336+
TargetPointer arrayInstanceMethodTablePtr = new TargetPointer(arrayInstanceMethodTableAddress);
337+
TargetPointer arrayInstanceEEClassPtr = new TargetPointer(arrayInstanceEEClassAddress);
338+
339+
const uint arrayInstanceComponentSize = 392;
340+
341+
RTSContractHelper(arch,
342+
(builder) =>
343+
{
344+
builder = AddSystemObject(targetTestHelpers, builder, systemObjectMethodTablePtr, systemObjectEEClassPtr);
345+
const ushort systemArrayNumInterfaces = 4;
346+
const ushort systemArrayNumMethods = 37; // Arbitrary. Not trying to exactly match the real System.Array
347+
const uint systemArrayCorTypeAttr = (uint)(System.Reflection.TypeAttributes.Public | System.Reflection.TypeAttributes.Class);
348+
349+
builder = AddEEClass(targetTestHelpers, builder, systemArrayEEClassPtr, "EEClass System.Array", systemArrayMethodTablePtr, attr: systemArrayCorTypeAttr, numMethods: systemArrayNumMethods);
350+
builder = AddMethodTable(targetTestHelpers, builder, systemArrayMethodTablePtr, "MethodTable System.Array", systemArrayEEClassPtr,
351+
mtflags: default, mtflags2: default, baseSize: targetTestHelpers.ObjectBaseSize,
352+
module: TargetPointer.Null, parentMethodTable: systemObjectMethodTablePtr, numInterfaces: systemArrayNumInterfaces, numVirtuals: 3);
353+
354+
const uint arrayInst_mtflags = (uint)(RuntimeTypeSystem_1.WFLAGS_HIGH.HasComponentSize | RuntimeTypeSystem_1.WFLAGS_HIGH.Category_Array) | arrayInstanceComponentSize;
355+
const uint arrayInstCorTypeAttr = (uint)(System.Reflection.TypeAttributes.Public | System.Reflection.TypeAttributes.Class | System.Reflection.TypeAttributes.Sealed);
356+
357+
builder = AddEEClass(targetTestHelpers, builder, arrayInstanceEEClassPtr, "EEClass ArrayInstance", arrayInstanceMethodTablePtr, attr: arrayInstCorTypeAttr, numMethods: systemArrayNumMethods);
358+
builder = AddMethodTable(targetTestHelpers, builder, arrayInstanceMethodTablePtr, "MethodTable ArrayInstance", arrayInstanceEEClassPtr,
359+
mtflags: arrayInst_mtflags, mtflags2: default, baseSize: targetTestHelpers.ObjectBaseSize,
360+
module: TargetPointer.Null, parentMethodTable: systemArrayMethodTablePtr, numInterfaces: systemArrayNumInterfaces, numVirtuals: 3);
361+
362+
return builder;
363+
},
364+
(target) =>
365+
{
366+
Contracts.IRuntimeTypeSystem metadataContract = target.Contracts.RuntimeTypeSystem;
367+
Assert.NotNull(metadataContract);
368+
Contracts.MethodTableHandle arrayInstanceMethodTableHandle = metadataContract.GetMethodTableHandle(arrayInstanceMethodTablePtr);
369+
Assert.Equal(arrayInstanceMethodTablePtr.Value, arrayInstanceMethodTableHandle.Address.Value);
370+
Assert.False(metadataContract.IsFreeObjectMethodTable(arrayInstanceMethodTableHandle));
371+
Assert.False(metadataContract.IsString(arrayInstanceMethodTableHandle));
372+
Assert.Equal(arrayInstanceComponentSize, metadataContract.GetComponentSize(arrayInstanceMethodTableHandle));
373+
});
374+
375+
}
318376
}

0 commit comments

Comments
 (0)