diff --git a/llvm/unittests/Support/ProcessTest.cpp b/llvm/unittests/Support/ProcessTest.cpp index dbfaf8ed0f614..83be3a910f0d7 100644 --- a/llvm/unittests/Support/ProcessTest.cpp +++ b/llvm/unittests/Support/ProcessTest.cpp @@ -6,6 +6,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/Triple.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/Host.h" #include "llvm/Support/Process.h" #include "gtest/gtest.h" @@ -61,4 +64,39 @@ TEST(ProcessTest, Wchar) { } #endif +class PageSizeTest : public testing::Test { + Triple Host; + +protected: + PageSizeTest() : Host(Triple::normalize(sys::getProcessTriple())) {} + + bool isSupported() const { + // For now just on X86-64 and Aarch64. This can be expanded in the future. + return (Host.getArch() == Triple::x86_64 || + Host.getArch() == Triple::aarch64) && + Host.getOS() == Triple::Linux; + } + + bool pageSizeAsExpected(unsigned PageSize) const { + switch (Host.getArch()) { + case Triple::x86_64: + return PageSize == 4096; + case Triple::aarch64: + // supported granule sizes are 4k, 16k and 64k + return PageSize == 4096 || PageSize == 16384 || PageSize == 65536; + default: + llvm_unreachable("unexpected arch!"); + } + } +}; + +TEST_F(PageSizeTest, PageSize) { + if (!isSupported()) + return; + + llvm::Expected Result = llvm::sys::Process::getPageSize(); + ASSERT_FALSE(!Result); + ASSERT_TRUE(pageSizeAsExpected(*Result)); +} + } // end anonymous namespace