chromium/third_party/angle/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/mathutil.h"
#include "common/system_utils.h"
#include "util/test_utils.h"

#include <fstream>
#include <sstream>
#include <vector>

#if defined(ANGLE_PLATFORM_POSIX)
#    include <signal.h>
#endif

usingnamespaceangle;

namespace
{
// Test getting the executable path
TEST(SystemUtils, ExecutablePath)
{}

// Test getting the executable directory
TEST(SystemUtils, ExecutableDir)
{}

// Test setting environment variables
TEST(SystemUtils, Environment)
{}

// Test CPU time measurement with a small operation
// (pretty much the measurement itself)
TEST(SystemUtils, CpuTimeSmallOp)
{}

// Test CPU time measurement with a sleepy operation
TEST(SystemUtils, CpuTimeSleepy)
{}

// Test CPU time measurement with a heavy operation
TEST(SystemUtils, CpuTimeHeavyOp)
{}

#if defined(ANGLE_PLATFORM_POSIX)
TEST(SystemUtils, ConcatenatePathSimple)
{}

TEST(SystemUtils, ConcatenatePath1Empty)
{}

TEST(SystemUtils, ConcatenatePath2Empty)
{}

TEST(SystemUtils, ConcatenatePath2FullPath)
{}

TEST(SystemUtils, ConcatenatePathRedundantSeparators)
{}

TEST(SystemUtils, IsFullPath)
{}
#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

// Temporary file creation is not supported on Android right now.
#if defined(ANGLE_PLATFORM_ANDROID)
#define MAYBE_CreateAndDeleteTemporaryFile
#define MAYBE_CreateAndDeleteFileInTempDir
#else
#define MAYBE_CreateAndDeleteTemporaryFile
#define MAYBE_CreateAndDeleteFileInTempDir
#endif  // defined(ANGLE_PLATFORM_ANDROID)

// Test creating/using temporary file
TEST(SystemUtils, MAYBE_CreateAndDeleteTemporaryFile)
{}

// Test creating/using file created in system's temporary directory
TEST(SystemUtils, MAYBE_CreateAndDeleteFileInTempDir)
{}

// Test retrieving page size
TEST(SystemUtils, PageSize)
{}

// mprotect is not supported on Fuchsia right now.
#if defined(ANGLE_PLATFORM_FUCHSIA)
#define MAYBE_PageFaultHandlerInit
#define MAYBE_PageFaultHandlerProtect
#define MAYBE_PageFaultHandlerDefaultHandler
// mprotect tests hang on macOS M1. Also applies to the iOS simulator.
#elif ANGLE_PLATFORM_MACOS || ANGLE_PLATFORM_IOS_FAMILY_SIMULATOR
#define MAYBE_PageFaultHandlerInit
#define MAYBE_PageFaultHandlerProtect
#define MAYBE_PageFaultHandlerDefaultHandler
#else
#define MAYBE_PageFaultHandlerInit
#define MAYBE_PageFaultHandlerProtect
#define MAYBE_PageFaultHandlerDefaultHandler
#endif  // defined(ANGLE_PLATFORM_FUCHSIA)

// Test initializing and cleaning up page fault handler.
TEST(SystemUtils, MAYBE_PageFaultHandlerInit)
{}

// Test write protecting and unprotecting memory
TEST(SystemUtils, MAYBE_PageFaultHandlerProtect)
{}

// Tests basic usage of StripFilenameFromPath.
TEST(SystemUtils, StripFilenameFromPathUsage)
{}

#if defined(ANGLE_PLATFORM_POSIX)
std::mutex gCustomHandlerMutex;
bool gCustomHandlerCalled =;

void CustomSegfaultHandlerFunction(int sig, siginfo_t *info, void *unused)
{}

// Test if the default page fault handler is called on OutOfRange.
TEST(SystemUtils, MAYBE_PageFaultHandlerDefaultHandler)
{}
#else
TEST(SystemUtils, MAYBE_PageFaultHandlerDefaultHandler) {}
#endif

// Tests basic usage of GetCurrentThreadId.
TEST(SystemUtils, GetCurrentThreadId)
{}

}  // anonymous namespace