test/hotspot/gtest/utilities/test_globalDefinitions.cpp
author manc
Mon, 14 Oct 2019 18:48:10 -0700
changeset 58652 9b67dd88a931
parent 57875 427b38332f20
permissions -rw-r--r--
8232232: G1RemSetSummary::_rs_threads_vtimes is not initialized to zero Summary: Fix error in "Concurrent refinement threads times" in GC log and cleanup. Reviewed-by: tschatzl, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42641
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     1
/*
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     4
 *
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     8
 *
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    13
 * accompanied this code).
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    14
 *
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    18
 *
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    21
 * questions.
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    22
 */
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    23
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    24
#include "precompiled.hpp"
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    25
#include "runtime/os.hpp"
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    26
#include "unittest.hpp"
57875
427b38332f20 8229836: Remove include of globals.hpp from allocation.hpp
stefank
parents: 53386
diff changeset
    27
#include "utilities/align.hpp"
42641
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    28
#include "utilities/globalDefinitions.hpp"
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    29
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    30
static ::testing::AssertionResult testPageAddress(
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    31
  const char* expected_addr_expr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    32
  const char* addr_expr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    33
  const char* page_addr_expr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    34
  const char* page_size_expr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    35
  const char* actual_addr_expr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    36
  address expected_addr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    37
  address addr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    38
  address page_addr,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    39
  intptr_t page_size,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    40
  address actual_addr) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    41
  if (expected_addr == actual_addr) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    42
    return ::testing::AssertionSuccess();
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    43
  }
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    44
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    45
  return ::testing::AssertionFailure()
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    46
    << actual_addr_expr << " returned unexpected address " << (void*) actual_addr << std::endl
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    47
    << "Expected " << expected_addr_expr << ": " << (void*) expected_addr << std::endl
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    48
    << "where" << std::endl
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    49
    << addr_expr << ": " << (void*) addr << std::endl
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    50
    << page_addr_expr << ": " << (void*) page_addr << std::endl
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    51
    << page_size_expr << ": " << page_size;
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    52
}
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    53
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    54
TEST_VM(globalDefinitions, clamp_address_in_page) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    55
  const intptr_t page_sizes[] = {os::vm_page_size(), 4096, 8192, 65536, 2 * 1024 * 1024};
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    56
  const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]);
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    57
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    58
  for (int i = 0; i < num_page_sizes; i++) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    59
    intptr_t page_size = page_sizes[i];
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    60
    address page_address = (address) (10 * page_size);
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    61
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    62
    const intptr_t within_page_offsets[] = {0, 128, page_size - 1};
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    63
    const int num_within_page_offsets = sizeof(within_page_offsets) / sizeof(within_page_offsets[0]);
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    64
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    65
    for (int k = 0; k < num_within_page_offsets; ++k) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    66
      address addr = page_address + within_page_offsets[k];
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    67
      address expected_address = addr;
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    68
      EXPECT_PRED_FORMAT5(testPageAddress, expected_address, addr, page_address, page_size,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    69
                          clamp_address_in_page(addr, page_address, page_size))
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    70
        << "Expect that address within page is returned as is";
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    71
    }
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    72
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    73
    const intptr_t above_page_offsets[] = {page_size, page_size + 1, 5 * page_size + 1};
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    74
    const int num_above_page_offsets = sizeof(above_page_offsets) / sizeof(above_page_offsets[0]);
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    75
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    76
    for (int k = 0; k < num_above_page_offsets; ++k) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    77
      address addr = page_address + above_page_offsets[k];
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    78
      address expected_address = page_address + page_size;
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    79
      EXPECT_PRED_FORMAT5(testPageAddress, expected_address, addr, page_address, page_size,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    80
                          clamp_address_in_page(addr, page_address, page_size))
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    81
        << "Expect that address above page returns start of next page";
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    82
    }
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    83
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    84
    const intptr_t below_page_offsets[] = {1, 2 * page_size + 1, 5 * page_size + 1};
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    85
    const int num_below_page_offsets = sizeof(below_page_offsets) / sizeof(below_page_offsets[0]);
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    86
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    87
    for (int k = 0; k < num_below_page_offsets; ++k) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    88
      address addr = page_address - below_page_offsets[k];
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    89
      address expected_address = page_address;
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    90
      EXPECT_PRED_FORMAT5(testPageAddress, expected_address, addr, page_address, page_size,
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    91
                          clamp_address_in_page(addr, page_address, page_size))
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    92
        << "Expect that address below page returns start of page";
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    93
    }
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    94
  }
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    95
}
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
    96
53386
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
    97
TEST(globalDefinitions, proper_unit) {
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
    98
  EXPECT_EQ(0u,     byte_size_in_proper_unit(0u));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
    99
  EXPECT_STREQ("B", proper_unit_for_byte_size(0u));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   100
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   101
  EXPECT_EQ(1u,     byte_size_in_proper_unit(1u));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   102
  EXPECT_STREQ("B", proper_unit_for_byte_size(1u));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   103
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   104
  EXPECT_EQ(1023u,  byte_size_in_proper_unit(K - 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   105
  EXPECT_STREQ("B", proper_unit_for_byte_size(K - 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   106
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   107
  EXPECT_EQ(1024u,  byte_size_in_proper_unit(K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   108
  EXPECT_STREQ("B", proper_unit_for_byte_size(K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   109
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   110
  EXPECT_EQ(1025u,  byte_size_in_proper_unit(K + 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   111
  EXPECT_STREQ("B", proper_unit_for_byte_size(K + 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   112
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   113
  EXPECT_EQ(51200u, byte_size_in_proper_unit(50*K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   114
  EXPECT_STREQ("B", proper_unit_for_byte_size(50*K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   115
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   116
  EXPECT_EQ(1023u,  byte_size_in_proper_unit(M - 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   117
  EXPECT_STREQ("K", proper_unit_for_byte_size(M - 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   118
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   119
  EXPECT_EQ(1024u,  byte_size_in_proper_unit(M));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   120
  EXPECT_STREQ("K", proper_unit_for_byte_size(M));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   121
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   122
  EXPECT_EQ(1024u,  byte_size_in_proper_unit(M + 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   123
  EXPECT_STREQ("K", proper_unit_for_byte_size(M + 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   124
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   125
  EXPECT_EQ(1025u,  byte_size_in_proper_unit(M + K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   126
  EXPECT_STREQ("K", proper_unit_for_byte_size(M + K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   127
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   128
  EXPECT_EQ(51200u, byte_size_in_proper_unit(50*M));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   129
  EXPECT_STREQ("K", proper_unit_for_byte_size(50*M));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   130
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   131
#ifdef _LP64
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   132
  EXPECT_EQ(1023u,  byte_size_in_proper_unit(G - 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   133
  EXPECT_STREQ("M", proper_unit_for_byte_size(G - 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   134
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   135
  EXPECT_EQ(1024u,  byte_size_in_proper_unit(G));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   136
  EXPECT_STREQ("M", proper_unit_for_byte_size(G));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   137
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   138
  EXPECT_EQ(1024u,  byte_size_in_proper_unit(G + 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   139
  EXPECT_STREQ("M", proper_unit_for_byte_size(G + 1));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   140
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   141
  EXPECT_EQ(1024u,  byte_size_in_proper_unit(G + K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   142
  EXPECT_STREQ("M", proper_unit_for_byte_size(G + K));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   143
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   144
  EXPECT_EQ(1025u,  byte_size_in_proper_unit(G + M));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   145
  EXPECT_STREQ("M", proper_unit_for_byte_size(G + M));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   146
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   147
  EXPECT_EQ(51200u, byte_size_in_proper_unit(50*G));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   148
  EXPECT_STREQ("M", proper_unit_for_byte_size(50*G));
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   149
#endif
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   150
}
d5f6540c6bb1 8217315: Proper units should print more significant digits
shade
parents: 53375
diff changeset
   151
42641
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   152
TEST(globalDefinitions, exact_unit_for_byte_size) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   153
  EXPECT_STREQ("B", exact_unit_for_byte_size(0));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   154
  EXPECT_STREQ("B", exact_unit_for_byte_size(1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   155
  EXPECT_STREQ("B", exact_unit_for_byte_size(K - 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   156
  EXPECT_STREQ("K", exact_unit_for_byte_size(K));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   157
  EXPECT_STREQ("B", exact_unit_for_byte_size(K + 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   158
  EXPECT_STREQ("B", exact_unit_for_byte_size(M - 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   159
  EXPECT_STREQ("M", exact_unit_for_byte_size(M));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   160
  EXPECT_STREQ("B", exact_unit_for_byte_size(M + 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   161
  EXPECT_STREQ("K", exact_unit_for_byte_size(M + K));
53375
ae4295a6a01e 8217321: [TESTBUG] utilities/test_globalDefinitions.cpp should use _LP64, not LP64
shade
parents: 47216
diff changeset
   162
#ifdef _LP64
42641
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   163
  EXPECT_STREQ("B", exact_unit_for_byte_size(G - 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   164
  EXPECT_STREQ("G", exact_unit_for_byte_size(G));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   165
  EXPECT_STREQ("B", exact_unit_for_byte_size(G + 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   166
  EXPECT_STREQ("K", exact_unit_for_byte_size(G + K));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   167
  EXPECT_STREQ("M", exact_unit_for_byte_size(G + M));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   168
  EXPECT_STREQ("K", exact_unit_for_byte_size(G + M + K));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   169
#endif
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   170
}
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   171
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   172
TEST(globalDefinitions, byte_size_in_exact_unit) {
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   173
  EXPECT_EQ(0u, byte_size_in_exact_unit(0));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   174
  EXPECT_EQ(1u, byte_size_in_exact_unit(1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   175
  EXPECT_EQ(K - 1, byte_size_in_exact_unit(K - 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   176
  EXPECT_EQ(1u, byte_size_in_exact_unit(K));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   177
  EXPECT_EQ(K + 1, byte_size_in_exact_unit(K + 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   178
  EXPECT_EQ(M - 1, byte_size_in_exact_unit(M - 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   179
  EXPECT_EQ(1u, byte_size_in_exact_unit(M));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   180
  EXPECT_EQ(M + 1, byte_size_in_exact_unit(M + 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   181
  EXPECT_EQ(K + 1, byte_size_in_exact_unit(M + K));
53375
ae4295a6a01e 8217321: [TESTBUG] utilities/test_globalDefinitions.cpp should use _LP64, not LP64
shade
parents: 47216
diff changeset
   182
#ifdef _LP64
42641
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   183
  EXPECT_EQ(G - 1, byte_size_in_exact_unit(G - 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   184
  EXPECT_EQ(1u, byte_size_in_exact_unit(G));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   185
  EXPECT_EQ(G + 1, byte_size_in_exact_unit(G + 1));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   186
  EXPECT_EQ(M + 1, byte_size_in_exact_unit(G + K));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   187
  EXPECT_EQ(K + 1, byte_size_in_exact_unit(G + M));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   188
  EXPECT_EQ(M + K + 1, byte_size_in_exact_unit(G + M + K));
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   189
#endif
0fc484157397 8166132: Convert TestGlobalDefinitions_test to GTest
bmoloden
parents:
diff changeset
   190
}