[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / unittests / Support / DebugCounterTest.cpp
blobe7345b13cc1729da7573141a772deed4bc15aa7b
1 //===- llvm/unittest/Support/DebugCounterTest.cpp -------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/DebugCounter.h"
10 #include "gtest/gtest.h"
12 #include <string>
13 using namespace llvm;
15 #ifndef NDEBUG
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));
40 #endif