[llvm-profgen][NFC] Fix test failure by making unwinder's output deterministic
authorwlei <wlei@fb.com>
Tue, 8 Dec 2020 06:01:17 +0000 (22:01 -0800)
committerwlei <wlei@fb.com>
Tue, 8 Dec 2020 06:36:25 +0000 (22:36 -0800)
Don't know why under Sanitizer build(asan/msan/ubsan), the `std::unordered_map<string, ...>`'s output order is reversed, make the regression test failed.

This change creates a workaround by using sorted container to make the output deterministic.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D92816

llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
llvm/tools/llvm-profgen/PerfReader.cpp

index 649e27e..98767a9 100644 (file)
 ; CHECK: 1: 14
 
 ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Range Counter:
-; CHECK-UNWINDER: main:1 @ foo:3.2 @ bar
-; CHECK-UNWINDER:   (6af, 6bb): 14
 ; CHECK-UNWINDER: main:1 @ foo
 ; CHECK-UNWINDER:   (670, 6ad): 1
 ; CHECK-UNWINDER:   (67e, 69b): 1
 ; CHECK-UNWINDER:   (67e, 6ad): 13
 ; CHECK-UNWINDER:   (6bd, 6c8): 14
+; CHECK-UNWINDER: main:1 @ foo:3.2 @ bar
+; CHECK-UNWINDER:   (6af, 6bb): 14
+
 
 ; CHECK-UNWINDER: Binary(inline-cs-noprobe.perfbin)'s Branch Counter:
 ; CHECK-UNWINDER: main:1 @ foo
index e6625d1..6a0d54e 100644 (file)
@@ -199,7 +199,10 @@ ProfiledBinary *PerfReader::getBinary(uint64_t Address) {
 }
 
 static void printSampleCounter(ContextRangeCounter &Counter) {
-  for (auto Range : Counter) {
+  // Use ordered map to make the output deterministic
+  std::map<std::string, RangeSample> OrderedCounter(Counter.begin(),
+                                                    Counter.end());
+  for (auto Range : OrderedCounter) {
     outs() << Range.first << "\n";
     for (auto I : Range.second) {
       outs() << "  (" << format("%" PRIx64, I.first.first) << ", "