George Burgess IV | b00fb46 | 2018-07-23 21:49:36 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/Support/DebugCounterTest.cpp -------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
George Burgess IV | b00fb46 | 2018-07-23 21:49:36 +0000 | [diff] [blame] | 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 |
George Burgess IV | b00fb46 | 2018-07-23 21:49:36 +0000 | [diff] [blame] | 16 | TEST(DebugCounterTest, CounterCheck) { |
Alexandre Ganea | bc2f06c | 2018-08-29 16:11:48 +0000 | [diff] [blame] | 17 | DEBUG_COUNTER(TestCounter, "test-counter", "Counter used for unit test"); |
| 18 | |
George Burgess IV | b00fb46 | 2018-07-23 21:49:36 +0000 | [diff] [blame] | 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 |