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