Module: tools
Branch: master
Commit: dbe7ab2a74b347e773a74d7076dc1dabc521f94f
URL: https://source.winehq.org/git/tools.git/?a=commit;h=dbe7ab2a74b347e773a74d7…
Author: Francois Gouget <fgouget(a)codeweavers.com>
Date: Thu Oct 31 17:03:23 2019 +0100
testbot/testagentd: Fix the console when redirecting stdin/out/err on Windows.
When When TestAgentd runs in --detach mode it does not have a console.
The child console processes still get a console but when using
STARTF_USESTDHANDLES the non-redirected stdin/out/err ifile handles
would not point to it. This appears to be because CreateProcess()
compares the STARTUPINFO handles with the parent's GetStdHandle() ones
and only reconnects them to the child console if they match.
So if the parent has no console the child inherits garbage values for
the GetStdHandle()s, that is GetFileType() returns FILE_TYPE_UNKNOWN for
those and their behavior is somewhat random. This would break some
kernel32:console STD_INPUT_HANDLE tests.
So when in --detach mode TestAgentd now creates a new console before
calling CreateProcess(). This resets stdin/out/err to point to the
console causing the child process to inherit proper handle values.
TestAgentd then detaches from the console which means it may just flash
on screen if starting a GUI application.
Increment the version so clients can check whether Run() redirections
are fully usable.
Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
---
testbot/src/testagentd/platform_windows.c | 8 +++++++-
testbot/src/testagentd/testagentd.c | 1 +
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/testbot/src/testagentd/platform_windows.c b/testbot/src/testagentd/platform_windows.c
index ea6f03f..057e8fc 100644
--- a/testbot/src/testagentd/platform_windows.c
+++ b/testbot/src/testagentd/platform_windows.c
@@ -29,9 +29,10 @@ struct child_t
DWORD pid;
HANDLE handle;
};
-
static struct list children = LIST_INIT(children);
+static BOOLEAN detached = FALSE;
+
uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
{
@@ -79,6 +80,8 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
*(d-1) = '\0';
/* Prepare the redirections */
+ if (detached)
+ AllocConsole();
has_redirects = 0;
for (i = 0; i < 3; i++)
{
@@ -149,6 +152,8 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
for (i = 0; i < 3; i++)
if (redirects[i][0])
CloseHandle(fhs[i]);
+ if (detached)
+ platform_detach_console();
return pi.dwProcessId;
}
@@ -692,6 +697,7 @@ void platform_detach_console(void)
SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);
SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
+ detached = TRUE;
}
int platform_init(void)
diff --git a/testbot/src/testagentd/testagentd.c b/testbot/src/testagentd/testagentd.c
index eb93aa2..994f7c2 100644
--- a/testbot/src/testagentd/testagentd.c
+++ b/testbot/src/testagentd/testagentd.c
@@ -41,6 +41,7 @@
* 1.7: Add --show-restarts and the setproperty RPC.
* 1.8: Add the restart RPC, server.arg* properties, fix upgrades if >1
* server.
+ * 1.9: Fix the console handling when redirecting stdin/out/err on Windows.
*/
#define PROTOCOL_VERSION "testagentd 1.8"
Module: tools
Branch: master
Commit: 443043bbe4c8d495912576b76625d82e43be57f9
URL: https://source.winehq.org/git/tools.git/?a=commit;h=443043bbe4c8d495912576b…
Author: Francois Gouget <fgouget(a)codeweavers.com>
Date: Thu Oct 31 16:54:23 2019 +0100
testbot/WineRunTask: Use a trampoline script to capture cmd errors.
This side-steps the console / redirection bug in the currently deployed
versions of TestAgentd.
This also side-steps cmd's command line parsing bug. When given
["cmd". "/c", "script.bat >Task.log"] TestAgent would build a command
line of the form '"cmd" "/c" "script.bat >Task.log"' which would lead
cmd to try to run '"script.bat >Task.log'. This would fail because of
the extraneous double quote. Note that cmd fails in the same way for
'cmd "/c" "script.bat >Task.log"'.
Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
---
testbot/bin/WineRunTask.pl | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/testbot/bin/WineRunTask.pl b/testbot/bin/WineRunTask.pl
index 0177e05..1f21050 100755
--- a/testbot/bin/WineRunTask.pl
+++ b/testbot/bin/WineRunTask.pl
@@ -502,14 +502,19 @@ if (!$TA->SendFileFromString($Script, "script.bat", $TestAgent::SENDFILE_EXE))
FatalTAError($TA, "Could not send the task script to the VM");
}
+my $Logger = "script.bat >Task.log 2>&1\r\n";
+if (!$TA->SendFileFromString($Logger, "cmdlogger.bat", $TestAgent::SENDFILE_EXE))
+{
+ FatalTAError($TA, "Could not send the logging script to the VM");
+}
+
#
# Run the test
#
Debug(Elapsed($Start), " Starting the script\n");
-my $TaskLog = $TA->HasMinVersion(1, 7) ? "Task.log" : undef;
-my $Pid = $TA->Run(["./script.bat"], 0, undef, $TaskLog, $TaskLog);
+my $Pid = $TA->Run(["./cmdlogger.bat"], 0);
if (!$Pid)
{
FatalTAError($TA, "Failed to start the test");
@@ -540,13 +545,10 @@ if (!defined $TA->Wait($Pid, $Timeout, $Keepalive))
}
}
-if (defined $TaskLog)
+Debug(Elapsed($Start), " Retrieving 'Task.log'\n");
+if (!$TA->GetFile("Task.log", "$TaskDir/log") and !defined $TAError)
{
- Debug(Elapsed($Start), " Retrieving 'Task.log'\n");
- if (!$TA->GetFile($TaskLog, "$TaskDir/log") and !defined $TAError)
- {
- $TAError = "An error occurred while retrieving the task log: ". $TA->GetLastError();
- }
+ $TAError = "An error occurred while retrieving the task log: ". $TA->GetLastError();
}
Debug(Elapsed($Start), " Retrieving the report file to '$RptFileName'\n");