[Lldb-commits] [lldb] 79809f5 - [LLDB] On Windows, fix tests

Alexandre Ganea via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 8 08:47:09 PDT 2020


Author: Alexandre Ganea
Date: 2020-10-08T11:46:59-04:00
New Revision: 79809f58b02419a5d1bfb6c9a59dbd13cd038c77

URL: https://github.com/llvm/llvm-project/commit/79809f58b02419a5d1bfb6c9a59dbd13cd038c77
DIFF: https://github.com/llvm/llvm-project/commit/79809f58b02419a5d1bfb6c9a59dbd13cd038c77.diff

LOG: [LLDB] On Windows, fix tests

This patch fixes a few issues seen when running `ninja check-lldb` in a Release build with VS2017:

- Some binaries couldn't be found (such as lldb-vscode.exe), because .exe wasn't appended to the file name.
- Many tests used to fail since our installed locale is in French - the OS error messages are not emitted in English.
- Our codepage being Windows-1252, python failed to decode some error messages with accentuations.

Differential Revision: https://reviews.llvm.org/D88975

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/decorators.py
    lldb/packages/Python/lldbsuite/test/dotest.py
    lldb/packages/Python/lldbsuite/test_event/build_exception.py
    lldb/test/API/commands/target/basic/TestTargetCommand.py
    lldb/unittests/Utility/StatusTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py
index 4e47165cdb1f..bb4a459abe68 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -3,6 +3,8 @@
 # System modules
 from distutils.version import LooseVersion
 from functools import wraps
+import ctypes
+import locale
 import os
 import platform
 import re
@@ -592,6 +594,17 @@ def skipIfWindows(func):
     """Decorate the item to skip tests that should be skipped on Windows."""
     return skipIfPlatform(["windows"])(func)
 
+def skipIfWindowsAndNonEnglish(func):
+    """Decorate the item to skip tests that should be skipped on non-English locales on Windows."""
+    def is_Windows_NonEnglish(self):
+        if lldbplatformutil.getPlatform() != "windows":
+            return None
+        kernel = ctypes.windll.kernel32
+        if locale.windows_locale[ kernel.GetUserDefaultUILanguage() ] == "en_US":
+            return None
+        return "skipping non-English Windows locale"
+    return skipTestIfFn(is_Windows_NonEnglish)(func)
+
 def skipUnlessWindows(func):
     """Decorate the item to skip tests that should be skipped on any non-Windows platform."""
     return skipUnlessPlatform(["windows"])(func)

diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 922d7c9377ee..0da60f11a609 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -52,6 +52,9 @@ def is_exe(fpath):
     """Returns true if fpath is an executable."""
     if fpath == None:
         return False
+    if sys.platform == 'win32':
+        if not fpath.endswith(".exe"):
+            fpath += ".exe"
     return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
 
 

diff  --git a/lldb/packages/Python/lldbsuite/test_event/build_exception.py b/lldb/packages/Python/lldbsuite/test_event/build_exception.py
index 993214edd871..e08b632eb9a9 100644
--- a/lldb/packages/Python/lldbsuite/test_event/build_exception.py
+++ b/lldb/packages/Python/lldbsuite/test_event/build_exception.py
@@ -12,4 +12,4 @@ def __str__(self):
     @staticmethod
     def format_build_error(command, command_output):
         return "Error when building test subject.\n\nBuild Command:\n{}\n\nBuild Command Output:\n{}".format(
-            command, command_output.decode("utf-8"))
+            command, command_output.decode("utf-8", errors='ignore'))

diff  --git a/lldb/test/API/commands/target/basic/TestTargetCommand.py b/lldb/test/API/commands/target/basic/TestTargetCommand.py
index be6eeb938ab8..74b6c1fdcaed 100644
--- a/lldb/test/API/commands/target/basic/TestTargetCommand.py
+++ b/lldb/test/API/commands/target/basic/TestTargetCommand.py
@@ -350,6 +350,7 @@ def test_target_create_multiple_args(self):
         self.expect("target create a b", error=True,
                     substrs=["'target create' takes exactly one executable path"])
 
+    @skipIfWindowsAndNonEnglish
     @no_debug_info_test
     def test_target_create_nonexistent_core_file(self):
         self.expect("target create -c doesntexist", error=True,
@@ -365,6 +366,7 @@ def test_target_create_unreadable_core_file(self):
         self.expect("target create -c '" + tf.name + "'", error=True,
                     substrs=["Cannot open '", "': Permission denied"])
 
+    @skipIfWindowsAndNonEnglish
     @no_debug_info_test
     def test_target_create_nonexistent_sym_file(self):
         self.expect("target create -s doesntexist doesntexisteither", error=True,

diff  --git a/lldb/unittests/Utility/StatusTest.cpp b/lldb/unittests/Utility/StatusTest.cpp
index 862c063b2e06..9b9d870cd12a 100644
--- a/lldb/unittests/Utility/StatusTest.cpp
+++ b/lldb/unittests/Utility/StatusTest.cpp
@@ -10,7 +10,7 @@
 #include "gtest/gtest.h"
 
 #ifdef _WIN32
-#include <winerror.h>
+#include <windows.h>
 #endif
 
 using namespace lldb_private;
@@ -71,14 +71,26 @@ TEST(StatusTest, ErrorWin32) {
   EXPECT_FALSE(success.ToError());
   EXPECT_TRUE(success.Success());
 
+  WCHAR name[128]{};
+  ULONG nameLen = llvm::array_lengthof(name);
+  ULONG langs = 0;
+  GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &langs,
+                              reinterpret_cast<PZZWSTR>(&name), &nameLen);
+  // Skip the following tests on non-English, non-US, locales because the
+  // formatted messages will be 
diff erent.
+  bool skip = wcscmp(L"en-US", name) != 0;
+
   auto s = Status(ERROR_ACCESS_DENIED, ErrorType::eErrorTypeWin32);
   EXPECT_TRUE(s.Fail());
-  EXPECT_STREQ("Access is denied. ", s.AsCString());
+  if (!skip)
+    EXPECT_STREQ("Access is denied. ", s.AsCString());
 
   s.SetError(ERROR_IPSEC_IKE_TIMED_OUT, ErrorType::eErrorTypeWin32);
-  EXPECT_STREQ("Negotiation timed out ", s.AsCString());
+  if (!skip)
+    EXPECT_STREQ("Negotiation timed out ", s.AsCString());
 
   s.SetError(16000, ErrorType::eErrorTypeWin32);
-  EXPECT_STREQ("unknown error", s.AsCString());
+  if (!skip)
+    EXPECT_STREQ("unknown error", s.AsCString());
 }
 #endif


        


More information about the lldb-commits mailing list