未验证 提交 f1dbe2ec 编写于 作者: S Steve Pfister 提交者: GitHub

[Android] Re-enable System.Security.Cryptography tests (#67057)

The crypto test suites were originally disabled as they would run out of memory on both emulators and devices somewhat frequently.

This change enables them again, with the difference being that xunit will run tests on a single thread.

Addresses #62547
上级 8c7120e2
......@@ -108,6 +108,19 @@
<MainLibraryFileName Condition="'$(MainLibraryFileName)' == ''">AndroidTestRunner.dll</MainLibraryFileName>
</PropertyGroup>
<ItemGroup>
<_AndroidEnv Condition="'$(XUnitSingleThreadedMode)' == 'true'" Include="XUNIT_SINGLE_THREADED">
<Value>1</Value>
</_AndroidEnv>
<_AndroidEnv Condition="'$(XUnitUseRandomizedTestOrderer)' == 'true'" Include="XUNIT_RANDOM_ORDER_SEED">
<Value>1883302047</Value>
</_AndroidEnv>
<_AndroidEnv Condition="'$(XUnitSingleThreadedMode)' == 'true'" Include="XUNIT_VERBOSE">
<Value>1</Value>
</_AndroidEnv>
</ItemGroup>
<ItemGroup Condition="'$(RunAOTCompilation)' == 'true'">
<AotInputAssemblies Include="$(PublishDir)\*.dll">
<AotArguments>@(MonoAOTCompilerDefaultAotArguments, ';')</AotArguments>
......@@ -140,6 +153,7 @@
MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackNativeDir)include\mono-2.0"
Assemblies="@(BundleAssemblies)"
MainLibraryFileName="$(MainLibraryFileName)"
EnvironmentVariables="@(_AndroidEnv)"
ForceAOT="$(RunAOTCompilation)"
ForceInterpreter="$(MonoForceInterpreter)"
StripDebugSymbols="False"
......
......@@ -30,7 +30,8 @@ public static async Task<int> Main(string[] args)
int exitCode = 0;
s_MainTestName = Path.GetFileNameWithoutExtension(s_testLibs[0]);
string? verbose = Environment.GetEnvironmentVariable("XUNIT_VERBOSE")?.ToLower();
var simpleTestRunner = new SimpleAndroidTestRunner(verbose == "true" || verbose == "1");
bool enableMaxThreads = (Environment.GetEnvironmentVariable("XUNIT_SINGLE_THREADED") != "1");
var simpleTestRunner = new SimpleAndroidTestRunner(verbose == "true" || verbose == "1", enableMaxThreads);
simpleTestRunner.TestsCompleted += (e, result) =>
{
if (result.FailedTests > 0)
......@@ -42,17 +43,14 @@ public static async Task<int> Main(string[] args)
return exitCode;
}
public SimpleAndroidTestRunner(bool verbose)
public SimpleAndroidTestRunner(bool verbose, bool enableMaxThreads)
{
if (verbose)
{
MinimumLogLevel = MinimumLogLevel.Verbose;
_maxParallelThreads = 1;
}
else
MinimumLogLevel = (verbose) ? MinimumLogLevel.Verbose : MinimumLogLevel.Info;
_maxParallelThreads = (enableMaxThreads) ? Environment.ProcessorCount : 1;
if (!enableMaxThreads)
{
MinimumLogLevel = MinimumLogLevel.Info;
_maxParallelThreads = Environment.ProcessorCount;
Console.WriteLine("XUNIT: SINGLE THREADED MODE ENABLED");
}
}
......
......@@ -11,9 +11,13 @@
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<DefineConstants Condition="'$(TargetPlatformIdentifier)' == 'Unix' or '$(TargetPlatformIdentifier)' == 'Android' or '$(TargetPlatformIdentifier)' == 'OSX' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'tvOS'">$(DefineConstants);Unix</DefineConstants>
<UseAndroidCrypto Condition="'$(TargetPlatformIdentifier)' == 'Android'">true</UseAndroidCrypto>
<UseAppleCrypto Condition="'$(TargetPlatformIdentifier)' == 'OSX' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'tvOS'">true</UseAppleCrypto>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'Android'">
<UseAndroidCrypto>true</UseAndroidCrypto>
<XUnitSingleThreadedMode>true</XUnitSingleThreadedMode>
<XUnitUseRandomizedTestOrderer>true</XUnitUseRandomizedTestOrderer>
</PropertyGroup>
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1Reader\System.Security.Cryptography.Asn1Reader.Shared.projitems" />
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
......
......@@ -9,7 +9,11 @@
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<UseAndroidCrypto Condition="'$(TargetPlatformIdentifier)' == 'Android'">true</UseAndroidCrypto>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'Android'">
<UseAndroidCrypto>true</UseAndroidCrypto>
<XUnitSingleThreadedMode>true</XUnitSingleThreadedMode>
<XUnitUseRandomizedTestOrderer>true</XUnitUseRandomizedTestOrderer>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonTestPath)System\IO\ConnectedStreams.cs"
......
......@@ -173,15 +173,11 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Private.Xml/tests/XPath/XPathDocument/System.Xml.XPath.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Private.Uri/tests/ExtendedFunctionalTests/System.Private.Uri.ExtendedFunctional.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Reflection.DispatchProxy/tests/System.Reflection.DispatchProxy.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography.X509Certificates\tests\System.Security.Cryptography.X509Certificates.Tests.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'Android' and '$(TargetArchitecture)' == 'x64' and '$(RunDisabledAndroidTests)' != 'true'">
<!-- Test flakiness on x64 https://github.com/dotnet/runtime/issues/49937 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Threading\tests\System.Threading.Tests.csproj" />
<!-- Out of memory https://github.com/dotnet/runtime/issues/66831 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography\tests\System.Security.Cryptography.Tests.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'Android' and '$(TargetArchitecture)' == 'x86' and '$(RunDisabledAndroidTests)' != 'true'">
......@@ -191,14 +187,6 @@
<!-- https://github.com/dotnet/runtime/issues/50493 -->
<ProjectExclusions Include="$(RepoRoot)\src\tests\FunctionalTests\Android\Device_Emulator\AOT\Android.Device_Emulator.Aot.Test.csproj" />
<!-- Out of memory https://github.com/dotnet/runtime/issues/66831 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography\tests\System.Security.Cryptography.Tests.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'Android' and '$(TargetArchitecture)' == 'arm' and '$(RunDisabledAndroidTests)' != 'true'">
<!-- Out of memory https://github.com/dotnet/runtime/issues/66831 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography\tests\System.Security.Cryptography.Tests.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetOS)' == 'iOS' and '$(RunDisablediOSTests)' != 'true'">
......
......@@ -28,6 +28,11 @@ public class AndroidAppBuilderTask : Task
/// </summary>
public ITaskItem[] Assemblies { get; set; } = Array.Empty<ITaskItem>();
/// <summary>
/// The set of environment variables to provide to the native embedded application
/// </summary>
public ITaskItem[] EnvironmentVariables { get; set; } = Array.Empty<ITaskItem>();
/// <summary>
/// Prefer FullAOT mode for Emulator over JIT
/// </summary>
......@@ -103,6 +108,7 @@ public override bool Execute()
apkBuilder.KeyStorePath = KeyStorePath;
apkBuilder.ForceInterpreter = ForceInterpreter;
apkBuilder.ForceAOT = ForceAOT;
apkBuilder.EnvironmentVariables = EnvironmentVariables;
apkBuilder.StaticLinkedRuntime = StaticLinkedRuntime;
apkBuilder.RuntimeComponents = RuntimeComponents;
apkBuilder.DiagnosticPorts = DiagnosticPorts;
......
......@@ -27,6 +27,7 @@ public class ApkBuilder
public string? KeyStorePath { get; set; }
public bool ForceInterpreter { get; set; }
public bool ForceAOT { get; set; }
public ITaskItem[] EnvironmentVariables { get; set; } = Array.Empty<ITaskItem>();
public bool InvariantGlobalization { get; set; }
public bool EnableRuntimeLogging { get; set; }
public bool StaticLinkedRuntime { get; set; }
......@@ -371,8 +372,17 @@ public ApkBuilder(TaskLoggingHelper logger)
if (!string.IsNullOrEmpty(NativeMainSource))
File.Copy(NativeMainSource, javaActivityPath, true);
string envVariables = "";
foreach (ITaskItem item in EnvironmentVariables)
{
string name = item.ItemSpec;
string value = item.GetMetadata("Value");
envVariables += $"\t\tsetEnv(\"{name}\", \"{value}\");\n";
}
string monoRunner = Utils.GetEmbeddedResource("MonoRunner.java")
.Replace("%EntryPointLibName%", Path.GetFileName(mainLibraryFileName));
.Replace("%EntryPointLibName%", Path.GetFileName(mainLibraryFileName))
.Replace("%EnvVariables%", envVariables);
File.WriteAllText(monoRunnerPath, monoRunner);
......
......@@ -65,6 +65,8 @@ public class MonoRunner extends Instrumentation
argsToForward = argsList.toArray(new String[argsList.size()]);
}
%EnvVariables%
super.onCreate(arguments);
start();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册