changeset 12243:572f4f11a35f

8157455: Convert TestOS_test to GTest Reviewed-by: dholmes, rehn
author jwilhelm
date Mon, 23 May 2016 19:46:43 +0200
parents dfe9fb173b3e
children a5fdf2f30c6e
files src/share/vm/runtime/os.cpp src/share/vm/utilities/internalVMTests.cpp test/native/runtime/test_os.cpp
diffstat 3 files changed, 71 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/os.cpp	Fri May 20 16:45:00 2016 +0200
+++ b/src/share/vm/runtime/os.cpp	Mon May 23 19:46:43 2016 +0200
@@ -1766,95 +1766,3 @@
   return result;
 }
 #endif
-
-/////////////// Unit tests ///////////////
-
-#ifndef PRODUCT
-
-#define assert_eq(a,b) assert(a == b, SIZE_FORMAT " != " SIZE_FORMAT, a, b)
-
-class TestOS : AllStatic {
-  static size_t small_page_size() {
-    return os::vm_page_size();
-  }
-
-  static size_t large_page_size() {
-    const size_t large_page_size_example = 4 * M;
-    return os::page_size_for_region_aligned(large_page_size_example, 1);
-  }
-
-  static void test_page_size_for_region_aligned() {
-    if (UseLargePages) {
-      const size_t small_page = small_page_size();
-      const size_t large_page = large_page_size();
-
-      if (large_page > small_page) {
-        size_t num_small_pages_in_large = large_page / small_page;
-        size_t page = os::page_size_for_region_aligned(large_page, num_small_pages_in_large);
-
-        assert_eq(page, small_page);
-      }
-    }
-  }
-
-  static void test_page_size_for_region_alignment() {
-    if (UseLargePages) {
-      const size_t small_page = small_page_size();
-      const size_t large_page = large_page_size();
-      if (large_page > small_page) {
-        const size_t unaligned_region = large_page + 17;
-        size_t page = os::page_size_for_region_aligned(unaligned_region, 1);
-        assert_eq(page, small_page);
-
-        const size_t num_pages = 5;
-        const size_t aligned_region = large_page * num_pages;
-        page = os::page_size_for_region_aligned(aligned_region, num_pages);
-        assert_eq(page, large_page);
-      }
-    }
-  }
-
-  static void test_page_size_for_region_unaligned() {
-    if (UseLargePages) {
-      // Given exact page size, should return that page size.
-      for (size_t i = 0; os::_page_sizes[i] != 0; i++) {
-        size_t expected = os::_page_sizes[i];
-        size_t actual = os::page_size_for_region_unaligned(expected, 1);
-        assert_eq(expected, actual);
-      }
-
-      // Given slightly larger size than a page size, return the page size.
-      for (size_t i = 0; os::_page_sizes[i] != 0; i++) {
-        size_t expected = os::_page_sizes[i];
-        size_t actual = os::page_size_for_region_unaligned(expected + 17, 1);
-        assert_eq(expected, actual);
-      }
-
-      // Given a slightly smaller size than a page size,
-      // return the next smaller page size.
-      if (os::_page_sizes[1] > os::_page_sizes[0]) {
-        size_t expected = os::_page_sizes[0];
-        size_t actual = os::page_size_for_region_unaligned(os::_page_sizes[1] - 17, 1);
-        assert_eq(actual, expected);
-      }
-
-      // Return small page size for values less than a small page.
-      size_t small_page = small_page_size();
-      size_t actual = os::page_size_for_region_unaligned(small_page - 17, 1);
-      assert_eq(small_page, actual);
-    }
-  }
-
- public:
-  static void run_tests() {
-    test_page_size_for_region_aligned();
-    test_page_size_for_region_alignment();
-    test_page_size_for_region_unaligned();
-  }
-};
-
-void TestOS_test() {
-  TestOS::run_tests();
-}
-
-#endif // PRODUCT
--- a/src/share/vm/utilities/internalVMTests.cpp	Fri May 20 16:45:00 2016 +0200
+++ b/src/share/vm/utilities/internalVMTests.cpp	Mon May 23 19:46:43 2016 +0200
@@ -42,7 +42,6 @@
 void InternalVMTests::run() {
   tty->print_cr("Running internal VM tests");
   run_unit_test(test_semaphore);
-  run_unit_test(TestOS_test);
   run_unit_test(TestReservedSpace_test);
   run_unit_test(TestReserveMemorySpecial_test);
   run_unit_test(TestVirtualSpace_test);
--- a/test/native/runtime/test_os.cpp	Fri May 20 16:45:00 2016 +0200
+++ b/test/native/runtime/test_os.cpp	Mon May 23 19:46:43 2016 +0200
@@ -25,6 +25,15 @@
 #include "runtime/os.hpp"
 #include "unittest.hpp"
 
+static size_t small_page_size() {
+  return os::vm_page_size();
+}
+
+static size_t large_page_size() {
+  const size_t large_page_size_example = 4 * M;
+  return os::page_size_for_region_aligned(large_page_size_example, 1);
+}
+
 TEST_VM(os, page_size_for_region) {
   size_t large_page_example = 4 * M;
   size_t large_page = os::page_size_for_region_aligned(large_page_example, 1);
@@ -37,6 +46,68 @@
   }
 }
 
+TEST_VM(os, page_size_for_region_aligned) {
+  if (UseLargePages) {
+    const size_t small_page = small_page_size();
+    const size_t large_page = large_page_size();
+
+    if (large_page > small_page) {
+      size_t num_small_pages_in_large = large_page / small_page;
+      size_t page = os::page_size_for_region_aligned(large_page, num_small_pages_in_large);
+
+      ASSERT_EQ(page, small_page);
+    }
+  }
+}
+
+TEST_VM(os, page_size_for_region_alignment) {
+  if (UseLargePages) {
+    const size_t small_page = small_page_size();
+    const size_t large_page = large_page_size();
+    if (large_page > small_page) {
+      const size_t unaligned_region = large_page + 17;
+      size_t page = os::page_size_for_region_aligned(unaligned_region, 1);
+      ASSERT_EQ(page, small_page);
+
+      const size_t num_pages = 5;
+      const size_t aligned_region = large_page * num_pages;
+      page = os::page_size_for_region_aligned(aligned_region, num_pages);
+      ASSERT_EQ(page, large_page);
+    }
+  }
+}
+
+TEST_VM(os, page_size_for_region_unaligned) {
+  if (UseLargePages) {
+    // Given exact page size, should return that page size.
+    for (size_t i = 0; os::_page_sizes[i] != 0; i++) {
+      size_t expected = os::_page_sizes[i];
+      size_t actual = os::page_size_for_region_unaligned(expected, 1);
+      ASSERT_EQ(expected, actual);
+    }
+
+    // Given slightly larger size than a page size, return the page size.
+    for (size_t i = 0; os::_page_sizes[i] != 0; i++) {
+      size_t expected = os::_page_sizes[i];
+      size_t actual = os::page_size_for_region_unaligned(expected + 17, 1);
+      ASSERT_EQ(expected, actual);
+    }
+
+    // Given a slightly smaller size than a page size,
+    // return the next smaller page size.
+    if (os::_page_sizes[1] > os::_page_sizes[0]) {
+      size_t expected = os::_page_sizes[0];
+      size_t actual = os::page_size_for_region_unaligned(os::_page_sizes[1] - 17, 1);
+      ASSERT_EQ(actual, expected);
+    }
+
+    // Return small page size for values less than a small page.
+    size_t small_page = small_page_size();
+    size_t actual = os::page_size_for_region_unaligned(small_page - 17, 1);
+    ASSERT_EQ(small_page, actual);
+  }
+}
+
 #ifdef ASSERT
 TEST_VM_ASSERT_MSG(os, page_size_for_region_with_zero_min_pages, "sanity") {
   size_t region_size = 16 * os::vm_page_size();