Skip to content

Commit 18e51d1

Browse files
authored
[tests] Enable more tests to run on all 3 runtimes, part 5 (#10592)
This expands test coverage across the MSBuild task tests to support and validate multiple Android runtimes (such as MonoVM, CoreCLR, and NativeAOT). **Multi-runtime test support and parameterization:** - Updated test methods in `AidlTest.cs`, `AndroidDependenciesTests.cs`, and `AndroidGradleProjectTests.cs` to accept an `AndroidRuntime` parameter using the `[Values]` attribute, enabling tests to run across all supported runtimes. Tests now call `proj.SetRuntime(runtime)` and set the `IsRelease` property based on the runtime. Unsupported configurations are skipped using `IgnoreUnsupportedConfiguration`. **Test data refactoring for runtime coverage:** - Refactored test case sources (e.g., `Get_AGPMetadataTestSources`, `Get_GetDependencyNdkRequiredConditionsData`) to generate test data for each runtime, ensuring comprehensive coverage and reducing code duplication. **Test output and assertion improvements:** - Adjusted file assertions to account for runtime-specific configuration, such as lowercasing configuration names to avoid failures on case-sensitive filesystems. **Graceful handling of unsupported scenarios:** - Incorporated logic to skip or ignore tests for runtimes that do not support certain features (e.g., AOT or profiled AOT), improving reliability and clarity of test results.
1 parent 3b378e3 commit 18e51d1

File tree

5 files changed

+602
-157
lines changed

5 files changed

+602
-157
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AidlTest.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,33 @@
55
using System.Linq;
66
using Microsoft.Build.Framework;
77
using System.Text;
8+
using Xamarin.Android.Tasks;
89

910
namespace Xamarin.Android.Build.Tests
1011
{
1112
[TestFixture]
1213
[Parallelizable (ParallelScope.Children)]
1314
public class AidlTest : BaseTest
1415
{
15-
void TestAidl (string testName, string aidl)
16+
void TestAidl (string testName, string aidl, AndroidRuntime runtime)
1617
{
1718
var proj = new XamarinAndroidApplicationProject () {
1819
IsRelease = true,
1920
};
21+
proj.SetRuntime (runtime);
2022
proj.OtherBuildItems.Add (new BuildItem (AndroidBuildActions.AndroidInterfaceDescription, "Test.aidl") { TextContent = () => aidl });
21-
using (var p = CreateApkBuilder (testName)) {
23+
using (var p = CreateApkBuilder (Path.Combine ("temp", testName))) {
2224
Assert.IsTrue (p.Build (proj), "Build should have succeeded.");
2325
}
2426
}
2527

2628
[Test]
27-
public void ListAndMap ()
29+
public void ListAndMap ([Values] AndroidRuntime runtime)
2830
{
31+
if (IgnoreUnsupportedConfiguration (runtime, release: true)) {
32+
return;
33+
}
34+
2935
string aidl = @"
3036
import android.os;
3137
import android.view;
@@ -36,12 +42,16 @@ interface Test {
3642
void map(inout Map m);
3743
}
3844
";
39-
TestAidl ($"temp/AidlTest.{nameof (ListAndMap)}", aidl);
45+
TestAidl (TestName, aidl, runtime);
4046
}
4147

4248
[Test]
43-
public void NamespaceResolution ()
49+
public void NamespaceResolution ([Values] AndroidRuntime runtime)
4450
{
51+
if (IgnoreUnsupportedConfiguration (runtime, release: true)) {
52+
return;
53+
}
54+
4555
string aidl = @"
4656
import android.os;
4757
import android.view;
@@ -50,12 +60,16 @@ public void NamespaceResolution ()
5060
interface Test {
5161
}
5262
";
53-
TestAidl ("temp/AidlTest.NamespaceResolution", aidl);
63+
TestAidl (TestName, aidl, runtime);
5464
}
5565

5666
[Test]
57-
public void PrimitiveTypes ()
67+
public void PrimitiveTypes ([Values] AndroidRuntime runtime)
5868
{
69+
if (IgnoreUnsupportedConfiguration (runtime, release: true)) {
70+
return;
71+
}
72+
5973
string aidl = @"
6074
package com.xamarin.test;
6175
interface Test {
@@ -71,18 +85,18 @@ interface Test {
7185
double test8 (inout double [] args);
7286
String test9 (inout String [] args);
7387
// thought that it's missing 'short' ? It's not supported - http://stackoverflow.com/questions/6742167/android-aidl-support-short-type
74-
88+
7589
void test10 (in byte [] args);
7690
void test11 (out byte [] args);
7791
void test12 (inout byte [] args);
78-
92+
7993
int [] test20 ();
8094
boolean [] test21 ();
8195
byte [] test22 ();
8296
String [] test23 ();
8397
}
8498
";
85-
TestAidl ("temp/AidlTest.PrimitiveTypes", aidl);
99+
TestAidl (TestName, aidl, runtime);
86100
}
87101
}
88102
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ public class AndroidDependenciesTests : BaseTest
1919
{
2020
[Test]
2121
[NonParallelizable] // Do not run environment modifying tests in parallel.
22-
public void InstallAndroidDependenciesTest ([Values ("GoogleV2", "Xamarin")] string manifestType)
22+
public void InstallAndroidDependenciesTest ([Values ("GoogleV2", "Xamarin")] string manifestType, [Values] AndroidRuntime runtime)
2323
{
24+
bool isRelease = runtime == AndroidRuntime.NativeAOT;
25+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
26+
return;
27+
}
28+
2429
// Set to true when we are marking a new Android API level as stable, but it has not
2530
// been added to the Xamarin manifest yet.
2631
var xamarin_manifest_needs_updating = false;
@@ -39,7 +44,10 @@ public void InstallAndroidDependenciesTest ([Values ("GoogleV2", "Xamarin")] str
3944
Directory.CreateDirectory (path);
4045
}
4146

42-
var proj = new XamarinAndroidApplicationProject ();
47+
var proj = new XamarinAndroidApplicationProject {
48+
IsRelease = isRelease,
49+
};
50+
proj.SetRuntime (runtime);
4351
var buildArgs = new List<string> {
4452
"AcceptAndroidSDKLicenses=true",
4553
$"AndroidManifestType={manifestType}",
@@ -117,14 +125,52 @@ static string GetCurrentPlatformToolsVersion ()
117125
return $"{revision.Element ("major")?.Value}.{revision.Element ("minor")?.Value}.{revision.Element ("micro")?.Value}";
118126
}
119127

128+
static IEnumerable<object[]> Get_GetDependencyNdkRequiredConditionsData ()
129+
{
130+
var ret = new List<object[]> ();
131+
132+
foreach (AndroidRuntime runtime in Enum.GetValues (typeof (AndroidRuntime))) {
133+
AddTestData ("AotAssemblies", false, runtime);
134+
AddTestData ("AndroidEnableProfiledAot", false, runtime);
135+
AddTestData ("EnableLLVM", true, runtime);
136+
}
137+
138+
return ret;
139+
140+
void AddTestData (string property, bool ndkRequired, AndroidRuntime runtime)
141+
{
142+
ret.Add (new object[] {
143+
property,
144+
ndkRequired,
145+
runtime,
146+
});
147+
}
148+
}
149+
120150
[Test]
121-
[TestCase ("AotAssemblies", false)]
122-
[TestCase ("AndroidEnableProfiledAot", false)]
123-
[TestCase ("EnableLLVM", true)]
124-
public void GetDependencyNdkRequiredConditions (string property, bool ndkRequired)
151+
[TestCaseSource (nameof (Get_GetDependencyNdkRequiredConditionsData))]
152+
public void GetDependencyNdkRequiredConditions (string property, bool ndkRequired, AndroidRuntime runtime)
125153
{
126-
var proj = new XamarinAndroidApplicationProject ();
127-
proj.AotAssemblies = true;
154+
bool isRelease = runtime == AndroidRuntime.NativeAOT;
155+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
156+
return;
157+
}
158+
159+
// CoreCLR doesn't support AOT so it doesn't ever need the NDK and it doesn't support profiled AOT
160+
if (runtime == AndroidRuntime.CoreCLR && (ndkRequired || property == "AndroidEnableProfiledAot")) {
161+
Assert.Ignore ("CoreCLR doesn't support AOT, it doesn't ever require the NDK");
162+
}
163+
164+
// NativeAOT doesn't support profiled AOT
165+
if (runtime == AndroidRuntime.NativeAOT && property == "AndroidEnableProfiledAot") {
166+
Assert.Ignore ("NativeAOT doesn't support profiled AOT");
167+
}
168+
169+
var proj = new XamarinAndroidApplicationProject {
170+
IsRelease = isRelease,
171+
};
172+
proj.SetRuntime (runtime);
173+
proj.AotAssemblies = runtime == AndroidRuntime.MonoVM;
128174
proj.SetProperty (property, "true");
129175
using (var builder = CreateApkBuilder ()) {
130176
builder.Verbosity = LoggerVerbosity.Detailed;
@@ -143,18 +189,24 @@ public void GetDependencyNdkRequiredConditions (string property, bool ndkRequire
143189
}
144190

145191
[Test]
146-
public void GetDependencyWhenBuildToolsAreMissingTest ()
192+
public void GetDependencyWhenBuildToolsAreMissingTest ([Values] AndroidRuntime runtime)
147193
{
194+
const bool isRelease = true;
195+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
196+
return;
197+
}
198+
148199
var apis = new ApiInfo [] {
149200
};
150201
var path = Path.Combine ("temp", TestName);
151202
var androidSdkPath = CreateFauxAndroidSdkDirectory (Path.Combine (path, "android-sdk"),
152203
null, apis);
153204
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
154205
var proj = new XamarinAndroidApplicationProject () {
155-
IsRelease = true,
206+
IsRelease = isRelease,
156207
TargetSdkVersion = "26",
157208
};
209+
proj.SetRuntime (runtime);
158210
var parameters = new string [] {
159211
$"TargetFrameworkRootPath={referencesPath}",
160212
$"AndroidSdkDirectory={androidSdkPath}",
@@ -177,8 +229,13 @@ public void GetDependencyWhenBuildToolsAreMissingTest ()
177229
}
178230

179231
[Test]
180-
public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool createSdkDirectory, [Values (true, false)] bool installJavaDeps)
232+
public void GetDependencyWhenSDKIsMissingTest ([Values] bool createSdkDirectory, [Values] bool installJavaDeps, [Values] AndroidRuntime runtime)
181233
{
234+
const bool isRelease = true;
235+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
236+
return;
237+
}
238+
182239
var apis = new ApiInfo [] {
183240
};
184241
var path = Path.Combine ("temp", TestName);
@@ -189,7 +246,7 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat
189246
Directory.Delete (androidSdkPath, recursive: true);
190247
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
191248
var proj = new XamarinAndroidApplicationProject () {
192-
IsRelease = true,
249+
IsRelease = isRelease,
193250
TargetSdkVersion = "26",
194251
};
195252
var requestedJdkVersion = "17.0.8.1";

0 commit comments

Comments
 (0)