提交 4be251ed 编写于 作者: A AlekseyTs

Merge pull request #9728 from AlekseyTs/Issue6077

Address flakiness of EmitSequenceOfBinaryExpressions_03 unit-test
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis.CSharp.UnitTests.Emit; using Microsoft.CodeAnalysis.CSharp.UnitTests.Emit;
using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities; using Roslyn.Test.Utilities;
using System.Collections.Immutable;
using Xunit; using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen
...@@ -4754,13 +4755,21 @@ public static double Calculate(long[] f) ...@@ -4754,13 +4755,21 @@ public static double Calculate(long[] f)
var result = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: "11461640193"); var result = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: "11461640193");
} }
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/6077")] [Fact]
[WorkItem(6077, "https://github.com/dotnet/roslyn/issues/6077")] [WorkItem(6077, "https://github.com/dotnet/roslyn/issues/6077")]
[WorkItem(5395, "https://github.com/dotnet/roslyn/issues/5395")] [WorkItem(5395, "https://github.com/dotnet/roslyn/issues/5395")]
public void EmitSequenceOfBinaryExpressions_03() public void EmitSequenceOfBinaryExpressions_03()
{ {
var source = var diagnostics = ImmutableArray<Diagnostic>.Empty;
@"
const int start = 8192;
const int step = 4096;
const int limit = start * 4;
for (int count = start; count <= limit && diagnostics.IsEmpty; count += step)
{
var source =
@"
class Test class Test
{ {
static void Main() static void Main()
...@@ -4769,24 +4778,27 @@ static void Main() ...@@ -4769,24 +4778,27 @@ static void Main()
public static bool Calculate(bool[] a, bool[] f) public static bool Calculate(bool[] a, bool[] f)
{ {
" + $" return { BuildSequenceOfBinaryExpressions_03() };" + @" " + $" return { BuildSequenceOfBinaryExpressions_03(count) };" + @"
} }
} }
"; ";
var compilation = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseExe); var compilation = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseExe);
compilation.VerifyEmitDiagnostics( diagnostics = compilation.GetEmitDiagnostics();
}
diagnostics.Verify(
// (10,16): error CS8078: An expression is too long or complex to compile // (10,16): error CS8078: An expression is too long or complex to compile
// return a[0] && f[0] || a[1] && f[1] || a[2] && f[2] || ... // return a[0] && f[0] || a[1] && f[1] || a[2] && f[2] || ...
Diagnostic(ErrorCode.ERR_InsufficientStack, "a").WithLocation(10, 16) Diagnostic(ErrorCode.ERR_InsufficientStack, "a").WithLocation(10, 16)
); );
} }
private static string BuildSequenceOfBinaryExpressions_03() private static string BuildSequenceOfBinaryExpressions_03(int count = 8192)
{ {
var builder = new System.Text.StringBuilder(); var builder = new System.Text.StringBuilder();
int i; int i;
for (i = 0; i < 8192; i++) for (i = 0; i < count; i++)
{ {
builder.Append("a["); builder.Append("a[");
builder.Append(i); builder.Append(i);
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Reflection Imports System.Reflection
Imports System.Xml.Linq Imports System.Xml.Linq
Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis
...@@ -13247,33 +13248,47 @@ End Class ...@@ -13247,33 +13248,47 @@ End Class
CompileAndVerify(compilation, expectedOutput:="11461640193") CompileAndVerify(compilation, expectedOutput:="11461640193")
End Sub End Sub
<Fact(Skip:="https://github.com/dotnet/roslyn/issues/6077")> <Fact>
<WorkItem(6077, "https://github.com/dotnet/roslyn/issues/6077")> <WorkItem(6077, "https://github.com/dotnet/roslyn/issues/6077")>
<WorkItem(5395, "https://github.com/dotnet/roslyn/issues/5395")> <WorkItem(5395, "https://github.com/dotnet/roslyn/issues/5395")>
Public Sub EmitSequenceOfBinaryExpressions_03() Public Sub EmitSequenceOfBinaryExpressions_03()
Dim source =
Dim diagnostics = ImmutableArray(Of Diagnostic).Empty
Const start = 8192
Const [step] = 4096
Const limit = start * 4
For count As Integer = start To limit Step [step]
Dim source =
$" $"
Class Test Class Test
Shared Sub Main() Shared Sub Main()
End Sub End Sub
Shared Function Calculate(a As Boolean(), f As Boolean()) As Boolean Shared Function Calculate(a As Boolean(), f As Boolean()) As Boolean
Return {BuildSequenceOfBinaryExpressions_03()} Return {BuildSequenceOfBinaryExpressions_03(count)}
End Function End Function
End Class End Class
" "
Dim compilation = CreateCompilationWithMscorlib({source}, options:=TestOptions.ReleaseExe.WithOverflowChecks(True)) Dim compilation = CreateCompilationWithMscorlib({source}, options:=TestOptions.ReleaseExe.WithOverflowChecks(True))
diagnostics = compilation.GetEmitDiagnostics()
compilation.VerifyEmitDiagnostics( If Not diagnostics.IsEmpty Then
Exit For
End If
Next
diagnostics.Verify(
Diagnostic(ERRID.ERR_TooLongOrComplexExpression, "a").WithLocation(7, 16) Diagnostic(ERRID.ERR_TooLongOrComplexExpression, "a").WithLocation(7, 16)
) )
End Sub End Sub
Private Shared Function BuildSequenceOfBinaryExpressions_03() As String Private Shared Function BuildSequenceOfBinaryExpressions_03(Optional count As Integer = 8192) As String
Dim builder = New System.Text.StringBuilder() Dim builder = New System.Text.StringBuilder()
Dim i As Integer Dim i As Integer
For i = 0 To 8192 - 1 For i = 0 To count - 1
builder.Append("a(") builder.Append("a(")
builder.Append(i) builder.Append(i)
builder.Append(")") builder.Append(")")
......
...@@ -235,22 +235,36 @@ public static bool IsDiagnosticAnalyzerSuppressed(this DiagnosticAnalyzer analyz ...@@ -235,22 +235,36 @@ public static bool IsDiagnosticAnalyzerSuppressed(this DiagnosticAnalyzer analyz
public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, EmitOptions options, params DiagnosticDescription[] expected) public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, EmitOptions options, params DiagnosticDescription[] expected)
where TCompilation : Compilation where TCompilation : Compilation
{ {
var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream(); c.GetEmitDiagnostics(options: options).Verify(expected);
c.Emit(new MemoryStream(), pdbStream: pdbStream, options: options).Diagnostics.Verify(expected);
return c; return c;
} }
public static ImmutableArray<Diagnostic> GetEmitDiagnostics<TCompilation>(
this TCompilation c,
EmitOptions options = null,
IEnumerable<ResourceDescription> manifestResources = null)
where TCompilation : Compilation
{
var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream();
return c.Emit(new MemoryStream(), pdbStream: pdbStream, options: options, manifestResources: manifestResources).Diagnostics;
}
public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, params DiagnosticDescription[] expected) public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, params DiagnosticDescription[] expected)
where TCompilation : Compilation where TCompilation : Compilation
{ {
return VerifyEmitDiagnostics(c, EmitOptions.Default, expected); return VerifyEmitDiagnostics(c, EmitOptions.Default, expected);
} }
public static ImmutableArray<Diagnostic> GetEmitDiagnostics<TCompilation>(this TCompilation c)
where TCompilation : Compilation
{
return GetEmitDiagnostics(c, EmitOptions.Default);
}
public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, IEnumerable<ResourceDescription> manifestResources, params DiagnosticDescription[] expected) public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, IEnumerable<ResourceDescription> manifestResources, params DiagnosticDescription[] expected)
where TCompilation : Compilation where TCompilation : Compilation
{ {
var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream(); c.GetEmitDiagnostics(manifestResources: manifestResources).Verify(expected);
c.Emit(new MemoryStream(), pdbStream: pdbStream, manifestResources: manifestResources).Diagnostics.Verify(expected);
return c; return c;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册