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