From bd3ee565f342bc0bb015594f303d13b67285a958 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Thu, 23 Apr 2020 12:17:32 +1000 Subject: Update ManagedHost tests to run off of a bundle. --- src/test/examples/TestEngine/ExampleTestEngine.cpp | 8 ++--- src/test/examples/TestEngine/ShutdownEngine.cpp | 8 ++++- src/test/examples/TestEngine/TestEngine.cpp | 34 ++++++++++++++++++---- src/test/examples/TestEngine/TestEngine.h | 6 ++++ src/test/examples/TestEngine/precomp.h | 2 ++ 5 files changed, 48 insertions(+), 10 deletions(-) (limited to 'src/test/examples/TestEngine') diff --git a/src/test/examples/TestEngine/ExampleTestEngine.cpp b/src/test/examples/TestEngine/ExampleTestEngine.cpp index 9f051875..848b385c 100644 --- a/src/test/examples/TestEngine/ExampleTestEngine.cpp +++ b/src/test/examples/TestEngine/ExampleTestEngine.cpp @@ -8,15 +8,15 @@ int __cdecl wmain(int argc, LPWSTR argv[]) ConsoleInitialize(); - if (argc != 2) + if (argc != 3) { - ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Usage: Example.TestEngine.exe BA.dll"); + ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Usage: Example.TestEngine.exe Bundle.exe BA.dll"); } else { - hr = RunShutdownEngine(argv[1]); + hr = RunShutdownEngine(argv[1], argv[2]); } ConsoleUninitialize(); - return HRESULT_CODE(hr); + return hr; } diff --git a/src/test/examples/TestEngine/ShutdownEngine.cpp b/src/test/examples/TestEngine/ShutdownEngine.cpp index 69321d91..912d36ba 100644 --- a/src/test/examples/TestEngine/ShutdownEngine.cpp +++ b/src/test/examples/TestEngine/ShutdownEngine.cpp @@ -3,6 +3,7 @@ #include "precomp.h" HRESULT RunShutdownEngine( + __in LPCWSTR wzBundleFilePath, __in LPCWSTR wzBAFilePath ) { @@ -12,12 +13,17 @@ HRESULT RunShutdownEngine( pTestEngine = new TestEngine(); ConsoleExitOnNull(pTestEngine, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to create new test engine."); - hr = pTestEngine->LoadBA(wzBAFilePath); + hr = pTestEngine->LoadBA(wzBundleFilePath, wzBAFilePath); ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to load BA."); + hr = pTestEngine->SendStartupEvent(); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnStartup."); + hr = pTestEngine->SendShutdownEvent(BOOTSTRAPPER_SHUTDOWN_ACTION_RELOAD_BOOTSTRAPPER); ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "BA returned failure for OnShutdown."); + pTestEngine->UnloadBA(); + LExit: return hr; } diff --git a/src/test/examples/TestEngine/TestEngine.cpp b/src/test/examples/TestEngine/TestEngine.cpp index c0a62eda..9d8f8638 100644 --- a/src/test/examples/TestEngine/TestEngine.cpp +++ b/src/test/examples/TestEngine/TestEngine.cpp @@ -3,13 +3,13 @@ #include "precomp.h" HRESULT TestEngine::LoadBA( + __in LPCWSTR wzBundleFilePath, __in LPCWSTR wzBAFilePath ) { HRESULT hr = S_OK; BOOTSTRAPPER_COMMAND command = { }; BOOTSTRAPPER_CREATE_ARGS args = { }; - HMODULE hBAModule = NULL; PFN_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = NULL; if (m_pCreateResults) @@ -19,7 +19,7 @@ HRESULT TestEngine::LoadBA( LogInitialize(::GetModuleHandleW(NULL)); - hr = LogOpen(NULL, L"ExampleTestEngine", NULL, L"txt", FALSE, FALSE, NULL); + hr = LogOpen(NULL, PathFile(wzBundleFilePath), NULL, L"txt", FALSE, FALSE, NULL); ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "Failed to open log."); m_pCreateResults = static_cast(MemAlloc(sizeof(BOOTSTRAPPER_CREATE_RESULTS), TRUE)); @@ -34,10 +34,10 @@ HRESULT TestEngine::LoadBA( m_pCreateResults->cbSize = sizeof(BOOTSTRAPPER_CREATE_RESULTS); - hBAModule = ::LoadLibraryExW(wzBAFilePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); - ExitOnNullWithLastError(hBAModule, hr, "Failed to load BA dll."); + m_hBAModule = ::LoadLibraryExW(wzBAFilePath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + ExitOnNullWithLastError(m_hBAModule, hr, "Failed to load BA dll."); - pfnCreate = (PFN_BOOTSTRAPPER_APPLICATION_CREATE)::GetProcAddress(hBAModule, "BootstrapperApplicationCreate"); + pfnCreate = (PFN_BOOTSTRAPPER_APPLICATION_CREATE)::GetProcAddress(m_hBAModule, "BootstrapperApplicationCreate"); ConsoleExitOnNull(pfnCreate, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "Failed to get address for BootstrapperApplicationCreate."); hr = pfnCreate(&args, m_pCreateResults); @@ -68,6 +68,29 @@ HRESULT TestEngine::SendShutdownEvent( return hr; } +HRESULT TestEngine::SendStartupEvent() +{ + HRESULT hr = S_OK; + BA_ONSTARTUP_ARGS startupArgs = { }; + BA_ONSTARTUP_RESULTS startupResults = { }; + startupArgs.cbSize = sizeof(BA_ONSTARTUP_ARGS); + startupResults.cbSize = sizeof(BA_ONSTARTUP_RESULTS); + hr = m_pCreateResults->pfnBootstrapperApplicationProc(BOOTSTRAPPER_APPLICATION_MESSAGE_ONSTARTUP, &startupArgs, &startupResults, m_pCreateResults->pvBootstrapperApplicationProcContext); + return hr; +} + +void TestEngine::UnloadBA() +{ + PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = NULL; + + pfnDestroy = (PFN_BOOTSTRAPPER_APPLICATION_DESTROY)::GetProcAddress(m_hBAModule, "BootstrapperApplicationDestroy"); + + if (pfnDestroy) + { + pfnDestroy(); + } +} + HRESULT TestEngine::BAEngineLog( __in TestEngine* pContext, __in BAENGINE_LOG_ARGS* pArgs, @@ -108,6 +131,7 @@ LExit: TestEngine::TestEngine() { + m_hBAModule = NULL; m_pCreateResults = NULL; } diff --git a/src/test/examples/TestEngine/TestEngine.h b/src/test/examples/TestEngine/TestEngine.h index 52872100..e5db9480 100644 --- a/src/test/examples/TestEngine/TestEngine.h +++ b/src/test/examples/TestEngine/TestEngine.h @@ -7,6 +7,7 @@ class TestEngine { public: HRESULT LoadBA( + __in LPCWSTR wzBundleFilePath, __in LPCWSTR wzBAFilePath ); @@ -18,6 +19,10 @@ public: __in BOOTSTRAPPER_SHUTDOWN_ACTION defaultAction ); + HRESULT SendStartupEvent(); + + void UnloadBA(); + private: static HRESULT BAEngineLog( __in TestEngine* pContext, @@ -38,5 +43,6 @@ public: ~TestEngine(); private: + HMODULE m_hBAModule; BOOTSTRAPPER_CREATE_RESULTS* m_pCreateResults; }; \ No newline at end of file diff --git a/src/test/examples/TestEngine/precomp.h b/src/test/examples/TestEngine/precomp.h index 6e867e89..d0068747 100644 --- a/src/test/examples/TestEngine/precomp.h +++ b/src/test/examples/TestEngine/precomp.h @@ -8,6 +8,7 @@ #include "conutil.h" #include "logutil.h" #include "memutil.h" +#include "pathutil.h" #include "BootstrapperEngine.h" #include "BootstrapperApplication.h" @@ -15,5 +16,6 @@ #include "TestEngine.h" HRESULT RunShutdownEngine( + __in LPCWSTR wzBundleFilePath, __in LPCWSTR wzBAFilePath ); -- cgit v1.2.3-55-g6feb