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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ TestResult-*.csv
Resource.designer.cs
logcat-*.txt
apk-sizes-*.txt
*.rawproto
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.props
1 change: 1 addition & 0 deletions Before.Xamarin.Android.sln.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\PrepareWindows.targets" Condition=" '$(OS)' == 'Windows_NT' " />
<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\RunTests.targets" />
</Project>
70 changes: 8 additions & 62 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ prefix = /usr/local
CONFIGURATION = Debug
RUNTIME := $(shell if [ -f "`which mono64`" ] ; then echo mono64 ; else echo mono; fi) --debug=casts
SOLUTION = Xamarin.Android.sln

NUNIT_TESTS = \
bin/Test$(CONFIGURATION)/Xamarin.Android.Build.Tests.dll

NUNIT_CONSOLE = packages/NUnit.ConsoleRunner.3.7.0/tools/nunit3-console.exe
TEST_TARGETS = build-tools/scripts/RunTests.targets

ifneq ($(V),0)
MONO_OPTIONS += --debug
Expand Down Expand Up @@ -121,12 +117,9 @@ prepare-image-dependencies:
include build-tools/scripts/BuildEverything.mk
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)
run-all-tests:
$(MSBUILD) $(MSBUILD_FLAGS) $(TEST_TARGETS) /t:RunAllTests
$(MAKE) run-api-compatibility-tests

clean:
$(MSBUILD) $(MSBUILD_FLAGS) /t:Clean Xamarin.Android.sln
Expand All @@ -138,60 +131,13 @@ distclean:
git clean -xdff
git submodule foreach git clean -xdff

# $(call RUN_NUNIT_TEST,filename,log-lref?)
define RUN_NUNIT_TEST
MONO_TRACE_LISTENER=Console.Out \
USE_MSBUILD=$(if $(USE_MSBUILD),$(USE_MSBUILD),0) \
$(RUNTIME) --runtime=v4.0.0 \
$(NUNIT_CONSOLE) $(NUNIT_EXTRA) $(1) \
$(if $(TEST),--test=$(TEST)) \
--result="TestResult-$(basename $(notdir $(1))).xml;format=nunit2" \
-output=bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt \
|| true ; \
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)
run-nunit-tests:
ifeq ($(SKIP_NUNIT_TESTS),)
$(foreach t,$(NUNIT_TESTS), $(call RUN_NUNIT_TEST,$(t),1))
$(MSBUILD) $(MSBUILD_FLAGS) $(TEST_TARGETS) /t:RunNUnitTests
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:
# (1) Have their .csproj files listed here
# (2) Add a `@(UnitTestApk)` entry to `tests/RunApkTests.targets`
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.Forms-Performance-Integration/Droid/Xamarin.Forms.Performance.Integration.Droid.csproj

TEST_APK_PROJECTS_AOT = \
src/Mono.Android/Test/Mono.Android-Tests.csproj \

# Syntax: $(call BUILD_TEST_APK,path/to/project.csproj,additional_msbuild_flags)
define BUILD_TEST_APK
# Must use xabuild to ensure correct assemblies are resolved
MSBUILD="$(MSBUILD)" tools/scripts/xabuild $(MSBUILD_FLAGS) /t:SignAndroidPackage $(2) $(1)
endef # BUILD_TEST_APK

# Syntax: $(call RUN_APK_TESTS,projects,additional_msbuild_flags)
define RUN_APK_TESTS
$(foreach p, $(1), $(call BUILD_TEST_APK, $(p),$(2)))
$(MSBUILD) $(MSBUILD_FLAGS) $(2) tests/RunApkTests.targets
endef
$(MSBUILD) $(MSBUILD_FLAGS) $(TEST_TARGETS) /t:RunJavaInteropTests

run-apk-tests:
$(call RUN_APK_TESTS, $(TEST_APK_PROJECTS), )
ifeq ($(CONFIGURATION),Release)
$(call RUN_APK_TESTS, $(TEST_APK_PROJECTS_AOT), /p:AotAssemblies=true)
endif
$(MSBUILD) $(MSBUILD_FLAGS) $(TEST_TARGETS) /t:RunApkTests
2 changes: 1 addition & 1 deletion build-tools/scripts/PrepareWindows.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
AndroidSdkPath="$(AndroidSdkDirectory)"
AndroidNdkPath="$(AndroidNdkDirectory)"
JavaSdkPath="$(JavaSdkDirectory)"
Output="$(_TopDir)\external\Java.Interop\bin\BuildDebug\JdkInfo.props">
Output="$(_TopDir)\external\Java.Interop\bin\Build$(Configuration)\JdkInfo.props">
<Output TaskParameter="JavaSdkDirectory" PropertyName="_JavaSdkDirectory" />
</JdkInfo>
<Copy
Expand Down
80 changes: 80 additions & 0 deletions build-tools/scripts/RunTests.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="RunAllTests" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<_TopDir>$(MSBuildThisFileDirectory)..\..</_TopDir>
</PropertyGroup>
<Import Project="$(_TopDir)\Configuration.props" />
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable" />
<PropertyGroup>
<XAIntegratedTests Condition=" '$(HostOS)' == 'Windows' ">False</XAIntegratedTests>
<_Runtime Condition=" '$(HostOS)' != 'Windows' ">$(ManagedRuntime)</_Runtime>
<_NUnit>$(_Runtime) packages\NUnit.ConsoleRunner.3.7.0\tools\nunit3-console.exe</_NUnit>
<_Test Condition=" '$(TEST)' != '' ">--test=&quot;$(TEST)&quot;</_Test>
<_XABuild>$(_TopDir)\bin\$(Configuration)\bin\xabuild</_XABuild>
<_XABuildProperties>/p:Configuration=$(Configuration) /p:XAIntegratedTests=$(XAIntegratedTests)</_XABuildProperties>
</PropertyGroup>
<ItemGroup>
<_TestAssembly Include="$(_TopDir)\bin\Test$(Configuration)\Xamarin.Android.Build.Tests.dll" />
<_JavaInteropTestResults Include="$(JavaInteropSourceDirectory)\TestResult-*.xml" />
<_ApkTestProject Include="$(_TopDir)\src\Mono.Android\Test\Mono.Android-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\CodeGen-Binding\Xamarin.Android.JcwGen-Tests\Xamarin.Android.JcwGen-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\locales\Xamarin.Android.Locale-Tests\Xamarin.Android.Locale-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj" />
<_ApkTestProjectAot Include="$(_TopDir)\src\Mono.Android\Test\Mono.Android-Tests.csproj" />
</ItemGroup>
<Target Name="RunNUnitTests">
<SetEnvironmentVariable Name="USE_MSBUILD" Value="0" Condition=" '$(USE_MSBUILD)' == '' " />
<Exec
Command="$(_NUnit) $(NUNIT_EXTRA) %(_TestAssembly.Identity) $(_Test) --result=&quot;TestResult-%(Filename).xml;format=nunit2&quot; --output=&quot;bin\Test$(Configuration)\TestOutput-%(Filename).txt&quot;"
WorkingDirectory="$(_TopDir)"
ContinueOnError="True"
/>
<ItemGroup>
<_RenameTestCasesGlob Include="$(_TopDir)\TestResult-*Tests.xml" />
</ItemGroup>
<PropertyGroup>
<_RenamedTestCases>@(_RenameTestCasesGlob)</_RenamedTestCases>
</PropertyGroup>
<MSBuild
Projects="$(MSBuildThisFileDirectory)TestApks.targets"
Targets="RenameTestCases"
Properties="Configuration=$(Configuration);RenameTestCasesGlob=$(_RenamedTestCases)"
/>
</Target>
<Target Name="RunJavaInteropTests">
<MSBuild Projects="$(JavaInteropSourceDirectory)\Java.Interop.sln" Condition=" '$(HostOS)' == 'Windows' " />
<Exec
Command ="make -C &quot;$(JavaInteropSourceDirectory)&quot; CONFIGURATION=$(Configuration) all"
Condition=" '$(HostOS)' != 'Windows' "
/>
<SetEnvironmentVariable Name="ANDROID_SDK_PATH" Value="$(AndroidSdkFullPath)" />
<MSBuild Projects="$(JavaInteropSourceDirectory)\build-tools\scripts\RunNUnitTests.targets" />
<ItemGroup>
<_RenameTestCasesGlob Include="$(JavaInteropSourceDirectory)\TestResult-*Tests.xml" />
</ItemGroup>
<PropertyGroup>
<_RenamedTestCases>@(_RenameTestCasesGlob)</_RenamedTestCases>
</PropertyGroup>
<MSBuild
Projects="$(MSBuildThisFileDirectory)TestApks.targets"
Targets="RenameTestCases"
Properties="Configuration=$(Configuration);RenameTestCasesGlob=$(_RenamedTestCases)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually work? Properties is a ;-delimited list of properties, and $(_RenamedTestCases) may in turn contain ;s. If that works....wow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem to work, even under xbuild. I will need to read the results of the Jenkins build carefully to make sure it looks the same as older builds.

/>
<Copy SourceFiles="@(_JavaInteropTestResults)" DestinationFolder="$(_TopDir)" />
</Target>
<Target Name="RunApkTests">
<Exec Command="$(_XABuild) %(_ApkTestProject.Identity) /t:SignAndroidPackage $(_XABuildProperties)" />
<MSBuild Projects="$(_TopDir)\tests\RunApkTests.targets" />
<Exec
Command="$(_XABuild) %(_ApkTestProjectAot.Identity) /t:SignAndroidPackage $(_XABuildProperties) /p:AotAssemblies=True"
Condition=" '$(Configuration)' == 'Release' "
/>
<MSBuild
Projects="$(_TopDir)\tests\RunApkTests.targets"
Condition=" '$(Configuration)' == 'Release' "
/>
</Target>
<Target Name="RunAllTests" DependsOnTargets="RunNUnitTests;RunJavaInteropTests;RunApkTests" />
</Project>
1 change: 1 addition & 0 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
Text="Please set `%24(Configuration)`."
/>
<PropertyGroup>
<_DeleteSource Condition=" '$(KEEP_TEST_SOURCES)' != '' ">False</_DeleteSource>
<_DeleteSource Condition=" '$(DeleteTestCaseSourceFiles)' != '' ">$(DeleteTestCaseSourceFiles)</_DeleteSource>
<_DeleteSource Condition=" '$(_DeleteSource)' == '' ">True</_DeleteSource>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

using System;

namespace Xamarin.Android.BuildTools.PrepTasks
{
public class SetEnvironmentVariable : Task
{
[Required]
public string Name { get; set; }

[Required]
public string Value { get; set; }

public override bool Execute ()
{
Log.LogMessage (MessageImportance.Low, $"Task {nameof (SetEnvironmentVariable)}");
Log.LogMessage (MessageImportance.Low, $" {nameof (Name)}: {Name}");
Log.LogMessage (MessageImportance.Low, $" {nameof (Value)}: {Value}");

Environment.SetEnvironmentVariable(Name, Value);

return !Log.HasLoggedErrors;
}
}
}
1 change: 1 addition & 0 deletions build-tools/xa-prep-tasks/xa-prep-tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Compile Include="Xamarin.Android.BuildTools.PrepTasks\HashFileContents.cs" />
<Compile Include="Xamarin.Android.BuildTools.PrepTasks\JdkInfo.cs" />
<Compile Include="Xamarin.Android.BuildTools.PrepTasks\PathToolTask.cs" />
<Compile Include="Xamarin.Android.BuildTools.PrepTasks\SetEnvironmentVariable.cs" />
<Compile Include="Xamarin.Android.BuildTools.PrepTasks\SystemUnzip.cs" />
<Compile Include="Xamarin.Android.BuildTools.PrepTasks\Which.cs" />
<Compile Include="Xamarin.Android.BuildTools.PrepTasks\GitBlame.cs" />
Expand Down
6 changes: 0 additions & 6 deletions src/Mono.Android/Test/Mono.Android-Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@
<Import Project="..\..\..\bin\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="Mono.Android-Tests.targets" />
<ItemGroup>
<ProjectReference Include="..\..\..\build-tools\android-toolchain\android-toolchain.mdproj">
<Name>android-toolchain</Name>
<Project>{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA}</Project>
<Private>False</Private>
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj" Condition=" '$(XAIntegratedTests)' == 'True' ">
<Name>Xamarin.Android.Build.Tasks</Name>
<Project>{3F1F2F50-AF1A-4A5A-BEDB-193372F068D7}</Project>
Expand Down