Skip to content

Porting compiler tests to run on Linux#82572

Open
jaredpar wants to merge 18 commits intomainfrom
port
Open

Porting compiler tests to run on Linux#82572
jaredpar wants to merge 18 commits intomainfrom
port

Conversation

@jaredpar
Copy link
Member

@jaredpar jaredpar commented Feb 28, 2026

Ported a number of the CSharp tests to run on .NET Core + Linux. This will increase our cross platform test coverage which will help with agent validation on Linux.

Note: used a ralph loop for this and it worked surprisingly well. The details of the loop are in the PR (will be removed before merging).

jaredpar and others added 5 commits February 27, 2026 23:44
Remove DesktopOnly restriction from VaryingCompilationReferences test.
Replace MscorlibRef with compilation0.References to use the correct
base references on any platform.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove WindowsDesktopOnly/WindowsOnly restrictions from three tests:
- InvalidCharacterInPdbPath: uses Embedded PDB, not native
- SwitchExpression_MethodBody_02: works with portable PDB
- SyntaxOffset_OutVarInInitializers_SwitchExpression: works with portable PDB

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove DesktopOnly restriction from PortablePdb_DeterministicCompilationWithSJIS.
Add Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) for SJIS
encoding availability on .NET Core.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove WindowsOnly restrictions from 5 of 7 EnC assembly reference tests:
- ChangingCompilationDependencies
- DependencyVersionWildcards_Compilation
- DependencyVersionWildcards_Metadata
- DependencyVersionWildcardsCollisions
- CurrentCompilationVersionWildcards

CompilationReferences_Less/More kept as WindowsOnly due to stream-based
EmitDifference producing BadImageFormatException on portable PDB path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… to .NET Core

Remove WindowsDesktopOnly restriction - dynamic types are available on
.NET Core via TargetFramework.StandardAndCSharp. The TestExecutionNeedsDesktopTypes
reason was overly conservative.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jaredpar and others added 13 commits February 28, 2026 00:09
34 test files with 155 desktop/Windows-only methods identified for porting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove DesktopOnly restriction from all 22 test methods. These are
pure compilation/diagnostic tests with no desktop-specific dependencies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove DesktopOnly restriction from LongTupleDeclaration and
Serialization tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove DesktopOnly restriction from:
- CodeGenThrowTests: 3 tests
- CodeGenUsingStatementTests: ObjectCreateInsideUsing
- CodeGenNullCoalescingAssignmentTests: IndexerLvalue
- CodeGenIterators: TestIteratorWithNullableAsCollectionVariable_Null

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 13 tests from DesktopOnly/WindowsOnly to Fact:
- DestructorTests: 4 ported
- CodeGenShortCircuitOperatorTests: 2 ported
- CodeGenScriptTests: 2 ported
- CodeGenDynamicTests: 1 ported
- CodeGenCapturing: 3 ported (2 WindowsOnly→Fact, 1 multi-condition fix)
- CodeGenOverridingAndHiding: already runs on .NET Core (ClrOnly)
- CodeGenInParametersTests: already runs on .NET Core (ClrOnly)

Skipped classes (cannot port):
- CodeGenTryFinally: ThreadAbort not supported on .NET Core
- BreakingChanges: WindowsDesktopOnly, fails on .NET Core
- CodeGenLocalFunctionTests: fails on .NET Core
- CodeGenDeconstructTests: fails on .NET Core

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 12 tests across 7 files:
- CodeGenExprLambdaTests: 2 ported (AnonymousCreation, AnonTypes2)
- CodeGenTests: 2 ported (TestBug15818, InitFromBlob)
- CodeGenOperators: 3 ported (negative zero tests)
- UnsafeTests: 2 ported (PointerArrayConversion, PointerArrayEnumerableConversion)
- CodeGenExplicitImplementationTests: 1 ported
- PatternTests: 1 ported (SwitchExpressionSequencePoints)
- OptionalArgumentsTests: 1 ported

Skipped: expression tree tests (#30160), varargs, runtime-dependent,
CRLF-dependent hashes, #if NET472 blocks, RestrictedTypes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 4 tests from WindowsOnly to Fact:
- CommandLineTests: CompilationWithWarnAsError_01, CompilationWithWarnAsError_02,
  PdbPathNotEmittedWithoutPdb
- SarifV2ErrorLoggerTests: AnalyzerDisabledWithCommandLineOptions

Remaining 103 methods skipped - genuinely Windows-specific:
- Hardcoded Windows paths (C:\, backslash normalization)
- Uses cmd.exe for process execution
- SARIF URI formatting differences on Linux
- Native PDB, NoPIA, SxS loading, locale requirements

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 11 additional tests by refactoring hardcoded Windows paths:
- NullBaseDirectory* (3): use platform-conditional source file path
- AppConfigParse: platform-conditional baseDirectory + Path.Combine
- AppConfigBasicFail: Path.Combine for config file path
- ParseDocAndOut/ParseErrorLogAndOut: platform-conditional baseDirectory
  + Path.DirectorySeparatorChar for sub-paths
- SdkPathAndLibEnvVariable: already cross-platform
- CompilationWithNonExistingOutPath: Path.DirectorySeparatorChar + Path.Combine
- ResponseFilesWithNoconfig_02/_04: removed \r\n dependency

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 9 tests across Syntax and Emit3 projects:
- MemberDeclarationParsingTests: ParseOverflow, ParseOverflow2
- SyntaxNormalizerTests: 2 raw string multiline tests
- OutVarTests: Scope_Query_01
- AttributeTests_Assembly: Bug16465
- AttributeTests_WellKnownAttributes: TestPseudoAttributes1
- AttributeTests_CallerInfoAttributes: TestCallerMemberName_ConstructorDestructor
- AttributeTests: TestWellKnownAttributeOnProperty_DynamicAttribute

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 8 tests across 3 files in the Semantic project:
- LocalFunctionTests: LocalFunctionResetsLockScopeFlag,
  LocalFunctionResetsTryCatchFinallyScopeFlags,
  LocalFunctionDoesNotOverwriteInnerLockScopeFlag,
  LocalFunctionDoesNotOverwriteInnerTryCatchFinallyScopeFlags,
  RethrowingExceptionsInCatchInsideLocalFuncIsAllowed,
  RethrowingExceptionsInLocalFuncInsideCatchIsNotAllowed
- OperatorTests: DynamicAmbiguousOrConversion
- QueryTests: StaticTypeInFromClause

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port 37 tests across 7 files in the Symbol project:
- CustomModifiersTests: 30 tests (DesktopOnly → Fact or ClrOnly)
- IndexedPropertyTests: 2 tests (ClrOnly+DesktopOnly → ClrOnly)
- OverriddenOrHiddenMembersTests: 1 test (DesktopOnly+ClrOnly → ClrOnly)
- GenericConstraintTests: 1 test (ClrOnly+DesktopOnly → ClrOnly)
- DynamicTransformsTests: 1 test (DesktopOnly+ClrOnly → ClrOnly)
- PropertyTests: 1 test (DesktopOnly → Fact)
- CustomModifierCopyTests: 1 test (ClrOnly+DesktopOnly → ClrOnly)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
All 6 remaining projects (Emit3, Semantic, Symbol, Syntax, WinRT,
IOperation) have been analyzed and attempted. Updated list.md and
actions.md with results.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@@ -0,0 +1,586 @@
# Porting Actions Log
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: all files in the copilot directory will be removed before merge. I included them to give some context about how I went about this change.

{
#if NET
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considered a module initializer to just ensure this happens for all of our unit tests. This is technically impacting the process execution since it's a shared component. Happy to hear thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I even understand what this is doing. It should definitely be documented here, at the very least.

@jaredpar
Copy link
Member Author

jaredpar commented Mar 2, 2026

@roslyn-compiler PTAL

@jaredpar jaredpar marked this pull request as ready for review March 2, 2026 18:38
@jaredpar jaredpar requested a review from a team as a code owner March 2, 2026 18:38
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think the ralph loop needs to be convinced to go again. There's a few things in #79615 that should be able to be updated as well.

public void NullBaseDirectoryNotAddedToKeyFileSearchPaths()
{
var parser = CSharpCommandLineParser.Default.Parse(new[] { "c:/test.cs" }, baseDirectory: null, SdkDirectory);
var sourceFile = ExecutionConditionUtil.IsWindows ? "c:/test.cs" : Path.Combine(Path.GetTempPath(), "test.cs");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say I like the use of Path.GetTempPath() in these. Can we just have it do /test.cs, for this and other added uses?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to do that.

Comment on lines +308 to +310
var lib0Ref = lib0.ToMetadataReference();
var compilation0 = CreateCompilation(source, new[] { lib0Ref }, options: TestOptions.DebugDll);
var compilation1 = compilation0.WithSource(source).WithReferences(compilation0.References.Where(r => r != lib0Ref).Append(lib1.ToMetadataReference()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I see why this is needed at all, tbh. Seems like the old code should run just fine.

{
#if NET
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I even understand what this is doing. It should definitely be documented here, at the very least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants