Skip to content

Microsoft.XmlSerializer.Generator.Tests Fails at SgenCommandTest when TestReadyToRun is Enabled #96796

Open
@ivdiazsa

Description

@ivdiazsa

Description

When building and running Microsoft.XmlSerializer.Generator.Tests with TestReadyToRun=true, the test run will fail with an assertion failure, indicating that the return value was different from the expected one.

Reproduction Steps

  1. Clone the repo and build the clr and libs subsets. Make sure you specify TestReadyToRun, so that some necessary pretest components get built.
git clone https://github.com/dotnet/runtime
cd runtime
./build.sh --subset clr+libs --configuration Release -p:TestReadyToRun=true
  1. If PR Add ActiveIssue Annotations to Failing TestReadyToRun Tests and Reenable the Executables #96721 has been merged when investigating this issue, then first reenable the test by removing its ActiveIssue annotation in src/libraries/Microsoft.XmlSerializer.Generator/tests/SGenTests.cs:
[Fact]
// Comment this one out --> [ActiveIssue("https://github.com/dotnet/runtime/issues/96796", typeof(PlatformDetection), nameof(PlatformDetection.IsReadyToRunCompiled))]
public static void SgenCommandTest()
{
    const string CodeFile = "SerializableAssembly.XmlSerializers.cs";
    const string LKGCodeFile = "Expected.SerializableAssembly.XmlSerializers.cs";

    var type = Type.GetType("Microsoft.XmlSerializer.Generator.Sgen, dotnet-Microsoft.XmlSerializer.Generator");
    MethodInfo md = type.GetMethod("Main", BindingFlags.Static | BindingFlags.Public);
    string[] args = new string[] { "SerializableAssembly.dll", "--force", "--quiet" };
    int n = (int)md.Invoke(null, new object[] { args });

    Assert.Equal(0, n);
    Assert.True(File.Exists(CodeFile), string.Format("Fail to generate {0}.", CodeFile));
    // Compare the generated CodeFiles from the LKG with the live built shared framework one.
    // Not comparing byte per byte as the generated output isn't deterministic.
    Assert.Equal(LineEndingsHelper.Normalize(File.ReadAllText(LKGCodeFile)).Length, File.ReadAllText(CodeFile).Length);
}
  1. Build and run the test
cd Microsoft.XmlSerializer.Generator/tests
# We have to specify the project file this time because this folder has two csproj files.
/path/to/runtime/dotnet.sh build Microsoft.XmlSerializer.Generator.Tests.csproj -c Release -t:Test -p:TestReadyToRun=true

Expected behavior

All tests pass, except the skipped ones.

Actual behavior

Test fails with the following error, making the whole run fail:

========================= Begin custom configuration settings ==============================
export __TestArchitecture=x64
export __IsXUnitLogCheckerSupported=1
========================== End custom configuration settings ===============================
----- start Wed Jan 10 10:23:10 AM PST 2024 =============== To repro directly: =====================================================
pushd /path/to/runtime/artifacts/bin/Microsoft.XmlSerializer.Generator.Tests/Release/net9.0/publish
chmod +rwx Microsoft.XmlSerializer.Generator.Tests ^&^& ./Microsoft.XmlSerializer.Generator.Tests -notrait category=OuterLoop -notrait category=failing -xml testResults.xml 
popd
===========================================================================================================
/path/to/runtime/artifacts/bin/Microsoft.XmlSerializer.Generator.Tests/Release/net9.0/publish /path/to/runtime/src/libraries/Microsoft.XmlSerializer.Generator/tests
Running assembly:Microsoft.XmlSerializer.Generator.Tests, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
.NET Xml Serialization Generation Utility, Version 9.0.0-dev]
Serialization Code File Name: /path/to/runtime/artifacts/bin/Microsoft.XmlSerializer.Generator.Tests/Release/net9.0/publish/SerializableAssembly.XmlSerializers.cs.
Generated serialization code for assembly /path/to/runtime/artifacts/bin/Microsoft.XmlSerializer.Generator.Tests/Release/net9.0/publish/SerializableAssembly.dll --> '/path/to/runtime/artifacts/bin/Microsoft.XmlSerializer.Generator.Tests/Release/net9.0/publish/SerializableAssembly.XmlSerializers.cs'.
[FAIL] Microsoft.XmlSerializer.Generator.Tests.SgenTests.SgenCommandTest
Assert.Equal() Failure: Values differ
Expected: 844696
Actual:   844713
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Finished Microsoft.XmlSerializer.Generator.Tests, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

Regression?

No

Known Workarounds

Keep the test disabled so that the other tests in the run can be executed unaffected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions