| File: | jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp |
| Warning: | line 78, column 26 Assigned value is garbage or undefined |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. | |||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||
| 4 | * | |||
| 5 | * This code is free software; you can redistribute it and/or modify it | |||
| 6 | * under the terms of the GNU General Public License version 2 only, as | |||
| 7 | * published by the Free Software Foundation. | |||
| 8 | * | |||
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | |||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |||
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | |||
| 13 | * accompanied this code). | |||
| 14 | * | |||
| 15 | * You should have received a copy of the GNU General Public License version | |||
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | |||
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |||
| 18 | * | |||
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |||
| 20 | * or visit www.oracle.com if you need additional information or have any | |||
| 21 | * questions. | |||
| 22 | * | |||
| 23 | */ | |||
| 24 | ||||
| 25 | #include "precompiled.hpp" | |||
| 26 | #include "utilities/count_trailing_zeros.hpp" | |||
| 27 | #include "utilities/globalDefinitions.hpp" | |||
| 28 | #include "unittest.hpp" | |||
| 29 | ||||
| 30 | ||||
| 31 | template <typename T> static void test_one_or_two_set_bits() { | |||
| 32 | unsigned i = 0; // Position of a set bit. | |||
| 33 | unsigned max = sizeof(T) * BitsPerByte; | |||
| 34 | for (T ix = T(1); i < max; ix <<= 1, ++i) { | |||
| 35 | unsigned j = 0; // Position of a set bit. | |||
| 36 | for (T jx = T(1); j < max; jx <<= 1, ++j) { | |||
| 37 | T value = ix | jx; | |||
| 38 | EXPECT_EQ(MIN2(i, j), count_trailing_zeros(value))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(MIN2(i, j))) == 1)>::Compare ("MIN2(i, j)", "count_trailing_zeros(value)", MIN2(i, j), count_trailing_zeros (value)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp" , 38, gtest_ar.failure_message()) = ::testing::Message() | |||
| 39 | << "value = " << value; | |||
| 40 | } | |||
| 41 | } | |||
| 42 | } | |||
| 43 | ||||
| 44 | TEST(count_trailing_zeros, one_or_two_set_bits)class count_trailing_zeros_one_or_two_set_bits_Test : public :: testing::Test { public: count_trailing_zeros_one_or_two_set_bits_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); count_trailing_zeros_one_or_two_set_bits_Test (count_trailing_zeros_one_or_two_set_bits_Test const &) = delete; void operator=(count_trailing_zeros_one_or_two_set_bits_Test const &) = delete;};::testing::TestInfo* const count_trailing_zeros_one_or_two_set_bits_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "count_trailing_zeros", "one_or_two_set_bits", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp" , 44), (::testing::internal::GetTestTypeId()), ::testing::Test ::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< count_trailing_zeros_one_or_two_set_bits_Test >);void count_trailing_zeros_one_or_two_set_bits_Test::TestBody () { | |||
| 45 | test_one_or_two_set_bits<int8_t>(); | |||
| 46 | test_one_or_two_set_bits<int16_t>(); | |||
| 47 | test_one_or_two_set_bits<int32_t>(); | |||
| 48 | test_one_or_two_set_bits<int64_t>(); | |||
| 49 | test_one_or_two_set_bits<uint8_t>(); | |||
| 50 | test_one_or_two_set_bits<uint16_t>(); | |||
| 51 | test_one_or_two_set_bits<uint32_t>(); | |||
| 52 | test_one_or_two_set_bits<uint64_t>(); | |||
| 53 | } | |||
| 54 | ||||
| 55 | template <typename T> static void test_high_zeros_low_ones() { | |||
| 56 | T value = std::numeric_limits<T>::max(); | |||
| 57 | for ( ; value != 0; value >>= 1) { | |||
| 58 | EXPECT_EQ(0u, count_trailing_zeros(value))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(0u)) == 1)>::Compare("0u", "count_trailing_zeros(value)", 0u, count_trailing_zeros(value )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp" , 58, gtest_ar.failure_message()) = ::testing::Message() | |||
| 59 | << "value = " << value; | |||
| 60 | } | |||
| 61 | } | |||
| 62 | ||||
| 63 | TEST(count_trailing_zeros, high_zeros_low_ones)class count_trailing_zeros_high_zeros_low_ones_Test : public :: testing::Test { public: count_trailing_zeros_high_zeros_low_ones_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); count_trailing_zeros_high_zeros_low_ones_Test (count_trailing_zeros_high_zeros_low_ones_Test const &) = delete; void operator=(count_trailing_zeros_high_zeros_low_ones_Test const &) = delete;};::testing::TestInfo* const count_trailing_zeros_high_zeros_low_ones_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "count_trailing_zeros", "high_zeros_low_ones", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp" , 63), (::testing::internal::GetTestTypeId()), ::testing::Test ::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< count_trailing_zeros_high_zeros_low_ones_Test >);void count_trailing_zeros_high_zeros_low_ones_Test::TestBody () { | |||
| 64 | test_high_zeros_low_ones<int8_t>(); | |||
| 65 | test_high_zeros_low_ones<int16_t>(); | |||
| 66 | test_high_zeros_low_ones<int32_t>(); | |||
| 67 | test_high_zeros_low_ones<int64_t>(); | |||
| 68 | test_high_zeros_low_ones<uint8_t>(); | |||
| 69 | test_high_zeros_low_ones<uint16_t>(); | |||
| 70 | test_high_zeros_low_ones<uint32_t>(); | |||
| 71 | test_high_zeros_low_ones<uint64_t>(); | |||
| 72 | } | |||
| 73 | ||||
| 74 | template <typename T> static void test_high_ones_low_zeros() { | |||
| 75 | unsigned i = 0; // Index of least significant set bit. | |||
| 76 | T value = ~T(0); | |||
| 77 | unsigned max = sizeof(T) * BitsPerByte; | |||
| 78 | for ( ; i < max; value <<= 1, ++i) { | |||
| ||||
| 79 | EXPECT_EQ(i, count_trailing_zeros(value))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal:: EqHelper<(sizeof(::testing ::internal::IsNullLiteralHelper(i)) == 1)>::Compare("i", "count_trailing_zeros(value)" , i, count_trailing_zeros(value)))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp" , 79, gtest_ar.failure_message()) = ::testing::Message() | |||
| 80 | << "value = " << value; | |||
| 81 | } | |||
| 82 | } | |||
| 83 | ||||
| 84 | TEST(count_trailing_zeros, high_ones_low_zeros)class count_trailing_zeros_high_ones_low_zeros_Test : public :: testing::Test { public: count_trailing_zeros_high_ones_low_zeros_Test () {} private: virtual void TestBody(); static ::testing::TestInfo * const test_info_ __attribute__ ((unused)); count_trailing_zeros_high_ones_low_zeros_Test (count_trailing_zeros_high_ones_low_zeros_Test const &) = delete; void operator=(count_trailing_zeros_high_ones_low_zeros_Test const &) = delete;};::testing::TestInfo* const count_trailing_zeros_high_ones_low_zeros_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "count_trailing_zeros", "high_ones_low_zeros", __null, __null , ::testing::internal::CodeLocation("/home/daniel/Projects/java/jdk/test/hotspot/gtest/utilities/test_count_trailing_zeros.cpp" , 84), (::testing::internal::GetTestTypeId()), ::testing::Test ::SetUpTestCase, ::testing::Test::TearDownTestCase, new ::testing ::internal::TestFactoryImpl< count_trailing_zeros_high_ones_low_zeros_Test >);void count_trailing_zeros_high_ones_low_zeros_Test::TestBody () { | |||
| 85 | test_high_ones_low_zeros<int8_t>(); | |||
| ||||
| 86 | test_high_ones_low_zeros<int16_t>(); | |||
| 87 | test_high_ones_low_zeros<int32_t>(); | |||
| 88 | test_high_ones_low_zeros<int64_t>(); | |||
| 89 | test_high_ones_low_zeros<uint8_t>(); | |||
| 90 | test_high_ones_low_zeros<uint16_t>(); | |||
| 91 | test_high_ones_low_zeros<uint32_t>(); | |||
| 92 | test_high_ones_low_zeros<uint64_t>(); | |||
| 93 | } |