[Support][NFC] Add an explicit unit test for Process::getPageSize()

It turns out that it was only tested indirectly. For now test only on Linux
X86-64 and aarch64.
This commit is contained in:
Bruno Ricci 2020-01-09 18:14:05 +00:00
parent 460cbabe17
commit 002be6cfa2
No known key found for this signature in database
GPG Key ID: D58C906B2F684D92
1 changed files with 38 additions and 0 deletions

View File

@ -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<unsigned> Result = llvm::sys::Process::getPageSize();
ASSERT_FALSE(!Result);
ASSERT_TRUE(pageSizeAsExpected(*Result));
}
} // end anonymous namespace