#include "llvm/Support/Process.h"
#include "llvm/Support/Error.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include "gtest/gtest.h"
#include <optional>
#ifdef _WIN32
#include <windows.h>
#endif
namespace {
usingnamespacellvm;
usingnamespacesys;
TEST(ProcessTest, GetProcessIdTest) { … }
TEST(ProcessTest, GetRandomNumberTest) { … }
#ifdef _MSC_VER
#define setenv …
#endif
#if HAVE_SETENV || _MSC_VER
TEST(ProcessTest, Basic) {
setenv("__LLVM_TEST_ENVIRON_VAR__", "abc", true);
std::optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
EXPECT_TRUE(val.has_value());
EXPECT_STREQ("abc", val->c_str());
}
TEST(ProcessTest, None) {
std::optional<std::string> val(
Process::GetEnv("__LLVM_TEST_ENVIRON_NO_SUCH_VAR__"));
EXPECT_FALSE(val.has_value());
}
#endif
#ifdef _WIN32
TEST(ProcessTest, EmptyVal) {
SetEnvironmentVariableA("__LLVM_TEST_ENVIRON_VAR__", "");
std::optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
EXPECT_TRUE(val.has_value());
EXPECT_STREQ("", val->c_str());
}
TEST(ProcessTest, Wchar) {
SetEnvironmentVariableW(L"__LLVM_TEST_ENVIRON_VAR__", L"abcdefghijklmnopqrs");
std::optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
EXPECT_TRUE(val.has_value());
EXPECT_STREQ("abcdefghijklmnopqrs", val->c_str());
}
#endif
class PageSizeTest : public testing::Test { … };
TEST_F(PageSizeTest, PageSize) { … }
}