Hash :
6e2e36cc
Author :
Date :
2021-11-19T00:57:29
[Fuchsia] Fix SwiftShader ICD discovery ANGLE needs to set VK_ICD_FILENAMES for the Vulkan loader to discover SwiftShader's ICD. Enable this logic on Fuchsia. Also updated ConcatenatePath() to handle absolute paths correctly. Bug: chromium:1225002 Change-Id: Ib69be0d7dcaef09f1da9d411023e90a3b7b4fca2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3292347 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
//
// 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"
#include "util/test_utils.h"
#include <vector>
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);
}
// Test CPU time measurement with a small operation
// (pretty much the measurement itself)
TEST(SystemUtils, CpuTimeSmallOp)
{
double cpuTimeStart = GetCurrentProcessCpuTime();
double cpuTimeEnd = GetCurrentProcessCpuTime();
EXPECT_GE(cpuTimeEnd, cpuTimeStart);
}
// Test CPU time measurement with a sleepy operation
TEST(SystemUtils, CpuTimeSleepy)
{
double wallTimeStart = GetCurrentSystemTime();
double cpuTimeStart = GetCurrentProcessCpuTime();
angle::Sleep(1);
double cpuTimeEnd = GetCurrentProcessCpuTime();
double wallTimeEnd = GetCurrentSystemTime();
EXPECT_GE(cpuTimeEnd, cpuTimeStart);
EXPECT_GE(wallTimeEnd - wallTimeStart, cpuTimeEnd - cpuTimeStart);
}
// Test CPU time measurement with a heavy operation
TEST(SystemUtils, CpuTimeHeavyOp)
{
constexpr size_t bufferSize = 1048576;
std::vector<uint8_t> buffer(bufferSize, 1);
double cpuTimeStart = GetCurrentProcessCpuTime();
memset(buffer.data(), 0, bufferSize);
double cpuTimeEnd = GetCurrentProcessCpuTime();
EXPECT_GE(cpuTimeEnd, cpuTimeStart);
}
#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/path2";
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\\path2";
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