1ac14bb14Swlei //===-- ContextCompressionTest.cpp -------------------------------*- C++ -*-===//
2ac14bb14Swlei //
3ac14bb14Swlei // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ac14bb14Swlei // See https://llvm.org/LICENSE.txt for license information.
5ac14bb14Swlei // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ac14bb14Swlei //
7ac14bb14Swlei //===----------------------------------------------------------------------===//
8ac14bb14Swlei #include "../tools/llvm-profgen/ProfileGenerator.h"
9*db29f437Sserge-sans-paille #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
10ac14bb14Swlei #include "gtest/gtest.h"
11ac14bb14Swlei
12ac14bb14Swlei using namespace llvm;
13ac14bb14Swlei using namespace sampleprof;
14ac14bb14Swlei
TEST(TestCompression,TestNoSizeLimit1)15ac14bb14Swlei TEST(TestCompression, TestNoSizeLimit1) {
16ac14bb14Swlei SmallVector<std::string, 16> Context = {"a", "b", "c", "a", "b", "c"};
17ac14bb14Swlei SmallVector<std::string, 16> Expect = {"a", "b", "c"};
18ac14bb14Swlei CSProfileGenerator::compressRecursionContext(Context, -1);
19ac14bb14Swlei EXPECT_TRUE(std::equal(Context.begin(), Context.end(), Expect.begin()));
20ac14bb14Swlei }
21ac14bb14Swlei
TEST(TestCompression,TestNoSizeLimit2)22ac14bb14Swlei TEST(TestCompression, TestNoSizeLimit2) {
23ac14bb14Swlei SmallVector<std::string, 16> Context = {"m", "a", "a", "b", "c", "a",
24ac14bb14Swlei "b", "c", "b", "c", "d"};
25ac14bb14Swlei SmallVector<std::string, 16> Expect = {"m", "a", "b", "c", "d"};
26ac14bb14Swlei CSProfileGenerator::compressRecursionContext(Context, -1);
27ac14bb14Swlei EXPECT_TRUE(std::equal(Context.begin(), Context.end(), Expect.begin()));
28ac14bb14Swlei }
29ac14bb14Swlei
TEST(TestCompression,TestMaxDedupSize)30ac14bb14Swlei TEST(TestCompression, TestMaxDedupSize) {
31ac14bb14Swlei SmallVector<std::string, 16> Context = {"m", "a", "a", "b", "c", "a",
32ac14bb14Swlei "b", "c", "b", "c", "d"};
33ac14bb14Swlei SmallVector<std::string, 16> Expect = {"m", "a", "b", "c",
34ac14bb14Swlei "a", "b", "c", "d"};
35ac14bb14Swlei CSProfileGenerator::compressRecursionContext(Context, 2);
36ac14bb14Swlei EXPECT_TRUE(std::equal(Context.begin(), Context.end(), Expect.begin()));
37ac14bb14Swlei }
38