[llvm] 002be6c - [Support][NFC] Add an explicit unit test for Process::getPageSize()

Bruno Ricci via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 10:21:18 PST 2020


Author: Bruno Ricci
Date: 2020-01-09T18:14:05Z
New Revision: 002be6cfa2b1de064d672dac6db53c01e9f150b0

URL: https://github.com/llvm/llvm-project/commit/002be6cfa2b1de064d672dac6db53c01e9f150b0
DIFF: https://github.com/llvm/llvm-project/commit/002be6cfa2b1de064d672dac6db53c01e9f150b0.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/unittests/Support/ProcessTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Support/ProcessTest.cpp b/llvm/unittests/Support/ProcessTest.cpp
index dbfaf8ed0f61..83be3a910f0d 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<unsigned> Result = llvm::sys::Process::getPageSize();
+  ASSERT_FALSE(!Result);
+  ASSERT_TRUE(pageSizeAsExpected(*Result));
+}
+
 } // end anonymous namespace


        


More information about the llvm-commits mailing list