1 //===-- size_class_map_test.cpp ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "tests/scudo_unit_test.h"
11 #include "size_class_map.h"
13 template <class SizeClassMap
> void testSizeClassMap() {
14 typedef SizeClassMap SCMap
;
15 scudo::printMap
<SCMap
>();
16 scudo::validateMap
<SCMap
>();
19 TEST(ScudoSizeClassMapTest
, DefaultSizeClassMap
) {
20 testSizeClassMap
<scudo::DefaultSizeClassMap
>();
23 TEST(ScudoSizeClassMapTest
, AndroidSizeClassMap
) {
24 testSizeClassMap
<scudo::AndroidSizeClassMap
>();
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;
37 TEST(ScudoSizeClassMapTest
, OneClassSizeClassMap
) {
38 testSizeClassMap
<scudo::FixedSizeClassMap
<OneClassSizeClassConfig
>>();
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;
52 TEST(ScudoSizeClassMapTest
, LargeMaxSizeClassMap
) {
53 testSizeClassMap
<scudo::FixedSizeClassMap
<LargeMaxSizeClassConfig
>>();