Skip to content

Commit dc603b0

Browse files
committed
[NFC][sanitizer] Add basic hash test
Differential Revision: https://reviews.llvm.org/D111176
1 parent 02c0183 commit dc603b0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(SANITIZER_UNITTESTS
1818
sanitizer_deadlock_detector_test.cpp
1919
sanitizer_flags_test.cpp
2020
sanitizer_format_interceptor_test.cpp
21+
sanitizer_hash_test.cpp
2122
sanitizer_ioctl_test.cpp
2223
sanitizer_libc_test.cpp
2324
sanitizer_linux_test.cpp
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- sanitizer_hash_test.cpp -------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file is a part of Sanitizers.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
#include "sanitizer_common/sanitizer_hash.h"
13+
14+
#include "gtest/gtest.h"
15+
16+
namespace __sanitizer {
17+
18+
// Tests matche a few hashes generated by https://github.com/aappleby/smhasher.
19+
20+
TEST(SanitizerCommon, Hash32Seed) {
21+
EXPECT_EQ(MurMur2HashBuilder(0).get(), 275646681u);
22+
EXPECT_EQ(MurMur2HashBuilder(1).get(), 3030210376u);
23+
EXPECT_EQ(MurMur2HashBuilder(3).get(), 1816185114u);
24+
}
25+
26+
TEST(SanitizerCommon, Hash32Add) {
27+
MurMur2HashBuilder h(123 * sizeof(u32));
28+
for (u32 i = 0; i < 123; ++i) h.add(i);
29+
EXPECT_EQ(h.get(), 351963665u);
30+
for (u32 i = 0; i < 123; ++i) h.add(-i);
31+
EXPECT_EQ(h.get(), 2640061027u);
32+
}
33+
34+
} // namespace __sanitizer

0 commit comments

Comments
 (0)