1 //===- bolt/unittests/Profile/DataAggregator.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 "bolt/Profile/DataAggregator.h"
10 #include "llvm/Support/CommandLine.h"
11 #include "gtest/gtest.h"
14 using namespace llvm::bolt
;
17 extern cl::opt
<bool> ReadPreAggregated
;
20 TEST(DataAggregatorTest
, buildID
) {
21 // Avoid looking for perf tool.
22 opts::ReadPreAggregated
= true;
24 DataAggregator
DA("<pseudo input>");
25 std::optional
<StringRef
> FileName
;
27 DA
.setParsingBuffer("");
28 ASSERT_FALSE(DA
.hasAllBuildIDs());
29 FileName
= DA
.getFileNameForBuildID("1234");
30 ASSERT_FALSE(FileName
);
32 StringRef PartialValidBuildIDs
= " File0\n"
35 DA
.setParsingBuffer(PartialValidBuildIDs
);
36 ASSERT_FALSE(DA
.hasAllBuildIDs());
37 FileName
= DA
.getFileNameForBuildID("0000");
38 ASSERT_FALSE(FileName
);
39 FileName
= DA
.getFileNameForBuildID("1111");
40 ASSERT_EQ(*FileName
, "File1");
42 StringRef AllValidBuildIDs
= "0000 File0\n"
46 DA
.setParsingBuffer(AllValidBuildIDs
);
47 ASSERT_TRUE(DA
.hasAllBuildIDs());
48 FileName
= DA
.getFileNameForBuildID("1234");
49 ASSERT_FALSE(FileName
);
50 FileName
= DA
.getFileNameForBuildID("2222");
51 ASSERT_EQ(*FileName
, "File2");
52 FileName
= DA
.getFileNameForBuildID("333");
53 ASSERT_EQ(*FileName
, "File3");