[PATCH] D97472: [test] Use host platform specific error message substitution in lit tests

Abhina Sree via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 26 06:05:51 PST 2021


abhina.sreeskantharajan updated this revision to Diff 326671.
abhina.sreeskantharajan added a comment.

Thanks for testing it out. Since os.strerror does not emit the correct message on Windows we have to go back to hardcoding the error message for Windows. I had the same thought of passing a regex but FileCheck does not allow it. I currently check the host_cxx to see if MSYS is in the path because the library path is not available in the config.

I see there is a check for msys bash in the same file that looks like this:

  if sys.platform in ['win32'] and not self.use_lit_shell:
      # Don't pass dosish path separator to msys bash.exe.

Is this a potential alternative to using host_cxx?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97472/new/

https://reviews.llvm.org/D97472

Files:
  llvm/test/tools/llvm-elfabi/fail-file-write-windows.test
  llvm/utils/lit/lit/llvm/config.py


Index: llvm/utils/lit/lit/llvm/config.py
===================================================================
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -4,6 +4,7 @@
 import re
 import subprocess
 import sys
+import errno
 
 import lit.util
 from lit.llvm.subst import FindTool
@@ -346,21 +347,17 @@
         return True
 
     def add_err_msg_substitutions(self):
-        if (sys.platform == 'zos'):
-            self.config.substitutions.append(('%errc_ENOENT', '\'EDC5129I No such file or directory.\''))
-            self.config.substitutions.append(('%errc_EISDIR', '\'EDC5123I Is a directory.\''))
-            self.config.substitutions.append(('%errc_EINVAL', '\'EDC5121I Invalid argument.\''))
-            self.config.substitutions.append(('%errc_EACCES', '\'EDC5111I Permission denied.\''))
-        elif (sys.platform == 'win32'):
+        host_cxx = getattr(self.config, 'host_cxx', None)
+        if (sys.platform == 'win32' and 'MSYS' not in host_cxx):
             self.config.substitutions.append(('%errc_ENOENT', '\'no such file or directory\''))
             self.config.substitutions.append(('%errc_EISDIR', '\'is a directory\''))
             self.config.substitutions.append(('%errc_EINVAL', '\'invalid argument\''))
             self.config.substitutions.append(('%errc_EACCES', '\'permission denied\''))
         else:
-            self.config.substitutions.append(('%errc_ENOENT', '\'No such file or directory\''))
-            self.config.substitutions.append(('%errc_EISDIR', '\'Is a directory\''))
-            self.config.substitutions.append(('%errc_EINVAL', '\'Invalid argument\''))
-            self.config.substitutions.append(('%errc_EACCES', '\'Permission denied\''))
+            self.config.substitutions.append(('%errc_ENOENT', '\'' + os.strerror(errno.ENOENT) + '\''))
+            self.config.substitutions.append(('%errc_EISDIR', '\'' + os.strerror(errno.EISDIR) + '\''))
+            self.config.substitutions.append(('%errc_EINVAL', '\'' + os.strerror(errno.EINVAL) + '\''))
+            self.config.substitutions.append(('%errc_EACCES', '\'' + os.strerror(errno.EACCES) + '\''))
 
     def use_default_substitutions(self):
         tool_patterns = [
Index: llvm/test/tools/llvm-elfabi/fail-file-write-windows.test
===================================================================
--- llvm/test/tools/llvm-elfabi/fail-file-write-windows.test
+++ llvm/test/tools/llvm-elfabi/fail-file-write-windows.test
@@ -3,7 +3,7 @@
 # REQUIRES: system-windows
 # RUN: touch %t.TestFile
 # RUN: chmod 400 %t.TestFile
-# RUN: not llvm-elfabi %s --output-target=elf64-little %t.TestFile 2>&1 | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-elfabi %s --output-target=elf64-little %t.TestFile 2>&1 | FileCheck -DMSG=%errc_EACCES %s --check-prefix=ERR
 # RUN: chmod 777 %t.TestFile
 # RUN: rm -rf %t.TestFile
 
@@ -13,4 +13,4 @@
 Symbols: {}
 ...
 
-# ERR: error: permission denied
+# ERR: error: [[MSG]]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97472.326671.patch
Type: text/x-patch
Size: 2969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210226/5c795425/attachment.bin>


More information about the llvm-commits mailing list