Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexandre Teoi <ateoi@users.noreply.github.com>2018-04-05 00:40:07 +0300
committerSantiago Fernandez Madero <safern@microsoft.com>2018-04-05 00:40:07 +0300
commit8d2f167da549322f0ed41b5fafa5c735aaf7d62e (patch)
tree22fd4305dd4b1bf82a36569e947dde762018cfba /src
parent76be44e809eedda866d66c218df7e1076d6f98f2 (diff)
Rethrown exception call stack tests (#28059)
* Added tests to verify the reported call stacks for rethrown exceptions, as specified by dotnet/coreclr#15780. 1. Exception rethrown in a method different than the method where it was originally thrown: the stack trace contains both the location in the method where the exception was originally thrown, and the location where the method that threw the exception was called. 2. Exception is thrown and later rethrown in the same method: the stack trace only contains the location where the exception was originally thrown and does not include the location where the exception was rethrown. * - Make test work with full framework. Test will fail after porting dotnet/core#15780 to full framework. - Fixed variable name * Write reported call stack to console Writing call stack to console to debug test errors on NETFX and Linux. * Add netfx configuration to test project * Remove redundant throw A redundant throw in "ThrowAndRethrowOtherMethod" was being removed by the optimizer and causing error in exception line calculation. * Remove full call stack verification Verify only the rethrown stack frame due to inconsistencies found on build/release exception call stacks - https://github.com/dotnet/corefx/pull/28059#issuecomment-378335456
Diffstat (limited to 'src')
-rw-r--r--src/System.Runtime/tests/Configurations.props2
-rw-r--r--src/System.Runtime/tests/System.Runtime.Tests.csproj6
-rw-r--r--src/System.Runtime/tests/System/ExceptionTests.cs100
3 files changed, 104 insertions, 4 deletions
diff --git a/src/System.Runtime/tests/Configurations.props b/src/System.Runtime/tests/Configurations.props
index 91486c3416..c0cb0f7fed 100644
--- a/src/System.Runtime/tests/Configurations.props
+++ b/src/System.Runtime/tests/Configurations.props
@@ -3,7 +3,7 @@
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
- netstandard;
+ netfx;
uap;
uapaot;
</BuildConfigurations>
diff --git a/src/System.Runtime/tests/System.Runtime.Tests.csproj b/src/System.Runtime/tests/System.Runtime.Tests.csproj
index 9fdbcd0b05..8c5b158bdd 100644
--- a/src/System.Runtime/tests/System.Runtime.Tests.csproj
+++ b/src/System.Runtime/tests/System.Runtime.Tests.csproj
@@ -8,12 +8,12 @@
<DefineConstants Condition="'$(TargetGroup)'=='netcoreapp'">$(DefineConstants);netcoreapp</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)'=='uapaot'">$(DefineConstants);uapaot</DefineConstants>
<!-- Please don't delete. We need App.config for netfx -->
- <NETFxTestRunnerAppConfig Condition="'$(TargetGroup)' == 'netstandard'">$(MSBuildProjectDirectory)\App.config</NETFxTestRunnerAppConfig>
+ <NETFxTestRunnerAppConfig Condition="'$(TargetGroup)' == 'netfx'">$(MSBuildProjectDirectory)\App.config</NETFxTestRunnerAppConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uapaot-Debug|AnyCPU'" />
diff --git a/src/System.Runtime/tests/System/ExceptionTests.cs b/src/System.Runtime/tests/System/ExceptionTests.cs
index 02651372dc..53b152efa3 100644
--- a/src/System.Runtime/tests/System/ExceptionTests.cs
+++ b/src/System.Runtime/tests/System/ExceptionTests.cs
@@ -5,6 +5,8 @@
using System;
using System.IO;
using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Text.RegularExpressions;
using Xunit;
namespace System.Tests
@@ -57,6 +59,104 @@ namespace System.Tests
Assert.True(caught);
}
+
+ [Fact]
+ public static void ThrowStatementDoesNotResetExceptionStackLineSameMethod()
+ {
+ (string, string, int) rethrownExceptionStackFrame = (null, null, 0);
+
+ try
+ {
+ ThrowAndRethrowSameMethod(out rethrownExceptionStackFrame);
+ }
+ catch (Exception ex)
+ {
+ VerifyCallStack(rethrownExceptionStackFrame, ex.StackTrace, 0);
+ }
+ }
+
+ private static (string, string, int) ThrowAndRethrowSameMethod(out (string, string, int) rethrownExceptionStackFrame)
+ {
+ try
+ {
+ if (!PlatformDetection.IsFullFramework)
+ rethrownExceptionStackFrame = GetSourceInformation(1);
+ throw new Exception("Boom!");
+ }
+ catch
+ {
+ if (PlatformDetection.IsFullFramework)
+ rethrownExceptionStackFrame = GetSourceInformation(1);
+ throw;
+ }
+ }
+
+ [Fact]
+ public static void ThrowStatementDoesNotResetExceptionStackLineOtherMethod()
+ {
+ (string, string, int) rethrownExceptionStackFrame = (null, null, 0);
+
+ try
+ {
+ ThrowAndRethrowOtherMethod(out rethrownExceptionStackFrame);
+ }
+ catch (Exception ex)
+ {
+ VerifyCallStack(rethrownExceptionStackFrame, ex.StackTrace, 1);
+ }
+ }
+
+ private static void ThrowAndRethrowOtherMethod(out (string, string, int) rethrownExceptionStackFrame)
+ {
+ try
+ {
+ if (!PlatformDetection.IsFullFramework)
+ rethrownExceptionStackFrame = GetSourceInformation(1);
+ ThrowException(); Assert.True(false, "Workaround for Linux Release builds (https://github.com/dotnet/corefx/pull/28059#issuecomment-378335456)");
+ }
+ catch
+ {
+ if (PlatformDetection.IsFullFramework)
+ rethrownExceptionStackFrame = GetSourceInformation(1);
+ throw;
+ }
+ rethrownExceptionStackFrame = (null, null, 0);
+ }
+
+ private static void ThrowException()
+ {
+ throw new Exception("Boom!");
+ }
+
+ private static void VerifyCallStack(
+ (string CallerMemberName, string SourceFilePath, int SourceLineNumber) expectedStackFrame,
+ string reportedCallStack, int skipFrames)
+ {
+ Console.WriteLine("* ExceptionTests - reported call stack:\n{0}", reportedCallStack);
+ const string frameParserRegex = @"\s+at\s.+\.(?<memberName>[^(.]+)\([^)]*\)\sin\s(?<filePath>.*)\:line\s(?<lineNumber>[\d]+)";
+
+ using (var sr = new StringReader(reportedCallStack))
+ {
+ for (int i = 0; i < skipFrames; i++)
+ sr.ReadLine();
+ string frame = sr.ReadLine();
+ Assert.NotNull(frame);
+ var match = Regex.Match(frame, frameParserRegex);
+ Assert.True(match.Success);
+ Assert.Equal(expectedStackFrame.CallerMemberName, match.Groups["memberName"].Value);
+ Assert.Equal(expectedStackFrame.SourceFilePath, match.Groups["filePath"].Value);
+ Assert.Equal(expectedStackFrame.SourceLineNumber, Convert.ToInt32(match.Groups["lineNumber"].Value));
+ }
+ }
+
+ private static (string, string, int) GetSourceInformation(
+ int offset,
+ [CallerMemberName] string memberName = "",
+ [CallerFilePath] string sourceFilePath = "",
+ [CallerLineNumber] int sourceLineNumber = 0)
+ {
+ return (memberName, sourceFilePath, sourceLineNumber + offset);
+ }
}
public class ExceptionDerivedTests: Exception