+// This test tests that when there are too many values
+// for a given site, the merged results are properly
+// truncated.
+TEST_F(InstrProfTest, get_icall_data_merge_site_trunc) {
+ static const char caller[] = "caller";
+
+ InstrProfRecord Record11(caller, 0x1234, {1, 2});
+ InstrProfRecord Record12(caller, 0x1234, {1, 2});
+
+ // 2 value sites.
+ Record11.reserveSites(IPVK_IndirectCallTarget, 2);
+ InstrProfValueData VD0[255];
+ for (int I = 0; I < 255; I++) {
+ VD0[I].Value = 2 * I;
+ VD0[I].Count = 2 * I + 1000;
+ }
+
+ Record11.addValueData(IPVK_IndirectCallTarget, 0, VD0, 255, nullptr);
+ Record11.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
+
+ Record12.reserveSites(IPVK_IndirectCallTarget, 2);
+ InstrProfValueData VD1[255];
+ for (int I = 0; I < 255; I++) {
+ VD1[I].Value = 2 * I + 1;
+ VD1[I].Count = 2 * I + 1001;
+ }
+
+ Record12.addValueData(IPVK_IndirectCallTarget, 0, VD1, 255, nullptr);
+ Record12.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
+
+ Writer.addRecord(std::move(Record11));
+ // Merge profile data.
+ Writer.addRecord(std::move(Record12));
+
+ auto Profile = Writer.writeBuffer();
+ readProfile(std::move(Profile));
+
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
+ std::unique_ptr<InstrProfValueData[]> VD(
+ R.get().getValueForSite(IPVK_IndirectCallTarget, 0));
+ ASSERT_EQ(2U, R.get().getNumValueSites(IPVK_IndirectCallTarget));
+ ASSERT_EQ(255U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
+ for (int I = 0; I < 255; I++) {
+ ASSERT_EQ(VD[I].Value, 509 - I);
+ ASSERT_EQ(VD[I].Count, 1509 - I);
+ }
+}
+