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::u32 MaxNumCachedHint = 0;
37   static const scudo::uptr MaxBytesCachedLog = 0;
38 };
39 
TEST(ScudoSizeClassMapTest,OneClassSizeClassMap)40 TEST(ScudoSizeClassMapTest, OneClassSizeClassMap) {
41   testSizeClassMap<scudo::FixedSizeClassMap<OneClassSizeClassConfig>>();
42 }
43 
44 #if SCUDO_CAN_USE_PRIMARY64
45 struct LargeMaxSizeClassConfig {
46   static const scudo::uptr NumBits = 3;
47   static const scudo::uptr MinSizeLog = 4;
48   static const scudo::uptr MidSizeLog = 8;
49   static const scudo::uptr MaxSizeLog = 63;
50   static const scudo::u32 MaxNumCachedHint = 128;
51   static const scudo::uptr MaxBytesCachedLog = 16;
52 };
53 
TEST(ScudoSizeClassMapTest,LargeMaxSizeClassMap)54 TEST(ScudoSizeClassMapTest, LargeMaxSizeClassMap) {
55   testSizeClassMap<scudo::FixedSizeClassMap<LargeMaxSizeClassConfig>>();
56 }
57 #endif
58