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