public MscorlibRegressionTest() { Type objectType = typeof(Object); asm = objectType.Assembly; reader = CLIFile.Open(asm.Location); }
public void StandAloneSigTest() { CLIFile f = CLIFile.Open(typeof(object).Assembly.Location); Table t = f[TableNames.StandAloneSig]; StandAloneSigTableCursor cur = t.GetCursor() as StandAloneSigTableCursor; while (cur.Next()) { Assert.IsTrue(cur.Signature < f.Blob.Size, "Wrong index into the blob heap!"); } }
public void MethodBodyAllTest() { Assembly mscorlib = typeof(object).Assembly; CLIFile f = CLIFile.Open(mscorlib.Location); MethodTableCursor cur = f[TableNames.Method].GetCursor() as MethodTableCursor; int instrcnt = 0; int methods = 0; int implmeth = 0; int brcnt = 0; while (cur.Next()) { // The token 0x0600449a is not resolved by ResolveMethod, it is likely a bug in reflection. // With .NET 3.5 SP1 the method has moved into token 0x44df. if (cur.Position == 0x44df) { continue; } MethodBase mb = mscorlib.ManifestModule.ResolveMethod(cur.MetadataToken); System.Reflection.MethodBody rb = mb.GetMethodBody(); methods++; if (rb == null) { Assert.IsTrue(rb == null && cur.RVA == 0); continue; } implmeth++; CLIFileRW.MethodBody cb = cur.MethodBody; Assert.AreEqual(rb.LocalSignatureMetadataToken & 0xFFFFFF, cb.LocalsSig); if (rb.LocalSignatureMetadataToken != 0) { LocalsVarSig locals = cb.LocalsSignature; IEnumerator <CLIType> lv = locals.GetVariables().GetEnumerator(); foreach (LocalVariableInfo v in rb.LocalVariables) { Assert.IsTrue(lv.MoveNext()); // Fetch instantiation from local type since we are not driven by CLIFile reflection Assert.AreSame(v.LocalType, lv.Current.GetReflectionType(mb.DeclaringType.ContainsGenericParameters ? mb.DeclaringType.GetGenericArguments() : null, mb.ContainsGenericParameters ? mb.GetGenericArguments() : null)); } } ILCursor ilc = cb.ILInstructions; while (ilc.Next()) { ILInstruction instr = ilc.Instr; object o = instr.ResolveParameter(f); instrcnt++; if (instr.op == System.Reflection.Emit.OpCodes.Br || instr.op == System.Reflection.Emit.OpCodes.Br_S) { brcnt++; } } } System.Diagnostics.Debug.WriteLine(string.Format("Total methods: {0}", methods)); System.Diagnostics.Debug.WriteLine(string.Format("Impl methods: {0}", implmeth)); System.Diagnostics.Debug.WriteLine(string.Format("Total instructions: {0}", instrcnt)); System.Diagnostics.Debug.WriteLine(string.Format("Total unconditional branch: {0}", brcnt)); System.Diagnostics.Debug.WriteLine(string.Format("Average method len: {0}", (instrcnt / (double)methods))); }
public GenericsUnitTest() { f = CLIFile.Open(GetType().Assembly.Location); }