| 1 | //===-- bytemap_test.cpp ----------------------------------------*- C++ -*-===// |
| 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 | #include "tests/scudo_unit_test.h" |
| 10 | |
| 11 | #include "bytemap.h" |
| 12 | |
| 13 | #include <pthread.h> |
| 14 | #include <string.h> |
| 15 | |
| 16 | template <typename T> void testMap(T &Map, scudo::uptr Size) { |
| 17 | Map.init(); |
| 18 | for (scudo::uptr I = 0; I < Size; I += 7) |
| 19 | Map.set(I, (I % 100) + 1); |
| 20 | for (scudo::uptr J = 0; J < Size; J++) { |
| 21 | if (J % 7) |
| 22 | EXPECT_EQ(Map[J], 0); |
| 23 | else |
| 24 | EXPECT_EQ(Map[J], (J % 100) + 1); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | TEST(ScudoByteMapTest, FlatByteMap) { |
| 29 | const scudo::uptr Size = 1U << 10; |
| 30 | scudo::FlatByteMap<Size> Map; |
| 31 | testMap(Map, Size); |
| 32 | Map.unmapTestOnly(); |
| 33 | } |
| 34 | |