Francois Gouget : testbot/TestAgent: Extend and fix the run RPC' s redirection options.

Alexandre Julliard julliard at winehq.org
Mon Feb 25 14:02:21 CST 2013


Module: tools
Branch: master
Commit: 3fca08b59407b3e7c215e5d9298ccd267cce3831
URL:    http://source.winehq.org/git/tools.git/?a=commit;h=3fca08b59407b3e7c215e5d9298ccd267cce3831

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Mon Feb 25 17:40:42 2013 +0100

testbot/TestAgent: Extend and fix the run RPC's redirection options.

Always set up the stdout and stderr redirections for append so they
don't overwrite each other.  Add options to prevent the truncation of
the files stdout and stderr are redirected to. This makes it possible
to run multiple commands in a row and to collect all their output in a
single file.

---

 testbot/lib/WineTestBot/TestAgent.pm      |    5 ++++-
 testbot/scripts/TestAgent                 |   10 ++++++++++
 testbot/src/testagentd/platform.h         |    2 ++
 testbot/src/testagentd/platform_unix.c    |   16 ++++++++++++++--
 testbot/src/testagentd/platform_windows.c |   19 ++++++++++++++++++-
 testbot/src/testagentd/testagentd.c       |   11 ++++++-----
 6 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/testbot/lib/WineTestBot/TestAgent.pm b/testbot/lib/WineTestBot/TestAgent.pm
index c3326d6..074e4f0 100644
--- a/testbot/lib/WineTestBot/TestAgent.pm
+++ b/testbot/lib/WineTestBot/TestAgent.pm
@@ -21,7 +21,7 @@
 package TestAgent;
 use strict;
 
-use vars qw (@ISA @EXPORT_OK $SENDFILE_EXE $RUN_DNT);
+use vars qw (@ISA @EXPORT_OK $SENDFILE_EXE $RUN_DNT $RUN_DNTRUNC_OUT $RUN_DNTRUNC_ERR $RUN_DNTRUNC);
 
 require Exporter;
 @ISA = qw(Exporter);
@@ -1031,6 +1031,9 @@ sub GetFileToString($$)
 }
 
 $RUN_DNT = 1;
+$RUN_DNTRUNC_OUT = 2;
+$RUN_DNTRUNC_ERR = 4;
+$RUN_DNTRUNC = $RUN_DNTRUNC_OUT | $RUN_DNTRUNC_ERR;
 
 sub Run($$$;$$$)
 {
diff --git a/testbot/scripts/TestAgent b/testbot/scripts/TestAgent
index 1424998..521e741 100755
--- a/testbot/scripts/TestAgent
+++ b/testbot/scripts/TestAgent
@@ -120,6 +120,14 @@ while (@ARGV)
     {
         $RunErr = check_opt_val($arg, $RunErr);
     }
+    elsif ($arg eq "--run-dntrunc-out")
+    {
+        $RunFlags |= $TestAgent::RUN_DNTRUNC_OUT;
+    }
+    elsif ($arg eq "--run-dntrunc-err")
+    {
+        $RunFlags |= $TestAgent::RUN_DNTRUNC_ERR;
+    }
     elsif (!defined $Hostname)
     {
         $Hostname = $arg;
@@ -252,8 +260,10 @@ if (defined $Usage)
     print "                  specified server file.\n";
     print "    --run-out <serverpath> Redirect the stdout or the command being run to the\n";
     print "                  specified server file.\n";
+    print "    --run-dntrunc-out Do not truncate the file stdout is redirected to.\n";
     print "    --run-err <serverpath> Redirect the stderr or the command being run to the\n";
     print "                  specified server file.\n";
+    print "    --run-dntrunc-err Do not truncate the file stderr is redirected to.\n";
     print "  rm            Deletes the specified files on the server.\n";
     print "  getversion    Returns the version of the server.\n";
     print "  ping          Makes sure the server is still alive.\n";
diff --git a/testbot/src/testagentd/platform.h b/testbot/src/testagentd/platform.h
index d2a3934..621ce98 100644
--- a/testbot/src/testagentd/platform.h
+++ b/testbot/src/testagentd/platform.h
@@ -60,6 +60,8 @@ int platform_init(void);
 
 enum run_flags_t {
     RUN_DNT = 1,
+    RUN_DNTRUNC_OUT = 2,
+    RUN_DNTRUNC_ERR = 4,
 };
 
 /* Starts the specified command in the background and reports the status to
diff --git a/testbot/src/testagentd/platform_unix.c b/testbot/src/testagentd/platform_unix.c
index 6552e05..48eef73 100644
--- a/testbot/src/testagentd/platform_unix.c
+++ b/testbot/src/testagentd/platform_unix.c
@@ -69,13 +69,25 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
 {
     pid_t pid;
     int fds[3] = {-1, -1, -1};
-    int i;
+    int ofl, i;
 
     for (i = 0; i < 3; i++)
     {
         if (redirects[i][0] == '\0')
             continue;
-        fds[i] = open(redirects[i], (i ? O_WRONLY : O_RDONLY) | O_CREAT | O_TRUNC);
+        switch (i)
+        {
+        case 0:
+            ofl = O_RDONLY;
+            break;
+        case 1:
+            ofl = O_APPEND | O_CREAT | (flags & RUN_DNTRUNC_OUT ? 0 : O_TRUNC);
+            break;
+        case 2:
+            ofl = O_APPEND | O_CREAT | (flags & RUN_DNTRUNC_ERR ? 0 : O_TRUNC);
+            break;
+        }
+        fds[i] = open(redirects[i], ofl, 0666);
         if (fds[i] < 0)
         {
             set_status(ST_ERROR, "unable to open '%s' for %s: %s", redirects[i], i ? "writing" : "reading", strerror(errno));
diff --git a/testbot/src/testagentd/platform_windows.c b/testbot/src/testagentd/platform_windows.c
index 9e5bf78..10ea55a 100644
--- a/testbot/src/testagentd/platform_windows.c
+++ b/testbot/src/testagentd/platform_windows.c
@@ -82,13 +82,30 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
     has_redirects = 0;
     for (i = 0; i < 3; i++)
     {
+        DWORD access, creation;
         if (redirects[i][0] == '\0')
         {
             fhs[i] = GetStdHandle(stdhandles[i]);
             continue;
         }
         has_redirects = 1;
-        fhs[i] = CreateFile(redirects[i], (i ? GENERIC_WRITE : GENERIC_READ), FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+        switch (i)
+        {
+        case 0:
+            access = GENERIC_READ;
+            creation = OPEN_EXISTING;
+            break;
+        case 1:
+            access = FILE_APPEND_DATA;
+            creation = (flags & RUN_DNTRUNC_OUT ? OPEN_ALWAYS : CREATE_ALWAYS);
+            break;
+        case 2:
+            access = FILE_APPEND_DATA;
+            creation = (flags & RUN_DNTRUNC_ERR ? OPEN_ALWAYS : CREATE_ALWAYS);
+            break;
+        }
+        fhs[i] = CreateFile(redirects[i], access, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, creation, FILE_ATTRIBUTE_NORMAL, NULL);
+        debug("  %d redirected -> %p\n", i, fhs[i]);
         if (fhs[i] == INVALID_HANDLE_VALUE)
         {
             set_status(ST_ERROR, "unable to open '%s' for %s: %lu", redirects[i], i ? "writing" : "reading", GetLastError());
diff --git a/testbot/src/testagentd/testagentd.c b/testbot/src/testagentd/testagentd.c
index 8a8f2bb..c06af72 100644
--- a/testbot/src/testagentd/testagentd.c
+++ b/testbot/src/testagentd/testagentd.c
@@ -33,8 +33,9 @@
  * Otherwise increase the minor version number:
  * 1.0:  Initial release.
  * 1.1:  Added the wait2 RPC.
+ * 1.2:  Add more redirection options to the run RPC.
  */
-#define PROTOCOL_VERSION "testagentd 1.1"
+#define PROTOCOL_VERSION "testagentd 1.2"
 
 #define BLOCK_SIZE       4096
 
@@ -730,10 +731,10 @@ static void do_run(SOCKET client)
         debug("  run '%s", argv[0]);
         for (i = 1; i < argc; i++)
             debug("' '%s", argv[i]);
-        debug("' %s%s%s%s%s%s\n",
-              redirects[0][0] ? " <" : "", redirects[0],
-              redirects[1][0] ? " >" : "", redirects[1],
-              redirects[2][0] ? " 2>" : "", redirects[2]);
+        debug("'%s%s%s%s%s%s\n",
+              !redirects[0][0] ? "" : " <", redirects[0],
+              !redirects[1][0] ? "" : (flags & RUN_DNTRUNC_OUT) ? " >>" : " >", redirects[1],
+              !redirects[2][0] ? "" : (flags & RUN_DNTRUNC_ERR) ? " 2>>" : " 2>", redirects[2]);
 
         pid = platform_run(argv, flags, redirects);
         if (!pid)




More information about the wine-cvs mailing list