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
, Basic
) {
17 DEBUG_COUNTER(TestCounter
, "test-counter", "Counter used for unit test");
19 EXPECT_FALSE(DebugCounter::isCounterSet(TestCounter
));
20 auto DC
= &DebugCounter::instance();
21 DC
->push_back("test-counter=1:3-5:78:79:89:100-102:150");
23 EXPECT_TRUE(DebugCounter::isCounterSet(TestCounter
));
25 SmallVector
<unsigned> Res
;
26 for (unsigned Idx
= 0; Idx
< 200; Idx
++) {
27 if (DebugCounter::shouldExecute(TestCounter
))
31 SmallVector
<unsigned> Expected
= {1, 3, 4, 5, 78, 79, 89, 100, 101, 102, 150};
32 EXPECT_EQ(Expected
, Res
);
35 llvm::raw_string_ostream
OS(Str
);
37 EXPECT_TRUE(StringRef(Str
).contains("{200,1:3-5:78:79:89:100-102:150}"));