File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
compiler-rt/lib/sanitizer_common/tests Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments