Skip to content

Commit d0d7bc3

Browse files
committed
Fix smoke test build for android
- Ensure they have Main entry point - Tighten MSBuild conditions: - Only set NativeLib/CustomNativeMain for Android when OutputType == Exe - Only import testing/tests.targets for Android when using MicrosoftNETSdk and building executables - Make TestNativeAOT/UseNativeAOTRuntime defaults apply when TestBuildMode == nativeaot and only include monodroid-nativeaot.cs for executable/XUnit-wrapper cases
1 parent 5c723f5 commit d0d7bc3

File tree

14 files changed

+337
-292
lines changed

14 files changed

+337
-292
lines changed

eng/testing/tests.android.targets

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
<DefineConstants>$(DefineConstants);SINGLE_FILE_TEST_RUNNER</DefineConstants>
1717
</PropertyGroup>
1818

19-
<ItemGroup Condition="'$(TestNativeAOT)' == 'true'">
19+
<PropertyGroup Condition="'$(TestBuildMode)' == 'nativeaot'">
20+
<TestNativeAOT Condition="'$(TestNativeAOT)' == ''">true</TestNativeAOT>
21+
<UseNativeAOTRuntime Condition="'$(UseNativeAOTRuntime)' == ''">true</UseNativeAOTRuntime>
22+
</PropertyGroup>
23+
24+
<ItemGroup Condition="'$(TestNativeAOT)' == 'true' and ('$(OutputType)' == 'Exe' or '$(ReferenceXUnitWrapperGenerator)' == 'true')">
2025
<Compile Include="$(RepoTasksDir)AndroidAppBuilder\Templates\monodroid-nativeaot.cs" />
2126
</ItemGroup>
2227
<PropertyGroup Condition="'$(TestNativeAOT)' == 'true'">

src/tests/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
<HybridGlobalization Condition="'$(_IsApplePlatform)' == 'true'">true</HybridGlobalization>
236236
</PropertyGroup>
237237

238-
<PropertyGroup Condition="'$(TargetOS)' == 'android' and '$(TestBuildMode)' == 'nativeaot'">
238+
<PropertyGroup Condition="'$(TargetOS)' == 'android' and '$(TestBuildMode)' == 'nativeaot' and '$(OutputType)' == 'Exe'">
239239
<NativeLib>shared</NativeLib>
240240
<CustomNativeMain>true</CustomNativeMain>
241241
</PropertyGroup>

src/tests/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@
508508
<Import Project="$(RepositoryEngineeringDir)toolAot.targets" />
509509
<Import Project="$(MSBuildProjectFullPath).targets" Condition="Exists('$(MSBuildProjectFullPath).targets')"/>
510510
<Import Project="$(RepoRoot)/src/tests/Common/mergedrunner.targets" Condition="'$(IsMergedTestRunnerAssembly)' == 'true'" />
511-
<Import Project="$(RepositoryEngineeringDir)testing\tests.targets" Condition="'$(TargetsAndroid)' == 'true'" />
511+
<Import Project="$(RepositoryEngineeringDir)testing\tests.targets" Condition="'$(TargetsAndroid)' == 'true' and '$(UsingMicrosoftNETSdk)' == 'true' and '$(_CLRTestBuildsExecutable)' == 'true'" />
512512

513513
<Target Name="GetBinPlaceTargetFramework" />
514514

src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,35 @@
44
using System;
55
using System.IO;
66

7-
using var baseline = File.OpenRead("baseline.object");
8-
using var compare = File.OpenRead("compare.object");
7+
public class Program
8+
{
9+
public static int Main(string[] args)
10+
{
11+
using var baseline = File.OpenRead("baseline.object");
12+
using var compare = File.OpenRead("compare.object");
913

10-
Console.WriteLine($"Baseline size: {baseline.Length}");
11-
Console.WriteLine($"Compare size: {compare.Length}");
14+
Console.WriteLine($"Baseline size: {baseline.Length}");
15+
Console.WriteLine($"Compare size: {compare.Length}");
1216

13-
if (baseline.Length != compare.Length)
14-
throw new Exception("Different sizes");
17+
if (baseline.Length != compare.Length)
18+
throw new Exception("Different sizes");
1519

16-
long length = baseline.Length;
17-
for (int i = 0; i < length; i++)
18-
{
19-
if (baseline.ReadByte() != compare.ReadByte())
20-
throw new Exception($"Different at byte {i}");
21-
}
20+
long length = baseline.Length;
21+
for (int i = 0; i < length; i++)
22+
{
23+
if (baseline.ReadByte() != compare.ReadByte())
24+
throw new Exception($"Different at byte {i}");
25+
}
2226

23-
// We're not interested in running this, we just want some junk to compile
24-
if (Environment.GetEnvironmentVariable("Never") == "Ever")
25-
{
26-
Delegates.Run();
27-
Devirtualization.Run();
28-
Generics.Run();
29-
Interfaces.Run();
30-
}
27+
// We're not interested in running this, we just want some junk to compile
28+
if (Environment.GetEnvironmentVariable("Never") == "Ever")
29+
{
30+
Delegates.Run();
31+
Devirtualization.Run();
32+
Generics.Run();
33+
Interfaces.Run();
34+
}
3135

32-
return 100;
36+
return 100;
37+
}
38+
}

src/tests/nativeaot/SmokeTests/DynamicGenerics/DynamicGenerics.main.cs

Lines changed: 151 additions & 150 deletions
Large diffs are not rendered by default.

src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
using System.Runtime.ExceptionServices;
88
using System.Text;
99

10-
public class BringUpTest
10+
public class Program
1111
{
1212
const int Pass = 100;
1313
const int Fail = -1;
1414

1515
volatile int myField;
1616
volatile Object myObjectField;
1717

18-
public BringUpTest()
18+
public Program()
1919
{
2020
myField = 1;
2121
}
2222

23-
static BringUpTest g = null;
23+
static Program g = null;
2424

2525
static int finallyCounter = 0;
2626

@@ -33,7 +33,7 @@ public static int Main(string[] args)
3333
if (string.Empty.Length > 0)
3434
{
3535
// Just something to make sure we generate reflection metadata for the type
36-
new BringUpTest().ToString();
36+
new Program().ToString();
3737
}
3838

3939
TestGenericExceptions();
@@ -63,7 +63,7 @@ public static int Main(string[] args)
6363
}
6464

6565
string stackTrace = e.StackTrace;
66-
if (!stackTrace.Contains("BringUpTest.Main"))
66+
if (!stackTrace.Contains("Program.Main"))
6767
{
6868
Console.WriteLine("Unexpected stack trace: " + stackTrace);
6969
return Fail;

src/tests/nativeaot/SmokeTests/FrameworkStrings/Program.cs

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,78 @@
44
using System;
55
using System.Collections.Generic;
66

7-
// Exception message from CoreLib
8-
const string expectedNullRefMessage =
7+
class Program
8+
{
9+
public static int Main(string[] args)
10+
{
11+
// Exception message from CoreLib
12+
const string expectedNullRefMessage =
913
#if RESOURCE_KEYS
10-
"Arg_NullReferenceException";
14+
"Arg_NullReferenceException";
1115
#else
12-
"Object reference not set to an instance of an object.";
16+
"Object reference not set to an instance of an object.";
1317
#endif
14-
string actualNullRefMessage = new NullReferenceException().Message;
15-
Console.WriteLine(expectedNullRefMessage);
16-
Console.WriteLine(actualNullRefMessage);
17-
if (actualNullRefMessage != expectedNullRefMessage)
18-
{
19-
throw new Exception();
20-
}
18+
string actualNullRefMessage = new NullReferenceException().Message;
19+
Console.WriteLine(expectedNullRefMessage);
20+
Console.WriteLine(actualNullRefMessage);
21+
if (actualNullRefMessage != expectedNullRefMessage)
22+
{
23+
throw new Exception();
24+
}
2125

22-
// Some exception message from the reflection library.
23-
const string expectedReflectionMessage =
26+
// Some exception message from the reflection library.
27+
const string expectedReflectionMessage =
2428
#if RESOURCE_KEYS
25-
"Argument_ArrayGetInterfaceMap";
29+
"Argument_ArrayGetInterfaceMap";
2630
#else
27-
"Interface maps for generic interfaces on arrays cannot be retrieved.";
31+
"Interface maps for generic interfaces on arrays cannot be retrieved.";
2832
#endif
29-
string actualReflectionMessage;
30-
try
31-
{
32-
typeof(int[]).GetInterfaceMap(typeof(IEnumerable<int>));
33-
actualReflectionMessage = "I guess we need to update the test";
34-
}
35-
catch (Exception ex)
36-
{
37-
actualReflectionMessage = ex.Message;
38-
}
39-
Console.WriteLine(expectedReflectionMessage);
40-
Console.WriteLine(actualReflectionMessage);
41-
if (expectedReflectionMessage != actualReflectionMessage)
42-
{
43-
throw new Exception(actualReflectionMessage);
44-
}
33+
string actualReflectionMessage;
34+
try
35+
{
36+
typeof(int[]).GetInterfaceMap(typeof(IEnumerable<int>));
37+
actualReflectionMessage = "I guess we need to update the test";
38+
}
39+
catch (Exception ex)
40+
{
41+
actualReflectionMessage = ex.Message;
42+
}
43+
Console.WriteLine(expectedReflectionMessage);
44+
Console.WriteLine(actualReflectionMessage);
45+
if (expectedReflectionMessage != actualReflectionMessage)
46+
{
47+
throw new Exception(actualReflectionMessage);
48+
}
4549

46-
Console.WriteLine("Resources in CoreLib:");
47-
string[] coreLibNames = typeof(object).Assembly.GetManifestResourceNames();
48-
foreach (var name in coreLibNames)
49-
Console.WriteLine(name);
50+
Console.WriteLine("Resources in CoreLib:");
51+
string[] coreLibNames = typeof(object).Assembly.GetManifestResourceNames();
52+
foreach (var name in coreLibNames)
53+
Console.WriteLine(name);
5054

5155
#if RESOURCE_KEYS
52-
if (coreLibNames.Length != 0)
53-
throw new Exception();
56+
if (coreLibNames.Length != 0)
57+
throw new Exception();
5458
#endif
5559

56-
Console.WriteLine("Resources in reflection library:");
57-
string[] refNames;
58-
const string reflectionAssembly = "System.Private.Reflection.Execution";
59-
try
60-
{
61-
refNames = System.Reflection.Assembly.Load(reflectionAssembly).GetManifestResourceNames();
62-
}
63-
catch (System.IO.FileNotFoundException)
64-
{
65-
refNames = Array.Empty<string>();
66-
}
67-
foreach (var name in refNames)
68-
Console.WriteLine(name);
60+
Console.WriteLine("Resources in reflection library:");
61+
string[] refNames;
62+
const string reflectionAssembly = "System.Private.Reflection.Execution";
63+
try
64+
{
65+
refNames = System.Reflection.Assembly.Load(reflectionAssembly).GetManifestResourceNames();
66+
}
67+
catch (System.IO.FileNotFoundException)
68+
{
69+
refNames = Array.Empty<string>();
70+
}
71+
foreach (var name in refNames)
72+
Console.WriteLine(name);
6973

7074
#if RESOURCE_KEYS
71-
if (refNames.Length != 0)
72-
throw new Exception();
75+
if (refNames.Length != 0)
76+
throw new Exception();
7377
#endif
7478

75-
return 100;
79+
return 100;
80+
}
81+
}

src/tests/nativeaot/SmokeTests/MultiModule/MultiModule.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<!-- This test always runs as multimodule. It's not supported if we don't have framework object files. -->
88
<CLRTestTargetUnsupported Condition="'$(BuildNativeAotFrameworkObjects)' != 'true'">true</CLRTestTargetUnsupported>
9+
<ClrTestTargetUnsupported Condition="'$(TargetsAndroid)' == 'true'">true</ClrTestTargetUnsupported>
910
<IlcMultiModule>true</IlcMultiModule>
1011
<RequiresProcessIsolation>true</RequiresProcessIsolation>
1112
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>

src/tests/nativeaot/SmokeTests/PInvoke/PInvoke.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
using System.Runtime.InteropServices;
1313
using System.Text;
1414

15+
#if GLOBAL_PROGRAM_MAIN
16+
public class Program
17+
{
18+
public static int Main(string[] args)
19+
{
20+
return PInvokeTests.Program.Main(args);
21+
}
22+
}
23+
#endif
24+
1525
// Name of namespace matches the name of the assembly on purpose to
1626
// ensure that we can handle this (mostly an issue for C++ code generation).
1727
namespace PInvokeTests

src/tests/nativeaot/SmokeTests/PInvoke/PInvoke.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<RequiresProcessIsolation>true</RequiresProcessIsolation>
1414
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>
1515
</PropertyGroup>
16+
<PropertyGroup Condition="'$(TargetsAndroid)' == 'true'">
17+
<DefineConstants>$(DefineConstants);GLOBAL_PROGRAM_MAIN</DefineConstants>
18+
<StartupObject>Program</StartupObject>
19+
</PropertyGroup>
1620
<ItemGroup>
1721
<Compile Include="PInvoke.cs" />
1822
</ItemGroup>

0 commit comments

Comments
 (0)