Edit

kc3-lang/angle/src/common/system_utils_unittest.cpp

Branch :

  • Show log

    Commit

  • Author : Jonah Ryan-Davis
    Date : 2021-05-05 11:51:00
    Hash : e2fc818a
    Message : Reland Change to module directory when loading swiftshader ICD. This is a reland of commit 3b10dda6a479612a07673b5c87d3560e0941d41b. Extra changes: Be explicit about calling GetModuleHandleA Do not use the general GetModuleHandle, which may use wide strings Refactored ConcatenatePath and add tests GetModuleDirectory should return the full path, not relative. ANGLE wasn't able to locate the vulkan ICD file because it was searching down an invalid relative path. This can be fixed by ensuring the module directory is always the full path. on some platforms. Original change's description: > When loading vulkan, we can be running from any directory. We need > to change to the module directory to ensure the swiftshader ICD is > loaded properly. For example, in some Chrome releases, libGLESv2.dll > and libvk_swiftshader.dll are in a subdirectory relative to chrome.exe > > Bug: chromium:1198567 > Change-Id: I9e68927e512b239728fb2903d1a04702508a4948 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2873452 > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > Reviewed-by: Jamie Madill <jmadill@chromium.org> Bug: chromium:1198567 Bug: angleproject:5949 Change-Id: I63fbe93f8492b7f23566f8193b1b8fe784a34f71 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2904586 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>

  • src/common/system_utils_unittest.cpp
  • //
    // Copyright 2019 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    
    // system_utils_unittest.cpp: Unit tests for ANGLE's system utility functions
    
    #include "gmock/gmock.h"
    #include "gtest/gtest.h"
    
    #include "common/system_utils.h"
    
    using namespace angle;
    
    namespace
    {
    // Test getting the executable path
    TEST(SystemUtils, ExecutablePath)
    {
        // TODO: fuchsia support. http://anglebug.com/3161
    #if !defined(ANGLE_PLATFORM_FUCHSIA)
        std::string executablePath = GetExecutablePath();
        EXPECT_NE("", executablePath);
    #endif
    }
    
    // Test getting the executable directory
    TEST(SystemUtils, ExecutableDir)
    {
        // TODO: fuchsia support. http://anglebug.com/3161
    #if !defined(ANGLE_PLATFORM_FUCHSIA)
        std::string executableDir = GetExecutableDirectory();
        EXPECT_NE("", executableDir);
    
        std::string executablePath = GetExecutablePath();
        EXPECT_LT(executableDir.size(), executablePath.size());
        EXPECT_EQ(0, strncmp(executableDir.c_str(), executablePath.c_str(), executableDir.size()));
    #endif
    }
    
    // Test setting environment variables
    TEST(SystemUtils, Environment)
    {
        constexpr char kEnvVarName[]  = "UNITTEST_ENV_VARIABLE";
        constexpr char kEnvVarValue[] = "The quick brown fox jumps over the lazy dog";
    
        bool setEnvDone = SetEnvironmentVar(kEnvVarName, kEnvVarValue);
        EXPECT_TRUE(setEnvDone);
    
        std::string readback = GetEnvironmentVar(kEnvVarName);
        EXPECT_EQ(kEnvVarValue, readback);
    
        bool unsetEnvDone = UnsetEnvironmentVar(kEnvVarName);
        EXPECT_TRUE(unsetEnvDone);
    
        readback = GetEnvironmentVar(kEnvVarName);
        EXPECT_EQ("", readback);
    }
    
    #if defined(ANGLE_PLATFORM_POSIX)
    TEST(SystemUtils, ConcatenatePathSimple)
    {
        std::string path1    = "/this/is/path1";
        std::string path2    = "this/is/path2";
        std::string expected = "/this/is/path1/this/is/path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePath1Empty)
    {
        std::string path1    = "";
        std::string path2    = "this/is/path2";
        std::string expected = "this/is/path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePath2Empty)
    {
        std::string path1    = "/this/is/path1";
        std::string path2    = "";
        std::string expected = "/this/is/path1";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePath2FullPath)
    {
        std::string path1    = "/this/is/path1";
        std::string path2    = "/this/is/path2";
        std::string expected = "/this/is/path1";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePathRedundantSeparators)
    {
        std::string path1    = "/this/is/path1/";
        std::string path2    = "this/is/path2";
        std::string expected = "/this/is/path1/this/is/path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, IsFullPath)
    {
        std::string path1 = "/this/is/path1/";
        std::string path2 = "this/is/path2";
        EXPECT_TRUE(IsFullPath(path1));
        EXPECT_FALSE(IsFullPath(path2));
    }
    #elif defined(ANGLE_PLATFORM_WINDOWS)
    TEST(SystemUtils, ConcatenatePathSimple)
    {
        std::string path1    = "C:\\this\\is\\path1";
        std::string path2    = "this\\is\\path2";
        std::string expected = "C:\\this\\is\\path1\\this\\is\\path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePath1Empty)
    {
        std::string path1    = "";
        std::string path2    = "this\\is\\path2";
        std::string expected = "this\\is\\path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePath2Empty)
    {
        std::string path1    = "C:\\this\\is\\path1";
        std::string path2    = "";
        std::string expected = "C:\\this\\is\\path1";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePath2FullPath)
    {
        std::string path1    = "C:\\this\\is\\path1";
        std::string path2    = "C:\\this\\is\\path2";
        std::string expected = "C:\\this\\is\\path1";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePathRedundantSeparators)
    {
        std::string path1    = "C:\\this\\is\\path1\\";
        std::string path2    = "this\\is\\path2";
        std::string expected = "C:\\this\\is\\path1\\this\\is\\path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePathRedundantSeparators2)
    {
        std::string path1    = "C:\\this\\is\\path1\\";
        std::string path2    = "\\this\\is\\path2";
        std::string expected = "C:\\this\\is\\path1\\this\\is\\path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, ConcatenatePathRedundantSeparators3)
    {
        std::string path1    = "C:\\this\\is\\path1";
        std::string path2    = "\\this\\is\\path2";
        std::string expected = "C:\\this\\is\\path1\\this\\is\\path2";
        EXPECT_EQ(ConcatenatePath(path1, path2), expected);
    }
    
    TEST(SystemUtils, IsFullPath)
    {
        std::string path1 = "C:\\this\\is\\path1\\";
        std::string path2 = "this\\is\\path2";
        EXPECT_TRUE(IsFullPath(path1));
        EXPECT_FALSE(IsFullPath(path2));
    }
    #endif
    
    }  // anonymous namespace