1 //===- llvm/unittest/Support/DebugCounterTest.cpp -------------------------===//
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 "llvm/Support/DebugCounter.h"
10 #include "gtest/gtest.h"
16 TEST(DebugCounterTest
, CounterCheck
) {
17 DEBUG_COUNTER(TestCounter
, "test-counter", "Counter used for unit test");
19 EXPECT_FALSE(DebugCounter::isCounterSet(TestCounter
));
21 auto DC
= &DebugCounter::instance();
22 DC
->push_back("test-counter-skip=1");
23 DC
->push_back("test-counter-count=3");
25 EXPECT_TRUE(DebugCounter::isCounterSet(TestCounter
));
27 EXPECT_EQ(0, DebugCounter::getCounterValue(TestCounter
));
28 EXPECT_FALSE(DebugCounter::shouldExecute(TestCounter
));
30 EXPECT_EQ(1, DebugCounter::getCounterValue(TestCounter
));
31 EXPECT_TRUE(DebugCounter::shouldExecute(TestCounter
));
33 DebugCounter::setCounterValue(TestCounter
, 3);
34 EXPECT_TRUE(DebugCounter::shouldExecute(TestCounter
));
35 EXPECT_FALSE(DebugCounter::shouldExecute(TestCounter
));
37 DebugCounter::setCounterValue(TestCounter
, 100);
38 EXPECT_FALSE(DebugCounter::shouldExecute(TestCounter
));