| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_utils.h" | 5 #include "net/quic/quic_utils.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/crypto_protocol.h" | 7 #include "net/quic/crypto/crypto_protocol.h" |
| 8 #include "net/quic/quic_flags.h" | 8 #include "net/quic/quic_flags.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // kPrime = 309485009821345068724781371 | 168 // kPrime = 309485009821345068724781371 |
| 169 const uint128 kPrime(16777216, 315); | 169 const uint128 kPrime(16777216, 315); |
| 170 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); | 170 const uint8_t* octets = reinterpret_cast<const uint8_t*>(data); |
| 171 for (size_t i = 0; i < len; ++i) { | 171 for (size_t i = 0; i < len; ++i) { |
| 172 hash = hash ^ uint128(0, octets[i]); | 172 hash = hash ^ uint128(0, octets[i]); |
| 173 hash = hash * kPrime; | 173 hash = hash * kPrime; |
| 174 } | 174 } |
| 175 return hash; | 175 return hash; |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST(QuicUtilsHashTest, ReferenceTestSlow) { | 178 TEST(QuicUtilsHashTest, ReferenceTest) { |
| 179 FLAGS_quic_utils_use_fast_incremental_hash = false; | |
| 180 std::vector<uint8_t> data(32); | 179 std::vector<uint8_t> data(32); |
| 181 for (size_t i = 0; i < data.size(); ++i) { | 180 for (size_t i = 0; i < data.size(); ++i) { |
| 182 data[i] = i % 255; | 181 data[i] = i % 255; |
| 183 } | |
| 184 EXPECT_EQ(IncrementalHashReference(data.data(), data.size()), | |
| 185 QuicUtils::FNV1a_128_Hash( | |
| 186 reinterpret_cast<const char*>(data.data()), data.size())); | |
| 187 } | |
| 188 | |
| 189 TEST(QuicUtilsHashTest, ReferenceTestFast) { | |
| 190 FLAGS_quic_utils_use_fast_incremental_hash = true; | |
| 191 std::vector<uint8_t> data(32); | |
| 192 for (size_t i = 0; i < data.size(); ++i) { | |
| 193 data[i] = i % 255; | |
| 194 } | 182 } |
| 195 EXPECT_EQ(IncrementalHashReference(data.data(), data.size()), | 183 EXPECT_EQ(IncrementalHashReference(data.data(), data.size()), |
| 196 QuicUtils::FNV1a_128_Hash( | 184 QuicUtils::FNV1a_128_Hash( |
| 197 reinterpret_cast<const char*>(data.data()), data.size())); | 185 reinterpret_cast<const char*>(data.data()), data.size())); |
| 198 } | 186 } |
| 199 | 187 |
| 200 } // namespace | 188 } // namespace |
| 201 } // namespace test | 189 } // namespace test |
| 202 } // namespace net | 190 } // namespace net |
| OLD | NEW |