1//===-- ContextCompressionTest.cpp -------------------------------*- C++ -*-===//
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//===----------------------------------------------------------------------===//
8#include "../tools/llvm-profgen/ProfileGenerator.h"
9#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
10#include "gtest/gtest.h"
11
12using namespace llvm;
13using namespace sampleprof;
14
15TEST(TestCompression, TestNoSizeLimit1) {
16 SmallVector<std::string, 16> Context = {"a", "b", "c", "a", "b", "c"};
17 SmallVector<std::string, 16> Expect = {"a", "b", "c"};
18 CSProfileGenerator::compressRecursionContext(Context, CSize: -1);
19 EXPECT_TRUE(std::equal(Context.begin(), Context.end(), Expect.begin()));
20}
21
22TEST(TestCompression, TestNoSizeLimit2) {
23 SmallVector<std::string, 16> Context = {"m", "a", "a", "b", "c", "a",
24 "b", "c", "b", "c", "d"};
25 SmallVector<std::string, 16> Expect = {"m", "a", "b", "c", "d"};
26 CSProfileGenerator::compressRecursionContext(Context, CSize: -1);
27 EXPECT_TRUE(std::equal(Context.begin(), Context.end(), Expect.begin()));
28}
29
30TEST(TestCompression, TestMaxDedupSize) {
31 SmallVector<std::string, 16> Context = {"m", "a", "a", "b", "c", "a",
32 "b", "c", "b", "c", "d"};
33 SmallVector<std::string, 16> Expect = {"m", "a", "b", "c",
34 "a", "b", "c", "d"};
35 CSProfileGenerator::compressRecursionContext(Context, CSize: 2);
36 EXPECT_TRUE(std::equal(Context.begin(), Context.end(), Expect.begin()));
37}
38

source code of llvm/unittests/tools/llvm-profgen/ContextCompressionTest.cpp