Skip to content

Commit 210a82a

Browse files
authored
Build tests as self contained apps for mobile targets (#36262)
This uses the SDK to publish tests as self contained apps before building the app bundle using the built runtime pack. I moved the `RunTests.sh` output path to `BundleDir` as whenever we start sending to helix, there is no need to .zip up the whole `OutDir` as we can just send the bundle + `RunTests.sh` script.
1 parent 5f2398b commit 210a82a

File tree

5 files changed

+125
-121
lines changed

5 files changed

+125
-121
lines changed

eng/testing/AndroidRunnerTemplate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ EXECUTION_DIR=$(dirname $0)
44
TEST_NAME=$1
55
TARGET_ARCH=$2
66

7-
APK=$EXECUTION_DIR/Bundle/bin/$TEST_NAME.apk
7+
APK=$EXECUTION_DIR/bin/$TEST_NAME.apk
88

99
# it doesn't support parallel execution yet, so, here is a hand-made semaphore:
1010
LOCKDIR=/tmp/androidtests.lock
@@ -20,4 +20,4 @@ done
2020

2121
dotnet xharness android test -i="net.dot.MonoRunner" \
2222
--package-name="net.dot.$TEST_NAME" \
23-
--app=$APK -o=$EXECUTION_DIR/Bundle/TestResults -v
23+
--app=$APK -o=$EXECUTION_DIR/TestResults -v

eng/testing/AppleRunnerTemplate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fi
2525

2626
# "Release" in SCHEME_SDK is what xcode produces (see "bool Optimized" property in AppleAppBuilderTask)
2727

28-
APP_BUNDLE=$EXECUTION_DIR/Bundle/$TEST_NAME/$SCHEME_SDK/$TEST_NAME.app
28+
APP_BUNDLE=$EXECUTION_DIR/$TEST_NAME/$SCHEME_SDK/$TEST_NAME.app
2929

3030
# it doesn't support parallel execution yet, so, here is a hand-made semaphore:
3131
LOCKDIR=/tmp/runonsim.lock
@@ -39,7 +39,7 @@ while true; do
3939
fi
4040
done
4141

42-
XHARNESS_OUT="$EXECUTION_DIR/Bundle/xharness-output"
42+
XHARNESS_OUT="$EXECUTION_DIR/xharness-output"
4343

4444
dotnet xharness ios test --app="$APP_BUNDLE" \
4545
--targets=$TARGET \

eng/testing/tests.mobile.targets

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<Project>
2+
<PropertyGroup>
3+
<!-- OutDir is not set early enough to set this property in .props file. -->
4+
<BundleDir>$([MSBuild]::NormalizeDirectory('$(OutDir)', 'AppBundle'))</BundleDir>
5+
<RunScriptOutputPath>$([MSBuild]::NormalizePath('$(BundleDir)', '$(RunScriptOutputName)'))</RunScriptOutputPath>
6+
</PropertyGroup>
7+
8+
<!-- Generate a self-contained app bundle for Android with tests. -->
9+
<UsingTask TaskName="AndroidAppBuilderTask"
10+
AssemblyFile="$(AndroidAppBuilderDir)AndroidAppBuilder.dll" />
11+
<Target Condition="'$(TargetOS)' == 'Android'" Name="BundleTestAndroidApp">
12+
<PropertyGroup>
13+
<AndroidAbi Condition="'$(TargetArchitecture)'=='arm64'">arm64-v8a</AndroidAbi>
14+
<AndroidAbi Condition="'$(TargetArchitecture)'=='arm'">armeabi</AndroidAbi>
15+
<AndroidAbi Condition="'$(TargetArchitecture)'=='x64'">x86_64</AndroidAbi>
16+
<AndroidAbi Condition="'$(AndroidAbi)'==''">$(TargetArchitecture)</AndroidAbi>
17+
</PropertyGroup>
18+
<ItemGroup>
19+
<AndroidTestRunnerBinaries Include="$(AndroidTestRunnerDir)*.*" />
20+
</ItemGroup>
21+
22+
<Error Condition="'@(AndroidTestRunnerBinaries)' == ''" Text="Could not find AndroidTestRunner in $(AndroidTestRunnerDir)" />
23+
<Error Condition="!Exists('$(RuntimePackRidDir)')" Text="RuntimePackRidDir=$(RuntimePackRidDir) doesn't exist" />
24+
25+
<RemoveDir Directories="$(BundleDir)" />
26+
<Copy SourceFiles="@(AndroidTestRunnerBinaries)" DestinationFolder="$(OutDir)%(RecursiveDir)" SkipUnchangedFiles="true"/>
27+
28+
<!-- TEMP: consume OpenSSL binaries from external sources via env. variables -->
29+
<Copy Condition="'$(AndroidOpenSslCryptoLib)' != ''"
30+
SourceFiles="$(AndroidOpenSslCryptoLib)"
31+
DestinationFolder="$(OutDir)" SkipUnchangedFiles="true"/>
32+
<Copy Condition="'$(AndroidOpenSslLib)' != ''"
33+
SourceFiles="$(AndroidOpenSslLib)"
34+
DestinationFolder="$(OutDir)" SkipUnchangedFiles="true"/>
35+
36+
<WriteLinesToFile File="$(OutDir)xunit-excludes.txt" Lines="$(_withoutCategories.Replace(';', '%0dcategory='))" />
37+
38+
<AndroidAppBuilderTask
39+
Abi="$(AndroidAbi)"
40+
ProjectName="$(AssemblyName)"
41+
MonoRuntimeHeaders="$(RuntimePackNativeDir)\include\mono-2.0"
42+
MainLibraryFileName="AndroidTestRunner.dll"
43+
OutputDir="$(BundleDir)"
44+
SourceDir="$(OutDir)">
45+
<Output TaskParameter="ApkPackageId" PropertyName="ApkPackageId" />
46+
<Output TaskParameter="ApkBundlePath" PropertyName="ApkBundlePath" />
47+
</AndroidAppBuilderTask>
48+
<Message Importance="High" Text="PackageId: $(ApkPackageId)"/>
49+
<Message Importance="High" Text="Instrumentation: net.dot.MonoRunner"/>
50+
<Message Importance="High" Text="Apk: $(ApkBundlePath)"/>
51+
</Target>
52+
53+
<!-- Generate a self-contained app bundle for iOS with tests. -->
54+
<UsingTask TaskName="AppleAppBuilderTask"
55+
AssemblyFile="$(AppleAppBuilderDir)AppleAppBuilder.dll" />
56+
<Target Condition="'$(TargetOS)' == 'iOS'" Name="BundleTestAppleApp">
57+
<ItemGroup>
58+
<AppleTestRunnerBinaries Include="$(AppleTestRunnerDir)*.*" />
59+
</ItemGroup>
60+
61+
<Error Condition="'@(AppleTestRunnerBinaries)' == ''" Text="Could not find AppleTestRunner in $(AppleTestRunnerDir) doesn't exist" />
62+
<Error Condition="!Exists('$(RuntimePackRidDir)')" Text="RuntimePackRidDir=$(RuntimePackRidDir) doesn't exist" />
63+
64+
<RemoveDir Directories="$(BundleDir)" />
65+
<Copy SourceFiles="@(AppleTestRunnerBinaries)" DestinationFolder="$(OutDir)%(RecursiveDir)" SkipUnchangedFiles="true"/>
66+
67+
<WriteLinesToFile File="$(OutDir)xunit-excludes.txt" Lines="$(_withoutCategories.Replace(';', '%0dcategory='))" />
68+
<!-- Run App bundler, it should AOT libs (if needed), link all native bits, compile simple UI (written in ObjC)
69+
and produce an app bundle (with xcode project) -->
70+
<AppleAppBuilderTask
71+
Arch="$(TargetArchitecture)"
72+
ProjectName="$(AssemblyName)"
73+
MonoRuntimeHeaders="$(RuntimePackNativeDir)\include\mono-2.0"
74+
CrossCompiler="$(RuntimePackNativeDir)\cross\mono-aot-cross"
75+
MainLibraryFileName="AppleTestRunner.dll"
76+
UseConsoleUITemplate="True"
77+
GenerateXcodeProject="True"
78+
BuildAppBundle="True"
79+
Optimized="True"
80+
UseLlvm="$(MonoEnableLLVM)"
81+
LlvmPath="$(RuntimePackNativeDir)\cross"
82+
DevTeamProvisioning="$(DevTeamProvisioning)"
83+
OutputDirectory="$(BundleDir)"
84+
AppDir="$(OutDir)">
85+
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
86+
<Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
87+
</AppleAppBuilderTask>
88+
<Message Importance="High" Text="Xcode: $(XcodeProjectPath)"/>
89+
<Message Importance="High" Text="App: $(AppBundlePath)"/>
90+
<Error Condition="$(TargetArchitecture.StartsWith('arm')) and '$(DevTeamProvisioning)' == ''"
91+
Text="'DevTeamProvisioning' shouldn't be empty for arm64" />
92+
<!-- This app is now can be consumed by xharness CLI to deploy on a device or simulator -->
93+
</Target>
94+
95+
<Target Name="AddFrameworkReference">
96+
<ItemGroup>
97+
<FrameworkReference Include="$(SharedFrameworkName)" />
98+
</ItemGroup>
99+
</Target>
100+
101+
<Target Name="UpdateRuntimePack"
102+
Condition="'$(IsCrossTargetingBuild)' != 'true'"
103+
AfterTargets="BeforeBuild"
104+
DependsOnTargets="AddFrameworkReference;ResolveFrameworkReferences">
105+
<ItemGroup>
106+
<ResolvedRuntimePack Update="@(ResolvedRuntimePack)" PackageDirectory="$(RuntimePackDir)" />
107+
</ItemGroup>
108+
</Target>
109+
110+
<Target Name="PublishTestAsSelfContained"
111+
Condition="'$(IsCrossTargetingBuild)' != 'true'"
112+
AfterTargets="PrepareForRun"
113+
DependsOnTargets="BundleTestAppleApp;BundleTestAndroidApp" />
114+
</Project>

eng/testing/tests.props

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020
<_withoutCategories Condition="!$(_withCategories.Contains('failing'))">$(_withoutCategories);failing</_withoutCategories>
2121
</PropertyGroup>
2222

23-
<PropertyGroup>
23+
<PropertyGroup Condition="'$(TargetsMobile)' == 'true'">
2424
<MobileHelpersDirSuffix>$(NetCoreAppCurrent)-$(MonoConfiguration)</MobileHelpersDirSuffix>
2525
<AppleAppBuilderDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'AppleAppBuilder', '$(MobileHelpersDirSuffix)'))</AppleAppBuilderDir>
2626
<AppleTestRunnerDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'AppleTestRunner', '$(MobileHelpersDirSuffix)'))</AppleTestRunnerDir>
2727
<AndroidAppBuilderDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'AndroidAppBuilder', '$(MobileHelpersDirSuffix)'))</AndroidAppBuilderDir>
2828
<AndroidTestRunnerDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'AndroidTestRunner', '$(MobileHelpersDirSuffix)'))</AndroidTestRunnerDir>
29+
30+
<RuntimeIdentifier>$(PackageRID)</RuntimeIdentifier>
31+
<SelfContained>true</SelfContained>
32+
<EnableTargetingPackDownload>false</EnableTargetingPackDownload>
33+
<PlatformManifestFile />
2934
</PropertyGroup>
3035

3136
<!--

eng/testing/tests.targets

Lines changed: 1 addition & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -101,122 +101,7 @@
101101
<Error Condition="'$(TestRunExitCode)' != '0'" Text="$(TestRunErrorMessage)" />
102102
</Target>
103103

104-
<!-- Generate a self-contained app bundle for Android with tests.
105-
This target is executed once build is done for a test lib (after CopyFilesToOutputDirectory target) -->
106-
<UsingTask TaskName="AndroidAppBuilderTask"
107-
AssemblyFile="$(AndroidAppBuilderDir)AndroidAppBuilder.dll" />
108-
<Target Condition="'$(TargetOS)' == 'Android'" Name="BundleTestAndroidApp" AfterTargets="CopyFilesToOutputDirectory">
109-
<PropertyGroup>
110-
<BundleDir>$(OutDir)\Bundle</BundleDir>
111-
<AndroidAbi Condition="'$(TargetArchitecture)'=='arm64'">arm64-v8a</AndroidAbi>
112-
<AndroidAbi Condition="'$(TargetArchitecture)'=='arm'">armeabi</AndroidAbi>
113-
<AndroidAbi Condition="'$(TargetArchitecture)'=='x64'">x86_64</AndroidAbi>
114-
<AndroidAbi Condition="'$(AndroidAbi)'==''">$(TargetArchitecture)</AndroidAbi>
115-
</PropertyGroup>
116-
<!-- TEMP: We need to copy additional stuff into $(OutDir)\Bundle
117-
1) The whole BCL
118-
2) Test Runner (with xharness client-side lib)
119-
-->
120-
<ItemGroup>
121-
<TestBinaries Include="$(OutDir)\*.*"/>
122-
<AndroidTestRunnerBinaries Include="$(AndroidTestRunnerDir)*.*" />
123-
<BclBinaries Include="$(RuntimePackLibDir)\*.*"
124-
Exclude="$(RuntimePackLibDir)\System.Runtime.WindowsRuntime.dll" />
125-
<BclBinaries Include="$(RuntimePackNativeDir)\*.*" Exclude="$(RuntimePackNativeDir)\libmono.dylib" />
126-
127-
<!-- remove PDBs and DBGs to save some space until we integrate ILLink -->
128-
<BclBinaries Remove="$(RuntimePackLibDir)\*.pdb" />
129-
<BclBinaries Remove="$(RuntimePackLibDir)\*.dbg" />
130-
</ItemGroup>
131-
132-
<Error Condition="'@(AndroidTestRunnerBinaries)' == ''" Text="Could not find AndroidTestRunner in $(AndroidTestRunnerDir)" />
133-
<Error Condition="!Exists('$(RuntimePackRidDir)')" Text="RuntimePackRidDir=$(RuntimePackRidDir) doesn't exist" />
134-
<RemoveDir Directories="$(BundleDir)" />
135-
<Copy SourceFiles="@(TestBinaries)" DestinationFolder="$(BundleDir)" SkipUnchangedFiles="true"/>
136-
<Copy SourceFiles="@(AndroidTestRunnerBinaries)" DestinationFolder="$(BundleDir)\%(RecursiveDir)" SkipUnchangedFiles="true"/>
137-
<Copy SourceFiles="@(BclBinaries)" DestinationFolder="$(BundleDir)\%(RecursiveDir)" SkipUnchangedFiles="true"/>
138-
139-
<!-- TEMP: consume OpenSSL binaries from external sources via env. variables -->
140-
<Copy Condition="'$(AndroidOpenSslCryptoLib)' != ''"
141-
SourceFiles="$(AndroidOpenSslCryptoLib)"
142-
DestinationFolder="$(BundleDir)" SkipUnchangedFiles="true"/>
143-
<Copy Condition="'$(AndroidOpenSslLib)' != ''"
144-
SourceFiles="$(AndroidOpenSslLib)"
145-
DestinationFolder="$(BundleDir)" SkipUnchangedFiles="true"/>
146-
147-
<WriteLinesToFile File="$(BundleDir)\xunit-excludes.txt" Lines="$(_withoutCategories.Replace(';', '%0dcategory='))" />
148-
149-
<AndroidAppBuilderTask
150-
Abi="$(AndroidAbi)"
151-
ProjectName="$(AssemblyName)"
152-
MonoRuntimeHeaders="$(RuntimePackNativeDir)\include\mono-2.0"
153-
MainLibraryFileName="AndroidTestRunner.dll"
154-
OutputDir="$(BundleDir)"
155-
SourceDir="$(BundleDir)">
156-
<Output TaskParameter="ApkPackageId" PropertyName="ApkPackageId" />
157-
<Output TaskParameter="ApkBundlePath" PropertyName="ApkBundlePath" />
158-
</AndroidAppBuilderTask>
159-
<Message Importance="High" Text="PackageId: $(ApkPackageId)"/>
160-
<Message Importance="High" Text="Instrumentation: net.dot.MonoRunner"/>
161-
<Message Importance="High" Text="Apk: $(ApkBundlePath)"/>
162-
</Target>
163-
164-
<!-- Generate a self-contained app bundle for iOS with tests.
165-
This target is executed once build is done for a test lib (after CopyFilesToOutputDirectory target) -->
166-
<UsingTask TaskName="AppleAppBuilderTask"
167-
AssemblyFile="$(AppleAppBuilderDir)AppleAppBuilder.dll" />
168-
<Target Condition="'$(TargetOS)' == 'iOS'" Name="BundleTestAppleApp" AfterTargets="CopyFilesToOutputDirectory">
169-
<PropertyGroup>
170-
<BundleDir>$(OutDir)\Bundle</BundleDir>
171-
</PropertyGroup>
172-
<!-- We need to copy additional stuff into $(OutDir)\Bundle
173-
1) The whole BCL
174-
2) Test Runner (with xharness client-side lib)
175-
-->
176-
<ItemGroup>
177-
<TestBinaries Include="$(OutDir)*.*"/>
178-
<AppleTestRunnerBinaries Include="$(AppleTestRunnerDir)*.*" />
179-
<BclBinaries Include="$(RuntimePackLibDir)*.*" Exclude="$(RuntimePackLibDir)\System.Runtime.WindowsRuntime.dll" />
180-
<BclBinaries Include="$(RuntimePackNativeDir)*.*" Exclude="$(RuntimePackNativeDir)\libmono.dylib" /> <!-- we use static libmono.a -->
181-
182-
<!-- remove PDBs to save some space until we integrate ILLink -->
183-
<BclBinaries Remove="$(RuntimePackLibDir)\*.pdb" />
184-
</ItemGroup>
185-
<Error Condition="'@(AppleTestRunnerBinaries)' == ''" Text="Could not find AppleTestRunner in $(AppleTestRunnerDir) doesn't exist" />
186-
<Error Condition="!Exists('$(RuntimePackRidDir)')" Text="RuntimePackRidDir=$(RuntimePackRidDir) doesn't exist" />
187-
<RemoveDir Directories="$(BundleDir)" />
188-
<Copy SourceFiles="@(TestBinaries)" DestinationFolder="$(BundleDir)" SkipUnchangedFiles="true"/>
189-
<Copy SourceFiles="@(AppleTestRunnerBinaries)" DestinationFolder="$(BundleDir)\%(RecursiveDir)" SkipUnchangedFiles="true"/>
190-
<Copy SourceFiles="@(BclBinaries)" DestinationFolder="$(BundleDir)\%(RecursiveDir)" SkipUnchangedFiles="true"/>
191-
192-
<WriteLinesToFile File="$(BundleDir)\xunit-excludes.txt" Lines="$(_withoutCategories.Replace(';', '%0dcategory='))" />
193-
<!-- Run App bundler, it should AOT libs (if needed), link all native bits, compile simple UI (written in ObjC)
194-
and produce an app bundle (with xcode project) -->
195-
<AppleAppBuilderTask
196-
Arch="$(TargetArchitecture)"
197-
ProjectName="$(AssemblyName)"
198-
MonoRuntimeHeaders="$(RuntimePackNativeDir)\include\mono-2.0"
199-
CrossCompiler="$(RuntimePackNativeDir)\cross\mono-aot-cross"
200-
MainLibraryFileName="AppleTestRunner.dll"
201-
UseConsoleUITemplate="True"
202-
GenerateXcodeProject="True"
203-
BuildAppBundle="True"
204-
Optimized="True"
205-
UseLlvm="$(MonoEnableLLVM)"
206-
LlvmPath="$(RuntimePackNativeDir)\cross"
207-
DevTeamProvisioning="$(DevTeamProvisioning)"
208-
OutputDirectory="$(BundleDir)"
209-
AppDir="$(BundleDir)">
210-
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
211-
<Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
212-
</AppleAppBuilderTask>
213-
<Message Importance="High" Text="Xcode: $(XcodeProjectPath)"/>
214-
<Message Importance="High" Text="App: $(AppBundlePath)"/>
215-
<Error Condition="$(TargetArchitecture.StartsWith('arm')) and '$(DevTeamProvisioning)' == ''"
216-
Text="'DevTeamProvisioning' shouldn't be empty for arm64" />
217-
<!-- This app is now can be consumed by xharness CLI to deploy on a device or simulator -->
218-
</Target>
219-
104+
<Import Project="$(MSBuildThisFileDirectory)tests.mobile.targets" Condition="'$(TargetsMobile)' == 'true'" />
220105
<Import Project="$(MSBuildThisFileDirectory)xunit\xunit.targets" Condition="'$(TestFramework)' == 'xunit'" />
221106

222107
<!-- Main test targets -->

0 commit comments

Comments
 (0)