Skip to content

Commit 2b61a81

Browse files
Update Smoke Test to Also Look at .NET Native Compiled output
1 parent f2301cf commit 2b61a81

File tree

1 file changed

+114
-6
lines changed

1 file changed

+114
-6
lines changed

SmokeTests/SmokeTestAnalysis.ps1

Lines changed: 114 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
$ErrorActionPreference = "Stop"
2-
$ProgressPreference="SilentlyContinue"
1+
$global:ErrorActionPreference = "Stop"
2+
$global:ProgressPreference="SilentlyContinue"
33

44
Write-Host "Running Smoke Test Package Analyis"
55
Write-Host "----------------------------------"
66

7+
#####
8+
# This script analyzes the final packaged outputs of
9+
# There are two things analyzed:
10+
# - The MSIX UPLOAD package has the raw dependencies before .NET Native compilation,
11+
# this can help determine the maximum impact of the package if everything were to be included.
12+
# - The MSIX BUNDLE package is the final .NET Native compiled app,
13+
# this can be used to help determine the minimal impact of the package if only a few things are used.
14+
# This is also what would end up on a user's machine and be the footprint of the app itself.
15+
#
16+
# Note: The 'minimum impact' can be larger than the 'maximum impact' as there are many
17+
# system dependencies which don't get included by default and are then referenced by a package.
18+
# This may seem counter-intuitive at first, but it is important to remember that when combining
19+
# package use along with the use of other platform APIs smooths these sizes out as they will
20+
# all be shared across all use cases.
21+
#####
22+
723
# Our script is at our SmokeTest root, we want to look for the AppPackages folder
824
$PackagePath = $PSScriptRoot + "\AppPackages\"
925
$FilePattern = "SmokeTest_{0}_x86_bundle.msixupload"
26+
$DirPattern = "SmokeTest_{0}_Test\SmokeTest_{0}_x86.msixbundle"
27+
1028
$BaselineName = $FilePattern -f "UWPBaseline"
29+
$BaselineBundleName = $DirPattern -f "UWPBaseline"
1130
$TempFolder = "ExplodedArchive"
31+
$TempFolder2 = "ExplodedBundle"
1232

1333
function Expand-MsixUploadPackage {
1434
param (
@@ -47,6 +67,34 @@ function Expand-MsixUploadPackage {
4767
Pop-Location
4868
}
4969

70+
function Expand-MsixBundlePackage {
71+
param (
72+
[string]$PackageFile,
73+
[string]$Destination
74+
)
75+
76+
$ZipBundle = $PackageFile.Replace("msixbundle", "zip")
77+
78+
Move-Item $PackageFile -Destination $ZipBundle
79+
80+
Expand-Archive $ZipBundle -DestinationPath $Destination
81+
82+
Move-Item $ZipBundle -Destination $PackageFile
83+
84+
Push-Location $Destination
85+
86+
$msix = (Get-ChildItem "*.msix").Name
87+
$ZipMSIX = $msix.Replace("msix", "zip")
88+
89+
Move-Item $msix -Destination $ZipMSIX
90+
91+
Expand-Archive $ZipMSIX -DestinationPath . -Force # Force here as we have some duplicate file names we don't really care about from parent archives
92+
93+
Remove-Item $ZipMSIX
94+
95+
Pop-Location
96+
}
97+
5098
if (Test-Path $PackagePath)
5199
{
52100
Push-Location $PackagePath
@@ -55,35 +103,48 @@ if (Test-Path $PackagePath)
55103

56104
# TODO: Theoretically we could grab bits from the bin directory instead of having to expand each package, not sure about what we ignore though
57105
Expand-MsixUploadPackage $BaselineName -Destination $TempFolder
106+
Expand-MsixBundlePackage $BaselineBundleName -Destination $TempFolder2
58107

59108
# Get all the base file info only (grab stuff in directories but not the directories themselves)
60109
$BaselineFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Exclude "SmokeTest*"
110+
$BaselineFiles2 = Get-ChildItem $TempFolder2 -Recurse -Attributes !Directory -Exclude "SmokeTest*"
61111
$SmokeTestFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Include "SmokeTest*"
112+
$SmokeTestFiles2 = Get-ChildItem $TempFolder2 -Recurse -Attributes !Directory -Include "SmokeTest*"
62113

63114
$BaselineFootprint = ($BaselineFiles | Measure-Object -Property Length -sum).Sum + ($SmokeTestFiles | Measure-Object -Property Length -sum).Sum
64-
Write-Host ("Baseline Footprint: {0:n0} bytes" -f $BaselineFootprint)
115+
$BaselineFootprint2 = ($BaselineFiles2 | Measure-Object -Property Length -sum).Sum + ($SmokeTestFiles2 | Measure-Object -Property Length -sum).Sum
116+
Write-Host ("Baseline Max Footprint: {0:n0} bytes" -f $BaselineFootprint)
117+
Write-Host ("Baseline Min Footprint: {0:n0} bytes" -f $BaselineFootprint2)
65118
Write-Host "-----------------------------------------"
66119

67120
$PackageList = Get-ChildItem "$PackagePath*.msixupload" -Exclude $BaselineName
68121

69122
#$i = 0
70123
foreach ($Package in $PackageList)
71124
{
125+
# Extract the root package name between the initial '_'
126+
$PackageShortName = ($Package.Name -split '_')[1]
127+
72128
#Write-Progress -Id 0 -Activity "Comparing Against Baseline..." -Status "Prepping Package" -PercentComplete (($i++ / $PackageList.count)*100) -CurrentOperation $Package.Name
73129

74130
# Make sure we've cleaned-up the last archive
75131
Remove-Item $TempFolder -Recurse -Force
132+
Remove-Item $TempFolder2 -Recurse -Force
76133

77134
#$ProgressPreference="SilentlyContinue"
78135
Expand-MsixUploadPackage $Package.Name -Destination $TempFolder
136+
137+
# Also expand the final bundle based on the namespace name within the package.
138+
Expand-MsixBundlePackage ($DirPattern -f $PackageShortName) -Destination $TempFolder2
79139
#$ProgressPreference="Continue"
80140

81141
[System.Collections.ArrayList]$PackageFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Exclude "SmokeTest*"
82142
$PackageSmokeTestFiles = Get-ChildItem $TempFolder -Recurse -Attributes !Directory -Include "SmokeTest*"
143+
[System.Collections.ArrayList]$PackageFiles2 = Get-ChildItem $TempFolder2 -Recurse -Attributes !Directory -Exclude "SmokeTest*"
144+
$PackageSmokeTestFiles2 = Get-ChildItem $TempFolder2 -Recurse -Attributes !Directory -Include "SmokeTest*"
83145

84-
# TODO: Make function or regex better to extra package name more easily based on a template string at the top or something...
85-
$PackageShortName = $Package.Name.substring(10, $Package.Name.Length - 32)
86-
Write-Host ("{0} Additional Footprint: {1:n0} bytes" -f $PackageShortName, (($PackageFiles | Measure-Object -Property Length -sum).Sum + ($PackageSmokeTestFiles | Measure-Object -Property Length -sum).Sum - $BaselineFootprint))
146+
Write-Host ("{0} Additional Max Footprint: {1:n0} bytes" -f $PackageShortName, (($PackageFiles | Measure-Object -Property Length -sum).Sum + ($PackageSmokeTestFiles | Measure-Object -Property Length -sum).Sum - $BaselineFootprint))
147+
Write-Host ("{0} Additional Min Footprint: {1:n0} bytes" -f $PackageShortName, (($PackageFiles2 | Measure-Object -Property Length -sum).Sum + ($PackageSmokeTestFiles2 | Measure-Object -Property Length -sum).Sum - $BaselineFootprint2))
87148

88149
# Quick check on the base exe file/symbols differences
89150
foreach ($file in $SmokeTestFiles)
@@ -132,6 +193,52 @@ if (Test-Path $PackagePath)
132193
# TODO: Especially if we add comparison to the main branch, we should format as an actual table and colorize via VT: https://stackoverflow.com/a/49038815/8798708
133194

134195
#Write-Progress -Id 1 -ParentId 0 -Activity "Comparing Against Baseline..." -Completed
196+
Write-Host "-----------------COMPILED----------------"
197+
198+
# Quick check on the base exe file/symbols differences
199+
foreach ($file in $SmokeTestFiles2)
200+
{
201+
$match = $null
202+
$match = $PackageSmokeTestFiles2 | Where-Object {$_.Extension -eq $file.Extension}
203+
if ($null -ne $match)
204+
{
205+
Write-Host (" App Diff: ({0}) = {1:n0}" -f $file.Extension, ($match.Length - $file.Length)) -ForegroundColor DarkCyan
206+
}
207+
}
208+
209+
#$j = 0
210+
foreach ($file in $BaselineFiles2)
211+
{
212+
#Write-Progress -Id 1 -ParentId 0 -Activity "Comparing Against Baseline..." -Status "Comparing Package" -PercentComplete (($j++ / $BaselineFiles.count)*100) -CurrentOperation $file.Name
213+
214+
$match = $null
215+
$match = $PackageFiles2 | Where-Object {$_.Name -eq $file.Name}
216+
if ($null -ne $match)
217+
{
218+
# File was in baseline, but has a different size
219+
if ($match.Length -ne $file.Length)
220+
{
221+
Write-Host (" Size Diff: {0} = {1:n0}" -f $file.Name, ($match.Length - $file.Length)) -ForegroundColor Magenta
222+
}
223+
224+
# Remove checked files (performance) and also remaining are new
225+
$PackageFiles2.Remove($match)
226+
}
227+
}
228+
229+
# List remaining (new) files to this package
230+
foreach ($file in $PackageFiles2)
231+
{
232+
if ($file.Name -match $PackageShortName)
233+
{
234+
Write-Host (" Lib (self): {0} = {1:n0}" -f $file.Name, $file.Length) -ForegroundColor White
235+
}
236+
else
237+
{
238+
Write-Host (" Additional: {0} = {1:n0}" -f $file.Name, $file.Length) -ForegroundColor Yellow
239+
}
240+
}
241+
135242
Write-Host "-----------------------------------------"
136243
Write-Host
137244
}
@@ -140,6 +247,7 @@ if (Test-Path $PackagePath)
140247

141248
# Clean-up
142249
Remove-Item $TempFolder -Recurse -Force
250+
Remove-Item $TempFolder2 -Recurse -Force
143251

144252
Pop-Location
145253
}

0 commit comments

Comments
 (0)