Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ include tests/api-compatibility/api-compatibility.mk

run-all-tests: run-nunit-tests run-ji-tests run-apk-tests run-api-compatibility-tests

rename-test-cases:
$(MSBUILD) $(MSBUILD_FLAGS) build-tools/scripts/TestApks.targets \
/t:RenameTestCases /p:RenameTestCasesGlob="$(if $(RENAME_GLOB),$(RENAME_GLOB),`pwd`/TestResult-\*.xml)" \
$(if $(KEEP_TEST_SOURCES),/p:DeleteTestCaseSourceFiles=False)

clean:
$(MSBUILD) $(MSBUILD_FLAGS) /t:Clean Xamarin.Android.sln
tools/scripts/xabuild $(MSBUILD_FLAGS) /t:Clean Xamarin.Android-Tests.sln
Expand All @@ -140,14 +145,18 @@ define RUN_NUNIT_TEST
if [ -f "bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt" ] ; then \
cat bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt ; \
fi
$(MAKE) rename-test-cases RENAME_GLOB="`pwd`/TestResult-$(basename $(notdir $(1))).xml"
endef

run-nunit-tests: $(NUNIT_TESTS)
ifneq ($(SKIP_NUNIT_TESTS),)
$(foreach t,$(NUNIT_TESTS), $(call RUN_NUNIT_TEST,$(t),1))
endif # $(SKIP_NUNIT_TESTS) == ''

run-ji-tests:
$(MAKE) -C "$(call GetPath,JavaInterop)" CONFIGURATION=$(CONFIGURATION) all
ANDROID_SDK_PATH="$(call GetPath,AndroidSdk)" $(MAKE) -C "$(call GetPath,JavaInterop)" CONFIGURATION=$(CONFIGURATION) run-all-tests || true
$(MAKE) rename-test-cases RENAME_GLOB='"$(call GetPath,JavaInterop)"/TestResult-*Tests.xml'
cp "$(call GetPath,JavaInterop)"/TestResult-*.xml .

# .apk files to test on-device need to:
Expand All @@ -157,11 +166,11 @@ TEST_APK_PROJECTS = \
src/Mono.Android/Test/Mono.Android-Tests.csproj \
tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj \
tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj \
tests/Xamarin.Android.Bcl-Tests/Xamarin.Android.Bcl-Tests.csproj
tests/Xamarin.Android.Bcl-Tests/Xamarin.Android.Bcl-Tests.csproj \
tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj

TEST_APK_PROJECTS_RELEASE = \
TEST_APK_PROJECTS_AOT = \
src/Mono.Android/Test/Mono.Android-Tests.csproj \
tests/Xamarin.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj

# Syntax: $(call BUILD_TEST_APK,path/to/project.csproj,additional_msbuild_flags)
define BUILD_TEST_APK
Expand All @@ -177,7 +186,6 @@ endef

run-apk-tests:
$(call RUN_APK_TESTS, $(TEST_APK_PROJECTS), )
ifneq ($(wildcard bin/Release),)
$(call RUN_APK_TESTS, $(TEST_APK_PROJECTS_RELEASE), /p:Configuration=Release)
$(call RUN_APK_TESTS, $(TEST_APK_PROJECTS_RELEASE), /p:Configuration=Release /p:AotAssemblies=true)
ifeq ($(CONFIGURATION),Release)
$(call RUN_APK_TESTS, $(TEST_APK_PROJECTS_AOT), /p:AotAssemblies=true)
endif
39 changes: 39 additions & 0 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.Adb" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.CheckAdbTarget" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.CreateAndroidEmulator" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.RenameTestCases" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.RunInstrumentationTests" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.RunUITests" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.StartAndroidEmulator" />
Expand Down Expand Up @@ -183,4 +184,42 @@
AddResults="true"
Activity="%(TestApk.Activity)" />
</Target>
<Target Name="RenameTestCases">
<Error
Condition=" '$(RenameTestCasesGlob)' == '' "
Text="Please set `%24(RenameTestCasesGlob)`."
/>
<Error
Condition=" '$(Configuration)' == '' "
Text="Please set `%24(Configuration)`."
/>
<PropertyGroup>
<_DeleteSource Condition=" '$(DeleteTestCaseSourceFiles)' != '' ">$(DeleteTestCaseSourceFiles)</_DeleteSource>
<_DeleteSource Condition=" '$(_DeleteSource)' == '' ">True</_DeleteSource>
</PropertyGroup>
<ItemGroup>
<_RenameSource1 Include="$(RenameTestCasesGlob)" />
</ItemGroup>
<ItemGroup>
<_RenameSource Include="%(_RenameSource1.Identity)">
<DestinationFolder>@(_RenameSource1->'%(RootDir)%(Directory)')</DestinationFolder>
</_RenameSource>
</ItemGroup>
<RenameTestCases
Configuration="$(Configuration)"
DeleteSourceFiles="$(_DeleteSource)"
SourceFile="%(_RenameSource.Identity)"
DestinationFolder="%(_RenameSource.DestinationFolder)"
/>
</Target>
<Target Name="RenameApkTestCases"
Condition=" '@(TestApk)' != '' ">
<RenameTestCases
Condition=" '%(TestApk.ResultsPath)' != '' "
Configuration="$(Configuration)$(_AotName)"
DeleteSourceFiles="True"
DestinationFolder="$(MSBuildThisFileDirectory)..\.."
SourceFile="%(TestApk.ResultsPath)"
/>
</Target>
</Project>
23 changes: 17 additions & 6 deletions src/Mono.Android/Test/Mono.Android-Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.ProcessPlotInput" />
<PropertyGroup>
<_MonoAndroidTestResultsPath>$(MSBuildThisFileDirectory)..\..\..\TestResult-Mono.Android_Tests.xml</_MonoAndroidTestResultsPath>
<_MonoAndroidTestResultsPath>$(OutputPath)TestResult-Mono.Android_Tests.xml</_MonoAndroidTestResultsPath>
<_MonoAndroidTestPackage>Mono.Android_Tests</_MonoAndroidTestPackage>
<_MonoAndroidTestApkFile>$(OutputPath)Mono.Android_Tests-Signed.apk</_MonoAndroidTestApkFile>
<_MonoAndroidTestApkSizesInput>apk-sizes-$(_MonoAndroidTestPackage)-$(Configuration)$(_AotName).txt</_MonoAndroidTestApkSizesInput>
Expand All @@ -16,10 +16,21 @@
</TestApk>
</ItemGroup>
<Target Name="_RecordApkSizes" AfterTargets="DeployTestApks">
<Delete Files="$(MSBuildThisFileDirectory)..\..\..\TestResult-Mono.Android_Tests-values.csv;$(MSBuildThisFileDirectory)..\..\..\TestResult-Mono.Android_Tests-times.csv" Condition=" '$(Configuration)' == 'Debug' " />
<Exec Condition=" '$(HostOS)' == 'Darwin' " Command="stat -f &quot;stat: %z %N&quot; &quot;$(_MonoAndroidTestApkFile)&quot; > $(_MonoAndroidTestApkSizesInput)" />
<Exec Condition=" '$(HostOS)' == 'Linux' " Command="stat -c &quot;stat: %s %N&quot; &quot;$(_MonoAndroidTestApkFile)&quot; > $(_MonoAndroidTestApkSizesInput)" />
<Exec Command="unzip -l &quot;$(_MonoAndroidTestApkFile)&quot; >> $(_MonoAndroidTestApkSizesInput)" />
<ProcessPlotInput InputFilename="$(_MonoAndroidTestApkSizesInput)" ApplicationPackageName="$(_MonoAndroidTestPackage)" ResultsFilename="$(MSBuildThisFileDirectory)..\..\..\TestResult-Mono.Android_Tests.xml" DefinitionsFilename="$(MSBuildThisFileDirectory)apk-sizes-definitions-$(Configuration)$(_AotName).txt" AddResults="true" />
<Exec
Condition=" '$(HostOS)' == 'Darwin' "
Command="stat -f &quot;stat: %z %N&quot; &quot;$(_MonoAndroidTestApkFile)&quot; > &quot;$(OutputPath)$(_MonoAndroidTestApkSizesInput)&quot;"
/>
<Exec
Condition=" '$(HostOS)' == 'Linux' "
Command="stat -c &quot;stat: %s %N&quot; &quot;$(_MonoAndroidTestApkFile)&quot; > &quot;$(OutputPath)$(_MonoAndroidTestApkSizesInput)&quot;"
/>
<Exec Command="unzip -l &quot;$(_MonoAndroidTestApkFile)&quot; >> &quot;$(OutputPath)$(_MonoAndroidTestApkSizesInput)&quot;" />
<ProcessPlotInput
InputFilename="$(OutputPath)$(_MonoAndroidTestApkSizesInput)"
ApplicationPackageName="$(_MonoAndroidTestPackage)"
ResultsFilename="$(_MonoAndroidTestResultsPath)"
DefinitionsFilename="$(MSBuildThisFileDirectory)apk-sizes-definitions-$(Configuration)$(_AotName).txt"
AddResults="True"
/>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -47,6 +48,7 @@
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\GenerateMonoDroidIncludes.cs" />
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\GenerateProfile.cs" />
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\GetNugetPackageBasePath.cs" />
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\RenameTestCases.cs" />
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\StartAndroidEmulator.cs" />
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\UnzipDirectoryChildren.cs" />
<Compile Include="Xamarin.Android.Tools.BootstrapTasks\Zip.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Xamarin.Android.Tools.BootstrapTasks
{
public class RenameTestCases : Task
{
public bool DeleteSourceFiles { get; set; }
public string Configuration { get; set; }
[Required]
public string SourceFile { get; set; }
[Required]
public string DestinationFolder { get; set; }

[Output]
public ITaskItem[] CreatedFiles { get; set; }

public override bool Execute ()
{
Log.LogMessage (MessageImportance.Low, $"Task {nameof (RenameTestCases)}");
Log.LogMessage (MessageImportance.Low, $" {nameof (Configuration)}: {Configuration}");
Log.LogMessage (MessageImportance.Low, $" {nameof (DeleteSourceFiles)}: {DeleteSourceFiles}");
Log.LogMessage (MessageImportance.Low, $" {nameof (DestinationFolder)}: {DestinationFolder}");
Log.LogMessage (MessageImportance.Low, $" {nameof (SourceFile)}: {SourceFile}");

var createdFiles = new List<ITaskItem> ();
var testNameSuffix = string.IsNullOrWhiteSpace (Configuration)
? ""
: $" / {Configuration}";
try {
var dest = FixupTestResultFile (SourceFile, testNameSuffix);
var item = new TaskItem (dest);
item.SetMetadata ("SourceFile", SourceFile);
createdFiles.Add (item);
}
catch (Exception e) {
Log.LogErrorFromException (e);
}

CreatedFiles = createdFiles.ToArray ();

Log.LogMessage (MessageImportance.Low, $" [Output] {nameof (CreatedFiles)}:");
foreach (var f in CreatedFiles) {
Log.LogMessage (MessageImportance.Low, $" [Output] {f}:");
}

return !Log.HasLoggedErrors;
}

string FixupTestResultFile (string source, string testNameSuffix)
{
var doc = XDocument.Load (source);
switch (doc.Root.Name.LocalName) {
case "test-results":
FixupNUnit2Results (doc, testNameSuffix);
break;
}
var destFilename = Path.GetFileNameWithoutExtension (source) +
(string.IsNullOrWhiteSpace (Configuration) ? "" : "-" + Configuration) +
Path.GetExtension (source);
var dest = Path.Combine (DestinationFolder, destFilename);

doc.Save (dest);
if (DeleteSourceFiles && Path.GetFullPath (source) != Path.GetFullPath (dest)) {
File.Delete (source);
}
return dest;
}

void FixupNUnit2Results (XDocument doc, string testNameSuffix)
{
foreach (var e in doc.Descendants ("test-case")) {
var name = (string) e.Attribute ("name");
if (name.EndsWith (testNameSuffix, StringComparison.OrdinalIgnoreCase))
continue;
name += testNameSuffix;
e.SetAttributeValue ("name", name);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TestApk Include="$(OutputPath)Xamarin.Android.JcwGen_Tests-Signed.apk">
<Package>Xamarin.Android.JcwGen_Tests</Package>
<InstrumentationType>xamarin.android.jcwgentests.TestInstrumentation</InstrumentationType>
<ResultsPath>$(MSBuildThisFileDirectory)..\..\..\TestResult-Xamarin.Android.JcwGen_Tests.xml</ResultsPath>
<ResultsPath>$(OutputPath)TestResult-Xamarin.Android.JcwGen_Tests.xml</ResultsPath>
<TimingDefinitionsFilename>$(MSBuildThisFileDirectory)..\..\..\build-tools\scripts\TimingDefinitions.txt</TimingDefinitionsFilename>
</TestApk>
</ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions tests/RunApkTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
`$(TEST_APK_PROJECTS_RELEASE)` within the toplevel `Makefile`.
-->
<Import Project="..\src\Mono.Android\Test\Mono.Android-Tests.projitems" />
<Import Project="..\tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.projitems" Condition=" '$(Configuration)' == 'Debug' " />
<Import Project="..\tests\CodeGen-Binding\Xamarin.Android.JcwGen-Tests\Xamarin.Android.JcwGen-Tests.projitems" Condition=" '$(Configuration)' == 'Debug' " />
<Import Project="..\tests\locales\Xamarin.Android.Locale-Tests\Xamarin.Android.Locale-Tests.projitems" Condition=" '$(Configuration)' == 'Debug' " />
<Import Project="..\tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.projitems" Condition=" '$(AotAssemblies)' != 'True' " />
<Import Project="..\tests\CodeGen-Binding\Xamarin.Android.JcwGen-Tests\Xamarin.Android.JcwGen-Tests.projitems" Condition=" '$(AotAssemblies)' != 'True' " />
<Import Project="..\tests\locales\Xamarin.Android.Locale-Tests\Xamarin.Android.Locale-Tests.projitems" Condition=" '$(AotAssemblies)' != 'True' " />
<Import Project="..\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.projitems" Condition=" '$(Configuration)' == 'Release' And '$(AotAssemblies)' != 'true' " />
<Import Project="..\build-tools\scripts\TestApks.targets" />
<PropertyGroup>
Expand All @@ -30,7 +30,8 @@
UndeployTestApks;
DeployTestApks;
RunTestApks;
ReleaseAndroidTarget
ReleaseAndroidTarget;
RenameApkTestCases;
</RunApkTestsDependsOn>
</PropertyGroup>
<Target Name="RunApkTests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<DebugType>Full</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\TestRelease</OutputPath>
<ErrorReport>prompt</ErrorReport>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TestApk Include="$(OutputPath)Xamarin.Android.Bcl_Tests-Signed.apk">
<Package>Xamarin.Android.Bcl_Tests</Package>
<InstrumentationType>xamarin.android.bcltests.TestInstrumentation</InstrumentationType>
<ResultsPath>$(MSBuildThisFileDirectory)..\..\TestResult-Xamarin.Android.Bcl_Tests.xml</ResultsPath>
<ResultsPath>$(OutputPath)TestResult-Xamarin.Android.Bcl_Tests.xml</ResultsPath>
<TimingDefinitionsFilename>$(MSBuildThisFileDirectory)..\..\build-tools\scripts\TimingDefinitions.txt</TimingDefinitionsFilename>
</TestApk>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
HostOS="$(HostOS)"
DestinationFolder="..\..\bin\$(Configuration)\bcl-tests"
/>
<Touch Files="@(_TestResource)" />
</Target>
<Target Name="_GenerateApp_cs"
Inputs="@(MonoTestAssembly->'..\..\bin\$(Configuration)\bcl-tests\%(Identity)')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TestApk Include="$(OutputPath)Xamarin.Forms_Performance_Integration-Signed.apk">
<Package>Xamarin.Forms_Performance_Integration</Package>
<Activity>Xamarin.Forms_Performance_Integration/md52b709e14dec302485bbcaeac0bd817ce.MainActivity</Activity>
<ResultsPath>$(MSBuildThisFileDirectory)..\..\..\TestResult-Xamarin.Forms_Test.xml</ResultsPath>
<ResultsPath></ResultsPath>
<TimingDefinitionsFilename>$(MSBuildThisFileDirectory)timing-definitions.txt</TimingDefinitionsFilename>
</TestApk>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TestApk Include="$(OutputPath)Xamarin.Android.Locale_Tests-Signed.apk">
<Package>Xamarin.Android.Locale_Tests</Package>
<InstrumentationType>xamarin.android.localetests.TestInstrumentation</InstrumentationType>
<ResultsPath>$(MSBuildThisFileDirectory)..\..\..\TestResult-Xamarin.Android.Locale_Tests.xml</ResultsPath>
<ResultsPath>$(OutputPath)TestResult-Xamarin.Android.Locale_Tests.xml</ResultsPath>
<TimingDefinitionsFilename>$(MSBuildThisFileDirectory)..\..\..\build-tools\scripts\TimingDefinitions.txt</TimingDefinitionsFilename>
</TestApk>
</ItemGroup>
Expand Down