//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/Process.h"
#include "gtest/gtest.h"
}
#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<unsigned> Result = llvm::sys::Process::getPageSize();
+ ASSERT_FALSE(!Result);
+ ASSERT_TRUE(pageSizeAsExpected(*Result));
+}
+
} // end anonymous namespace