1 //===-- stats_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"
13 TEST(ScudoStatsTest
, LocalStats
) {
14 scudo::LocalStats LStats
;
16 for (scudo::uptr I
= 0; I
< scudo::StatCount
; I
++)
17 EXPECT_EQ(LStats
.get(static_cast<scudo::StatType
>(I
)), 0U);
18 LStats
.add(scudo::StatAllocated
, 4096U);
19 EXPECT_EQ(LStats
.get(scudo::StatAllocated
), 4096U);
20 LStats
.sub(scudo::StatAllocated
, 4096U);
21 EXPECT_EQ(LStats
.get(scudo::StatAllocated
), 0U);
22 LStats
.set(scudo::StatAllocated
, 4096U);
23 EXPECT_EQ(LStats
.get(scudo::StatAllocated
), 4096U);
26 TEST(ScudoStatsTest
, GlobalStats
) {
27 scudo::GlobalStats GStats
;
29 scudo::uptr Counters
[scudo::StatCount
] = {};
31 for (scudo::uptr I
= 0; I
< scudo::StatCount
; I
++)
32 EXPECT_EQ(Counters
[I
], 0U);
33 scudo::LocalStats LStats
;
36 for (scudo::uptr I
= 0; I
< scudo::StatCount
; I
++)
37 LStats
.add(static_cast<scudo::StatType
>(I
), 4096U);
39 for (scudo::uptr I
= 0; I
< scudo::StatCount
; I
++)
40 EXPECT_EQ(Counters
[I
], 4096U);
41 // Unlinking the local stats move numbers to the global stats.
42 GStats
.unlink(&LStats
);
44 for (scudo::uptr I
= 0; I
< scudo::StatCount
; I
++)
45 EXPECT_EQ(Counters
[I
], 4096U);