[Lldb-commits] [lldb] r237328 - [TestAttachDenied] Use a file instead of a pipe for synchronization.

Siva Chandra sivachandra at google.com
Wed May 13 18:36:47 PDT 2015


Author: sivachandra
Date: Wed May 13 20:36:47 2015
New Revision: 237328

URL: http://llvm.org/viewvc/llvm-project?rev=237328&view=rev
Log:
[TestAttachDenied] Use a file instead of a pipe for synchronization.

Summary:
One cannot use mknod or mkfifo on user Android devices. This commit
changes the use of pipe to a file to synchronize between the inferior
and the test.

Test Plan: dotest.py -P TestAttachDenied

Reviewers: ovyalov, chaoren

Reviewed By: chaoren

Subscribers: tberghammer, lldb-commits

Differential Revision: http://reviews.llvm.org/D9768

Modified:
    lldb/trunk/test/functionalities/process_attach/attach_denied/TestAttachDenied.py
    lldb/trunk/test/functionalities/process_attach/attach_denied/main.cpp

Modified: lldb/trunk/test/functionalities/process_attach/attach_denied/TestAttachDenied.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/process_attach/attach_denied/TestAttachDenied.py?rev=237328&r1=237327&r2=237328&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/process_attach/attach_denied/TestAttachDenied.py (original)
+++ lldb/trunk/test/functionalities/process_attach/attach_denied/TestAttachDenied.py Wed May 13 20:36:47 2015
@@ -18,7 +18,7 @@ class AttachDeniedTestCase(TestBase):
         platform = self.dbg.GetSelectedPlatform()
         shell_command = lldb.SBPlatformShellCommand(cmd)
         err = platform.Run(shell_command)
-        return (err, shell_command.GetOutput())
+        return (err, shell_command.GetStatus(), shell_command.GetOutput())
 
     @skipIfWindows
     def test_attach_to_process_by_id_denied(self):
@@ -27,26 +27,30 @@ class AttachDeniedTestCase(TestBase):
         self.buildDefault()
         exe = os.path.join(os.getcwd(), exe_name)
 
-        # Use named pipe as a synchronization point between test and inferior.
-        pid_pipe_path = os.path.join(self.get_process_working_directory(),
-                                     "pid_pipe_%d" % (int(time.time())))
-
-        triple = self.dbg.GetSelectedPlatform().GetTriple()
-        if re.match(".*-.*-.*-android", triple):
-            err, _ = self.run_platform_command("mknod %s p" % (pid_pipe_path))
-        else:
-            err, _ = self.run_platform_command("mkfifo %s" % (pid_pipe_path))
-
-        self.assertTrue(err.Success(), "Failed to create FIFO %s: %s" % (pid_pipe_path, err.GetCString()))
-
-        self.addTearDownHook(lambda: self.run_platform_command("rm %s" % (pid_pipe_path)))
+        # Use a file as a synchronization point between test and inferior.
+        pid_file_path = os.path.join(self.get_process_working_directory(),
+                                     "pid_file_%d" % (int(time.time())))
+        self.addTearDownHook(lambda: self.run_platform_command("rm %s" % (pid_file_path)))
 
         # Spawn a new process
-        popen = self.spawnSubprocess(exe, [pid_pipe_path])
+        popen = self.spawnSubprocess(exe, [pid_file_path])
         self.addTearDownHook(self.cleanupSubprocesses)
 
-        err, pid = self.run_platform_command("cat %s" % (pid_pipe_path))
-        self.assertTrue(err.Success(), "Failed to read FIFO %s: %s" % (pid_pipe_path, err.GetCString()))
+        max_attempts = 5
+        for i in range(max_attempts):
+            err, retcode, msg = self.run_platform_command("ls %s" % pid_file_path)
+            if err.Success() and retcode == 0:
+                break
+            else:
+                print msg
+            if i < max_attempts:
+                # Exponential backoff!
+                time.sleep(pow(2, i) * 0.25)
+        else:
+            self.fail("Child PID file %s not found even after %d attempts." % (pid_file_path, max_attempts))
+        err, retcode, pid = self.run_platform_command("cat %s" % (pid_file_path))
+        self.assertTrue(err.Success() and retcode == 0,
+                        "Failed to read file %s: %s, retcode: %d" % (pid_file_path, err.GetCString(), retcode))
 
         self.expect('process attach -p ' + pid,
                     startstr = 'error: attach failed:',

Modified: lldb/trunk/test/functionalities/process_attach/attach_denied/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/process_attach/attach_denied/main.cpp?rev=237328&r1=237327&r2=237328&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/process_attach/attach_denied/main.cpp (original)
+++ lldb/trunk/test/functionalities/process_attach/attach_denied/main.cpp Wed May 13 20:36:47 2015
@@ -5,6 +5,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <linux/limits.h>
+
 #include <sys/types.h>
 #include <sys/ptrace.h>
 #include <sys/stat.h>
@@ -22,10 +24,13 @@
 
 bool writePid (const char* file_name, const pid_t pid)
 {
-    int fd = open (file_name, O_WRONLY);
+    char tmp_file_name[PATH_MAX];
+    strcpy(tmp_file_name, file_name);
+    strcat(tmp_file_name, "_tmp");
+    int fd = open (tmp_file_name, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);
     if (fd == -1)
     {
-        fprintf (stderr, "open(%s) failed: %s\n", file_name, strerror (errno));
+        fprintf (stderr, "open(%s) failed: %s\n", tmp_file_name, strerror (errno));
         return false;
     }
     char buffer[64];
@@ -38,6 +43,13 @@ bool writePid (const char* file_name, co
         res = false;
     }
     close (fd);
+
+    if (rename (tmp_file_name, file_name) == -1)
+    {
+        fprintf (stderr, "rename(%s, %s) failed: %s\n", tmp_file_name, file_name, strerror (errno));
+        res = false;
+    }
+
     return res;
 }
 





More information about the lldb-commits mailing list