blob: e7345b13cc1729da7573141a772deed4bc15aa7b [file] [log] [blame]
George Burgess IVb00fb462018-07-23 21:49:36 +00001//===- llvm/unittest/Support/DebugCounterTest.cpp -------------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 IVb00fb462018-07-23 21:49:36 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/Support/DebugCounter.h"
10#include "gtest/gtest.h"
11
12#include <string>
13using namespace llvm;
14
15#ifndef NDEBUG
George Burgess IVb00fb462018-07-23 21:49:36 +000016TEST(DebugCounterTest, CounterCheck) {
Alexandre Ganeabc2f06c2018-08-29 16:11:48 +000017 DEBUG_COUNTER(TestCounter, "test-counter", "Counter used for unit test");
18
George Burgess IVb00fb462018-07-23 21:49:36 +000019 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