Commit 2486f5a0 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

kernel32/tests: Improve loading of debugger's test children results.

Even if there's a synchronisation mechanism between kernel32:debugger and its children which ensures that child has finished writing to and closed the blackbox logging file before reading it, there's no guarantee that the file is not re-opened by another process: antivirus, file indexing... And according to [1], even the OS itself can still have opened references to it. So, always open/read the blackbox file in read share mode to work around this issue. Also, harden the code for potential errors, and be nicer in where failures come from. [1] https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/irp-mj-cleanup Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53456Signed-off-by: 's avatarEric Pouech <eric.pouech@gmail.com>
parent 2acacb83
......@@ -132,38 +132,45 @@ static void save_blackbox(const char* logfile, void* blackbox, int size, const c
{
HANDLE hFile;
DWORD written;
BOOL ret;
hFile=CreateFileA(logfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
hFile = CreateFileA(logfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, 0);
ok(hFile != INVALID_HANDLE_VALUE, "Couldn't create %s: %lu\n", logfile, GetLastError());
if (hFile == INVALID_HANDLE_VALUE)
return;
WriteFile(hFile, blackbox, size, &written, NULL);
ret = WriteFile(hFile, blackbox, size, &written, NULL);
ok(ret && written == size, "Error writing\n");
if (dbgtrace && dbgtrace[0])
WriteFile(hFile, dbgtrace, strlen(dbgtrace), &written, NULL);
{
ret = WriteFile(hFile, dbgtrace, strlen(dbgtrace), &written, NULL);
ok(ret && written == strlen(dbgtrace), "Error writing\n");
}
CloseHandle(hFile);
}
static int load_blackbox(const char* logfile, void* blackbox, int size)
#define load_blackbox(a, b, c) _load_blackbox(__LINE__, (a), (b), (c))
static int _load_blackbox(unsigned int line, const char* logfile, void* blackbox, int size)
{
HANDLE hFile;
DWORD read;
BOOL ret;
char buf[4096];
hFile=CreateFileA(logfile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
hFile = CreateFileA(logfile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
if (hFile == INVALID_HANDLE_VALUE)
{
ok(0, "unable to open '%s'\n", logfile);
ok_(__FILE__, line)(0, "unable to open '%s': %#lx\n", logfile, GetLastError());
return 0;
}
SetLastError(0xdeadbeef);
ret=ReadFile(hFile, blackbox, size, &read, NULL);
ret = ReadFile(hFile, blackbox, size, &read, NULL);
ok(ret, "ReadFile failed: %ld\n", GetLastError());
ok(read == size, "wrong size for '%s': read=%ld\n", logfile, read);
ret = ReadFile(hFile, buf, sizeof(buf) - 1, &read, NULL);
if (ret && read)
{
buf[read] = 0;
trace("debugger traces:\n%s", buf);
trace("debugger traces:>>>\n%s\n<<< Done.\n", buf);
}
CloseHandle(hFile);
return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment