icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.45k stars 3.35k forks source link

Unit test issues #1695

Closed lambertlb closed 4 years ago

lambertlb commented 5 years ago

I have been writing a lot of tests outside of you test infrastructure. I wanted to analyze your infrastructure to see ii could marry into it. I am having a problem. Many tests run ok but a lot don't for example (ExplicitConversions_32). This test does run and pass but takes 3 minutes to do so. When i tried debugging it to see what was going on, I noticed the debug output log is getting flooded with the following. Exception thrown: 'System.OverflowException' in ICSharpCode.Decompiler.dll Very many of the tests have this same issue. Sadly the visual studio debugger has no explicit break on this exception so i was not able to narrow it down. Because a lot of tests take so long to run it is not practical for me to really run them. Have you noticed the same issue when you run the tests? I could try a deep dive to narrow this down if you are interested.

trivalik commented 5 years ago

For your debugger does not break issue, please go in VS2015 or heigher do menu Debug -> Windows -> Exceptions... Here you can check "Common Language Runtime Exceptions" or a more specific exception to let the debugger break.

siegfriedpammer commented 5 years ago

Sorry for taking so long to get to this issue!

As far as I can tell, the OverflowExceptions are expected in the ExpectedConversions tests. We want to make sure that the decompiled/recompiled code shows the same behavior as the original code.

For example, the following is trying to convert a very large 64-bit unsigned integer to signed 16-bit integer:

try
{
    Console.WriteLine(UInt64_Conv_Ovf_I2_Int16(18446744073709551488uL));
}
catch (Exception ex4)
{
    Console.WriteLine((object)((object)ex4).GetType().Name);
}

Of course this is always going to throw an OverflowException, if it doesn't, we messed up pretty badly in the decompilation process.

As for OverflowExceptions from inside the decompiler engine: Yes, some of these are expected, if they are thrown by Util.CSharpPrimitiveCast:

https://github.com/icsharpcode/ILSpy/blob/c98cae20a9460649685f49c266dbfd21a28b7970/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs#L23-L38

I hope this helps! If you have further questions, do not hesitate to ask!

Sorry again for taking so long to get to this!