diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-29 10:29:14 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-29 15:08:37 -0500 |
| commit | ec413164bd0285d1e9b9d36538974641a109b579 (patch) | |
| tree | a8c38c1c1c883eee7897efa179ce1379384871c8 /src/burn/test/BurnUnitTest/EmbeddedTest.cpp | |
| parent | 7cca75c8e95f129a21c33f1f4568e90e9e397f9d (diff) | |
| download | wix-ec413164bd0285d1e9b9d36538974641a109b579.tar.gz wix-ec413164bd0285d1e9b9d36538974641a109b579.tar.bz2 wix-ec413164bd0285d1e9b9d36538974641a109b579.zip | |
Add embedded test.
Diffstat (limited to '')
| -rw-r--r-- | src/burn/test/BurnUnitTest/EmbeddedTest.cpp | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/src/burn/test/BurnUnitTest/EmbeddedTest.cpp b/src/burn/test/BurnUnitTest/EmbeddedTest.cpp new file mode 100644 index 00000000..cac1ba81 --- /dev/null +++ b/src/burn/test/BurnUnitTest/EmbeddedTest.cpp | |||
| @@ -0,0 +1,175 @@ | |||
| 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 | |||
| 6 | const HRESULT S_TEST_SUCCEEDED = 0x3133; | ||
| 7 | const DWORD TEST_EXIT_CODE = 666; | ||
| 8 | |||
| 9 | struct BUNDLE_RUNNER_CONTEXT | ||
| 10 | { | ||
| 11 | DWORD dwResult; | ||
| 12 | }; | ||
| 13 | |||
| 14 | |||
| 15 | static BOOL STDAPICALLTYPE EmbeddedTest_CreateProcessW( | ||
| 16 | __in_opt LPCWSTR lpApplicationName, | ||
| 17 | __inout_opt LPWSTR lpCommandLine, | ||
| 18 | __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, | ||
| 19 | __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, | ||
| 20 | __in BOOL bInheritHandles, | ||
| 21 | __in DWORD dwCreationFlags, | ||
| 22 | __in_opt LPVOID lpEnvironment, | ||
| 23 | __in_opt LPCWSTR lpCurrentDirectory, | ||
| 24 | __in LPSTARTUPINFOW lpStartupInfo, | ||
| 25 | __out LPPROCESS_INFORMATION lpProcessInformation | ||
| 26 | ); | ||
| 27 | static DWORD CALLBACK EmbeddedTest_ThreadProc( | ||
| 28 | __in LPVOID lpThreadParameter | ||
| 29 | ); | ||
| 30 | static int EmbeddedTest_GenericMessageHandler( | ||
| 31 | __in GENERIC_EXECUTE_MESSAGE* pMessage, | ||
| 32 | __in LPVOID pvContext | ||
| 33 | ); | ||
| 34 | |||
| 35 | namespace Microsoft | ||
| 36 | { | ||
| 37 | namespace Tools | ||
| 38 | { | ||
| 39 | namespace WindowsInstallerXml | ||
| 40 | { | ||
| 41 | namespace Test | ||
| 42 | { | ||
| 43 | namespace Bootstrapper | ||
| 44 | { | ||
| 45 | using namespace System; | ||
| 46 | using namespace System::IO; | ||
| 47 | using namespace System::Threading; | ||
| 48 | using namespace Xunit; | ||
| 49 | |||
| 50 | public ref class EmbeddedTest : BurnUnitTest | ||
| 51 | { | ||
| 52 | public: | ||
| 53 | EmbeddedTest(BurnTestFixture^ fixture) : BurnUnitTest(fixture) | ||
| 54 | { | ||
| 55 | } | ||
| 56 | |||
| 57 | [Fact] | ||
| 58 | void EmbeddedProtocolTest() | ||
| 59 | { | ||
| 60 | HRESULT hr = S_OK; | ||
| 61 | BUNDLE_RUNNER_CONTEXT bundleRunnerContext = { }; | ||
| 62 | DWORD dwExitCode = 0; | ||
| 63 | |||
| 64 | try | ||
| 65 | { | ||
| 66 | CoreFunctionOverride(EmbeddedTest_CreateProcessW, ThrdWaitForCompletion); | ||
| 67 | |||
| 68 | // | ||
| 69 | // bundle runner setup | ||
| 70 | // | ||
| 71 | hr = EmbeddedRunBundle(L"C:\\ignored\\target.exe", L"\"C:\\ignored\\target.exe\"", NULL, EmbeddedTest_GenericMessageHandler, &bundleRunnerContext, &dwExitCode); | ||
| 72 | TestThrowOnFailure(hr, L"Failed to run embedded bundle."); | ||
| 73 | |||
| 74 | // check results | ||
| 75 | Assert::Equal<HRESULT>(S_TEST_SUCCEEDED, (HRESULT)bundleRunnerContext.dwResult); | ||
| 76 | Assert::Equal<DWORD>(TEST_EXIT_CODE, dwExitCode); | ||
| 77 | } | ||
| 78 | finally | ||
| 79 | { | ||
| 80 | } | ||
| 81 | } | ||
| 82 | }; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | static BOOL STDAPICALLTYPE EmbeddedTest_CreateProcessW( | ||
| 91 | __in_opt LPCWSTR /*lpApplicationName*/, | ||
| 92 | __inout_opt LPWSTR lpCommandLine, | ||
| 93 | __in_opt LPSECURITY_ATTRIBUTES /*lpProcessAttributes*/, | ||
| 94 | __in_opt LPSECURITY_ATTRIBUTES /*lpThreadAttributes*/, | ||
| 95 | __in BOOL /*bInheritHandles*/, | ||
| 96 | __in DWORD /*dwCreationFlags*/, | ||
| 97 | __in_opt LPVOID /*lpEnvironment*/, | ||
| 98 | __in_opt LPCWSTR /*lpCurrentDirectory*/, | ||
| 99 | __in LPSTARTUPINFOW /*lpStartupInfo*/, | ||
| 100 | __out LPPROCESS_INFORMATION lpProcessInformation | ||
| 101 | ) | ||
| 102 | { | ||
| 103 | HRESULT hr = S_OK; | ||
| 104 | LPWSTR scz = NULL; | ||
| 105 | LPCWSTR wzArgs = lpCommandLine + 24; //skip '"C:\ignored\target.exe" ' | ||
| 106 | |||
| 107 | hr = StrAllocString(&scz, wzArgs, 0); | ||
| 108 | ExitOnFailure(hr, "Failed to copy arguments."); | ||
| 109 | |||
| 110 | // Pretend this thread is the embedded process. | ||
| 111 | lpProcessInformation->hProcess = ::CreateThread(NULL, 0, EmbeddedTest_ThreadProc, scz, 0, NULL); | ||
| 112 | ExitOnNullWithLastError(lpProcessInformation->hProcess, hr, "Failed to create thread."); | ||
| 113 | |||
| 114 | scz = NULL; | ||
| 115 | |||
| 116 | LExit: | ||
| 117 | ReleaseStr(scz); | ||
| 118 | |||
| 119 | return SUCCEEDED(hr); | ||
| 120 | } | ||
| 121 | |||
| 122 | static DWORD CALLBACK EmbeddedTest_ThreadProc( | ||
| 123 | __in LPVOID lpThreadParameter | ||
| 124 | ) | ||
| 125 | { | ||
| 126 | HRESULT hr = S_OK; | ||
| 127 | LPWSTR sczArguments = (LPWSTR)lpThreadParameter; | ||
| 128 | BURN_ENGINE_STATE engineState = { }; | ||
| 129 | BURN_PIPE_CONNECTION* pConnection = &engineState.embeddedConnection; | ||
| 130 | DWORD dwResult = 0; | ||
| 131 | |||
| 132 | engineState.internalCommand.mode = BURN_MODE_EMBEDDED; | ||
| 133 | |||
| 134 | PipeConnectionInitialize(pConnection); | ||
| 135 | |||
| 136 | StrAlloc(&pConnection->sczName, MAX_PATH); | ||
| 137 | StrAlloc(&pConnection->sczSecret, MAX_PATH); | ||
| 138 | |||
| 139 | // parse command line arguments | ||
| 140 | if (3 != swscanf_s(sczArguments, L"-burn.embedded %s %s %u", pConnection->sczName, MAX_PATH, pConnection->sczSecret, MAX_PATH, &pConnection->dwProcessId)) | ||
| 141 | { | ||
| 142 | ExitWithRootFailure(hr, E_INVALIDARG, "Failed to parse argument string."); | ||
| 143 | } | ||
| 144 | |||
| 145 | // set up connection with parent bundle runner | ||
| 146 | hr = PipeChildConnect(pConnection, FALSE); | ||
| 147 | ExitOnFailure(hr, "Failed to connect to parent bundle runner."); | ||
| 148 | |||
| 149 | // post known message | ||
| 150 | hr = ExternalEngineSendEmbeddedError(&engineState, S_TEST_SUCCEEDED, NULL, 0, reinterpret_cast<int*>(&dwResult)); | ||
| 151 | ExitOnFailure(hr, "Failed to post known message to parent bundle runner."); | ||
| 152 | |||
| 153 | LExit: | ||
| 154 | PipeConnectionUninitialize(pConnection); | ||
| 155 | ReleaseStr(sczArguments); | ||
| 156 | |||
| 157 | return FAILED(hr) ? (DWORD)hr : dwResult; | ||
| 158 | } | ||
| 159 | |||
| 160 | static int EmbeddedTest_GenericMessageHandler( | ||
| 161 | __in GENERIC_EXECUTE_MESSAGE* pMessage, | ||
| 162 | __in LPVOID pvContext | ||
| 163 | ) | ||
| 164 | { | ||
| 165 | BUNDLE_RUNNER_CONTEXT* pContext = reinterpret_cast<BUNDLE_RUNNER_CONTEXT*>(pvContext); | ||
| 166 | DWORD dwResult = 0; | ||
| 167 | |||
| 168 | if (GENERIC_EXECUTE_MESSAGE_ERROR == pMessage->type) | ||
| 169 | { | ||
| 170 | pContext->dwResult = pMessage->error.dwErrorCode; | ||
| 171 | dwResult = TEST_EXIT_CODE; | ||
| 172 | } | ||
| 173 | |||
| 174 | return dwResult; | ||
| 175 | } | ||
