Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic testing infrastructure in NativeAOT (port from dotnet/linker) #70408

Merged
merged 6 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@
Test="true" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true'"/>
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\ILCompiler.Compiler.Tests\ILCompiler.Compiler.Tests.csproj"
Test="true" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(NativeAotSupported)' == 'true'"/>
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\aot\Mono.Linker.Tests\Mono.Linker.Tests.csproj"
Test="true" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(NativeAotSupported)' == 'true'"/>
</ItemGroup>

<ItemGroup Condition="$(_subset.Contains('+clr.nativecorelib+'))">
Expand Down
2 changes: 2 additions & 0 deletions eng/pipelines/coreclr/templates/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ jobs:

# Run CoreCLR Tools unit tests
- ${{ if eq(parameters.testGroup, 'clrTools') }}:
- script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -subset libs $(crossArg) -arch $(archType) $(osArg) -c $(buildConfig) $(officialBuildIdArg) -ci
displayName: Build libs
- script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -subset clr.toolstests $(crossArg) -arch $(archType) $(osArg) -c $(buildConfig) $(officialBuildIdArg) -ci -test
displayName: Run CoreCLR Tools unit tests

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/Common/Compiler/DisplayNameHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace ILCompiler
{
internal static class DisplayNameHelpers
public static class DisplayNameHelpers
{
public static string GetDisplayName(this TypeSystemEntity entity)
{
Expand Down
81 changes: 81 additions & 0 deletions src/coreclr/tools/aot/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,84 @@ dotnet_sort_system_directives_first = true
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

[Mono.Linker.Tests/**.cs]
indent_style = tab
indent_size = 4
csharp_new_line_before_open_brace = types,methods
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_name_and_open_parenthesis = true
csharp_space_between_method_call_name_and_opening_parenthesis = true
csharp_space_before_open_square_brackets = false
csharp_space_after_cast = true

csharp_indent_switch_labels = false

# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

[Mono.Linker.Tests.Cases/**.cs]
indent_style = tab
indent_size = 4
csharp_new_line_before_open_brace = types,methods
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_name_and_open_parenthesis = true
csharp_space_between_method_call_name_and_opening_parenthesis = true
csharp_space_before_open_square_brackets = false
csharp_space_after_cast = true

csharp_indent_switch_labels = false

# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

[Mono.Linker.Tests.Cases.Expectations/**.cs]
indent_style = tab
indent_size = 4
csharp_new_line_before_open_brace = types,methods
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_name_and_open_parenthesis = true
csharp_space_between_method_call_name_and_opening_parenthesis = true
csharp_space_before_open_square_brackets = false
csharp_space_after_cast = true

csharp_indent_switch_labels = false

# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event, AllowMultiple = true, Inherited = false)]
public class AddedPseudoAttributeAttribute : BaseExpectedLinkedBehaviorAttribute
{
public AddedPseudoAttributeAttribute (uint value)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
/// <summary>
/// Base attribute for attributes that mark up the expected behavior of the linker on a member
/// </summary>
[Conditional ("INCLUDE_EXPECTATIONS")]
public abstract class BaseExpectedLinkedBehaviorAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
public abstract class BaseInAssemblyAttribute : BaseExpectedLinkedBehaviorAttribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
/// A base class for attributes that make assertions about a particular member.
// The test infrastructure is expected to check the assertion on the member to which
// the attribute is applied.
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Delegate, AllowMultiple = true)]
public abstract class BaseMemberAssertionAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Delegate | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = true, Inherited = false)]
public sealed class CreatedMemberAttribute : BaseExpectedLinkedBehaviorAttribute
{

public CreatedMemberAttribute (string name)
{
if (string.IsNullOrEmpty (name))
throw new ArgumentException ("Value cannot be null or empty.", nameof (name));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class DependencyRecordedAttribute : BaseExpectedLinkedBehaviorAttribute
{
public DependencyRecordedAttribute (string source, string target, string marked = null)
{
if (string.IsNullOrEmpty (source))
throw new ArgumentException ("Value cannot be null or empty.", nameof (source));

if (string.IsNullOrEmpty (target))
throw new ArgumentException ("Value cannot be null or empty.", nameof (target));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
public class DisplayNameAttribute : BaseMemberAssertionAttribute
{
public DisplayNameAttribute (string expectedDisplayName)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
public abstract class EnableLoggerAttribute : BaseExpectedLinkedBehaviorAttribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)]
public class ExpectBodyModifiedAttribute : BaseInAssemblyAttribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
/// Asserts that the given documentation signature string resolves to the
// member with this attribute, and only that member.
public class ExpectExactlyResolvedDocumentationSignatureAttribute : BaseMemberAssertionAttribute
{
public ExpectExactlyResolvedDocumentationSignatureAttribute (string input)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)]
public class ExpectExceptionHandlersModifiedAttribute : BaseInAssemblyAttribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
/// Asserts that the member to which this attribute is applied has the given
/// documentation signature.
public class ExpectGeneratedDocumentationSignatureAttribute : BaseMemberAssertionAttribute
{
public ExpectGeneratedDocumentationSignatureAttribute (string expected)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)]
public class ExpectLocalsModifiedAttribute : BaseInAssemblyAttribute
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
/// Asserts that the given documentation signature string resolves to the
// member with this attribute.
public class ExpectResolvedDocumentationSignatureAttribute : BaseMemberAssertionAttribute
{
public ExpectResolvedDocumentationSignatureAttribute (string input)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
/// Asserts that the given documentation signature string does not resolve
/// to the member with this attribute.
public class ExpectUnresolvedDocumentationSignatureAttribute : BaseMemberAssertionAttribute
{
public ExpectUnresolvedDocumentationSignatureAttribute (string expected)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)]
public class ExpectedInstructionSequenceAttribute : BaseInAssemblyAttribute
{
public ExpectedInstructionSequenceAttribute (string[] opCodes)
{
if (opCodes == null)
throw new ArgumentNullException (nameof (opCodes));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Mono.Linker.Tests.Cases.Expectations.Assertions
{
[AttributeUsage (AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
public class ExpectedInstructionSequenceOnMemberInAssemblyAttribute : BaseInAssemblyAttribute
{
public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFileName, Type type, string memberName, string[] opCodes)
{
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));
if (type == null)
throw new ArgumentNullException (nameof (type));
if (string.IsNullOrEmpty (memberName))
throw new ArgumentNullException (nameof (memberName));
if (opCodes == null)
throw new ArgumentNullException (nameof (opCodes));
}

public ExpectedInstructionSequenceOnMemberInAssemblyAttribute (string assemblyFileName, string typeName, string memberName, string[] opCodes)
{
if (string.IsNullOrEmpty (assemblyFileName))
throw new ArgumentNullException (nameof (assemblyFileName));
if (string.IsNullOrEmpty (typeName))
throw new ArgumentNullException (nameof (typeName));
if (string.IsNullOrEmpty (memberName))
throw new ArgumentNullException (nameof (memberName));
if (opCodes == null)
throw new ArgumentNullException (nameof (opCodes));
}
}
}
Loading