Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / unittests / Support / DebugCounterTest.cpp
blob820b1ce5ca0d3783e85014341c764db333a98c92
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, 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))
28 Res.push_back(Idx);
31 SmallVector<unsigned> Expected = {1, 3, 4, 5, 78, 79, 89, 100, 101, 102, 150};
32 EXPECT_EQ(Expected, Res);
34 std::string Str;
35 llvm::raw_string_ostream OS(Str);
36 DC->print(OS);
37 EXPECT_TRUE(StringRef(Str).contains("{200,1:3-5:78:79:89:100-102:150}"));
40 #endif