Skip to content

Commit 8ae9e9f

Browse files
committed
EnvironmentContentTests.BuildApplicationWithMonoEnvironment updated (broken on NAOT)
1 parent f07c1ea commit 8ae9e9f

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,37 @@ public class EnvironmentContentTests : BaseTest
1616
{
1717
[Test]
1818
[NonParallelizable]
19-
public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode,
20-
[Values (AndroidRuntime.MonoVM, AndroidRuntime.CoreCLR)] AndroidRuntime runtime)
19+
public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode, [Values] AndroidRuntime runtime)
2120
{
21+
const bool isRelease = true;
22+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
23+
return;
24+
}
25+
26+
// TODO: NativeAOT fails all the tests, `MONO_DEBUG` is not found in the environment. Question is - should we fix it for backward compatibility,
27+
// even though NativeAOT won't use it (and CoreCLR passes the tests), or should we just ignore this test for NativeAOT?
28+
if (runtime == AndroidRuntime.NativeAOT) {
29+
Assert.Ignore ("NativeAOT doesn't currently export the MONO_DEBUG environment variable");
30+
}
31+
2232
string supportedAbis = runtime switch {
2333
AndroidRuntime.MonoVM => "armeabi-v7a;x86",
2434
AndroidRuntime.CoreCLR => "arm64-v8a;x86_64",
35+
AndroidRuntime.NativeAOT => "arm64-v8a;x86_64",
2536
_ => throw new NotSupportedException ($"Unsupported runtime '{runtime}'")
2637
};
2738

2839
var lib = new XamarinAndroidLibraryProject {
2940
ProjectName = "Library1",
30-
IsRelease = true,
41+
IsRelease = isRelease,
3142
OtherBuildItems = { new AndroidItem.AndroidEnvironment ("Mono.env") {
3243
TextContent = () => "MONO_DEBUG=soft-breakpoints"
3344
},
3445
},
3546
};
3647
lib.SetRuntime (runtime);
3748
var app = new XamarinFormsAndroidApplicationProject () {
38-
IsRelease = true,
49+
IsRelease = isRelease,
3950
AndroidLinkModeRelease = AndroidLinkMode.Full,
4051
References = {
4152
new BuildItem ("ProjectReference","..\\Library1\\Library1.csproj"),
@@ -53,7 +64,7 @@ public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline
5364
Assert.IsTrue (appb.Build (app), "App should have succeeded.");
5465

5566
string intermediateOutputDir = Path.Combine (Root, appb.ProjectDirectory, app.IntermediateOutputPath);
56-
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true);
67+
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime);
5768
Dictionary<string, string> envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, runtime);
5869
Assert.IsTrue (envvars.Count > 0, $"No environment variables defined");
5970

@@ -99,7 +110,7 @@ public void CheckMonoDebugIsAddedToEnvironment ([Values ("", "Normal", "Offline"
99110
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
100111

101112
string intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
102-
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true);
113+
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, AndroidRuntime.MonoVM);
103114
Dictionary<string, string> envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, AndroidRuntime.MonoVM);
104115
Assert.IsTrue (envvars.Count > 0, $"No environment variables defined");
105116

@@ -117,11 +128,16 @@ public void CheckMonoDebugIsAddedToEnvironment ([Values ("", "Normal", "Offline"
117128
}
118129

119130
[Test]
120-
public void CheckConcurrentGC ()
131+
public void CheckConcurrentGC ([Values] AndroidRuntime runtime)
121132
{
133+
const bool isRelease = true;
134+
if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) {
135+
return;
136+
}
122137
var proj = new XamarinAndroidApplicationProject () {
123-
IsRelease = true,
138+
IsRelease = isRelease,
124139
};
140+
proj.SetRuntime (runtime);
125141
var gcVarName = "MONO_GC_PARAMS";
126142
var expectedDefaultValue = "major=marksweep";
127143
var expectedUpdatedValue = "major=marksweep-conc";
@@ -135,14 +151,14 @@ public void CheckConcurrentGC ()
135151
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
136152
var intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
137153
// AndroidEnableSGenConcurrent=False by default
138-
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true);
154+
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime);
139155
Dictionary<string, string> envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, AndroidRuntime.MonoVM);
140156
Assert.IsTrue (envvars.ContainsKey (gcVarName), $"Environment should contain '{gcVarName}'.");
141157
Assert.AreEqual (expectedDefaultValue, envvars[gcVarName], $"'{gcVarName}' should have been '{expectedDefaultValue}' when concurrent GC is disabled.");
142158

143159
proj.SetProperty ("AndroidEnableSGenConcurrent", "True");
144160
Assert.IsTrue (b.Build (proj), "Second build should have succeeded.");
145-
envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true);
161+
envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime);
146162
envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, AndroidRuntime.MonoVM);
147163
Assert.IsTrue (envvars.ContainsKey (gcVarName), $"Environment should contain '{gcVarName}'.");
148164
Assert.AreEqual (expectedUpdatedValue, envvars[gcVarName], $"'{gcVarName}' should have been '{expectedUpdatedValue}' when concurrent GC is enabled.");
@@ -187,14 +203,14 @@ public void CheckHttpClientHandlerType ([Values (AndroidRuntime.MonoVM, AndroidR
187203
proj.SetProperty ("AndroidHttpClientHandlerType", expectedDefaultValue);
188204
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
189205
var intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
190-
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true);
206+
List<EnvironmentHelper.EnvironmentFile> envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime);
191207
Dictionary<string, string> envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, runtime);
192208
Assert.IsTrue (envvars.ContainsKey (httpClientHandlerVarName), $"Environment should contain '{httpClientHandlerVarName}'.");
193209
Assert.AreEqual (expectedDefaultValue, envvars[httpClientHandlerVarName]);
194210

195211
proj.SetProperty ("AndroidHttpClientHandlerType", expectedUpdatedValue);
196212
Assert.IsTrue (b.Build (proj), "Second build should have succeeded.");
197-
envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true);
213+
envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime);
198214
envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, runtime);
199215
Assert.IsTrue (envvars.ContainsKey (httpClientHandlerVarName), $"Environment should contain '{httpClientHandlerVarName}'.");
200216
Assert.AreEqual (expectedUpdatedValue, envvars[httpClientHandlerVarName]);

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,15 @@ static void AssertApplicationConfigIsIdentical (ApplicationConfig_MonoVM firstAp
765765
Assert.AreEqual (firstAppConfig.android_package_name, secondAppConfig.android_package_name, $"Field 'android_package_name' has different value in environment file '{secondEnvFile}' than in environment file '{firstEnvFile}'");
766766
}
767767

768-
public static List<EnvironmentFile> GatherEnvironmentFiles (string outputDirectoryRoot, string supportedAbis, bool required)
768+
// TODO: remove the default from the `runtime` parameter once all tests are updated
769+
public static List<EnvironmentFile> GatherEnvironmentFiles (string outputDirectoryRoot, string supportedAbis, bool required, AndroidRuntime runtime = AndroidRuntime.CoreCLR)
769770
{
770771
var environmentFiles = new List <EnvironmentFile> ();
772+
bool isNativeAOT = runtime == AndroidRuntime.NativeAOT;
771773

772774
foreach (string abi in supportedAbis.Split (';')) {
773-
string envFilePath = Path.Combine (outputDirectoryRoot, "android", $"environment.{abi}.ll");
775+
string prefixDir = isNativeAOT ? MonoAndroidHelper.AbiToRid (abi) : String.Empty;
776+
string envFilePath = Path.Combine (outputDirectoryRoot, prefixDir, "android", $"environment.{abi}.ll");
774777

775778
Assert.IsTrue (File.Exists (envFilePath), $"Environment file {envFilePath} does not exist");
776779
environmentFiles.Add (new EnvironmentFile (envFilePath, abi));

0 commit comments

Comments
 (0)