From c878590782760487971f299c2dc1f96a388f9dd0 Mon Sep 17 00:00:00 2001 From: Michael Sharp Date: Fri, 8 Nov 2024 14:19:07 -0700 Subject: [PATCH 1/5] updated remote executor --- Microsoft.ML.sln | 11 - eng/Versions.props | 10 +- .../Helpers/AdditionalMetadataReferences.cs | 4 +- .../RemoteExecutor.cs | 68 ------ .../UnitTests.cs | 158 +++++++------- .../Microsoft.ML.NightlyBuild.Tests.csproj | 1 + .../Microsoft.ML.TestFramework.csproj | 3 +- .../RemoteExecutor.cs | 204 ------------------ .../RemoteExecutorConsoleApp.cs | 124 ----------- .../RemoteExecutorConsoleApp.csproj | 8 - 10 files changed, 86 insertions(+), 505 deletions(-) delete mode 100644 test/Microsoft.ML.CpuMath.UnitTests/RemoteExecutor.cs delete mode 100644 test/Microsoft.ML.TestFramework/RemoteExecutor.cs delete mode 100644 test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.cs delete mode 100644 test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.csproj diff --git a/Microsoft.ML.sln b/Microsoft.ML.sln index d57cc442bd..4e7f81d66a 100644 --- a/Microsoft.ML.sln +++ b/Microsoft.ML.sln @@ -110,8 +110,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.EntryPoints", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.DataView", "src\Microsoft.ML.DataView\Microsoft.ML.DataView.csproj", "{85D0CAFD-2FE8-496A-88C7-585D35B94243}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RemoteExecutorConsoleApp", "test\RemoteExecutorConsoleApp\RemoteExecutorConsoleApp.csproj", "{5E920CAC-5A28-42FB-936E-49C472130953}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Experimental", "src\Microsoft.ML.Experimental\Microsoft.ML.Experimental.csproj", "{E02DA82D-3FEE-4C60-BD80-9EC3C3448DFC}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.ML", "src\Microsoft.Extensions.ML\Microsoft.Extensions.ML.csproj", "{D6741C37-B5E6-4050-BCBA-9715809EA15B}" @@ -598,14 +596,6 @@ Global {85D0CAFD-2FE8-496A-88C7-585D35B94243}.Release|Any CPU.Build.0 = Release|Any CPU {85D0CAFD-2FE8-496A-88C7-585D35B94243}.Release|x64.ActiveCfg = Release|Any CPU {85D0CAFD-2FE8-496A-88C7-585D35B94243}.Release|x64.Build.0 = Release|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Debug|x64.ActiveCfg = Debug|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Debug|x64.Build.0 = Debug|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Release|Any CPU.Build.0 = Release|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Release|x64.ActiveCfg = Release|Any CPU - {5E920CAC-5A28-42FB-936E-49C472130953}.Release|x64.Build.0 = Release|Any CPU {E02DA82D-3FEE-4C60-BD80-9EC3C3448DFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E02DA82D-3FEE-4C60-BD80-9EC3C3448DFC}.Debug|Any CPU.Build.0 = Debug|Any CPU {E02DA82D-3FEE-4C60-BD80-9EC3C3448DFC}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -1031,7 +1021,6 @@ Global {DB7CEB5E-8BE6-48A7-87BE-B91D9AE96F71} = {09EADF06-BE25-4228-AB53-95AE3E15B530} {7504D46F-E4B3-43CB-9B1C-82F3131F1C99} = {09EADF06-BE25-4228-AB53-95AE3E15B530} {85D0CAFD-2FE8-496A-88C7-585D35B94243} = {09EADF06-BE25-4228-AB53-95AE3E15B530} - {5E920CAC-5A28-42FB-936E-49C472130953} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4} {E02DA82D-3FEE-4C60-BD80-9EC3C3448DFC} = {09EADF06-BE25-4228-AB53-95AE3E15B530} {D6741C37-B5E6-4050-BCBA-9715809EA15B} = {09EADF06-BE25-4228-AB53-95AE3E15B530} {21CAD3A1-5E1F-42C1-BB73-46B6E67F4206} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4} diff --git a/eng/Versions.props b/eng/Versions.props index e2e60447fa..fd8dd0187c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -21,17 +21,17 @@ 8.0.2 6.9.1 2.88.8 - 4.5.1 + 4.6.0-preview.1.24529.4 8.0.0 8.0.0 6.0.1 8.0.1 5.0.0 - 4.5.5 + 4.6.0-preview.1.24529.4 8.0.0 4.7.0 4.3.0 - 6.0.0 + 6.1.0-preview.1.24529.4 5.0.0 8.0.0 8.0.5 @@ -40,7 +40,7 @@ 14.0.2 3.27.1 3.3.5 - 1.1.1 + 6.0.0-preview.1.24529.4 9.0.0-rc.1.24431.7 3.3.4 4.9.2 @@ -91,7 +91,7 @@ 6.12.0 1.1.2-beta1.23431.1 5.0.0-preview.5.20278.1 - 8.0.0-beta.24165.4 + 8.0.0-beta.24525.2 10.0.0-beta.24504.4 8.0.1 0.0.6-test diff --git a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs index 8bcc0cc325..b4e2ff8cbc 100644 --- a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs +++ b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs @@ -16,10 +16,10 @@ internal static class AdditionalMetadataReferences { #if NETCOREAPP internal static readonly ReferenceAssemblies DefaultReferenceAssemblies = ReferenceAssemblies.Default - .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.5.1"))); + .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0"))); #else internal static readonly ReferenceAssemblies DefaultReferenceAssemblies = ReferenceAssemblies.NetFramework.Net472.Default - .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.5.1"))); + .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0"))); #endif internal static readonly MetadataReference MSDataDataViewReference = RefFromType(); diff --git a/test/Microsoft.ML.CpuMath.UnitTests/RemoteExecutor.cs b/test/Microsoft.ML.CpuMath.UnitTests/RemoteExecutor.cs deleted file mode 100644 index f3e6e06e38..0000000000 --- a/test/Microsoft.ML.CpuMath.UnitTests/RemoteExecutor.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; - -#if NET6_0_OR_GREATER -using Executor = Microsoft.DotNet.RemoteExecutor.RemoteExecutor; -#else -using Executor = Microsoft.ML.TestFramework.RemoteExecutor; -#endif - -namespace Microsoft.ML.CpuMath.UnitTests -{ - - internal static class RemoteExecutor - { - public const int SuccessExitCode = 42; - - public static void RemoteInvoke( - Func method, - string arg1, string arg2, string arg3, string arg4, -#if NETFRAMEWORK - Microsoft.ML.TestFramework.RemoteInvokeOptions options = null) -#else - Microsoft.DotNet.RemoteExecutor.RemoteInvokeOptions options = null) -#endif - { -#if NETFRAMEWORK - Executor.RemoteInvoke(method, arg1, arg2, arg3, arg4, options); -#else - Executor.Invoke(method, arg1, arg2, arg3, arg4, options).Dispose(); -#endif - } - - public static void RemoteInvoke( - Func method, - string arg1, string arg2, string arg3, -#if NETFRAMEWORK - Microsoft.ML.TestFramework.RemoteInvokeOptions options = null) -#else - Microsoft.DotNet.RemoteExecutor.RemoteInvokeOptions options = null) -#endif - { -#if NETFRAMEWORK - Executor.RemoteInvoke(method, arg1, arg2, arg3, options); -#else - Executor.Invoke(method, arg1, arg2, arg3, options).Dispose(); -#endif - } - - public static void RemoteInvoke( - Func method, - string arg1, string arg2, -#if NETFRAMEWORK - Microsoft.ML.TestFramework.RemoteInvokeOptions options = null) -#else - Microsoft.DotNet.RemoteExecutor.RemoteInvokeOptions options = null) -#endif - { -#if NETFRAMEWORK - Executor.RemoteInvoke(method, arg1, arg2, options); -#else - Executor.Invoke(method, arg1, arg2, options).Dispose(); -#endif - } - } -} diff --git a/test/Microsoft.ML.CpuMath.UnitTests/UnitTests.cs b/test/Microsoft.ML.CpuMath.UnitTests/UnitTests.cs index edf99ef5c9..d223ef6fa5 100644 --- a/test/Microsoft.ML.CpuMath.UnitTests/UnitTests.cs +++ b/test/Microsoft.ML.CpuMath.UnitTests/UnitTests.cs @@ -8,16 +8,12 @@ using System.Globalization; using System.Reflection; using System.Runtime.InteropServices; +using Microsoft.DotNet.RemoteExecutor; using Microsoft.ML.Internal.CpuMath; using Microsoft.ML.TestFramework; using Xunit; using Xunit.Abstractions; -#if NETFRAMEWORK -using RemoteOptions = Microsoft.ML.TestFramework.RemoteInvokeOptions; -#else -using RemoteOptions = Microsoft.DotNet.RemoteExecutor.RemoteInvokeOptions; -#endif namespace Microsoft.ML.CpuMath.UnitTests { @@ -239,10 +235,10 @@ public static TheoryData environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2, arg3) => + RemoteExecutor.Invoke((arg0, arg1, arg2, arg3) => { CheckProperFlag(arg0); @@ -266,7 +262,7 @@ public void MatMulTest(string mode, string matTest, string srcTest, string dstTe dst.CopyTo(actual, 0, dst.Size); Assert.Equal(expected, actual, _matMulComparer); return RemoteExecutor.SuccessExitCode; - }, mode, matTest, srcTest, dstTest, options); + }, mode, matTest, srcTest, dstTest, options).Dispose(); } @@ -274,10 +270,10 @@ public void MatMulTest(string mode, string matTest, string srcTest, string dstTe [MemberData(nameof(MatMulData))] public void MatMulTranTest(string mode, string matTest, string srcTest, string dstTest, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2, arg3) => + RemoteExecutor.Invoke((arg0, arg1, arg2, arg3) => { CheckProperFlag(arg0); AlignedArray mat = _testMatrices[int.Parse(arg1)]; @@ -300,17 +296,17 @@ public void MatMulTranTest(string mode, string matTest, string srcTest, string d dst.CopyTo(actual, 0, dst.Size); Assert.Equal(expected, actual, _matMulComparer); return RemoteExecutor.SuccessExitCode; - }, mode, matTest, srcTest, dstTest, options); + }, mode, matTest, srcTest, dstTest, options).Dispose(); } [Theory] [MemberData(nameof(MatMulData))] public void MatTimesSrcSparseTest(string mode, string matTest, string srcTest, string dstTest, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2, arg3) => + RemoteExecutor.Invoke((arg0, arg1, arg2, arg3) => { CheckProperFlag(arg0); AlignedArray mat = _testMatrices[int.Parse(arg1)]; @@ -337,7 +333,7 @@ public void MatTimesSrcSparseTest(string mode, string matTest, string srcTest, s Assert.Equal(expected, actual, _matMulComparer); return RemoteExecutor.SuccessExitCode; - }, mode, matTest, srcTest, dstTest, options); + }, mode, matTest, srcTest, dstTest, options).Dispose(); } [Theory] @@ -345,10 +341,10 @@ public void MatTimesSrcSparseTest(string mode, string matTest, string srcTest, s [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters", Justification = "")] public void AddScalarUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -364,17 +360,17 @@ public void AddScalarUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -390,17 +386,17 @@ public void ScaleTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -417,17 +413,17 @@ public void ScaleSrcUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -443,7 +439,7 @@ public void ScaleAddUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -471,17 +467,17 @@ public void AddScaleUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -500,17 +496,17 @@ public void AddScaleSUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse("1.7", CultureInfo.InvariantCulture); @@ -528,17 +524,17 @@ public void AddScaleCopyUTest(string mode, string test, string scale, Dictionary var actual = result; Assert.Equal(expected, actual, _comparer); return RemoteExecutor.SuccessExitCode; - }, mode, test, scale, options); + }, mode, test, scale, options).Dispose(); } [Theory] [MemberData(nameof(AddData))] public void AddUTest(string mode, string test, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -560,7 +556,7 @@ public void AddUTest(string mode, string test, Dictionary enviro var actual = dst; Assert.Equal(expected, actual, _comparer); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } @@ -568,10 +564,10 @@ public void AddUTest(string mode, string test, Dictionary enviro [MemberData(nameof(AddData))] public void AddSUTest(string mode, string test, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -590,17 +586,17 @@ public void AddSUTest(string mode, string test, Dictionary envir var actual = dst; Assert.Equal(expected, actual, _comparer); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] [MemberData(nameof(AddData))] public void MulElementWiseUTest(string mode, string test, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg1); float[] src1 = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -624,17 +620,17 @@ public void MulElementWiseUTest(string mode, string test, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -647,17 +643,17 @@ public void SumTest(string mode, string test, Dictionary environ var actual = CpuMathUtils.Sum(src); Assert.Equal((double)expected, (double)actual, 0.01); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] [MemberData(nameof(AddData))] public void SumSqUTest(string mode, string test, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -670,17 +666,17 @@ public void SumSqUTest(string mode, string test, Dictionary envi var actual = CpuMathUtils.SumSq(src); Assert.Equal((double)expected, (double)actual, 0.01); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] [MemberData(nameof(AddScaleData))] public void SumSqDiffUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -695,17 +691,17 @@ public void SumSqDiffUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -718,17 +714,17 @@ public void SumAbsUTest(string mode, string test, Dictionary env var actual = CpuMathUtils.SumAbs(src); Assert.Equal((double)expected, (double)actual, 0.01); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] [MemberData(nameof(AddScaleData))] public void SumAbsDiffUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -743,17 +739,17 @@ public void SumAbsDiffUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -771,17 +767,17 @@ public void MaxAbsUTest(string mode, string test, Dictionary env Assert.Equal((double)expected, (double)actual, 0.01); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] [MemberData(nameof(AddScaleData))] public void MaxAbsDiffUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -799,17 +795,17 @@ public void MaxAbsDiffUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -829,17 +825,17 @@ public void DotUTest(string mode, string test, Dictionary enviro var actual = CpuMathUtils.DotProductDense(src, dst, dst.Length); Assert.Equal((double)expected, (double)actual, 0.1); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] [MemberData(nameof(AddData))] public void DotSUTest(string mode, string test, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -863,17 +859,17 @@ public void DotSUTest(string mode, string test, Dictionary envir var actual = CpuMathUtils.DotProductSparse(src, dst, idx, limit); Assert.Equal((double)expected, (double)actual, 0.01); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] [MemberData(nameof(AddData))] public void Dist2Test(string mode, string test, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1) => + RemoteExecutor.Invoke((arg0, arg1) => { CheckProperFlag(arg0); float[] src = (float[])_testArrays[int.Parse(arg1)].Clone(); @@ -895,7 +891,7 @@ public void Dist2Test(string mode, string test, Dictionary envir var actual = CpuMathUtils.L2DistSquared(src, dst, dst.Length); Assert.Equal((double)expected, (double)actual, 0); return RemoteExecutor.SuccessExitCode; - }, mode, test, options); + }, mode, test, options).Dispose(); } [Theory] @@ -930,10 +926,10 @@ public void ZeroMatrixItemsCoreTest(int test, int[] idx, float[] expected) [MemberData(nameof(AddScaleData))] public void SdcaL1UpdateUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -952,7 +948,7 @@ public void SdcaL1UpdateUTest(string mode, string test, string scale, Dictionary var actual = w; Assert.Equal(expected, actual, _comparer); return RemoteExecutor.SuccessExitCode; - }, mode, test, scale, options); + }, mode, test, scale, options).Dispose(); } @@ -960,10 +956,10 @@ public void SdcaL1UpdateUTest(string mode, string test, string scale, Dictionary [MemberData(nameof(AddScaleData))] public void SdcaL1UpdateSUTest(string mode, string test, string scale, Dictionary environmentVariables) { - var options = new RemoteOptions(); + var options = new RemoteInvokeOptions(); UpdateEnvVars(options, environmentVariables); - RemoteExecutor.RemoteInvoke((arg0, arg1, arg2) => + RemoteExecutor.Invoke((arg0, arg1, arg2) => { CheckProperFlag(arg0); float defaultScale = float.Parse(arg2, CultureInfo.InvariantCulture); @@ -985,10 +981,10 @@ public void SdcaL1UpdateSUTest(string mode, string test, string scale, Dictionar var actual = w; Assert.Equal(expected, actual, _comparer); return RemoteExecutor.SuccessExitCode; - }, mode, test, scale, options); + }, mode, test, scale, options).Dispose(); } - private void UpdateEnvVars(RemoteOptions options, Dictionary environmentVariables) + private void UpdateEnvVars(RemoteInvokeOptions options, Dictionary environmentVariables) { if (environmentVariables == null) return; diff --git a/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj b/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj index b9ea65932b..5efe9b4326 100644 --- a/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj +++ b/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj @@ -6,6 +6,7 @@ false false + $(NoWarn);NU1605 diff --git a/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj b/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj index 483cb1ab7a..53783ee35b 100644 --- a/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj +++ b/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj @@ -19,7 +19,6 @@ - @@ -33,7 +32,7 @@ - + diff --git a/test/Microsoft.ML.TestFramework/RemoteExecutor.cs b/test/Microsoft.ML.TestFramework/RemoteExecutor.cs deleted file mode 100644 index 097de7ad8e..0000000000 --- a/test/Microsoft.ML.TestFramework/RemoteExecutor.cs +++ /dev/null @@ -1,204 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using Xunit; -using Xunit.Sdk; - -namespace Microsoft.ML.TestFramework -{ - /// - /// Base class used for all tests that need to spawn a remote process. - /// Most of the code has been taken from RemoteExecutorTestBase class in the corefx repo. - /// - public static class RemoteExecutor - { - /// The name of the test console app. - public static readonly string TestConsoleApp = Path.GetFullPath(@"RemoteExecutorConsoleApp.dll"); -#if NETFRAMEWORK - public static readonly string HostRunner = Path.GetFullPath(@"RemoteExecutorConsoleApp.exe"); - private static readonly string _extraParameter = ""; -#else - public static readonly string HostRunner = Process.GetCurrentProcess().MainModule.FileName; - private static readonly string _extraParameter = TestConsoleApp; -#endif - /// A timeout (milliseconds) after which a wait on a remote operation should be considered a failure. - public const int FailWaitTimeoutMilliseconds = 60 * 1000; - - /// The exit code returned when the test process exits successfully. - public const int SuccessExitCode = 42; - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// Options to use for the invocation. - public static void RemoteInvoke( - Func method, - string arg1, string arg2, - RemoteInvokeOptions options = null) - { - RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// The third argument to pass to the method. - /// Options to use for the invocation. - public static void RemoteInvoke( - Func method, - string arg1, string arg2, string arg3, - RemoteInvokeOptions options = null) - { - RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2, arg3 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// The third argument to pass to the method. - /// The fourth argument to pass to the method. - /// Options to use for the invocation. - public static void RemoteInvoke( - Func method, - string arg1, string arg2, string arg3, string arg4, - RemoteInvokeOptions options = null) - { - RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2, arg3, arg4 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The arguments to pass to the method. - /// Options to use for the invocation. - /// true if this function should paste the arguments (e.g. surrounding with quotes); false if that responsibility is left up to the caller. - private static void RemoteInvoke(MethodInfo method, string[] args, RemoteInvokeOptions options, bool pasteArguments = true) - { - options = options ?? new RemoteInvokeOptions(); - - // Verify the specified method returns an int (the exit code) or nothing, - // and that if it accepts any arguments, they're all strings. - Assert.True(method.ReturnType == typeof(void) || method.ReturnType == typeof(int) || method.ReturnType == typeof(Task)); - Assert.All(method.GetParameters(), pi => Assert.Equal(typeof(string), pi.ParameterType)); - - // And make sure it's in this assembly. This isn't critical, but it helps with deployment to know - // that the method to invoke is available because we're already running in this assembly. - Type t = method.DeclaringType; - Assembly a = t.GetTypeInfo().Assembly; - - // Start the other process and return a wrapper for it to handle its lifetime and exit checking. - ProcessStartInfo psi = options.StartInfo; - psi.UseShellExecute = false; - - // If we need the host (if it exists), use it, otherwise target the console app directly. - string metadataArgs = PasteArguments.Paste(new string[] { a.FullName, t.FullName, method.Name, options.ExceptionFile }, pasteFirstArgumentUsingArgV0Rules: false); - string passedArgs = pasteArguments ? PasteArguments.Paste(args, pasteFirstArgumentUsingArgV0Rules: false) : string.Join(" ", args); - string testConsoleAppArgs = _extraParameter + " " + metadataArgs + " " + passedArgs; - - psi.FileName = HostRunner; - psi.Arguments = testConsoleAppArgs; - - // Return the handle to the process, which may or not be started - CheckProcess(Process.Start(psi), options); - } - - private static void CheckProcess(Process process, RemoteInvokeOptions options) - { - if (process != null) - { - // A bit unorthodox to do throwing operations in a Dispose, but by doing it here we avoid - // needing to do this in every derived test and keep each test much simpler. - try - { - Assert.True(process.WaitForExit(options.TimeOut), - $"Timed out after {options.TimeOut}ms waiting for remote process {process.Id}"); - - if (File.Exists(options.ExceptionFile)) - { - throw new RemoteExecutionException(File.ReadAllText(options.ExceptionFile)); - } - - if (options.CheckExitCode) - { - int expected = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? options.ExpectedExitCode : unchecked((sbyte)options.ExpectedExitCode); - int actual = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? process.ExitCode : unchecked((sbyte)process.ExitCode); - - Assert.True(expected == actual, $"Exit code was {process.ExitCode} but it should have been {options.ExpectedExitCode}"); - } - } - finally - { - if (File.Exists(options.ExceptionFile)) - { - File.Delete(options.ExceptionFile); - } - - // Cleanup - try { process.Kill(); } - catch { } // ignore all cleanup errors - - process.Dispose(); - process = null; - } - } - } - - private sealed class RemoteExecutionException : XunitException - { - internal RemoteExecutionException(string stackTrace) : base($"Remote process failed with an unhandled exception. {stackTrace}") { } - } - - private static MethodInfo GetMethodInfo(Delegate d) - { - // RemoteInvoke doesn't support marshaling state on classes associated with - // the delegate supplied (often a display class of a lambda). If such fields - // are used, odd errors result, e.g. NullReferenceExceptions during the remote - // execution. Try to ward off the common cases by proactively failing early - // if it looks like such fields are needed. - if (d.Target != null) - { - // The only fields on the type should be compiler-defined (any fields of the compiler's own - // making generally include '<' and '>', as those are invalid in C# source). Note that this logic - // may need to be revised in the future as the compiler changes, as this relies on the specifics of - // actually how the compiler handles lifted fields for lambdas. - Type targetType = d.Target.GetType(); - Assert.All( - targetType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fi => Assert.True(fi.Name.IndexOf('<') != -1, $"Field marshaling is not supported by {nameof(RemoteInvoke)}: {fi.Name}")); - } - - return d.GetMethodInfo(); - } - } - - /// Options used with RemoteInvoke. - public sealed class RemoteInvokeOptions - { - public RemoteInvokeOptions(Dictionary environmentVariables = null) - { - if (environmentVariables != null) - { - foreach (var item in environmentVariables) - { - StartInfo.EnvironmentVariables.Add(item.Key, item.Value); - } - } - } - - public ProcessStartInfo StartInfo { get; set; } = new ProcessStartInfo(); - public bool CheckExitCode { get; set; } = true; - public int TimeOut { get; set; } = RemoteExecutor.FailWaitTimeoutMilliseconds; - public int ExpectedExitCode { get; set; } = RemoteExecutor.SuccessExitCode; - public string ExceptionFile { get; } = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - } -} diff --git a/test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.cs b/test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.cs deleted file mode 100644 index 113ee6a4c1..0000000000 --- a/test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.cs +++ /dev/null @@ -1,124 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Runtime.ExceptionServices; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace RemoteExecutorConsoleApp -{ - class Program - { - static int Main(string[] args) - { - if (args.Length < 4) - { - Console.Error.WriteLine("Usage: {0} assemblyName typeName methodName exceptionFile [additionalArgs]", typeof(Program).GetTypeInfo().Assembly.GetName().Name); - Environment.Exit(-1); - return -1; - } - - string assemblyName = args[0]; - string typeName = args[1]; - string methodName = args[2]; - string exceptionFile = args[3]; - string[] additionalArgs = args.Length > 4 ? - Subarray(args, 4, args.Length - 4) : - Array.Empty(); - - // Load the specified assembly, type, and method, then invoke the method. - // The program's exit code is the return value of the invoked method. - Assembly a = null; - Type t = null; - MethodInfo mi = null; - object instance = null; - int exitCode = 0; - - try - { - // Create the test class if necessary - try - { - a = Assembly.Load(assemblyName); - } - catch (FileNotFoundException) - { - a = Assembly.LoadFrom(assemblyName.Split(',')[0] + ".dll"); - } - - t = a.GetType(typeName); - mi = t.GetTypeInfo().GetDeclaredMethod(methodName); - if (!mi.IsStatic) - { - instance = Activator.CreateInstance(t); - } - - // Invoke the test - object result = mi.Invoke(instance, additionalArgs); - - if (result is Task task) - { - exitCode = task.GetAwaiter().GetResult(); - } - else if (result is int exit) - { - exitCode = exit; - } - } - catch (Exception exc) - { - if (exc is TargetInvocationException && exc.InnerException != null) - exc = exc.InnerException; - - var output = new StringBuilder(); - output.AppendLine(); - output.AppendLine("Child exception:"); - output.AppendLine(" " + exc); - output.AppendLine(); - output.AppendLine("Child process:"); - output.AppendLine(string.Format(" {0} {1} {2}", a, t, mi)); - output.AppendLine(); - - if (additionalArgs.Length > 0) - { - output.AppendLine("Child arguments:"); - output.AppendLine(" " + string.Join(", ", additionalArgs)); - } - - File.WriteAllText(exceptionFile, output.ToString()); - - ExceptionDispatchInfo.Capture(exc).Throw(); - } - finally - { - (instance as IDisposable)?.Dispose(); - } - - // Use Exit rather than simply returning the exit code so that we forcibly shut down - // the process even if there are foreground threads created by the operation that would - // end up keeping the process alive potentially indefinitely. - try - { - Environment.Exit(exitCode); - } - catch (PlatformNotSupportedException) - { - } - - return exitCode; - } - - private static T[] Subarray(T[] arr, int offset, int count) - { - var newArr = new T[count]; - Array.Copy(arr, offset, newArr, 0, count); - return newArr; - } - } -} diff --git a/test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.csproj b/test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.csproj deleted file mode 100644 index 580d921f67..0000000000 --- a/test/RemoteExecutorConsoleApp/RemoteExecutorConsoleApp.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - false - - - From 34141f302a1de7afc76cc77780788bc08ee37955 Mon Sep 17 00:00:00 2001 From: Michael Sharp Date: Fri, 8 Nov 2024 16:41:12 -0700 Subject: [PATCH 2/5] fixing test reference issue --- .../Microsoft.ML.CpuMath.UnitTests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.ML.CpuMath.UnitTests/Microsoft.ML.CpuMath.UnitTests.csproj b/test/Microsoft.ML.CpuMath.UnitTests/Microsoft.ML.CpuMath.UnitTests.csproj index a1fc06863d..bc9ea1b650 100644 --- a/test/Microsoft.ML.CpuMath.UnitTests/Microsoft.ML.CpuMath.UnitTests.csproj +++ b/test/Microsoft.ML.CpuMath.UnitTests/Microsoft.ML.CpuMath.UnitTests.csproj @@ -3,6 +3,7 @@ + From bd5589c74e3bd8a0bcc804818edb017355b01388 Mon Sep 17 00:00:00 2001 From: Michael Sharp Date: Fri, 8 Nov 2024 16:53:26 -0700 Subject: [PATCH 3/5] full version string --- .../Helpers/AdditionalMetadataReferences.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs index b4e2ff8cbc..c9e832fdc8 100644 --- a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs +++ b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs @@ -16,10 +16,10 @@ internal static class AdditionalMetadataReferences { #if NETCOREAPP internal static readonly ReferenceAssemblies DefaultReferenceAssemblies = ReferenceAssemblies.Default - .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0"))); + .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0-preview.1.24529.4"))); #else internal static readonly ReferenceAssemblies DefaultReferenceAssemblies = ReferenceAssemblies.NetFramework.Net472.Default - .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0"))); + .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0-preview.1.24529.4"))); #endif internal static readonly MetadataReference MSDataDataViewReference = RefFromType(); From 1ea0d80bdad0941ea1e8f19296dacb1293ec5850 Mon Sep 17 00:00:00 2001 From: Michael Sharp Date: Fri, 8 Nov 2024 17:19:09 -0700 Subject: [PATCH 4/5] old memory version --- .../Helpers/AdditionalMetadataReferences.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs index c9e832fdc8..8bcc0cc325 100644 --- a/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs +++ b/test/Microsoft.ML.CodeAnalyzer.Tests/Helpers/AdditionalMetadataReferences.cs @@ -16,10 +16,10 @@ internal static class AdditionalMetadataReferences { #if NETCOREAPP internal static readonly ReferenceAssemblies DefaultReferenceAssemblies = ReferenceAssemblies.Default - .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0-preview.1.24529.4"))); + .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.5.1"))); #else internal static readonly ReferenceAssemblies DefaultReferenceAssemblies = ReferenceAssemblies.NetFramework.Net472.Default - .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.6.0-preview.1.24529.4"))); + .AddPackages(ImmutableArray.Create(new PackageIdentity("System.Memory", "4.5.1"))); #endif internal static readonly MetadataReference MSDataDataViewReference = RefFromType(); From 52abd6aa0b1af737548ac2eba94f3b34ef99750e Mon Sep 17 00:00:00 2001 From: Michael Sharp Date: Mon, 11 Nov 2024 11:59:07 -0700 Subject: [PATCH 5/5] removed nowarn --- .../Microsoft.ML.NightlyBuild.Tests.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj b/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj index 5efe9b4326..b9ea65932b 100644 --- a/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj +++ b/test/Microsoft.ML.NightlyBuild.Tests/Microsoft.ML.NightlyBuild.Tests.csproj @@ -6,7 +6,6 @@ false false - $(NoWarn);NU1605