[PATCH] D51648: [UBSan] Partially fix `test/ubsan/TestCases/Misc/log-path_test.cc` so that it can run on devices.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 11:20:23 PDT 2018


delcypher created this revision.
delcypher added reviewers: vsk, kubamracek, george.karpenkov, eugenis.
Herald added a subscriber: Sanitizers.

In order for this test to work the log file needs to be removed from both
from the host and device. To fix this the `rm` `RUN` lines have been
replaced with `RUN: rm` followed by `RUN: %run rm`.

Initially I tried having it so that `RUN: %run rm` implicitly runs `rm`
on the host as well so that only one `RUN` line is needed. This
simplified writing the test however that has two large drawbacks.

- It's potentially very confusing for use of the device scripts outside of the lit tests if asking for `rm` to run on device also causes files on the host to be deleted.

- This doesn't work well with the glob patterns used in the test. The host shell expands the `%t.log.*` glob pattern and not on the device so we could easily miss deleting old log files from previous test runs if the corresponding file doesn't exist on the host.

So instead deletion of files on the device and host are explicitly
separate commands.

To solve the globbing problem, the glob pattern passed to `%run rm` is
quoted so that the handling script can passed the unexpanded glob
pattern to the device so it can be expanded there. All implementations
of `%run` need to handle `rm` specially so that globbing patterns are
expanded on the device.

The `iossim_run.py` script has been fixed so that it just runs `rm`
on the host operating system because the device and host file system
are the same.

A visual inspection of `android_run.py` suggests that shell globbing
should work because it makes no attempt to quote paths when invoking
`adb shell`.

rdar://problem/41126835


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D51648

Files:
  test/sanitizer_common/ios_commands/iossim_run.py
  test/ubsan/TestCases/Misc/log-path_test.cc


Index: test/ubsan/TestCases/Misc/log-path_test.cc
===================================================================
--- test/ubsan/TestCases/Misc/log-path_test.cc
+++ test/ubsan/TestCases/Misc/log-path_test.cc
@@ -12,11 +12,13 @@
 
 // Good log_path.
 // RUN: rm -f %t.log.*
+// RUN: %run rm -f '%t.log.*'
 // RUN: %env_ubsan_opts=log_path='"%t.log"' %run %t -4 2> %t.out
 // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.*
 
 // Run w/o errors should not produce any log.
 // RUN: rm -f %t.log.*
+// RUN: %run rm -f '%t.log.*'
 // RUN: %env_ubsan_opts=log_path='"%t.log"'  %run %t 4
 // RUN: not cat %t.log.*
 
Index: test/sanitizer_common/ios_commands/iossim_run.py
===================================================================
--- test/sanitizer_common/ios_commands/iossim_run.py
+++ test/sanitizer_common/ios_commands/iossim_run.py
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import os, sys, subprocess
+import glob, os, sys, subprocess
 
 
 if not "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" in os.environ:
@@ -12,7 +12,29 @@
   if e in os.environ:
     os.environ["SIMCTL_CHILD_" + e] = os.environ[e]
 
-exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:])
+prog = sys.argv[1]
+exit_code = None
+if prog == 'rm':
+  # The simulator and host actually share the same file system so we can just
+  # execute directly on the host.
+  rm_args = sys.argv[2:]
+  rm_args_expanded = []
+  for arg in rm_args:
+    # We might get glob patterns that are intended to be resolved on the device.
+    # Here we can just resolve them on the host.
+    if '*' in arg or '?' in arg:
+      matches = glob.glob(arg)
+      if len(matches) > 0:
+        rm_args_expanded.extend(matches)
+      else:
+        # Just pass through unexpanded if we can't find a match.
+        rm_args_expanded.append(arg)
+    else:
+      rm_args_expanded.append(arg)
+  rm_cmd_line = ["/bin/rm"] + rm_args_expanded
+  exitcode = subprocess.call(rm_cmd_line)
+else:
+  exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:])
 if exitcode > 125:
   exitcode = 126
 sys.exit(exitcode)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51648.163878.patch
Type: text/x-patch
Size: 2119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180904/815fb7e0/attachment.bin>


More information about the llvm-commits mailing list