Add reload engine and test.
Sean Hall committed
Apr 23, 2020 at 12:26 UTC
ab495395492055c8c016e54ab0b1f7af2e9f164c
13 files changed
+217
-18
src/test/WixToolsetTest.ManagedHost/MbaHostFixture.cs
+78
@@ -78,5 +78,83 @@ namespace WixToolsetTest.ManagedHost
78
Assert.Equal("Shutdown,ReloadBootstrapper,0", logMessages[3]);
79
}
80
}
81
+
82
+ [Fact]
83
+ public void CanReloadFullFramework2MBA()
84
+ {
85
+ using (var fs = new DisposableFileSystem())
86
+ {
87
+ var baseFolder = fs.GetFolder();
88
+ var binFolder = Path.Combine(baseFolder, "bin");
89
+ var bundleFile = Path.Combine(binFolder, "FullFramework2MBA.exe");
90
+ var baSourceFolder = TestData.Get(@"..\examples");
91
+ var bundleSourceFolder = TestData.Get(@"TestData\FullFramework2MBA");
92
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
93
+
94
+ var compileResult = WixRunner.Execute(new[]
95
+ {
96
+ "build",
97
+ Path.Combine(bundleSourceFolder, "Bundle.wxs"),
98
+ "-ext", TestData.Get(@"WixToolset.Bal.wixext.dll"),
99
+ "-ext", TestData.Get(@"WixToolset.NetFx.wixext.dll"),
100
+ "-intermediateFolder", intermediateFolder,
101
+ "-bindpath", baSourceFolder,
102
+ "-burnStub", TestEngine.BurnStubFile,
103
+ "-o", bundleFile,
104
+ });
105
+ compileResult.AssertSuccess();
106
+ var testEngine = new TestEngine();
107
+
108
+ var result = testEngine.RunReloadEngine(bundleFile, baseFolder);
109
+ var logMessages = result.Output;
110
+ Assert.Equal("Loading managed bootstrapper application.", logMessages[0]);
111
+ Assert.Equal("Creating BA thread to run asynchronously.", logMessages[1]);
112
+ Assert.Equal("FullFramework2BA", logMessages[2]);
113
+ Assert.Equal("Shutdown,ReloadBootstrapper,0", logMessages[3]);
114
+ Assert.Equal("Loading managed bootstrapper application.", logMessages[4]);
115
+ Assert.Equal("Creating BA thread to run asynchronously.", logMessages[5]);
116
+ Assert.Equal("FullFramework2BA", logMessages[6]);
117
+ Assert.Equal("Shutdown,Restart,0", logMessages[7]);
118
+ }
119
+ }
120
+
121
+ [Fact]
122
+ public void CanReloadFullFramework4MBA()
123
+ {
124
+ using (var fs = new DisposableFileSystem())
125
+ {
126
+ var baseFolder = fs.GetFolder();
127
+ var binFolder = Path.Combine(baseFolder, "bin");
128
+ var bundleFile = Path.Combine(binFolder, "FullFramework4MBA.exe");
129
+ var baSourceFolder = TestData.Get(@"..\examples");
130
+ var bundleSourceFolder = TestData.Get(@"TestData\FullFramework4MBA");
131
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
132
+
133
+ var compileResult = WixRunner.Execute(new[]
134
+ {
135
+ "build",
136
+ Path.Combine(bundleSourceFolder, "Bundle.wxs"),
137
+ "-ext", TestData.Get(@"WixToolset.Bal.wixext.dll"),
138
+ "-ext", TestData.Get(@"WixToolset.NetFx.wixext.dll"),
139
+ "-intermediateFolder", intermediateFolder,
140
+ "-bindpath", baSourceFolder,
141
+ "-burnStub", TestEngine.BurnStubFile,
142
+ "-o", bundleFile,
143
+ });
144
+ compileResult.AssertSuccess();
145
+ var testEngine = new TestEngine();
146
+
147
+ var result = testEngine.RunReloadEngine(bundleFile, baseFolder);
148
+ var logMessages = result.Output;
149
+ Assert.Equal("Loading managed bootstrapper application.", logMessages[0]);
150
+ Assert.Equal("Creating BA thread to run asynchronously.", logMessages[1]);
151
+ Assert.Equal("FullFramework4BA", logMessages[2]);
152
+ Assert.Equal("Shutdown,ReloadBootstrapper,0", logMessages[3]);
153
+ Assert.Equal("Loading managed bootstrapper application.", logMessages[4]);
154
+ Assert.Equal("Creating BA thread to run asynchronously.", logMessages[5]);
155
+ Assert.Equal("FullFramework4BA", logMessages[6]);
156
+ Assert.Equal("Shutdown,Restart,0", logMessages[7]);
157
+ }
158
+ }
159
}
160
}
src/test/WixToolsetTest.ManagedHost/TestEngine.cs
+11
@@ -13,7 +13,17 @@ namespace WixToolsetTest.ManagedHost
13
private static readonly string TestEngineFile = TestData.Get(@"..\Win32\examples\Example.TestEngine\Example.TestEngine.exe");
14
public static readonly string BurnStubFile = TestData.Get(@"runtimes\win-x86\native\burn.x86.exe");
15
16
+ public TestEngineResult RunReloadEngine(string bundleFilePath, string tempFolderPath)
17
+ {
18
+ return this.RunTestEngine("reload", bundleFilePath, tempFolderPath);
19
+ }
20
+
21
public TestEngineResult RunShutdownEngine(string bundleFilePath, string tempFolderPath)
22
+ {
23
+ return this.RunTestEngine("shutdown", bundleFilePath, tempFolderPath);
24
+ }
25
+
26
+ private TestEngineResult RunTestEngine(string engineMode, string bundleFilePath, string tempFolderPath)
27
{
28
var baFolderPath = Path.Combine(tempFolderPath, "ba");
29
var extractFolderPath = Path.Combine(tempFolderPath, "extract");
@@ -21,6 +31,7 @@ namespace WixToolsetTest.ManagedHost
31
extractResult.AssertSuccess();
32
33
var args = new string[] {
34
+ engineMode,
35
'"' + bundleFilePath + '"',
36
'"' + extractResult.GetBAFilePath(baFolderPath) + '"',
37
};
src/test/examples/FullFramework2MBA/FullFramework2BAFactory.cs
+7
@@ -6,8 +6,15 @@ namespace Example.FullFramework2MBA
6
7
public class FullFramework2BAFactory : BaseBootstrapperApplicationFactory
8
{
9
+ private static int loadCount = 0;
10
+
11
protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand)
12
{
13
+ if (loadCount > 0)
14
+ {
15
+ engine.Log(LogLevel.Standard, $"Reloaded {loadCount} time(s)");
16
+ }
17
+ ++loadCount;
18
return new FullFramework2BA(engine);
19
}
20
}
src/test/examples/FullFramework4MBA/FullFramework4BAFactory.cs
+7
@@ -7,8 +7,15 @@ namespace Example.FullFramework4MBA
7
8
public class FullFramework4BAFactory : BaseBootstrapperApplicationFactory
9
{
10
+ private static int loadCount = 0;
11
+
12
protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand)
13
{
14
+ if (loadCount > 0)
15
+ {
16
+ engine.Log(LogLevel.Standard, $"Reloaded {loadCount} time(s)");
17
+ }
18
+ ++loadCount;
19
return new FullFramework4BA(engine);
20
}
21
}
src/test/examples/TestEngine/Example.TestEngine.vcxproj
+3
@@ -46,12 +46,15 @@
46
<ClCompile Include="precomp.cpp">
47
<PrecompiledHeader>Create</PrecompiledHeader>
48
</ClCompile>
49
+ <ClCompile Include="ReloadEngine.cpp" />
50
<ClCompile Include="ShutdownEngine.cpp" />
51
<ClCompile Include="ExampleTestEngine.cpp" />
52
<ClCompile Include="TestEngine.cpp" />
53
</ItemGroup>
54
<ItemGroup>
55
<ClInclude Include="precomp.h" />
56
+ <ClInclude Include="ReloadEngine.h" />
57
+ <ClInclude Include="ShutdownEngine.h" />
58
<ClInclude Include="TestEngine.h" />
59
</ItemGroup>
60
<ItemGroup>
src/test/examples/TestEngine/ExampleTestEngine.cpp
+17
-3
@@ -5,16 +5,30 @@
5
int __cdecl wmain(int argc, LPWSTR argv[])
6
{
7
HRESULT hr = E_INVALIDARG;
8
+ BOOL fShowUsage = FALSE;
9
10
ConsoleInitialize();
11
11
- if (argc != 3)
12
+ if (argc != 4)
13
{
13
- ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Usage: Example.TestEngine.exe Bundle.exe BA.dll");
14
+ fShowUsage = TRUE;
15
+ }
16
+ else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"reload", -1))
17
+ {
18
+ hr = RunReloadEngine(argv[2], argv[3]);
19
+ }
20
+ else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"shutdown", -1))
21
+ {
22
+ hr = RunShutdownEngine(argv[2], argv[3]);
23
}
24
else
25
{
17
- hr = RunShutdownEngine(argv[1], argv[2]);
26
+ fShowUsage = TRUE;
27
+ }
28
+
29
+ if (fShowUsage)
30
+ {
31
+ ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Usage: {reload|shutdown} Example.TestEngine.exe Bundle.exe BA.dll");
32
}
33
34
ConsoleUninitialize();
src/test/examples/TestEngine/ReloadEngine.cpp
new
+43
@@ -0,0 +1,43 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+#include "precomp.h"
4
+
5
+HRESULT RunReloadEngine(
6
+ __in LPCWSTR wzBundleFilePath,
7
+ __in LPCWSTR wzBAFilePath
8
+ )
9
+{
10
+ HRESULT hr = S_OK;
11
+ TestEngine* pTestEngine = NULL;
12
+
13
+ pTestEngine = new TestEngine();
14
+ ConsoleExitOnNull(pTestEngine, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to create new test engine.");
15
+
16
+ hr = pTestEngine->Initialize(wzBundleFilePath);
17
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to initialize engine.");
18
+
19
+ hr = pTestEngine->LoadBA(wzBAFilePath);
20
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to load BA.");
21
+
22
+ hr = pTestEngine->SendStartupEvent();
23
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
24
+
25
+ hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER);
26
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
27
+
28
+ pTestEngine->UnloadBA();
29
+
30
+ hr = pTestEngine->LoadBA(wzBAFilePath);
31
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to load BA.");
32
+
33
+ hr = pTestEngine->SendStartupEvent();
34
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup.");
35
+
36
+ hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RESTART);
37
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown.");
38
+
39
+ pTestEngine->UnloadBA();
40
+
41
+LExit:
42
+ return hr;
43
+}
src/test/examples/TestEngine/ReloadEngine.h
new
+8
@@ -0,0 +1,8 @@
1
+#pragma once
2
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
+
4
+
5
+HRESULT RunReloadEngine(
6
+ __in LPCWSTR wzBundleFilePath,
7
+ __in LPCWSTR wzBAFilePath
8
+ );
src/test/examples/TestEngine/ShutdownEngine.cpp
+4
-1
@@ -13,7 +13,10 @@ HRESULT RunShutdownEngine(
13
pTestEngine = new TestEngine();
14
ConsoleExitOnNull(pTestEngine, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to create new test engine.");
15
16
- hr = pTestEngine->LoadBA(wzBundleFilePath, wzBAFilePath);
16
+ hr = pTestEngine->Initialize(wzBundleFilePath);
17
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to initialize engine.");
18
+
19
+ hr = pTestEngine->LoadBA(wzBAFilePath);
20
ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to load BA.");
21
22
hr = pTestEngine->SendStartupEvent();
src/test/examples/TestEngine/ShutdownEngine.h
new
+8
@@ -0,0 +1,8 @@
1
+#pragma once
2
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
+
4
+
5
+HRESULT RunShutdownEngine(
6
+ __in LPCWSTR wzBundleFilePath,
7
+ __in LPCWSTR wzBAFilePath
8
+ );
src/test/examples/TestEngine/TestEngine.cpp
+25
-7
@@ -2,8 +2,22 @@
2
3
#include "precomp.h"
4
5
+HRESULT TestEngine::Initialize(
6
+ __in LPCWSTR wzBundleFilePath
7
+ )
8
+{
9
+ HRESULT hr = S_OK;
10
+
11
+ LogInitialize(::GetModuleHandleW(NULL));
12
+
13
+ hr = LogOpen(NULL, PathFile(wzBundleFilePath), NULL, L"txt", FALSE, FALSE, NULL);
14
+ ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log.");
15
+
16
+LExit:
17
+ return hr;
18
+}
19
+
20
HRESULT TestEngine::LoadBA(
6
- __in LPCWSTR wzBundleFilePath,
21
__in LPCWSTR wzBAFilePath
22
)
23
{
@@ -12,16 +26,11 @@ HRESULT TestEngine::LoadBA(
26
BOOTSTRAPPER_CREATE_ARGS args = { };
27
PFN_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = NULL;
28
15
- if (m_pCreateResults)
29
+ if (m_pCreateResults || m_hBAModule)
30
{
31
ExitFunction1(hr = E_INVALIDSTATE);
32
}
33
20
- LogInitialize(::GetModuleHandleW(NULL));
21
-
22
- hr = LogOpen(NULL, PathFile(wzBundleFilePath), NULL, L"txt", FALSE, FALSE, NULL);
23
- ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log.");
24
-
34
m_pCreateResults = static_cast<BOOTSTRAPPER_CREATE_RESULTS*>(MemAlloc(sizeof(BOOTSTRAPPER_CREATE_RESULTS), TRUE));
35
36
command.cbSize = sizeof(BOOTSTRAPPER_COMMAND);
@@ -51,6 +60,7 @@ HRESULT TestEngine::Log(
60
__in LPCWSTR wzMessage
61
)
62
{
63
+ LogStringLine(REPORT_STANDARD, "%ls", wzMessage);
64
return ConsoleWriteLine(CONSOLE_COLOR_NORMAL, "%ls", wzMessage);
65
}
66
@@ -83,12 +93,20 @@ void TestEngine::UnloadBA()
93
{
94
PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = NULL;
95
96
+ ReleaseNullMem(m_pCreateResults);
97
+
98
pfnDestroy = (PFN_BOOTSTRAPPER_APPLICATION_DESTROY)::GetProcAddress(m_hBAModule, "BootstrapperApplicationDestroy");
99
100
if (pfnDestroy)
101
{
102
pfnDestroy();
103
}
104
+
105
+ if (m_hBAModule)
106
+ {
107
+ ::FreeLibrary(m_hBAModule);
108
+ m_hBAModule = NULL;
109
+ }
110
}
111
112
HRESULT TestEngine::BAEngineLog(
src/test/examples/TestEngine/TestEngine.h
+4
-2
@@ -1,13 +1,15 @@
1
#pragma once
2
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
4
-#include "precomp.h"
4
5
class TestEngine
6
{
7
public:
8
+ HRESULT Initialize(
9
+ __in LPCWSTR wzBundleFilePath
10
+ );
11
+
12
HRESULT LoadBA(
10
- __in LPCWSTR wzBundleFilePath,
13
__in LPCWSTR wzBAFilePath
14
);
15
src/test/examples/TestEngine/precomp.h
+2
-5
@@ -14,8 +14,5 @@
14
#include "BootstrapperApplication.h"
15
16
#include "TestEngine.h"
17
-
18
-HRESULT RunShutdownEngine(
19
- __in LPCWSTR wzBundleFilePath,
20
- __in LPCWSTR wzBAFilePath
21
- );
17
+#include "ReloadEngine.h"
18
+#include "ShutdownEngine.h"