Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor embedded tests for better automation #1166

Merged
merged 8 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
59 changes: 41 additions & 18 deletions build/AzurePipelineTemplates/CsWinRT-BuildAndTest-Stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,23 @@ stages:
set cswinrt_build_params=/bl:$(Build.SourcesDirectory)\cswinrt.binlog /p:CleanIntermediateDirs=true /p:AllowedReferenceRelatedFileExtensions=".xml;.pri;.dll.config;.exe.config"
build.cmd $(BuildPlatform) $(BuildConfiguration) $(VersionNumber) $(Build.BuildNumber) $(WinRT.Runtime.AssemblyVersion)

# Mask BuildConfiguration
# Build Tool for Embedded Sample
- task: CmdLine@2
displayName: Mask BuildConfiguration
enabled: False
displayName: Build TestEmbedded Sample
inputs:
workingDirectory: $(Build.SourcesDirectory)\src\Samples\TestEmbedded
script: |
@echo off

rem Although BuildConfiguration is PipelineRelease or PipelineDebug, the build outputs still go to Release or Debug
rem change BuildConfiguration variable so staging succeeds
rem the alternative would be to add configuration property for Pipeline* to every project in cswinrt.sln

if "$(BuildConfiguration)"=="PipelineRelease" (
set NewBuildConfiguration=Release
) else if "$(BuildConfiguration)"=="PipelineDebug" (
set NewBuildConfiguration=Debug
if "%VSCMD_VER%"=="" (
pushd c:
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" >nul 2>&1
popd
)

if "%NewBuildConfiguration%"!="" (
echo ##vso[task.setvariable variable=BuildConfiguration;]%NewBuildConfiguration%
)
set echo_build=on
set only_build=true
rem PDBs being copied for each project reference are causing out of disk space issues in the pipeline. Making use of AllowedReferenceRelatedFileExtensions to avoid them being copied.
set embed_build_params=/p:AllowedReferenceRelatedFileExtensions=".xml;.pri;.dll.config;.exe.config"
build.cmd $(BuildPlatform) $(BuildConfiguration)

# Component Detection
- task: ComponentGovernanceComponentDetection@0
Expand All @@ -208,6 +204,15 @@ stages:
Contents: cswinrt.binlog
TargetFolder: $(Build.ArtifactStagingDirectory)\binlog

# Stage BinLog
- task: CopyFiles@2
displayName: Stage Embedded Sample BinLog
condition: always()
inputs:
SourceFolder: $(Build.SourcesDirectory)\src\Samples\TestEmbedded
Contents: embeddedsample.binlog
TargetFolder: $(Build.ArtifactStagingDirectory)\binlog

# Publish BinLog
- task: PublishBuildArtifacts@1
displayName: Publish BinLog
Expand Down Expand Up @@ -401,10 +406,20 @@ stages:
condition: and(succeeded(), or(eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildPlatform'], 'x64')))
inputs:
command: test
projects: 'src/Tests/UnitTest/UnitTest.csproj '
projects: 'src/Tests/UnitTest/UnitTest.csproj'
arguments: --diag $(Build.ArtifactStagingDirectory)\unittest\test.log --no-build --logger xunit;LogFilePath=UNITTEST-$(Build.BuildNumber).xml /nologo /m /p:platform=$(BuildPlatform);configuration=$(BuildConfiguration)
testRunTitle: Unit Tests

# Run Embedded Unit Tests
- task: DotNetCoreCLI@2
displayName: Run Embedded Unit Tests
condition: and(succeeded(), or(eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildPlatform'], 'x64')))
inputs:
command: test
projects: 'src/Samples/TestEmbedded/UnitTestEmbedded/UnitTestEmbedded.csproj'
arguments: --diag $(Build.ArtifactStagingDirectory)\unittestembedded\test.log --no-build --logger xunit;LogFilePath=EMBEDDEDUNITTEST-$(Build.BuildNumber).xml /nologo /m /p:platform=$(BuildPlatform);configuration=$(BuildConfiguration)
testRunTitle: Embedded Unit Tests

# Run Object Lifetime Tests
- task: VSTest@2
displayName: Run Object Lifetime Tests
Expand All @@ -421,6 +436,14 @@ stages:
PathtoPublish: $(Build.ArtifactStagingDirectory)\unittest
ArtifactName: $(BuildConfiguration)_$(BuildPlatform)_UnitTest

# Publish Embedded Test Log
- task: PublishBuildArtifacts@1
displayName: Publish Embedded Test Log
condition: and(succeeded(), or(eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildPlatform'], 'x64')))
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)\unittestembedded
ArtifactName: $(BuildConfiguration)_$(BuildPlatform)_UnitTestEmbedded

# Run Host Tests
- task: CmdLine@2
displayName: Run Host Tests
Expand All @@ -446,8 +469,8 @@ stages:
exit /b 0

- job: Benchmarks
condition: eq(variables['_RunBenchmarks'],'true')
displayName: Run Benchmarks
condition: eq(variables['_RunBenchmarks'],'true')
dependsOn: []
pool:
vmImage: windows-2019
Expand Down
20 changes: 10 additions & 10 deletions build/AzurePipelineTemplates/CsWinRT-Pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
variables:
- template: CsWinRT-Variables.yml
name: $(MajorVersion).$(MinorVersion).$(PatchVersion)$(PrereleaseVersion).$(date:yyMMdd)$(rev:.r)
stages:
- template: CsWinRT-BuildAndTest-Stage.yml
- template: CsWinRT-PublishToNuget-Stage.yml
variables:
- template: CsWinRT-Variables.yml

name: $(MajorVersion).$(MinorVersion).$(PatchVersion)$(PrereleaseVersion).$(date:yyMMdd)$(rev:.r)

stages:
- template: CsWinRT-BuildAndTest-Stage.yml

- template: CsWinRT-PublishToNuget-Stage.yml

- template: CsWinRT-PublishToMaestro-Stage.yml
3 changes: 2 additions & 1 deletion nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
-include WinRT.Interop
</CsWinRTIncludeWinRTInterop>
<CsWinRTEmbeddedParam Condition="'$(CsWinRTEmbedded)' == 'true'">-embedded</CsWinRTEmbeddedParam>
<CsWinRTExeTFM Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 5">$(TargetFramework)</CsWinRTExeTFM>
<CsWinRTExeTFM Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) == 5">net5.0</CsWinRTExeTFM>
<CsWinRTExeTFM Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) > 5">net6.0</CsWinRTExeTFM>
<CsWinRTExeTFM Condition="'$(CsWinRTExeTFM)' == ''">netstandard2.0</CsWinRTExeTFM>
<CsWinRTParams Condition="'$(CsWinRTParams)' == ''">
$(CsWinRTCommandVerbosity)
Expand Down
2 changes: 2 additions & 0 deletions src/Samples/TestEmbedded/C++ Components/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
17 changes: 17 additions & 0 deletions src/Samples/TestEmbedded/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$([MSBuild]::GetPathOfFileAbove('Microsoft.Windows.CsWinRT.props', '$(MSBuildThisFileDirectory)../../../nuget'))"
Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(SimulateCsWinRTNugetReference)' == 'true'" />

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../../'))" />

<PropertyGroup>

<BuildPlatform>$(Platform)</BuildPlatform>
<BuildOutDir>$([MSBuild]::NormalizeDirectory('$(SolutionDir)../../_build', '$(BuildPlatform)', '$(Configuration)'))</BuildOutDir>
<CsWinRTPath>$([MSBuild]::NormalizeDirectory('$(BuildOutDir)', 'cswinrt', 'bin'))</CsWinRTPath>
<CsWinRTPath Condition="'$(Platform)'=='ARM' or '$(Platform)'=='ARM64'">$([MSBuild]::NormalizeDirectory('$(SolutionDir)../../_build', 'x86', '$(Configuration)', 'cswinrt', 'bin'))</CsWinRTPath>
<CsWinRTExe>$(CsWinRTPath)cswinrt.exe</CsWinRTExe>
<WinRTRuntimeSourcesDir>$([MSBuild]::NormalizeDirectory('$(SolutionDir)../../WinRT.Runtime'))</WinRTRuntimeSourcesDir>

</PropertyGroup>

</Project>
119 changes: 119 additions & 0 deletions src/Samples/TestEmbedded/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,2 +1,121 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import
Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(SimulateCsWinRTNugetReference)' == 'true'"
Project="$([MSBuild]::GetPathOfFileAbove('Microsoft.Windows.CsWinRT.targets', '$(MSBuildThisFileDirectory)../../../nuget'))" />

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../../'))" />

<!-- CsWinRTCheckDependencies is also defined in the src/ targets file, and prevents issues when using TestWinRT.
We skip the check here because we need the targets but aren't using TestWinRT.
-->
<Target Name="CsWinRTCheckDependencies" />

<!-- We overwrite the targets from Microsoft.Windows.CsWinRT.Embedded.targets
They copy WinRT.Runtime sources based on the target platform; the filenames designate what platform they're for. -->

<Target Name="CsWinRTAddEmbeddedRuntime_AnySources"
Condition="'$(CsWinRTEmbedded)' == 'true'"
DependsOnTargets="CsWinRTPrepareProjection"
AfterTargets="CsWinRTGenerateProjection"
BeforeTargets="CsWinRTIncludeProjection">

<PropertyGroup>
<EmbeddedAnyFiles>
$(WinRTRuntimeSourcesDir)TypeNameSupport.cs;
j0shuams marked this conversation as resolved.
Show resolved Hide resolved
$(WinRTRuntimeSourcesDir)TypeExtensions.cs;
$(WinRTRuntimeSourcesDir)Projections.cs;
$(WinRTRuntimeSourcesDir)ObjectReference.cs;
$(WinRTRuntimeSourcesDir)MonoSupport.cs;
$(WinRTRuntimeSourcesDir)Module.cs;
$(WinRTRuntimeSourcesDir)Marshalers.cs;
$(WinRTRuntimeSourcesDir)IInspectable.cs;
$(WinRTRuntimeSourcesDir)GuidGenerator.cs;
$(WinRTRuntimeSourcesDir)FundamentalMarshalers.cs;
$(WinRTRuntimeSourcesDir)ExceptionHelpers.cs;
$(WinRTRuntimeSourcesDir)EventRegistrationToken.cs;
$(WinRTRuntimeSourcesDir)DerivedComposed.cs;
$(WinRTRuntimeSourcesDir)Context.cs;
$(WinRTRuntimeSourcesDir)ComWrappersSupport.cs;
$(WinRTRuntimeSourcesDir)CastExtensions.cs;
$(WinRTRuntimeSourcesDir)Attributes.cs;
$(WinRTRuntimeSourcesDir)AgileReference.cs;
$(WinRTRuntimeSourcesDir)WinRTRuntimeErrorStrings.Designer.cs;
$(WinRTRuntimeSourcesDir)Projections\EventHandler.cs;
$(WinRTRuntimeSourcesDir)Projections\Geometry.cs;
$(WinRTRuntimeSourcesDir)Projections\IStringable.cs;
$(WinRTRuntimeSourcesDir)Projections\KeyValuePair.cs;
$(WinRTRuntimeSourcesDir)Projections\NotifyCollectionChangedAction.cs;
$(WinRTRuntimeSourcesDir)Projections\NotifyCollectionChangedEventArgs.cs;
$(WinRTRuntimeSourcesDir)Projections\NotifyCollectionChangedEventHandler.cs;
$(WinRTRuntimeSourcesDir)Projections\Nullable.cs;
$(WinRTRuntimeSourcesDir)Projections\Numerics.cs;
$(WinRTRuntimeSourcesDir)Projections\PropertyChangedEventArgs.cs;
$(WinRTRuntimeSourcesDir)Projections\PropertyChangedEventHandler.cs;
$(WinRTRuntimeSourcesDir)Projections\SystemTypes.cs;
$(WinRTRuntimeSourcesDir)Projections\Type.cs;
$(WinRTRuntimeSourcesDir)Projections\Uri.cs;
$(WinRTRuntimeSourcesDir)Projections\DataErrorsChangedEventArgs.cs;
$(WinRTRuntimeSourcesDir)Interop\IReferenceTracker.cs;
$(WinRTRuntimeSourcesDir)Interop\IUnknownVftbl.cs;
$(WinRTRuntimeSourcesDir)Interop\StandardDelegates.cs;
$(WinRTRuntimeSourcesDir)Interop\ExceptionErrorInfo.cs;
$(WinRTRuntimeSourcesDir)Interop\IActivationFactory.cs;
$(WinRTRuntimeSourcesDir)Interop\IContextCallback.cs;
$(WinRTRuntimeSourcesDir)Interop\IMarshal.cs;
</EmbeddedAnyFiles>
</PropertyGroup>


<ItemGroup>
<CsWinRTEmbeddedSourcesAny Remove="@(CsWinRTEmbeddedSourcesAny)" />
<CsWinRTEmbeddedSourcesAny Include="$(EmbeddedAnyFiles)" />
</ItemGroup>

<Copy SourceFiles="@(CsWinRTEmbeddedSourcesAny)"
DestinationFolder="$(CsWinRTGeneratedFilesDir)"
UseHardlinksIfPossible="false"
SkipUnchangedFiles="true"/>
</Target>

<!-- NetStandard 2.0
-->
<Target Name="CsWinRTAddEmbeddedRuntime_Net2Sources"
Condition="'$(CsWinRTEmbeddedTFMNet5OrGreater)' != 'true' and '$(CsWinRTEmbedded)' == 'true'"
DependsOnTargets="CsWinRTPrepareProjection"
AfterTargets="CsWinRTGenerateProjection"
BeforeTargets="CsWinRTIncludeProjection">

<ItemGroup>
<NetStandardSources Include="$(WinRTRuntimeSourcesDir)**\*netstandard2.0.cs" />
<CsWinRTEmbeddedSourcesNet2 Include="@(NetStandardSources)" />
</ItemGroup>

<Copy SourceFiles="@(CsWinRTEmbeddedSourcesNet2)"
DestinationFolder="$(CsWinRTGeneratedFilesDir)"
UseHardlinksIfPossible="false"
SkipUnchangedFiles="true"/>
</Target>

<!-- Net 5.0
-->
<Target Name="CsWinRTAddEmbeddedRuntime_Net5Sources"
Condition="'$(CsWinRTEmbeddedTFMNet5OrGreater)' == 'true' and '$(CsWinRTEmbedded)' == 'true'"
DependsOnTargets="CsWinRTPrepareProjection"
AfterTargets="CsWinRTGenerateProjection"
BeforeTargets="CsWinRTIncludeProjection">

<ItemGroup>
<Net5Sources Include="$(WinRTRuntimeSourcesDir)**\*net5.cs" />
<CsWinRTEmbeddedSourcesNet5 Include="@(Net5Sources)" />
</ItemGroup>

<Copy SourceFiles="@(CsWinRTEmbeddedSourcesNet5)"
DestinationFolder="$(CsWinRTGeneratedFilesDir)"
UseHardlinksIfPossible="false"
SkipUnchangedFiles="true"/>
</Target>

<Target Name="RemoveWinRTRuntimeReference" />

</Project>
33 changes: 13 additions & 20 deletions src/Samples/TestEmbedded/Net5App.Bootstrap/Net5App.Bootstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<Platforms>x64;x86;ARM64</Platforms>
<Platforms>x64;x86</Platforms>
</PropertyGroup>

<PropertyGroup>
<LangVersion>9</LangVersion>
<SimulateCsWinRTNugetReference>true</SimulateCsWinRTNugetReference>
<CsWinRTEmbedded>true</CsWinRTEmbedded>
<CsWinRTWindowsMetadata>sdk</CsWinRTWindowsMetadata>
<CsWinRTGenerateProjection>true</CsWinRTGenerateProjection>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.4.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\C++ Components\Alpha\Alpha.vcxproj" />
<ProjectReference Include="..\C++ Components\Beta\Beta.vcxproj" />
Expand All @@ -31,21 +29,16 @@
Alpha;
Beta;
Gamma;
Windows.Devices.Geolocation;
Windows.Foundation.Metadata
Windows.Foundation.UniversalApiContract;
Windows.Foundation.IAsyncOperation;
Windows.Foundation.TypedEventHandler;
Windows.Foundation.FoundationContract;
Windows.Foundation.IAsyncInfo;
Windows.Foundation.IAsyncAction;
Windows.Foundation.AsyncStatus;
Windows.Foundation.AsyncActionCompletedHandler;
Windows.Foundation.AsyncActionProgressHandler;
Windows.Foundation.AsyncActionWithProgressCompletedHandler;
Windows.Foundation.AsyncOperationProgressHandler;
Windows.Foundation.AsyncOperationCompletedHandler;
Windows.Foundation.AsyncOperationWithProgressCompletedHandler;
Windows.Media.AudioFrame;
Windows.Media.AudioBuffer;
Windows.Media.IAudioBuffer;
Windows.Media.IMediaFrame;
Windows.Media.IAudioFrame;
Windows.Foundation;
</CsWinRTIncludes>
<CsWinRTExcludes>
Windows.Foundation.Diagnostics;
Windows.Foundation.PropertyType;
</CsWinRTExcludes>
</PropertyGroup>
</Project>
Loading