| 1 | //===-- size_class_map_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 "size_class_map.h" |
| 12 | |
| 13 | template <class SizeClassMap> void testSizeClassMap() { |
| 14 | typedef SizeClassMap SCMap; |
| 15 | scudo::printMap<SCMap>(); |
| 16 | scudo::validateMap<SCMap>(); |
| 17 | } |
| 18 | |
| 19 | TEST(ScudoSizeClassMapTest, DefaultSizeClassMap) { |
| 20 | testSizeClassMap<scudo::DefaultSizeClassMap>(); |
| 21 | } |
| 22 | |
| 23 | TEST(ScudoSizeClassMapTest, AndroidSizeClassMap) { |
| 24 | testSizeClassMap<scudo::AndroidSizeClassMap>(); |
| 25 | } |
| 26 | |
| 27 | struct OneClassSizeClassConfig { |
| 28 | static const scudo::uptr NumBits = 1; |
| 29 | static const scudo::uptr MinSizeLog = 5; |
| 30 | static const scudo::uptr MidSizeLog = 5; |
| 31 | static const scudo::uptr MaxSizeLog = 5; |
| 32 | static const scudo::u16 MaxNumCachedHint = 0; |
| 33 | static const scudo::uptr MaxBytesCachedLog = 0; |
| 34 | static const scudo::uptr SizeDelta = 0; |
| 35 | }; |
| 36 | |
| 37 | TEST(ScudoSizeClassMapTest, OneClassSizeClassMap) { |
| 38 | testSizeClassMap<scudo::FixedSizeClassMap<OneClassSizeClassConfig>>(); |
| 39 | } |
| 40 | |
| 41 | #if SCUDO_CAN_USE_PRIMARY64 |
| 42 | struct LargeMaxSizeClassConfig { |
| 43 | static const scudo::uptr NumBits = 3; |
| 44 | static const scudo::uptr MinSizeLog = 4; |
| 45 | static const scudo::uptr MidSizeLog = 8; |
| 46 | static const scudo::uptr MaxSizeLog = 63; |
| 47 | static const scudo::u16 MaxNumCachedHint = 128; |
| 48 | static const scudo::uptr MaxBytesCachedLog = 16; |
| 49 | static const scudo::uptr SizeDelta = 0; |
| 50 | }; |
| 51 | |
| 52 | TEST(ScudoSizeClassMapTest, LargeMaxSizeClassMap) { |
| 53 | testSizeClassMap<scudo::FixedSizeClassMap<LargeMaxSizeClassConfig>>(); |
| 54 | } |
| 55 | #endif |
| 56 |
