[NFC] Cleanup the code used to run shell commands from tests

Previously we had 3 different method to run shell commands on the
target and 4 copy of code waiting until a given file appears on the
target device (used for syncronization). This CL merges these methods
to 1 run_platform_command and 1 wait_for_file_on_target functions
located in some utility classes.

Differential revision: http://reviews.llvm.org/D18789

llvm-svn: 265398
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index ea34ed6..00f0da9 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1029,3 +1029,20 @@
     def find_library_callable(test):
         return find_library(target, library)
     return skip_if_callable(test, find_library_callable, "could not find library matching '%s' in target %s" % (library, target))
+
+def wait_for_file_on_target(testcase, file_path, max_attempts = 6):
+    for i in range(max_attempts):
+        err, retcode, msg = testcase.run_platform_command("ls %s" % file_path)
+        if err.Success() and retcode == 0:
+            break
+        if i < max_attempts:
+            # Exponential backoff!
+            time.sleep(pow(2, i) * 0.25)
+    else:
+        testcase.fail("File %s not found even after %d attempts." % (file_path, max_attempts))
+
+    err, retcode, data = testcase.run_platform_command("cat %s" % (file_path))
+
+    testcase.assertTrue(err.Success() and retcode == 0,
+            "Failed to read file %s: %s, retcode: %d" % (file_path, err.GetCString(), retcode))
+    return data