[PATCH 2/9] dbghelp/tests: Added ability to launch an external process instead of debugging self
Eric Pouech
eric.pouech at gmail.com
Mon Jul 12 07:20:14 CDT 2021
Signed-off-by: Eric Pouech <eric.pouech at gmail.com>
---
dlls/dbghelp/tests/dbghelp.c | 77 +++++++++++++++++++++++++++++++++++-------
1 file changed, 65 insertions(+), 12 deletions(-)
diff --git a/dlls/dbghelp/tests/dbghelp.c b/dlls/dbghelp/tests/dbghelp.c
index c9bbd90deb4..b0302b85ad1 100644
--- a/dlls/dbghelp/tests/dbghelp.c
+++ b/dlls/dbghelp/tests/dbghelp.c
@@ -24,6 +24,7 @@
struct debuggee
{
const char* name; /* name of main module */
+ BOOL external_process;
HANDLE hProcess;
HANDLE hThread; /* either new thread calling stack_walk_thread, or main thread */
};
@@ -126,30 +127,82 @@ static void test_stack_walk(const struct debuggee* dbg)
#endif /* __i386__ || __x86_64__ */
-START_TEST(dbghelp)
+static BOOL start_process(struct debuggee* dbg, const char* other)
{
- struct debuggee dbg;
DWORD count;
- BOOL ret;
- dbg.name = "self";
- dbg.hProcess = GetCurrentProcess();
- dbg.hThread = CreateThread(NULL, 0, stack_walk_thread, NULL, 0, NULL);
+ memset(dbg, 0, sizeof(*dbg));
+ if (other)
+ {
+ STARTUPINFOA siA;
+ PROCESS_INFORMATION pi;
+ memset(&siA, 0, sizeof(siA));
+ siA.cb = sizeof(siA);
+ memset(&pi, 0, sizeof(pi));
+
+ if (!CreateProcessA(other, NULL, NULL, NULL, FALSE,
+ NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL, &siA, &pi))
+ {
+ skip("Cannot launch %s\n", other);
+ return FALSE;
+ }
+ dbg->name = other;
+ dbg->external_process = TRUE;
+ dbg->hProcess = pi.hProcess;
+ dbg->hThread = pi.hThread;
+ }
+ else
+ {
+ char** argv;
+ winetest_get_mainargs(&argv);
+ dbg->name = argv[0];
+ dbg->external_process = FALSE;
+ dbg->hProcess = GetCurrentProcess();
+ dbg->hThread = CreateThread(NULL, 0, stack_walk_thread, NULL, 0, NULL);
+ }
+
+ if (!SymInitialize(dbg->hProcess, NULL, TRUE))
+ {
+ skip("Cannot init dbghelp on %s\n", dbg->name);
+ return FALSE;
+ }
/* wait for the thread to suspend itself */
do
{
Sleep(50);
- count = SuspendThread(dbg.hThread);
- ResumeThread(dbg.hThread);
+ count = SuspendThread(dbg->hThread);
+ ResumeThread(dbg->hThread);
}
while (!count);
- ret = SymInitialize(dbg.hProcess, NULL, TRUE);
- ok(ret, "got error %u\n", GetLastError());
+ return TRUE;
+}
- test_stack_walk(&dbg);
+static void close_process(const struct debuggee* dbg)
+{
+ BOOL ret;
- ret = SymCleanup(dbg.hProcess);
+ ret = SymCleanup(dbg->hProcess);
ok(ret, "got error %u\n", GetLastError());
+
+ if (dbg->external_process)
+ {
+ ok(TerminateProcess(dbg->hProcess, 1), "Couldn't terminate debuggee %u\n", GetLastError());
+ CloseHandle(dbg->hProcess);
+ CloseHandle(dbg->hThread);
+ }
+}
+
+START_TEST(dbghelp)
+{
+ struct debuggee dbg;
+ const char* other = getenv("WINETEST_DBGHELP_OTHER");
+
+ if (start_process(&dbg, other))
+ {
+ test_stack_walk(&dbg);
+
+ close_process(&dbg);
+ }
}
More information about the wine-devel
mailing list