[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
Wed Sep 12 07:26:33 PDT 2018


delcypher updated this revision to Diff 165083.
delcypher added a comment.

Use `%device_rm` instead of `%run rm`.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D51648

Files:
  test/lit.common.cfg
  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: %device_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: %device_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, pipes, sys, subprocess
 
 
 if not "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" in os.environ:
@@ -12,7 +12,25 @@
   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 = []
+  for arg in sys.argv[2:]:
+    if '*' in arg or '?' in arg:
+      # Don't quote glob pattern
+      rm_args.append(arg)
+    else:
+      # FIXME(dliew): pipes.quote() is deprecated
+      rm_args.append(pipes.quote(arg))
+  rm_cmd_line = ["/bin/rm"] + rm_args
+  rm_cmd_line_str = ' '.join(rm_cmd_line)
+  # We use `shell=True` so that any wildcard globs get expanded by the shell.
+  exitcode = subprocess.call(rm_cmd_line_str, shell=True)
+else:
+  exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:])
 if exitcode > 125:
   exitcode = 126
 sys.exit(exitcode)
Index: test/lit.common.cfg
===================================================================
--- test/lit.common.cfg
+++ test/lit.common.cfg
@@ -106,6 +106,10 @@
 if config.emulator:
   config.substitutions.append( ('%run', config.emulator) )
   config.substitutions.append( ('%env ', "env ") )
+  # TODO: Implement `%device_rm` to perform removal of files in the emulator.
+  # For now just make it a no-op.
+  lit_config.warning('%device_rm is not implemented')
+  config.substitutions.append( ('%device_rm', 'echo ') )
   config.compile_wrapper = ""
 elif config.host_os == 'Darwin' and config.apple_platform != "osx":
   # Darwin tests can be targetting macOS, a device or a simulator. All devices
@@ -148,6 +152,9 @@
     config.environment[device_id_env] = os.environ[device_id_env]
   config.substitutions.append(('%run', run_wrapper))
   config.substitutions.append(('%env ', env_wrapper + " "))
+  # Current implementation of %device_rm uses the run_wrapper to do
+  # the work.
+  config.substitutions.append(('%device_rm', '{} rm '.format(run_wrapper)))
   config.compile_wrapper = compile_wrapper
 
   prepare_output = subprocess.check_output([prepare_script, config.apple_platform, config.clang]).strip()
@@ -161,9 +168,15 @@
   config.compile_wrapper = compile_wrapper
   config.substitutions.append( ('%run', "") )
   config.substitutions.append( ('%env ', "env ") )
+  # TODO: Implement `%device_rm` to perform removal of files on a device.  For
+  # now just make it a no-op.
+  lit_config.warning('%device_rm is not implemented')
+  config.substitutions.append( ('%device_rm', 'echo ') )
 else:
   config.substitutions.append( ('%run', "") )
   config.substitutions.append( ('%env ', "env ") )
+  # When running locally %device_rm is a no-op.
+  config.substitutions.append( ('%device_rm', 'echo ') )
   config.compile_wrapper = ""
 
 # Define CHECK-%os to check for OS-dependent output.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51648.165083.patch
Type: text/x-patch
Size: 3904 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180912/51d45919/attachment.bin>


More information about the llvm-commits mailing list