| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "llvm/Support/DebugCounter.h" |
| 10 |
#include "gtest/gtest.h" |
| 11 |
|
| 12 |
#include <string> |
| 13 |
using namespace llvm; |
| 14 |
|
| 15 |
#ifndef NDEBUG |
| 16 |
TEST(DebugCounterTest, CounterCheck) { |
| 17 |
DEBUG_COUNTER(TestCounter, "test-counter", "Counter used for unit test"); |
| 18 |
|
| 19 |
EXPECT_FALSE(DebugCounter::isCounterSet(TestCounter)); |
| 20 |
|
| 21 |
auto DC = &DebugCounter::instance(); |
| 22 |
DC->push_back("test-counter-skip=1"); |
| 23 |
DC->push_back("test-counter-count=3"); |
| 24 |
|
| 25 |
EXPECT_TRUE(DebugCounter::isCounterSet(TestCounter)); |
| 26 |
|
| 27 |
EXPECT_EQ(0, DebugCounter::getCounterValue(TestCounter)); |
| 28 |
EXPECT_FALSE(DebugCounter::shouldExecute(TestCounter)); |
| 29 |
|
| 30 |
EXPECT_EQ(1, DebugCounter::getCounterValue(TestCounter)); |
| 31 |
EXPECT_TRUE(DebugCounter::shouldExecute(TestCounter)); |
| 32 |
|
| 33 |
DebugCounter::setCounterValue(TestCounter, 3); |
| 34 |
EXPECT_TRUE(DebugCounter::shouldExecute(TestCounter)); |
| 35 |
EXPECT_FALSE(DebugCounter::shouldExecute(TestCounter)); |
| 36 |
|
| 37 |
DebugCounter::setCounterValue(TestCounter, 100); |
| 38 |
EXPECT_FALSE(DebugCounter::shouldExecute(TestCounter)); |
| 39 |
} |
| 40 |
#endif |