Skip to content

Commit f1ad49e

Browse files
committed
Merge from master
2 parents c313906 + 7055f8a commit f1ad49e

File tree

6 files changed

+117
-25
lines changed

6 files changed

+117
-25
lines changed

.github/actions/spelling/expect.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ ERRORONEXIT
161161
errstr
162162
ESRB
163163
etl
164+
evtx
164165
ewgp
165166
ewgs
166167
execustom
@@ -323,6 +324,7 @@ MBH
323324
MBs
324325
mday
325326
mdmp
327+
mdmpto
326328
MDs
327329
megamorf
328330
microsoftentraid
@@ -616,6 +618,7 @@ wincodec
616618
windir
617619
windowsdeveloper
618620
winerror
621+
winevt
619622
wingdi
620623
wingetconfigroot
621624
wingetcreate

azure-pipelines.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ jobs:
340340
341341
- pwsh: |
342342
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
343-
PsExec -accepteula -s -i $(buildOutDir)\AppInstallerCLITests\AppInstallerCLITests.exe -logto $(artifactsDir)\AICLI-Unpackaged-System.log -s -r junit -o $(artifactsDir)\TEST-AppInstallerCLI-Unpackaged-System.xml
343+
PsExec -accepteula -s -i $(buildOutDir)\AppInstallerCLITests\AppInstallerCLITests.exe -logto $(artifactsDir)\AICLI-Unpackaged-System.log -mdmpto $(artifactsDir)\AICLI-Unpackaged-System.mdmp -s -r junit -o $(artifactsDir)\TEST-AppInstallerCLI-Unpackaged-System.xml
344344
displayName: Run Unit Tests Unpackaged Under System Context
345345
workingDirectory: '$(buildOutDir)\AppInstallerCLITests'
346346
condition: succeededOrFailed()
@@ -354,7 +354,7 @@ jobs:
354354
displayName: Run Unit Tests Packaged
355355
inputs:
356356
filePath: 'src\AppInstallerCLITests\Run-TestsInPackage.ps1'
357-
arguments: '-Args "~[pips]" -BuildRoot $(buildOutDir) -PackageRoot $(packageLayoutDir) -LogTarget $(artifactsDir)\AICLI-Packaged.log -TestResultsTarget $(artifactsDir)\TEST-AppInstallerCLI-Packaged.xml -ScriptWait'
357+
arguments: '-Args "~[pips]" -BuildRoot $(buildOutDir) -PackageRoot $(packageLayoutDir) -LogTarget $(artifactsDir)\AICLI-Packaged.log -MdmpTarget $(artifactsDir)\AICLI-Packaged.mdmp -TestResultsTarget $(artifactsDir)\TEST-AppInstallerCLI-Packaged.xml -ScriptWait'
358358
workingDirectory: 'src'
359359
condition: succeededOrFailed()
360360

@@ -482,6 +482,34 @@ jobs:
482482
- powershell: Get-Process LocalhostWebServer | Stop-Process
483483
displayName: Stop LocalhostWebServer
484484
condition: succeededOrFailed()
485+
486+
- task: PowerShell@2
487+
displayName: 'Copy GA WinGet Log to artifacts folder'
488+
inputs:
489+
targetType: 'inline'
490+
script: |
491+
$source = "$env:LocalAppData\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir"
492+
$destination = "$(artifactsDir)\GA_WinGet_Logs"
493+
if (Test-Path $source) {
494+
Copy-Item -Path $source -Destination $destination -Recurse -Force
495+
} else {
496+
Write-Host "WinGet logs not found at $source"
497+
}
498+
condition: succeededOrFailed()
499+
500+
- task: PowerShell@2
501+
displayName: 'Copy Application Event Logs to Artifacts'
502+
inputs:
503+
targetType: 'inline'
504+
script: |
505+
$source = "$env:SystemRoot\System32\winevt\Logs\Application.evtx"
506+
$destination = "$(artifactsDir)\Application.evtx"
507+
if (Test-Path $source) {
508+
Copy-Item -Path $source -Destination $destination -Force
509+
} else {
510+
Write-Host "Application event log not found at $source"
511+
}
512+
condition: succeededOrFailed()
485513

486514
- task: PublishPipelineArtifact@1
487515
displayName: Publish Pipeline Artifacts

src/AppInstallerCLITests/Run-TestsInPackage.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
location relative to this script.
1313
.PARAMETER LogTarget
1414
The file path to log to.
15+
.PARAMETER MdmpTarget
16+
The path to write a minidump to if the tests crash.
1517
.PARAMETER TestResultsTarget
1618
The file path to place the test result file in.
1719
.PARAMETER Args
@@ -31,6 +33,9 @@ param(
3133
[Parameter(Mandatory=$false)]
3234
[string]$LogTarget,
3335

36+
[Parameter(Mandatory=$false)]
37+
[string]$MdmpTarget,
38+
3439
[Parameter(Mandatory=$false)]
3540
[string]$TestResultsTarget,
3641

@@ -93,6 +98,14 @@ if (![String]::IsNullOrEmpty($LogTarget))
9398
Write-Host "Using LogTarget = $LogTarget"
9499
}
95100

101+
if (![String]::IsNullOrEmpty($MdmpTarget))
102+
{
103+
$Local:temp = Split-Path -Parent $MdmpTarget
104+
$Local:temp = Resolve-Path $Local:temp
105+
$MdmpTarget = Join-Path $Local:temp (Split-Path -Leaf $MdmpTarget)
106+
Write-Host "Using MdmpTarget = $MdmpTarget"
107+
}
108+
96109
if (![String]::IsNullOrEmpty($TestResultsTarget))
97110
{
98111
$Local:temp = Split-Path -Parent $TestResultsTarget
@@ -123,6 +136,15 @@ else
123136
$Local:TestArgs = $Local:TestArgs + " -logto ""$LogTarget"""
124137
}
125138

139+
if ([String]::IsNullOrEmpty($MdmpTarget))
140+
{
141+
$Local:TestArgs = $Local:TestArgs + " -mdmp"
142+
}
143+
else
144+
{
145+
$Local:TestArgs = $Local:TestArgs + " -mdmpto ""$MdmpTarget"""
146+
}
147+
126148
if (![String]::IsNullOrEmpty($TestResultsTarget))
127149
{
128150
$Local:TestArgs = $Local:TestArgs + " -s -r junit -o ""$TestResultsTarget"""

src/AppInstallerCLITests/main.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <AppInstallerFileLogger.h>
66
#include <Public/AppInstallerTelemetry.h>
77
#include <Telemetry/TraceLogging.h>
8+
#include <winget/Debugging.h>
89
#include "TestCommon.h"
910
#include "TestSettings.h"
1011

@@ -82,22 +83,23 @@ int main(int argc, char** argv)
8283
TestCommon::TempFile::SetDestructorBehavior(TestCommon::TempFileDestructionBehavior::ShellExecuteOnFailure);
8384
}
8485
else if ("-log"s == argv[i])
85-
{
86-
auto logger = std::make_unique<Logging::FileLogger>();
86+
{
87+
auto logger = std::make_unique<Logging::FileLogger>();
8788
logger->SetMaximumSize(0);
8889
Logging::Log().AddLogger(std::move(logger));
8990
}
9091
else if ("-logto"s == argv[i])
9192
{
92-
++i;
93-
auto logger = std::make_unique<Logging::FileLogger>(std::filesystem::path{ argv[i] });
94-
logger->SetMaximumSize(0);
95-
Logging::Log().AddLogger(std::move(logger));
93+
if (++i < argc)
94+
{
95+
auto logger = std::make_unique<Logging::FileLogger>(std::filesystem::path{ argv[i] });
96+
logger->SetMaximumSize(0);
97+
Logging::Log().AddLogger(std::move(logger));
98+
}
9699
}
97100
else if ("-tdd"s == argv[i])
98101
{
99-
++i;
100-
if (i < argc)
102+
if (++i < argc)
101103
{
102104
TestCommon::TestDataFile::SetTestDataBasePath(argv[i]);
103105
hasSetTestDataBasePath = true;
@@ -111,6 +113,17 @@ int main(int argc, char** argv)
111113
{
112114
keepSQLLogging = true;
113115
}
116+
else if ("-mdmp"s == argv[i])
117+
{
118+
Debugging::EnableSelfInitiatedMinidump();
119+
}
120+
else if ("-mdmpto"s == argv[i])
121+
{
122+
if (++i < argc)
123+
{
124+
Debugging::EnableSelfInitiatedMinidump(std::filesystem::path{ argv[i] });
125+
}
126+
}
114127
else
115128
{
116129
args.push_back(argv[i]);

src/AppInstallerCommonCore/Debugging.cpp

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@ namespace AppInstaller::Debugging
1414

1515
struct SelfInitiatedMinidumpHelper
1616
{
17-
SelfInitiatedMinidumpHelper() : m_keepFile(false)
18-
{
19-
m_filePath = Runtime::GetPathTo(Runtime::PathName::DefaultLogLocation);
20-
m_filePath /= c_minidumpPrefix.data() + ('-' + Utility::GetCurrentTimeForFilename() + c_minidumpExtension.data());
21-
22-
m_file.reset(CreateFile(m_filePath.wstring().c_str(), GENERIC_READ | GENERIC_WRITE,
23-
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr));
24-
THROW_LAST_ERROR_IF(!m_file);
25-
26-
SetUnhandledExceptionFilter(UnhandledExceptionCallback);
27-
}
17+
SelfInitiatedMinidumpHelper() = default;
2818

2919
~SelfInitiatedMinidumpHelper()
3020
{
@@ -57,6 +47,30 @@ namespace AppInstaller::Debugging
5747
return EXCEPTION_CONTINUE_SEARCH;
5848
}
5949

50+
SelfInitiatedMinidumpHelper& Enable(const std::filesystem::path& filePath = {})
51+
{
52+
std::call_once(m_enableFlag, [&]()
53+
{
54+
if (filePath.empty())
55+
{
56+
m_filePath = Runtime::GetPathTo(Runtime::PathName::DefaultLogLocation);
57+
m_filePath /= c_minidumpPrefix.data() + ('-' + Utility::GetCurrentTimeForFilename() + c_minidumpExtension.data());
58+
}
59+
else
60+
{
61+
m_filePath = filePath;
62+
}
63+
64+
m_file.reset(CreateFile(m_filePath.wstring().c_str(), GENERIC_READ | GENERIC_WRITE,
65+
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr));
66+
THROW_LAST_ERROR_IF(!m_file);
67+
68+
SetUnhandledExceptionFilter(UnhandledExceptionCallback);
69+
});
70+
71+
return *this;
72+
}
73+
6074
void WriteMinidump()
6175
{
6276
std::thread([&]() {
@@ -66,20 +80,25 @@ namespace AppInstaller::Debugging
6680
}
6781

6882
private:
83+
std::once_flag m_enableFlag;
6984
std::filesystem::path m_filePath;
7085
wil::unique_handle m_file;
71-
std::atomic_bool m_keepFile;
86+
std::atomic_bool m_keepFile{ false };
7287
};
7388
}
7489

7590
void EnableSelfInitiatedMinidump()
7691
{
77-
// Force object creation and thus enabling of the crash detection.
78-
SelfInitiatedMinidumpHelper::Instance();
92+
SelfInitiatedMinidumpHelper::Instance().Enable();
93+
}
94+
95+
void EnableSelfInitiatedMinidump(const std::filesystem::path& filePath)
96+
{
97+
SelfInitiatedMinidumpHelper::Instance().Enable(filePath);
7998
}
8099

81100
void WriteMinidump()
82101
{
83-
SelfInitiatedMinidumpHelper::Instance().WriteMinidump();
102+
SelfInitiatedMinidumpHelper::Instance().Enable().WriteMinidump();
84103
}
85104
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33
#pragma once
4+
#include <filesystem>
45

56
namespace AppInstaller::Debugging
67
{
78
// Enables a self initiated minidump on certain process level failures.
9+
// Only the first call to EnableSelfInitiatedMinidump has any effect.
810
void EnableSelfInitiatedMinidump();
911

12+
// Enables a self initiated minidump on certain process level failures.
13+
// Creates the minidump in the given location.
14+
// Only the first call to EnableSelfInitiatedMinidump has any effect.
15+
void EnableSelfInitiatedMinidump(const std::filesystem::path& filePath);
16+
1017
// Forces the minidump to be written.
1118
void WriteMinidump();
1219
}

0 commit comments

Comments
 (0)