Squashed 'third_party/llvm-7.0/llvm/' content from commit 65ce2e56889
git-subtree-dir: third_party/llvm-7.0/llvm
git-subtree-split: 65ce2e56889af84e8be8e311f484a4dfe4b62d7a
diff --git a/test/tools/llvm-profdata/Inputs/IR_profile.proftext b/test/tools/llvm-profdata/Inputs/IR_profile.proftext
new file mode 100644
index 0000000..7b7340e
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/IR_profile.proftext
@@ -0,0 +1,9 @@
+:ir
+main
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+1
+
diff --git a/test/tools/llvm-profdata/Inputs/bad-hash.proftext b/test/tools/llvm-profdata/Inputs/bad-hash.proftext
new file mode 100644
index 0000000..faa6f40
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/bad-hash.proftext
@@ -0,0 +1,4 @@
+function_count_not
+badhash
+1
+1
diff --git a/test/tools/llvm-profdata/Inputs/bar3-1.proftext b/test/tools/llvm-profdata/Inputs/bar3-1.proftext
new file mode 100644
index 0000000..5486e9d
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/bar3-1.proftext
@@ -0,0 +1,6 @@
+bar
+3
+3
+1
+2
+3
diff --git a/test/tools/llvm-profdata/Inputs/basic.proftext b/test/tools/llvm-profdata/Inputs/basic.proftext
new file mode 100644
index 0000000..db934da
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/basic.proftext
@@ -0,0 +1,19 @@
+foo
+10
+2
+499500
+179900
+
+main
+16650
+4
+1
+1000
+1000000
+499500
+
+foo2
+10
+2
+500500
+180100
diff --git a/test/tools/llvm-profdata/Inputs/c-general.profraw b/test/tools/llvm-profdata/Inputs/c-general.profraw
new file mode 100644
index 0000000..332d11b
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/c-general.profraw
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/clang_profile.proftext b/test/tools/llvm-profdata/Inputs/clang_profile.proftext
new file mode 100644
index 0000000..5419d23
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/clang_profile.proftext
@@ -0,0 +1,8 @@
+main
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
+
diff --git a/test/tools/llvm-profdata/Inputs/compat.profdata.v1 b/test/tools/llvm-profdata/Inputs/compat.profdata.v1
new file mode 100644
index 0000000..fd17459
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/compat.profdata.v1
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/compat.profdata.v2 b/test/tools/llvm-profdata/Inputs/compat.profdata.v2
new file mode 100644
index 0000000..9698675
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/compat.profdata.v2
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/compat.profdata.v4 b/test/tools/llvm-profdata/Inputs/compat.profdata.v4
new file mode 100644
index 0000000..7db0d1d
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/compat.profdata.v4
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/compressed.profraw b/test/tools/llvm-profdata/Inputs/compressed.profraw
new file mode 100644
index 0000000..0cfaa07
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/compressed.profraw
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
new file mode 100644
index 0000000..45d028e
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-1.proftext
@@ -0,0 +1,13 @@
+foo
+1024
+1
+0
+
+foo
+1024
+5
+0
+0
+0
+0
+0
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext
new file mode 100644
index 0000000..261bfdd
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-2.proftext
@@ -0,0 +1,5 @@
+foo
+1024
+2
+0
+0
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext
new file mode 100644
index 0000000..ca70a71
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-3.proftext
@@ -0,0 +1,6 @@
+foo
+1024
+3
+0
+0
+0
diff --git a/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext b/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext
new file mode 100644
index 0000000..f403382
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/counter-mismatch-4.proftext
@@ -0,0 +1,7 @@
+foo
+1024
+4
+0
+0
+0
+0
diff --git a/test/tools/llvm-profdata/Inputs/empty.proftext b/test/tools/llvm-profdata/Inputs/empty.proftext
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/empty.proftext
diff --git a/test/tools/llvm-profdata/Inputs/extra-word.proftext b/test/tools/llvm-profdata/Inputs/extra-word.proftext
new file mode 100644
index 0000000..67a6629
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/extra-word.proftext
@@ -0,0 +1,2 @@
+extra 1 word
+1
diff --git a/test/tools/llvm-profdata/Inputs/foo3-1.proftext b/test/tools/llvm-profdata/Inputs/foo3-1.proftext
new file mode 100644
index 0000000..14a6200
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/foo3-1.proftext
@@ -0,0 +1,6 @@
+foo
+3
+3
+1
+2
+3
diff --git a/test/tools/llvm-profdata/Inputs/foo3-2.proftext b/test/tools/llvm-profdata/Inputs/foo3-2.proftext
new file mode 100644
index 0000000..801846e
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/foo3-2.proftext
@@ -0,0 +1,6 @@
+foo
+3
+3
+7
+5
+3
diff --git a/test/tools/llvm-profdata/Inputs/foo3bar3-1.proftext b/test/tools/llvm-profdata/Inputs/foo3bar3-1.proftext
new file mode 100644
index 0000000..12157b9
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/foo3bar3-1.proftext
@@ -0,0 +1,13 @@
+foo
+3
+3
+2
+3
+5
+
+bar
+3
+3
+7
+11
+13
diff --git a/test/tools/llvm-profdata/Inputs/gcc-sample-profile.gcov b/test/tools/llvm-profdata/Inputs/gcc-sample-profile.gcov
new file mode 100644
index 0000000..0099280
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/gcc-sample-profile.gcov
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/inline-samples.afdo b/test/tools/llvm-profdata/Inputs/inline-samples.afdo
new file mode 100644
index 0000000..f8680d8
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/inline-samples.afdo
@@ -0,0 +1,20 @@
+main:366846:0
+ 2.1: 60401
+ 4: 0
+ 3: 0
+ 0: 0
+ 2.3: 60401
+ 1: 0
+ 2.3: _Z3fool:246044
+ 1.2: 39280
+ 1.4: 46871
+ 1: 60401
+ 1.3: _Z3bari:0
+ 1.2: 0
+ 1.1: 0
+ 1.8: _Z3bari:0
+ 1.2: 0
+ 1.1: 0
+ 1.7: _Z3bari:99492
+ 1.2: 46732
+ 1.1: 52760
diff --git a/test/tools/llvm-profdata/Inputs/invalid-count-later.proftext b/test/tools/llvm-profdata/Inputs/invalid-count-later.proftext
new file mode 100644
index 0000000..2b61c55
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/invalid-count-later.proftext
@@ -0,0 +1,4 @@
+invalid_count
+1
+1
+1later
diff --git a/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext b/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext
new file mode 100644
index 0000000..090a40f
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext
@@ -0,0 +1,106 @@
+# IR level Instrumentation Flag
+:ir
+foo
+# Func Hash:
+36982789018
+# Num Counters:
+4
+# Counter Values:
+700000
+700000
+0
+0
+
+foo
+# Func Hash:
+59188585735
+# Num Counters:
+6
+# Counter Values:
+400000
+400000
+0
+0
+0
+0
+
+foo
+# Func Hash:
+27904764724
+# Num Counters:
+3
+# Counter Values:
+200000
+200000
+0
+
+foo
+# Func Hash:
+60466382370
+# Num Counters:
+6
+# Counter Values:
+0
+100000
+0
+0
+0
+0
+
+bar
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo2
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo3
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo4
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo5
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo1
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+100000
+
+main
+# Func Hash:
+29212902728
+# Num Counters:
+2
+# Counter Values:
+1400000
+14
+
diff --git a/test/tools/llvm-profdata/Inputs/no-counts.proftext b/test/tools/llvm-profdata/Inputs/no-counts.proftext
new file mode 100644
index 0000000..5c1fa15
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/no-counts.proftext
@@ -0,0 +1,3 @@
+no_counts
+0
+0
diff --git a/test/tools/llvm-profdata/Inputs/overflow-instr.proftext b/test/tools/llvm-profdata/Inputs/overflow-instr.proftext
new file mode 100644
index 0000000..48d1db8
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/overflow-instr.proftext
@@ -0,0 +1,6 @@
+overflow
+1
+3
+18446744073709551615
+9223372036854775808
+18446744073709551615
diff --git a/test/tools/llvm-profdata/Inputs/overflow-sample.proftext b/test/tools/llvm-profdata/Inputs/overflow-sample.proftext
new file mode 100644
index 0000000..a5486bb
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/overflow-sample.proftext
@@ -0,0 +1,7 @@
+_Z3bari:18446744073709551615:1000
+ 1: 18446744073709551615
+_Z3fooi:18446744073709551615:1000
+ 1: 18446744073709551615
+main:1000:0
+ 1: 500 _Z3bari:18446744073709551615
+ 2: 500 _Z3fooi:18446744073709551615
diff --git a/test/tools/llvm-profdata/Inputs/sample-profile.proftext b/test/tools/llvm-profdata/Inputs/sample-profile.proftext
new file mode 100644
index 0000000..e34128f
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/sample-profile.proftext
@@ -0,0 +1,16 @@
+_Z3bari:20301:1437
+ 1: 1437
+_Z3fooi:7711:610
+ 1: 610
+main:184019:0
+ 4: 534
+ 4.2: 534
+ 5: 1075
+ 5.1: 1075
+ 6: 2080
+ 7: 534
+ 9: 2064 _Z3bari:1471 _Z3fooi:631
+ 10: inline1:1000
+ 1: 1000
+ 10: inline2:2000
+ 1: 2000
diff --git a/test/tools/llvm-profdata/Inputs/text-format-errors.text.bin b/test/tools/llvm-profdata/Inputs/text-format-errors.text.bin
new file mode 100644
index 0000000..9e2e3f5
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/text-format-errors.text.bin
@@ -0,0 +1 @@
+ÿåбôɨ
\ No newline at end of file
diff --git a/test/tools/llvm-profdata/Inputs/vp-malform.proftext b/test/tools/llvm-profdata/Inputs/vp-malform.proftext
new file mode 100644
index 0000000..2db3096
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/vp-malform.proftext
@@ -0,0 +1,42 @@
+foo
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+999000
+359800
+
+foo2
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+1001000
+360200
+
+main
+# Func Hash:
+16650
+# Num Counters:
+4
+# Counter Values:
+2
+2000
+2000000
+999000
+# NumValueKinds
+1
+# Value Kind IPVK_IndirectCallTarget
+0
+# NumSites
+3
+# Values for each site
+0
+2
+# !!!! Malformed Value/Count pair
+foo+100
+foo2:1000
+1
+foo2:20000
diff --git a/test/tools/llvm-profdata/Inputs/vp-malform2.proftext b/test/tools/llvm-profdata/Inputs/vp-malform2.proftext
new file mode 100644
index 0000000..02ed5a9
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/vp-malform2.proftext
@@ -0,0 +1,32 @@
+foo
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+999000
+359800
+
+main
+# Func Hash:
+16650
+# Num Counters:
+4
+# Counter Values:
+2
+2000
+2000000
+999000
+# NumValueKinds
+1
+# Value Kind IPVK_IndirectCallTarget
+0
+# NumSites
+3
+# Values for each site
+0
+# !! Malformed value site, missing one value
+2
+foo:100
+1
+foo2:20000
diff --git a/test/tools/llvm-profdata/Inputs/vp-truncate.proftext b/test/tools/llvm-profdata/Inputs/vp-truncate.proftext
new file mode 100644
index 0000000..98b4b57
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/vp-truncate.proftext
@@ -0,0 +1,36 @@
+foo
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+999000
+359800
+
+foo2
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+1001000
+360200
+
+main
+# Func Hash:
+16650
+# Num Counters:
+4
+# Counter Values:
+2
+2000
+2000000
+999000
+# NumValueKinds
+1
+# Value Kind IPVK_IndirectCallTarget
+0
+# NumSites
+3
+# Values for each site
+0
diff --git a/test/tools/llvm-profdata/Inputs/weight-instr-bar.profdata b/test/tools/llvm-profdata/Inputs/weight-instr-bar.profdata
new file mode 100644
index 0000000..4ed0766
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/weight-instr-bar.profdata
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/weight-instr-foo.profdata b/test/tools/llvm-profdata/Inputs/weight-instr-foo.profdata
new file mode 100644
index 0000000..581ef39
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/weight-instr-foo.profdata
Binary files differ
diff --git a/test/tools/llvm-profdata/Inputs/weight-sample-bar.proftext b/test/tools/llvm-profdata/Inputs/weight-sample-bar.proftext
new file mode 100644
index 0000000..a910f74
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/weight-sample-bar.proftext
@@ -0,0 +1,8 @@
+bar:1772037:35370
+ 17: 35370
+ 18: 35370
+ 19: 7005
+ 20: 29407
+ 21: 12170
+ 23: 18150 bar:19829
+ 25: 36666
diff --git a/test/tools/llvm-profdata/Inputs/weight-sample-foo.proftext b/test/tools/llvm-profdata/Inputs/weight-sample-foo.proftext
new file mode 100644
index 0000000..155ec5d
--- /dev/null
+++ b/test/tools/llvm-profdata/Inputs/weight-sample-foo.proftext
@@ -0,0 +1,8 @@
+foo:1763288:35327
+ 7: 35327
+ 8: 35327
+ 9: 6930
+ 10: 29341
+ 11: 11906
+ 13: 18185 foo:19531
+ 15: 36458
diff --git a/test/tools/llvm-profdata/c-general.test b/test/tools/llvm-profdata/c-general.test
new file mode 100644
index 0000000..ed4e619
--- /dev/null
+++ b/test/tools/llvm-profdata/c-general.test
@@ -0,0 +1,27 @@
+You need a checkout of clang with compiler-rt to generate the
+binary file here. These shell commands can be used to regenerate
+it.
+$ SRC=path/to/llvm
+$ CFE=$SRC/tools/clang
+$ TESTDIR=$SRC/test/tools/llvm-profdata
+$ CFE_TESTDIR=$CFE/test/Profile
+$ clang -o a.out -fprofile-instr-generate $CFE_TESTDIR/c-general.c
+$ LLVM_PROFILE_FILE=$TESTDIR/Inputs/c-general.profraw ./a.out
+
+RUN: llvm-profdata show %p/Inputs/c-general.profraw -o - | FileCheck %s
+RUN: llvm-profdata show %p/Inputs/c-general.profraw --topn=3 -o - | FileCheck %s --check-prefix=TOPN
+RUN: llvm-profdata show %p/Inputs/c-general.profraw -o - --function=switches | FileCheck %s -check-prefix=SWITCHES -check-prefix=CHECK
+
+SWITCHES-LABEL: Counters:
+SWITCHES-NEXT: switches:
+SWITCHES-NEXT: Hash: 0x2618e4f23f2e8daa
+SWITCHES-NEXT: Counters: 19
+SWITCHES-NEXT: Function count: 1
+SWITCHES-LABEL: Functions shown: 1
+
+CHECK-LABEL: Total functions: 12
+CHECK-NEXT: Maximum function count: 1
+CHECK-NEXT: Maximum internal block count: 100
+TOPN: boolean_operators, max count = 100
+TOPN-NEXT: simple_loops, max count = 100
+TOPN-NEXT: conditionals, max count = 100
diff --git a/test/tools/llvm-profdata/compat.proftext b/test/tools/llvm-profdata/compat.proftext
new file mode 100644
index 0000000..73321cc
--- /dev/null
+++ b/test/tools/llvm-profdata/compat.proftext
@@ -0,0 +1,89 @@
+# Compatibility tests for older profile format versions. These ensure
+# that we don't break compatibility with an older profile version
+# without noticing it.
+
+# The input file at %S/Inputs/compat.profdata.v1 was generated with
+# llvm-profdata merge from r214548.
+
+# RUN: llvm-profdata show %S/Inputs/compat.profdata.v1 --function function_count_only --counts | FileCheck %s -check-prefix=FUNC_COUNT_ONLY
+function_count_only
+0
+1
+97531
+# FUNC_COUNT_ONLY: Hash: 0x{{0+$}}
+# FUNC_COUNT_ONLY-NEXT: Counters: 1
+# FUNC_COUNT_ONLY-NEXT: Function count: 97531
+# FUNC_COUNT_ONLY-NEXT: Block counts: []
+
+# RUN: llvm-profdata show %S/Inputs/compat.profdata.v1 --function "name with spaces" --counts | FileCheck %s -check-prefix=SPACES
+name with spaces
+1024
+2
+0
+0
+# SPACES: Hash: 0x{{0+}}400
+# SPACES-NEXT: Counters: 2
+# SPACES-NEXT: Function count: 0
+# SPACES-NEXT: Block counts: [0]
+
+# RUN: llvm-profdata show %S/Inputs/compat.profdata.v1 --function large_numbers --counts | FileCheck %s -check-prefix=LARGENUM
+large_numbers
+4611686018427387903
+6
+2305843009213693952
+1152921504606846976
+576460752303423488
+288230376151711744
+144115188075855872
+72057594037927936
+# LARGENUM: Hash: 0x3fffffffffffffff
+# LARGENUM-NEXT: Counters: 6
+# LARGENUM-NEXT: Function count: 2305843009213693952
+# LARGENUM-NEXT: Block counts: [1152921504606846976, 576460752303423488, 288230376151711744, 144115188075855872, 72057594037927936]
+
+# RUN: llvm-profdata show %S/Inputs/compat.profdata.v1 | FileCheck %s -check-prefix=SUMMARY
+# SUMMARY: Total functions: 3
+# SUMMARY: Maximum function count: 2305843009213693952
+# SUMMARY: Maximum internal block count: 1152921504606846976
+
+# RUN: llvm-profdata show %S/Inputs/compat.profdata.v2 -all-functions --counts | FileCheck %s -check-prefix=FORMATV2
+
+# FORMATV2: Counters:
+# FORMATV2-NEXT: foo:
+# FORMATV2-NEXT: Hash: 0x000000000000000a
+# FORMATV2-NEXT: Counters: 2
+# FORMATV2-NEXT: Function count: 499500
+# FORMATV2-NEXT: Block counts: [179900]
+# FORMATV2-NEXT: main:
+# FORMATV2-NEXT: Hash: 0x000000000000410a
+# FORMATV2-NEXT: Counters: 4
+# FORMATV2-NEXT: Function count: 1
+# FORMATV2-NEXT: Block counts: [1000, 1000000, 499500]
+# FORMATV2-NEXT: Instrumentation level: Front-end
+# FORMATV2-NEXT: Functions shown: 2
+# FORMATV2-NEXT: Total functions: 2
+# FORMATV2-NEXT: Maximum function count: 499500
+# FORMATV2-NEXT: Maximum internal block count: 1000000
+#
+# RUN: llvm-profdata show %S/Inputs/compat.profdata.v4 -all-functions --counts | FileCheck %s -check-prefix=FORMATV4
+
+# FORMATV4: Counters:
+# FORMATV4: name with spaces:
+# FORMATV4: Hash: 0x0000000000000400
+# FORMATV4: Counters: 2
+# FORMATV4: Function count: 0
+# FORMATV4: Block counts: [0]
+# FORMATV4: function_count_only:
+# FORMATV4: Hash: 0x0000000000000000
+# FORMATV4: Counters: 1
+# FORMATV4: Function count: 97531
+# FORMATV4: Block counts: []
+# FORMATV4: large_numbers:
+# FORMATV4: Hash: 0x3fffffffffffffff
+# FORMATV4: Counters: 6
+# FORMATV4: Function count: 2305843009213693952
+# FORMATV4: Block counts: [1152921504606846976, 576460752303423488, 288230376151711744, 144115188075855872, 72057594037927936]
+# FORMATV4: Functions shown: 3
+# FORMATV4: Total functions: 3
+# FORMATV4: Maximum function count: 2305843009213693952
+# FORMATV4: Maximum internal block count: 1152921504606846976
diff --git a/test/tools/llvm-profdata/count-mismatch.proftext b/test/tools/llvm-profdata/count-mismatch.proftext
new file mode 100644
index 0000000..b42b11d
--- /dev/null
+++ b/test/tools/llvm-profdata/count-mismatch.proftext
@@ -0,0 +1,41 @@
+# Make sure we don't try to combine counters with the same function
+# name and a matching hash if the number of counters differs
+
+# RUN: llvm-profdata merge %s -o %t.profdata 2>&1 | FileCheck -check-prefix=MERGE_ERRS %s
+# RUN: llvm-profdata show %t.profdata -all-functions -counts > %t.out
+# RUN: FileCheck %s -input-file %t.out
+foo
+1024
+4
+1
+2
+4
+8
+
+# The hash matches, but we can't combine these because the number of
+# counters differs.
+# MERGE_ERRS: count-mismatch.proftext: foo: Function basic block count change detected (counter mismatch)
+# MERGE_ERRS: Make sure that all profile data to be merged is generated from the same binary.
+foo
+1024
+3
+2
+4
+8
+
+# This one does match, so it should combine with the first just fine.
+# CHECK: Hash: 0x{{0+}}400
+# CHECK-NEXT: Counters: 4
+# CHECK-NEXT: Function count: 5
+# CHECK-NEXT: Block counts: [10, 20, 40]
+foo
+1024
+4
+4
+8
+16
+32
+
+# CHECK: Total functions: 1
+# CHECK: Maximum function count: 5
+# CHECK: Maximum internal block count: 40
diff --git a/test/tools/llvm-profdata/gcc-gcov-sample-profile.test b/test/tools/llvm-profdata/gcc-gcov-sample-profile.test
new file mode 100644
index 0000000..087c8a7
--- /dev/null
+++ b/test/tools/llvm-profdata/gcc-gcov-sample-profile.test
@@ -0,0 +1,29 @@
+The input gcov file has been generated on a little endian machine. Expect
+failures on big endian systems.
+
+XFAIL: powerpc-, powerpc64-, s390x, mips-, mips64-, sparc
+
+Tests for sample profiles encoded in GCC's gcov format.
+
+1- Show all functions. This profile has a single main() function with several
+ inlined callees.
+RUN: llvm-profdata show --sample %p/Inputs/gcc-sample-profile.gcov | FileCheck %s --check-prefix=SHOW1
+SHOW1: Function: main: 364084, 0, 6 sampled lines
+SHOW1: 2.3: inlined callee: _Z3fool: 243786, 0, 3 sampled lines
+SHOW1: 1.3: inlined callee: _Z3bari: 0, 0, 2 sampled lines
+SHOW1: 1.7: inlined callee: _Z3bari: 98558, 0, 2 sampled lines
+SHOW1: 1.8: inlined callee: _Z3bari: 0, 0, 2 sampled lines
+
+2- Convert the profile to text encoding and check that they are both
+ identical.
+RUN: llvm-profdata merge --sample %p/Inputs/gcc-sample-profile.gcov --text -o - | llvm-profdata show --sample - -o %t-text
+RUN: llvm-profdata show --sample %p/Inputs/gcc-sample-profile.gcov -o %t-gcov
+RUN: diff %t-text %t-gcov
+
+4- Merge the gcov and text encodings of the profile and check that the
+ counters have doubled.
+RUN: llvm-profdata merge --sample --text %p/Inputs/gcc-sample-profile.gcov -o %t-gcov
+RUN: llvm-profdata merge --sample --text %p/Inputs/gcc-sample-profile.gcov %t-gcov -o - | FileCheck %s --check-prefix=MERGE1
+MERGE1: main:728168:0
+MERGE1: 2.3: 120298
+MERGE1: 2.3: _Z3fool:487572
diff --git a/test/tools/llvm-profdata/general.proftext b/test/tools/llvm-profdata/general.proftext
new file mode 100644
index 0000000..6669cd6
--- /dev/null
+++ b/test/tools/llvm-profdata/general.proftext
@@ -0,0 +1,88 @@
+# RUN: llvm-profdata merge -sparse=true %s -o %t.profdata
+
+# RUN: llvm-profdata merge -sparse=false %s -o %t.profdata.dense
+
+# RUN: llvm-profdata show %t.profdata --function function_count_only --counts | FileCheck %s -check-prefix=FUNC_COUNT_ONLY
+function_count_only
+0
+1
+97531
+# FUNC_COUNT_ONLY: Hash: 0x{{0+$}}
+# FUNC_COUNT_ONLY-NEXT: Counters: 1
+# FUNC_COUNT_ONLY-NEXT: Function count: 97531
+# FUNC_COUNT_ONLY-NEXT: Block counts: []
+
+# RUN: llvm-profdata show %t.profdata.dense --function "name with spaces" --counts | FileCheck %s -check-prefix=SPACES
+# RUN: llvm-profdata show %t.profdata --function "name with spaces" --counts | FileCheck %s --check-prefix=SPARSE_SPACES
+name with spaces
+1024
+2
+0
+0
+# SPACES: Hash: 0x{{0+}}400
+# SPACES-NEXT: Counters: 2
+# SPACES-NEXT: Function count: 0
+# SPACES-NEXT: Block counts: [0]
+# SPARSE_SPACES-NOT: Function count: 0
+
+# RUN: llvm-profdata show %t.profdata --function large_numbers --counts | FileCheck %s -check-prefix=LARGENUM
+large_numbers
+4611686018427387903
+6
+2305843009213693952
+1152921504606846976
+576460752303423488
+288230376151711744
+144115188075855872
+72057594037927936
+# LARGENUM: Hash: 0x3fffffffffffffff
+# LARGENUM-NEXT: Counters: 6
+# LARGENUM-NEXT: Function count: 2305843009213693952
+# LARGENUM-NEXT: Block counts: [1152921504606846976, 576460752303423488, 288230376151711744, 144115188075855872, 72057594037927936]
+
+# RUN: llvm-profdata show %t.profdata.dense --function hex_hash | FileCheck %s -check-prefix=HEX-HASH
+hex_hash
+0x1234
+1
+0
+# HEX-HASH: Hash: 0x0000000000001234
+# HEX-HASH-NEXT: Counters: 1
+
+# RUN: llvm-profdata show %t.profdata --function NOSUCHFUNC | FileCheck %s -check-prefix=NOSUCHFUNC
+# NOSUCHFUNC-NOT: Counters:
+# NOSUCHFUNC: Functions shown: 0
+
+# RUN: llvm-profdata show %t.profdata --function _ | FileCheck %s -check-prefix=SOMEFUNCS
+# RUN: llvm-profdata show %t.profdata.dense --function _ | FileCheck %s -check-prefix=SOMEFUNCS_DENSE
+# SOMEFUNCS: Counters:
+# SOMEFUNCS-DAG: large_numbers:
+# SOMEFUNCS-DAG: function_count_only:
+# SOMEFUNCS: Functions shown: 2
+# SOMEFUNCS_DENSE: Functions shown: 3
+
+# RUN: llvm-profdata show %t.profdata.dense | FileCheck %s -check-prefix=SUMMARY
+# SUMMARY-NOT: Counters:
+# SUMMARY-NOT: Functions shown:
+# SUMMARY: Total functions: 4
+# SUMMARY: Maximum function count: 2305843009213693952
+# SUMMARY: Maximum internal block count: 1152921504606846976
+
+# RUN: llvm-profdata show --detailed-summary %t.profdata.dense | FileCheck %s -check-prefix=DETAILED-SUMMARY
+# DETAILED-SUMMARY: Detailed summary:
+# DETAILED-SUMMARY: Total number of blocks: 10
+# DETAILED-SUMMARY: Total count: 4539628424389557499
+# DETAILED-SUMMARY: 3 blocks with count >= 576460752303423488 account for 80 percentage of the total counts.
+# DETAILED-SUMMARY: 4 blocks with count >= 288230376151711744 account for 90 percentage of the total counts.
+# DETAILED-SUMMARY: 4 blocks with count >= 288230376151711744 account for 95 percentage of the total counts.
+# DETAILED-SUMMARY: 6 blocks with count >= 72057594037927936 account for 99 percentage of the total counts.
+# DETAILED-SUMMARY: 6 blocks with count >= 72057594037927936 account for 99.9 percentage of the total counts.
+# DETAILED-SUMMARY: 6 blocks with count >= 72057594037927936 account for 99.99 percentage of the total counts.
+# DETAILED-SUMMARY: 6 blocks with count >= 72057594037927936 account for 99.999 percentage of the total counts.
+
+# RUN: llvm-profdata show --detailed-summary --detailed-summary-cutoffs=600000 %t.profdata | FileCheck %s -check-prefix=DETAILED-SUMMARY-2
+# DETAILED-SUMMARY-2: 2 blocks with count >= 1152921504606846976 account for 60 percentage of the total counts.
+#
+# RUN: llvm-profdata show --detailed-summary --detailed-summary-cutoffs=600000,900000,999999 %t.profdata | FileCheck %s -check-prefix=DETAILED-SUMMARY-3
+# DETAILED-SUMMARY-3: 2 blocks with count >= 1152921504606846976 account for 60 percentage of the total counts.
+# DETAILED-SUMMARY-3: 4 blocks with count >= 288230376151711744 account for 90 percentage of the total counts.
+# DETAILED-SUMMARY-3: 6 blocks with count >= 72057594037927936 account for 99.9999 percentage of the total counts.
diff --git a/test/tools/llvm-profdata/hash-mismatch.proftext b/test/tools/llvm-profdata/hash-mismatch.proftext
new file mode 100644
index 0000000..fe0d4fb
--- /dev/null
+++ b/test/tools/llvm-profdata/hash-mismatch.proftext
@@ -0,0 +1,37 @@
+# If we see the same function name, but with different hashes, make
+# sure we keep both.
+
+# RUN: llvm-profdata merge %s -o %t 2>&1
+# RUN: llvm-profdata show %t -all-functions -counts > %t.out
+
+# The function ordering is non-deterministic, so we need to do our
+# checks in multiple runs.
+# RUN: FileCheck -check-prefix=FOO3 -check-prefix=BOTH %s -input-file %t.out
+# RUN: FileCheck -check-prefix=FOO4 -check-prefix=BOTH %s -input-file %t.out
+
+# FOO3: Hash: 0x{{0+}}3
+# FOO3-NEXT: Counters: 3
+# FOO3-NEXT: Function count: 1
+# FOO3-NEXT: Block counts: [2, 3]
+foo
+3
+3
+1
+2
+3
+
+# FOO4: Hash: 0x{{0+}}4
+# FOO4-NEXT: Counters: 4
+# FOO4-NEXT: Function count: 11
+# FOO4-NEXT: Block counts: [22, 33, 44]
+foo
+4
+4
+11
+22
+33
+44
+
+# BOTH: Total functions: 2
+# BOTH: Maximum function count: 11
+# BOTH: Maximum internal block count: 44
diff --git a/test/tools/llvm-profdata/inline-samples.test b/test/tools/llvm-profdata/inline-samples.test
new file mode 100644
index 0000000..d97d82e
--- /dev/null
+++ b/test/tools/llvm-profdata/inline-samples.test
@@ -0,0 +1,31 @@
+Tests for conversion between text and binary encoded sample profiles.
+
+1- Encode the original profile into binary form. All the tests below will use
+ the binary profile.
+RUN: llvm-profdata merge --sample %p/Inputs/inline-samples.afdo -o %t.profbin
+
+2- Show all functions. This profile has a single main() function with several
+ inlined callees.
+RUN: llvm-profdata show --sample %t.profbin | FileCheck %s --check-prefix=SHOW1
+SHOW1: Function: main: 366846, 0, 6 sampled lines
+SHOW1: 2.3: inlined callee: _Z3fool: 246044, 0, 3 sampled lines
+SHOW1: 1.3: inlined callee: _Z3bari: 0, 0, 2 sampled lines
+SHOW1: 1.7: inlined callee: _Z3bari: 99492, 0, 2 sampled lines
+SHOW1: 1.2: 46732
+SHOW1: 1.8: inlined callee: _Z3bari: 0, 0, 2 sampled lines
+
+3- Convert the binary profile to text encoding and check that they are both
+ identical.
+RUN: llvm-profdata merge --sample %t.profbin --text -o - | llvm-profdata show --sample - -o %t-bintext
+RUN: llvm-profdata show --sample %p/Inputs/inline-samples.afdo -o %t-text
+RUN: diff %t-bintext %t-text
+
+4- Merge the binary and text encodings of the profile and check that the
+ counters have doubled.
+RUN: llvm-profdata merge --sample --text %t.profbin %p/Inputs/inline-samples.afdo -o - | FileCheck %s --check-prefix=MERGE1
+RUN: llvm-profdata merge --sample --text - < %t.profbin %p/Inputs/inline-samples.afdo -o - | FileCheck %s --check-prefix=MERGE1
+MERGE1: main:733692:0
+MERGE1: 2.3: 120802
+MERGE1: 2.3: _Z3fool:492088
+MERGE1: 1.7: _Z3bari:198984
+MERGE1: 1.1: 105520
diff --git a/test/tools/llvm-profdata/input-dir.test b/test/tools/llvm-profdata/input-dir.test
new file mode 100644
index 0000000..93918c1
--- /dev/null
+++ b/test/tools/llvm-profdata/input-dir.test
@@ -0,0 +1,22 @@
+# Create an input file.
+RUN: echo "#" > %t.input
+RUN: echo "%t.dir1" >> %t.input
+RUN: echo "2,%t.dir2" >> %t.input
+
+RUN: mkdir -p %t.dir1
+RUN: mkdir -p %t.dir2/subdir
+
+RUN: echo ' ' > %t.dir1/bar
+RUN: echo ' ' > %t.dir1/foo
+RUN: echo ' ' > %t.dir2/bar
+RUN: echo ' ' > %t.dir2/foo
+RUN: echo ' ' > %t.dir2/subdir/baz
+
+RUN: llvm-profdata merge -f %t.input -dump-input-file-list -o /dev/null | FileCheck %s
+RUN: llvm-profdata merge -weighted-input=2,%t.dir2 -dump-input-file-list -o /dev/null %t.dir1 | FileCheck %s
+
+CHECK-DAG: 1,{{.*}}.dir1{{[/\\]}}bar
+CHECK-DAG: 1,{{.*}}.dir1{{[/\\]}}foo
+CHECK-DAG: 2,{{.*}}.dir2{{[/\\]}}bar
+CHECK-DAG: 2,{{.*}}.dir2{{[/\\]}}foo
+CHECK-DAG: 2,{{.*}}.dir2{{[/\\]}}subdir{{[/\\]}}baz
diff --git a/test/tools/llvm-profdata/input-filenames.test b/test/tools/llvm-profdata/input-filenames.test
new file mode 100644
index 0000000..4f29e7b
--- /dev/null
+++ b/test/tools/llvm-profdata/input-filenames.test
@@ -0,0 +1,19 @@
+# Create an input file.
+RUN: echo '# comment 1' > %t.input
+RUN: echo ' # comment 2' >> %t.input
+RUN: echo " %t.bar" >> %t.input
+RUN: echo " %t.baz" >> %t.input
+RUN: echo "2,%t.weighted" >> %t.input
+
+RUN: echo ' ' > %t.weighted
+RUN: echo ' ' > %t.foo
+RUN: echo ' ' > %t.bar
+RUN: echo ' ' > %t.baz
+
+RUN: llvm-profdata merge -f %t.input -dump-input-file-list -o /dev/null %t.foo | FileCheck %s
+RUN: llvm-profdata merge -input-files %t.input -dump-input-file-list -o /dev/null %t.foo | FileCheck %s
+
+CHECK: 1,{{.*}}.foo
+CHECK-NEXT: 1,{{.*}}.bar
+CHECK-NEXT: 1,{{.*}}.baz
+CHECK-NEXT: 2,{{.*}}.weighted
diff --git a/test/tools/llvm-profdata/invalid-profdata.test b/test/tools/llvm-profdata/invalid-profdata.test
new file mode 100644
index 0000000..b6391b0
--- /dev/null
+++ b/test/tools/llvm-profdata/invalid-profdata.test
@@ -0,0 +1,50 @@
+RUN: echo ":ir" > %t.input
+RUN: echo "_ZN6Thread5StartEv" >> %t.input
+RUN: echo "# Func Hash:" >> %t.input
+RUN: echo "288793635542036872" >> %t.input
+RUN: echo "# Num Counters:" >> %t.input
+RUN: echo "3" >> %t.input
+RUN: echo "# Counter Values:" >> %t.input
+RUN: echo "0" >> %t.input
+RUN: echo "12" >> %t.input
+RUN: echo "12" >> %t.input
+RUN: echo "# Num Value Kinds:" >> %t.input
+RUN: echo "1" >> %t.input
+RUN: echo "# ValueKind = IPVK_IndirectCallTarget:" >> %t.input
+RUN: echo "0" >> %t.input
+RUN: echo "# NumValueSites:" >> %t.input
+RUN: echo "2" >> %t.input
+RUN: echo "2" >> %t.input
+RUN: echo "f1:10" >> %t.input
+RUN: echo "f2:0" >> %t.input
+RUN: echo "1" >> %t.input
+RUN: echo ":10" >> %t.input
+
+RUN: not llvm-profdata merge %t.input -text -output=/dev/null 2>&1 | FileCheck %s --check-prefix=BROKEN
+BROKEN: Malformed instrumentation profile data
+
+RUN: echo ":ir" > %t.input
+RUN: echo "_ZN6Thread5StartEv" >> %t.input
+RUN: echo "# Func Hash:" >> %t.input
+RUN: echo "288793635542036872" >> %t.input
+RUN: echo "# Num Counters:" >> %t.input
+RUN: echo "3" >> %t.input
+RUN: echo "# Counter Values:" >> %t.input
+RUN: echo "0" >> %t.input
+RUN: echo "12" >> %t.input
+RUN: echo "12" >> %t.input
+RUN: echo "# Num Value Kinds:" >> %t.input
+RUN: echo "1" >> %t.input
+RUN: echo "# ValueKind = IPVK_IndirectCallTarget:" >> %t.input
+RUN: echo "0" >> %t.input
+RUN: echo "# NumValueSites:" >> %t.input
+RUN: echo "2" >> %t.input
+RUN: echo "2" >> %t.input
+RUN: echo "f1:10" >> %t.input
+RUN: echo "f2:0" >> %t.input
+RUN: echo "1" >> %t.input
+RUN: echo "** External Symbol **:10" >> %t.input
+
+# RUN: llvm-profdata merge %t.input -text -output=%t.out && cat %t.out | FileCheck %s
+
+CHECK: ** External Symbol **:10
diff --git a/test/tools/llvm-profdata/lit.local.cfg b/test/tools/llvm-profdata/lit.local.cfg
new file mode 100644
index 0000000..d44913a
--- /dev/null
+++ b/test/tools/llvm-profdata/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes.add('.proftext')
diff --git a/test/tools/llvm-profdata/memop-size-prof.proftext b/test/tools/llvm-profdata/memop-size-prof.proftext
new file mode 100644
index 0000000..79dc0f8
--- /dev/null
+++ b/test/tools/llvm-profdata/memop-size-prof.proftext
@@ -0,0 +1,123 @@
+# RUN: llvm-profdata show -memop-sizes -ic-targets -function=foo %s | FileCheck %s --check-prefixes=MEMOP,MEMOP_SUM,ICALL,ICALL_SUM
+# RUN: llvm-profdata show -memop-sizes -ic-targets -counts -text -function=foo %s | FileCheck %s --check-prefixes=TEXT,MEMOP_TEXT,ICALL_TEXT
+# RUN: llvm-profdata merge -o %t.profdata %s
+# RUN: llvm-profdata show -memop-sizes -ic-targets -function=foo %t.profdata | FileCheck %s --check-prefixes=MEMOP,MEMOP_SUM,ICALL,ICALL_SUM
+# RUN: llvm-profdata merge -o %t.proftext -text %s
+# RUN: llvm-profdata show -memop-sizes -ic-targets -function=foo %t.proftext| FileCheck %s --check-prefixes=MEMOP,MEMOP_SUM,ICALL,ICALL_SUM
+
+# IR level Instrumentation Flag
+:ir
+ic1
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+999000
+359800
+
+ic2
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+1001000
+360200
+
+foo
+# Func Hash:
+35277121310
+# Num Counters:
+3
+# Counter Values:
+20
+556
+1
+# Num Value Kinds:
+2
+# Value Kind IPVK_IndirectCallTarget
+0
+# NumSites
+3
+# Values for each site
+0
+2
+ic2:1000
+ic1:100
+1
+ic2:20000
+#ICALL: Indirect Target Results:
+#ICALL-NEXT: [ 1, ic2, 1000 ]
+#ICALL-NEXT: [ 1, ic1, 100 ]
+#ICALL-NEXT: [ 2, ic2, 20000 ]
+
+# ValueKind = IPVK_MemOPSize:
+1
+# NumValueSites:
+1
+9
+1:99
+2:88
+3:77
+9:72
+4:66
+5:55
+6:44
+7:33
+8:22
+
+#MEMOP: Memory Intrinsic Size Results:
+#MEMOP-NEXT: [ 0, 1, 99 ]
+#MEMOP-NEXT: [ 0, 2, 88 ]
+#MEMOP-NEXT: [ 0, 3, 77 ]
+#MEMOP-NEXT: [ 0, 9, 72 ]
+#MEMOP-NEXT: [ 0, 4, 66 ]
+#MEMOP-NEXT: [ 0, 5, 55 ]
+#MEMOP-NEXT: [ 0, 6, 44 ]
+#MEMOP-NEXT: [ 0, 7, 33 ]
+#MEMOP-NEXT: [ 0, 8, 22 ]
+
+#ICALL_SUM: Statistics for indirect call sites profile:
+#ICALL_SUM: Total number of sites: 3
+#ICALL_SUM: Total number of sites with values: 2
+#ICALL_SUM: Total number of profiled values: 3
+#ICALL_SUM: Value sites histogram:
+#ICALL_SUM: NumTargets, SiteCount
+#ICALL_SUM: 1, 1
+#ICALL_SUM: 2, 1
+
+#MEMOP_SUM: Statistics for memory intrinsic calls sizes profile:
+#MEMOP_SUM: Total number of sites: 1
+#MEMOP_SUM: Total number of sites with values: 1
+#MEMOP_SUM: Total number of profiled values: 9
+#MEMOP_SUM: Value sites histogram:
+#MEMOP_SUM: NumTargets, SiteCount
+#MEMOP_SUM: 9, 1
+
+#TEXT: # Num Value Kinds:
+#TEXT: 2
+#ICALL_TEXT: # ValueKind = IPVK_IndirectCallTarget:
+#ICALL_TEXT: 0
+#ICALL_TEXT: # NumValueSites:
+#ICALL_TEXT: 3
+#ICALL_TEXT: 0
+#ICALL_TEXT: 2
+#ICALL_TEXT: ic2:1000
+#ICALL_TEXT: ic1:100
+#ICALL_TEXT: 1
+#ICALL_TEXT: ic2:20000
+#MEMOP_TEXT: # ValueKind = IPVK_MemOPSize:
+#MEMOP_TEXT: 1
+#MEMOP_TEXT: # NumValueSites:
+#MEMOP_TEXT: 1
+#MEMOP_TEXT: 9
+#MEMOP_TEXT: 1:99
+#MEMOP_TEXT: 2:88
+#MEMOP_TEXT: 3:77
+#MEMOP_TEXT: 9:72
+#MEMOP_TEXT: 4:66
+#MEMOP_TEXT: 5:55
+#MEMOP_TEXT: 6:44
+#MEMOP_TEXT: 7:33
+#MEMOP_TEXT: 8:22
diff --git a/test/tools/llvm-profdata/merge_empty_profile.test b/test/tools/llvm-profdata/merge_empty_profile.test
new file mode 100644
index 0000000..7f9d31b
--- /dev/null
+++ b/test/tools/llvm-profdata/merge_empty_profile.test
@@ -0,0 +1,17 @@
+# Tests for merge of empty profile files.
+
+RUN: touch %t_empty.proftext
+RUN: llvm-profdata merge -text -o %t_clang.proftext %t_empty.proftext %p/Inputs/clang_profile.proftext
+RUN: FileCheck --input-file=%t_clang.proftext %s -check-prefix=CLANG_PROF_TEXT
+CLANG_PROF_TEXT: main
+CLANG_PROF_TEXT: 0
+CLANG_PROF_TEXT: 1
+CLANG_PROF_TEXT: 1
+
+RUN: llvm-profdata merge -text -o %t_ir.proftext %t_empty.proftext %p/Inputs/IR_profile.proftext
+RUN: FileCheck --input-file=%t_ir.proftext %s -check-prefix=IR_PROF_TEXT
+IR_PROF_TEXT: :ir
+IR_PROF_TEXT: main
+IR_PROF_TEXT: 0
+IR_PROF_TEXT: 1
+IR_PROF_TEXT: 1
diff --git a/test/tools/llvm-profdata/multiple-inputs.test b/test/tools/llvm-profdata/multiple-inputs.test
new file mode 100644
index 0000000..399438a
--- /dev/null
+++ b/test/tools/llvm-profdata/multiple-inputs.test
@@ -0,0 +1,93 @@
+Some very basic tests for the multiple input cases.
+
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3-2.proftext -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO3
+RUN: llvm-profdata merge %p/Inputs/foo3-2.proftext %p/Inputs/foo3-1.proftext -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO3
+FOO3: foo:
+FOO3: Counters: 3
+FOO3: Function count: 8
+FOO3: Block counts: [7, 6]
+FOO3: Total functions: 1
+FOO3: Maximum function count: 8
+FOO3: Maximum internal block count: 7
+
+RUN: llvm-profdata merge %p/Inputs/empty.proftext %p/Inputs/foo3-1.proftext -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO3EMPTY
+FOO3EMPTY: foo:
+FOO3EMPTY: Counters: 3
+FOO3EMPTY: Function count: 1
+FOO3EMPTY: Block counts: [2, 3]
+FOO3EMPTY: Total functions: 1
+FOO3EMPTY: Maximum function count: 1
+FOO3EMPTY: Maximum internal block count: 3
+
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3bar3-1.proftext -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO3FOO3BAR3 --check-prefix=FOO3FOO3BAR3-1
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO3FOO3BAR3 --check-prefix=FOO3FOO3BAR3-2
+FOO3FOO3BAR3-1: foo:
+FOO3FOO3BAR3-1: Counters: 3
+FOO3FOO3BAR3-1: Function count: 3
+FOO3FOO3BAR3-1: Block counts: [5, 8]
+FOO3FOO3BAR3-2: bar:
+FOO3FOO3BAR3-2: Counters: 3
+FOO3FOO3BAR3-2: Function count: 7
+FOO3FOO3BAR3-2: Block counts: [11, 13]
+FOO3FOO3BAR3: Total functions: 2
+FOO3FOO3BAR3: Maximum function count: 7
+FOO3FOO3BAR3: Maximum internal block count: 13
+
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/bar3-1.proftext -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=DISJOINT --check-prefix=DISJOINT-1
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=DISJOINT --check-prefix=DISJOINT-2
+DISJOINT-1: foo:
+DISJOINT-1: Counters: 3
+DISJOINT-1: Function count: 1
+DISJOINT-1: Block counts: [2, 3]
+DISJOINT-2: bar:
+DISJOINT-2: Counters: 3
+DISJOINT-2: Function count: 1
+DISJOINT-2: Block counts: [2, 3]
+DISJOINT: Total functions: 2
+DISJOINT: Maximum function count: 1
+DISJOINT: Maximum internal block count: 3
+
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: -num-threads 2 -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO4
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: -j 3 -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO4
+FOO4: foo:
+FOO4: Counters: 3
+FOO4: Function count: 4
+FOO4: Block counts: [8, 12]
+FOO4: Total functions: 1
+FOO4: Maximum function count: 4
+FOO4: Maximum internal block count: 12
+
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext -j 2 -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO5
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext -j 3 -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO5
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO5
+RUN: llvm-profdata merge %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext %p/Inputs/foo3-1.proftext \
+RUN: %p/Inputs/foo3-1.proftext -j 1 -o %t
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=FOO5
+FOO5: foo:
+FOO5: Counters: 3
+FOO5: Function count: 5
+FOO5: Block counts: [10, 15]
+FOO5: Total functions: 1
+FOO5: Maximum function count: 5
+FOO5: Maximum internal block count: 15
diff --git a/test/tools/llvm-profdata/multiple-profdata-merge.test b/test/tools/llvm-profdata/multiple-profdata-merge.test
new file mode 100644
index 0000000..da24cc9
--- /dev/null
+++ b/test/tools/llvm-profdata/multiple-profdata-merge.test
@@ -0,0 +1,11 @@
+Test multi-thread merge of multiple profdata files.
+
+RUN: llvm-profdata merge %p/Inputs/multiple-profdata-merge.proftext -o %t
+RUN: llvm-profdata merge -j 4 %t %t %t %t -o %t_2
+RUN: llvm-profdata show %t_2 | FileCheck %s
+
+; CHECK:Total functions: 11
+; CHECK:Maximum function count: 5600000
+; CHECK:Maximum internal block count: 2800000
+
+
diff --git a/test/tools/llvm-profdata/nocompress.test b/test/tools/llvm-profdata/nocompress.test
new file mode 100644
index 0000000..65db61d
--- /dev/null
+++ b/test/tools/llvm-profdata/nocompress.test
@@ -0,0 +1,15 @@
+You need a checkout of clang with compiler-rt to generate the
+binary file here. These shell commands can be used to regenerate
+it.
+$ SRC=path/to/llvm
+$ CFE=$SRC/tools/clang
+$ TESTDIR=$SRC/test/tools/llvm-profdata
+$ CFE_TESTDIR=$CFE/test/Profile
+$ clang -o a.out -fprofile-instr-generate $CFE_TESTDIR/c-general.c
+$ LLVM_PROFILE_FILE=$TESTDIR/Inputs/compressed.profraw ./a.out
+
+RUN: not llvm-profdata show %p/Inputs/compressed.profraw -o %t 2>&1 | FileCheck %s
+
+REQUIRES: nozlib
+
+CHECK: error: {{.*}} Profile uses zlib compression but the profile reader was built without zlib support
diff --git a/test/tools/llvm-profdata/overflow-instr.test b/test/tools/llvm-profdata/overflow-instr.test
new file mode 100644
index 0000000..5b9a94a
--- /dev/null
+++ b/test/tools/llvm-profdata/overflow-instr.test
@@ -0,0 +1,17 @@
+Tests for overflow when merging instrumented profiles.
+
+1- Merge profile having maximum counts with itself and verify overflow detected and saturation occurred
+RUN: llvm-profdata merge -instr %p/Inputs/overflow-instr.proftext %p/Inputs/overflow-instr.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=MERGE_OVERFLOW
+RUN: llvm-profdata show -instr %t.out | FileCheck %s --check-prefix=SHOW_OVERFLOW
+MERGE_OVERFLOW: {{.*}}: overflow: Counter overflow
+SHOW_OVERFLOW: Total functions: 1
+SHOW_OVERFLOW-NEXT: Maximum function count: 18446744073709551615
+SHOW_OVERFLOW-NEXT: Maximum internal block count: 18446744073709551615
+
+2- Merge profile having maximum counts by itself and verify no overflow
+RUN: llvm-profdata merge -instr %p/Inputs/overflow-instr.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=MERGE_NO_OVERFLOW -allow-empty
+RUN: llvm-profdata show -instr %t.out | FileCheck %s --check-prefix=SHOW_NO_OVERFLOW
+MERGE_NO_OVERFLOW-NOT: {{.*}}: overflow: Counter overflow
+SHOW_NO_OVERFLOW: Total functions: 1
+SHOW_NO_OVERFLOW-NEXT: Maximum function count: 18446744073709551615
+SHOW_NO_OVERFLOW-NEXT: Maximum internal block count: 18446744073709551615
diff --git a/test/tools/llvm-profdata/overflow-sample.test b/test/tools/llvm-profdata/overflow-sample.test
new file mode 100644
index 0000000..83adf6d
--- /dev/null
+++ b/test/tools/llvm-profdata/overflow-sample.test
@@ -0,0 +1,43 @@
+Tests for overflow when merging sampled profiles.
+
+1- Merge profile having maximum counts with itself and verify overflow detected
+RUN: llvm-profdata merge -sample %p/Inputs/overflow-sample.proftext %p/Inputs/overflow-sample.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=MERGE_OVERFLOW
+RUN: llvm-profdata show -sample %t.out | FileCheck %s --check-prefix=SHOW_OVERFLOW
+MERGE_OVERFLOW: {{.*}}: main: Counter overflow
+SHOW_OVERFLOW-DAG: Function: main: 2000, 0, 2 sampled lines
+SHOW_OVERFLOW-DAG: Samples collected in the function's body {
+SHOW_OVERFLOW-DAG: 1: 1000, calls: _Z3bari:18446744073709551615
+SHOW_OVERFLOW-DAG: 2: 1000, calls: _Z3fooi:18446744073709551615
+SHOW_OVERFLOW-DAG: }
+SHOW_OVERFLOW-DAG: No inlined callsites in this function
+SHOW_OVERFLOW-DAG: Function: _Z3fooi: 18446744073709551615, 2000, 1 sampled lines
+SHOW_OVERFLOW-DAG: Samples collected in the function's body {
+SHOW_OVERFLOW-DAG: 1: 18446744073709551615
+SHOW_OVERFLOW-DAG: }
+SHOW_OVERFLOW-DAG: No inlined callsites in this function
+SHOW_OVERFLOW-DAG: Function: _Z3bari: 18446744073709551615, 2000, 1 sampled lines
+SHOW_OVERFLOW-DAG: Samples collected in the function's body {
+SHOW_OVERFLOW-DAG: 1: 18446744073709551615
+SHOW_OVERFLOW-DAG: }
+SHOW_OVERFLOW-DAG: No inlined callsites in this function
+
+2- Merge profile having maximum counts by itself and verify no overflow
+RUN: llvm-profdata merge -sample %p/Inputs/overflow-sample.proftext -o %t.out 2>&1 | FileCheck %s -allow-empty -check-prefix=MERGE_NO_OVERFLOW
+RUN: llvm-profdata show -sample %t.out | FileCheck %s --check-prefix=SHOW_NO_OVERFLOW
+MERGE_NO_OVERFLOW-NOT: {{.*}}: main: Counter overflow
+SHOW_NO_OVERFLOW-DAG: Function: main: 1000, 0, 2 sampled lines
+SHOW_NO_OVERFLOW-DAG: Samples collected in the function's body {
+SHOW_NO_OVERFLOW-DAG: 1: 500, calls: _Z3bari:18446744073709551615
+SHOW_NO_OVERFLOW-DAG: 2: 500, calls: _Z3fooi:18446744073709551615
+SHOW_NO_OVERFLOW-DAG: }
+SHOW_NO_OVERFLOW-DAG: No inlined callsites in this function
+SHOW_NO_OVERFLOW-DAG: Function: _Z3fooi: 18446744073709551615, 1000, 1 sampled lines
+SHOW_NO_OVERFLOW-DAG: Samples collected in the function's body {
+SHOW_NO_OVERFLOW-DAG: 1: 18446744073709551615
+SHOW_NO_OVERFLOW-DAG: }
+SHOW_NO_OVERFLOW-DAG: No inlined callsites in this function
+SHOW_NO_OVERFLOW-DAG: Function: _Z3bari: 18446744073709551615, 1000, 1 sampled lines
+SHOW_NO_OVERFLOW-DAG: Samples collected in the function's body {
+SHOW_NO_OVERFLOW-DAG: 1: 18446744073709551615
+SHOW_NO_OVERFLOW-DAG: }
+SHOW_NO_OVERFLOW-DAG: No inlined callsites in this function
diff --git a/test/tools/llvm-profdata/raw-32-bits-be.test b/test/tools/llvm-profdata/raw-32-bits-be.test
new file mode 100644
index 0000000..d6e1daa
--- /dev/null
+++ b/test/tools/llvm-profdata/raw-32-bits-be.test
@@ -0,0 +1,47 @@
+RUN: printf '\377lprofR\201' > %t
+RUN: printf '\0\0\0\0\0\0\0\4' >> %t
+RUN: printf '\0\0\0\0\0\0\0\2' >> %t
+RUN: printf '\0\0\0\0\0\0\0\3' >> %t
+RUN: printf '\0\0\0\0\0\0\0\20' >> %t
+RUN: printf '\0\0\0\0\1\0\0\0' >> %t
+RUN: printf '\0\0\0\0\2\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\134\370\302\114\333\030\275\254' >> %t
+RUN: printf '\0\0\0\0\0\0\0\1' >> %t
+RUN: printf '\1\0\0\0' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\0\0\0\1' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\344\023\165\112\031\035\265\067' >> %t
+RUN: printf '\0\0\0\0\0\0\0\2' >> %t
+RUN: printf '\1\0\0\10' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\0\0\0\2' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\0\0\0\0\0\0\0\023' >> %t
+RUN: printf '\0\0\0\0\0\0\0\067' >> %t
+RUN: printf '\0\0\0\0\0\0\0\101' >> %t
+RUN: printf '\7\0foo\1bar\0\0\0\0\0\0\0' >> %t
+
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s
+
+CHECK: Counters:
+CHECK: foo:
+CHECK: Hash: 0x0000000000000001
+CHECK: Counters: 1
+CHECK: Function count: 19
+CHECK: Block counts: []
+CHECK: bar:
+CHECK: Hash: 0x0000000000000002
+CHECK: Counters: 2
+CHECK: Function count: 55
+CHECK: Block counts: [65]
+CHECK: Functions shown: 2
+CHECK: Total functions: 2
+CHECK: Maximum function count: 55
+CHECK: Maximum internal block count: 65
diff --git a/test/tools/llvm-profdata/raw-32-bits-le.test b/test/tools/llvm-profdata/raw-32-bits-le.test
new file mode 100644
index 0000000..cd36aaf
--- /dev/null
+++ b/test/tools/llvm-profdata/raw-32-bits-le.test
@@ -0,0 +1,47 @@
+RUN: printf '\201Rforpl\377' > %t
+RUN: printf '\4\0\0\0\0\0\0\0' >> %t
+RUN: printf '\2\0\0\0\0\0\0\0' >> %t
+RUN: printf '\3\0\0\0\0\0\0\0' >> %t
+RUN: printf '\20\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\1\0\0\0\0' >> %t
+RUN: printf '\0\0\0\2\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\254\275\030\333\114\302\370\134' >> %t
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\1' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\1\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\067\265\035\031\112\165\023\344' >> %t
+RUN: printf '\02\0\0\0\0\0\0\0' >> %t
+RUN: printf '\10\0\0\1' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0' >> %t
+RUN: printf '\2\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\023\0\0\0\0\0\0\0' >> %t
+RUN: printf '\067\0\0\0\0\0\0\0' >> %t
+RUN: printf '\101\0\0\0\0\0\0\0' >> %t
+RUN: printf '\7\0foo\1bar\0\0\0\0\0\0\0' >> %t
+
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s
+
+CHECK: Counters:
+CHECK: foo:
+CHECK: Hash: 0x0000000000000001
+CHECK: Counters: 1
+CHECK: Function count: 19
+CHECK: Block counts: []
+CHECK: bar:
+CHECK: Hash: 0x0000000000000002
+CHECK: Counters: 2
+CHECK: Function count: 55
+CHECK: Block counts: [65]
+CHECK: Functions shown: 2
+CHECK: Total functions: 2
+CHECK: Maximum function count: 55
+CHECK: Maximum internal block count: 65
diff --git a/test/tools/llvm-profdata/raw-64-bits-be.test b/test/tools/llvm-profdata/raw-64-bits-be.test
new file mode 100644
index 0000000..75cc84d
--- /dev/null
+++ b/test/tools/llvm-profdata/raw-64-bits-be.test
@@ -0,0 +1,45 @@
+RUN: printf '\377lprofr\201' > %t
+RUN: printf '\0\0\0\0\0\0\0\4' >> %t
+RUN: printf '\0\0\0\0\0\0\0\2' >> %t
+RUN: printf '\0\0\0\0\0\0\0\3' >> %t
+RUN: printf '\0\0\0\0\0\0\0\20' >> %t
+RUN: printf '\0\0\0\1\0\4\0\0' >> %t
+RUN: printf '\0\0\0\2\0\4\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\134\370\302\114\333\030\275\254' >> %t
+RUN: printf '\0\0\0\0\0\0\0\1' >> %t
+RUN: printf '\0\0\0\1\0\4\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\1\0\0\0\0' >> %t
+
+RUN: printf '\344\023\165\112\031\035\265\067' >> %t
+RUN: printf '\0\0\0\0\0\0\0\02' >> %t
+RUN: printf '\0\0\0\1\0\4\0\10' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\02\0\0\0\0' >> %t
+
+RUN: printf '\0\0\0\0\0\0\0\023' >> %t
+RUN: printf '\0\0\0\0\0\0\0\067' >> %t
+RUN: printf '\0\0\0\0\0\0\0\101' >> %t
+RUN: printf '\7\0foo\1bar\0\0\0\0\0\0\0' >> %t
+
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s
+
+CHECK: Counters:
+CHECK: foo:
+CHECK: Hash: 0x0000000000000001
+CHECK: Counters: 1
+CHECK: Function count: 19
+CHECK: Block counts: []
+CHECK: bar:
+CHECK: Hash: 0x0000000000000002
+CHECK: Counters: 2
+CHECK: Function count: 55
+CHECK: Block counts: [65]
+CHECK: Functions shown: 2
+CHECK: Total functions: 2
+CHECK: Maximum function count: 55
+CHECK: Maximum internal block count: 65
diff --git a/test/tools/llvm-profdata/raw-64-bits-le.test b/test/tools/llvm-profdata/raw-64-bits-le.test
new file mode 100644
index 0000000..d8a9c9a
--- /dev/null
+++ b/test/tools/llvm-profdata/raw-64-bits-le.test
@@ -0,0 +1,45 @@
+RUN: printf '\201rforpl\377' > %t
+RUN: printf '\4\0\0\0\0\0\0\0' >> %t
+RUN: printf '\2\0\0\0\0\0\0\0' >> %t
+RUN: printf '\3\0\0\0\0\0\0\0' >> %t
+RUN: printf '\20\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t
+RUN: printf '\0\0\4\0\2\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\254\275\030\333\114\302\370\134' >> %t
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\067\265\035\031\112\165\023\344' >> %t
+RUN: printf '\02\0\0\0\0\0\0\0' >> %t
+RUN: printf '\10\0\4\0\1\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t
+RUN: printf '\02\0\0\0\0\0\0\0' >> %t
+
+RUN: printf '\023\0\0\0\0\0\0\0' >> %t
+RUN: printf '\067\0\0\0\0\0\0\0' >> %t
+RUN: printf '\101\0\0\0\0\0\0\0' >> %t
+RUN: printf '\7\0foo\1bar\0\0\0\0\0\0\0' >> %t
+
+RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s
+
+CHECK: Counters:
+CHECK: foo:
+CHECK: Hash: 0x0000000000000001
+CHECK: Counters: 1
+CHECK: Function count: 19
+CHECK: Block counts: []
+CHECK: bar:
+CHECK: Hash: 0x0000000000000002
+CHECK: Counters: 2
+CHECK: Function count: 55
+CHECK: Block counts: [65]
+CHECK: Functions shown: 2
+CHECK: Total functions: 2
+CHECK: Maximum function count: 55
+CHECK: Maximum internal block count: 65
diff --git a/test/tools/llvm-profdata/raw-magic-but-no-header.test b/test/tools/llvm-profdata/raw-magic-but-no-header.test
new file mode 100644
index 0000000..76894fa
--- /dev/null
+++ b/test/tools/llvm-profdata/raw-magic-but-no-header.test
@@ -0,0 +1,6 @@
+RUN: printf '\201rforpl\377' > %t
+RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
+RUN: printf '\377lprofr\201' > %t
+RUN: not llvm-profdata show %t 2>&1 | FileCheck %s
+
+CHECK: error: {{.+}}: Invalid instrumentation profile data (file header is corrupt)
diff --git a/test/tools/llvm-profdata/raw-two-profiles.test b/test/tools/llvm-profdata/raw-two-profiles.test
new file mode 100644
index 0000000..a377375
--- /dev/null
+++ b/test/tools/llvm-profdata/raw-two-profiles.test
@@ -0,0 +1,57 @@
+RUN: printf '\201rforpl\377' > %t-foo.profraw
+RUN: printf '\4\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\10\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t-foo.profraw
+RUN: printf '\0\0\4\0\2\0\0\0' >> %t-foo.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
+
+RUN: printf '\254\275\030\333\114\302\370\134' >> %t-foo.profraw
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\0\0\4\0\1\0\0\0' >> %t-foo.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t-foo.profraw
+
+RUN: printf '\023\0\0\0\0\0\0\0' >> %t-foo.profraw
+RUN: printf '\3\0foo\0\0\0' >> %t-foo.profraw
+
+RUN: printf '\201rforpl\377' > %t-bar.profraw
+RUN: printf '\4\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\2\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\10\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\0\0\6\0\1\0\0\0' >> %t-bar.profraw
+RUN: printf '\0\0\6\0\2\0\0\0' >> %t-bar.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
+
+RUN: printf '\067\265\035\031\112\165\023\344' >> %t-bar.profraw
+RUN: printf '\02\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\0\0\6\0\1\0\0\0' >> %t-bar.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\0\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\02\0\0\0\0\0\0\0' >> %t-bar.profraw
+
+RUN: printf '\067\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\101\0\0\0\0\0\0\0' >> %t-bar.profraw
+RUN: printf '\3\0bar\0\0\0' >> %t-bar.profraw
+
+RUN: cat %t-foo.profraw %t-bar.profraw > %t-pad.profraw
+RUN: llvm-profdata show %t-pad.profraw -all-functions -counts | FileCheck %s
+
+CHECK: Counters:
+CHECK: foo:
+CHECK: Hash: 0x0000000000000001
+CHECK: Counters: 1
+CHECK: Function count: 19
+CHECK: Block counts: []
+CHECK: bar:
+CHECK: Hash: 0x0000000000000002
+CHECK: Counters: 2
+CHECK: Function count: 55
+CHECK: Block counts: [65]
+CHECK: Functions shown: 2
+CHECK: Total functions: 2
+CHECK: Maximum function count: 55
+CHECK: Maximum internal block count: 65
diff --git a/test/tools/llvm-profdata/sample-profile-basic.test b/test/tools/llvm-profdata/sample-profile-basic.test
new file mode 100644
index 0000000..3ba42c2
--- /dev/null
+++ b/test/tools/llvm-profdata/sample-profile-basic.test
@@ -0,0 +1,35 @@
+Basic tests for sample profiles.
+
+1- Show all functions
+RUN: llvm-profdata show --sample %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=SHOW1
+SHOW1-DAG: Function: main: 184019, 0, 7 sampled lines
+SHOW1-DAG: 9: 2064, calls: _Z3fooi:631 _Z3bari:1471
+SHOW1-DAG: Function: _Z3fooi: 7711, 610, 1 sampled lines
+SHOW1-DAG: Function: _Z3bari: 20301, 1437, 1 sampled lines
+SHOW1-DAG: 1: 1437
+
+2- Show only bar
+RUN: llvm-profdata show --sample --function=_Z3bari %p/Inputs/sample-profile.proftext | FileCheck %s --check-prefix=SHOW2
+SHOW2: Function: _Z3bari: 20301, 1437, 1 sampled lines
+SHOW2: 1: 1437
+SHOW2-NOT: Function: main: 184019, 0, 7 sampled lines
+SHOW2-NOT: Function: _Z3fooi: 7711, 610, 1 sampled lines
+
+3- Convert the profile to binary encoding and check that they are both
+ identical.
+RUN: llvm-profdata merge --sample %p/Inputs/sample-profile.proftext --binary -o - | llvm-profdata show --sample - -o %t-binary
+RUN: llvm-profdata show --sample %p/Inputs/sample-profile.proftext -o %t-text
+RUN: diff %t-binary %t-text
+
+4- Merge the binary and text encodings of the profile and check that the
+ counters have doubled.
+RUN: llvm-profdata merge --sample %p/Inputs/sample-profile.proftext -o %t-binprof
+RUN: llvm-profdata merge --sample --text %p/Inputs/sample-profile.proftext %t-binprof -o - | FileCheck %s --check-prefix=MERGE1
+MERGE1: main:368038:0
+MERGE1: 9: 4128 _Z3fooi:1262 _Z3bari:2942
+MERGE1: _Z3bari:40602:2874
+MERGE1: _Z3fooi:15422:1220
+
+5- Detect invalid text encoding (e.g. instrumentation profile text format).
+RUN: not llvm-profdata show --sample %p/Inputs/foo3bar3-1.proftext 2>&1 | FileCheck %s --check-prefix=BADTEXT
+BADTEXT: error: {{.+}}: Unrecognized sample profile encoding format
diff --git a/test/tools/llvm-profdata/show-instr-level.test b/test/tools/llvm-profdata/show-instr-level.test
new file mode 100644
index 0000000..ed00326
--- /dev/null
+++ b/test/tools/llvm-profdata/show-instr-level.test
@@ -0,0 +1,7 @@
+RUN: llvm-profdata merge -o %t_clang.profdata %p/Inputs/clang_profile.proftext
+RUN: llvm-profdata show %t_clang.profdata | FileCheck %s -check-prefix=FE
+FE: Instrumentation level: Front-end
+
+RUN: llvm-profdata merge -o %t_ir.profdata %p/Inputs/IR_profile.proftext
+RUN: llvm-profdata show %t_ir.profdata | FileCheck %s -check-prefix=IR
+IR: Instrumentation level: IR
diff --git a/test/tools/llvm-profdata/text-dump.test b/test/tools/llvm-profdata/text-dump.test
new file mode 100644
index 0000000..94a78d9
--- /dev/null
+++ b/test/tools/llvm-profdata/text-dump.test
@@ -0,0 +1,21 @@
+Basic tests for testing text dump functions.
+
+RUN: llvm-profdata show --all-functions -counts --text %p/Inputs/basic.proftext > %t-basic.proftext1
+RUN: llvm-profdata merge -o %t-basic.proftext2 --text %p/Inputs/basic.proftext
+
+RUN: llvm-profdata merge -binary -o %t-basic.profdata1 %t-basic.proftext1
+RUN: llvm-profdata merge -o %t-basic.profdata2 %t-basic.proftext2
+
+RUN: llvm-profdata show --all-functions -counts %t-basic.profdata1 > %t-basic.dump3
+RUN: llvm-profdata show --all-functions -counts %t-basic.profdata2 > %t-basic.dump4
+
+RUN: llvm-profdata merge -text -o %t-basic.proftext5 %t-basic.profdata1
+RUN: llvm-profdata merge -text -o %t-basic.proftext6 %t-basic.profdata2
+
+RUN: diff %t-basic.dump3 %t-basic.dump4
+RUN: diff %t-basic.proftext5 %t-basic.proftext6
+
+RUN: not llvm-profdata merge -gcc -o %t-basic-profdata3 %t-basic.proftext2 2>&1 | FileCheck %s --check-prefix=UNKNOWN
+UNKNOWN: Unknown
+
+
diff --git a/test/tools/llvm-profdata/text-format-errors.test b/test/tools/llvm-profdata/text-format-errors.test
new file mode 100644
index 0000000..05de2e3
--- /dev/null
+++ b/test/tools/llvm-profdata/text-format-errors.test
@@ -0,0 +1,29 @@
+Tests for instrumentation profile bad encoding.
+
+1- Detect invalid count
+RUN: not llvm-profdata show %p/Inputs/invalid-count-later.proftext 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER
+RUN: not llvm-profdata merge %p/Inputs/invalid-count-later.proftext %p/Inputs/invalid-count-later.proftext -o %t.out 2>&1 | FileCheck %s --check-prefix=INVALID-COUNT-LATER
+INVALID-COUNT-LATER: error: {{.*}}invalid-count-later.proftext: Malformed instrumentation profile data
+
+2- Detect bad hash
+RUN: not llvm-profdata show %p/Inputs/bad-hash.proftext 2>&1 | FileCheck %s --check-prefix=BAD-HASH
+RUN: not llvm-profdata merge %p/Inputs/bad-hash.proftext %p/Inputs/bad-hash.proftext -o %t.out 2>&1 | FileCheck %s --check-prefix=BAD-HASH
+BAD-HASH: error: {{.*}}bad-hash.proftext: Malformed instrumentation profile data
+
+3- Detect no counts
+RUN: not llvm-profdata show %p/Inputs/no-counts.proftext 2>&1 | FileCheck %s --check-prefix=NO-COUNTS
+NO-COUNTS: error: {{.*}}no-counts.proftext: Malformed instrumentation profile data
+
+4- Detect binary input
+RUN: not llvm-profdata show %p/Inputs/text-format-errors.text.bin 2>&1 | FileCheck %s --check-prefix=BINARY
+BINARY: error: {{.+}}: Unrecognized instrumentation profile encoding format
+BINARY: Perhaps you forgot to use the -sample option?
+
+5- Detect malformed value profile data
+RUN: not llvm-profdata show %p/Inputs/vp-malform.proftext 2>&1 | FileCheck %s --check-prefix=VP
+RUN: not llvm-profdata show %p/Inputs/vp-malform2.proftext 2>&1 | FileCheck %s --check-prefix=VP
+VP: Malformed instrumentation profile data
+
+6- Detect truncated value profile data
+RUN: not llvm-profdata show %p/Inputs/vp-truncate.proftext 2>&1 | FileCheck %s --check-prefix=VPTRUNC
+VPTRUNC: Truncated profile data
diff --git a/test/tools/llvm-profdata/threaded-count-mismatch.test b/test/tools/llvm-profdata/threaded-count-mismatch.test
new file mode 100644
index 0000000..8e704cf
--- /dev/null
+++ b/test/tools/llvm-profdata/threaded-count-mismatch.test
@@ -0,0 +1,10 @@
+# Test multithreaded error reporting.
+
+RUN: llvm-profdata merge -j 4 -o %t.profdata \
+RUN: %S/Inputs/counter-mismatch-1.proftext \
+RUN: %S/Inputs/counter-mismatch-2.proftext \
+RUN: %S/Inputs/counter-mismatch-3.proftext \
+RUN: %S/Inputs/counter-mismatch-4.proftext \
+RUN: 2>&1 | FileCheck %s
+
+CHECK: Function basic block count change detected (counter mismatch)
diff --git a/test/tools/llvm-profdata/value-prof.proftext b/test/tools/llvm-profdata/value-prof.proftext
new file mode 100644
index 0000000..31a7698
--- /dev/null
+++ b/test/tools/llvm-profdata/value-prof.proftext
@@ -0,0 +1,81 @@
+# RUN: llvm-profdata show -ic-targets -all-functions %s | FileCheck %s --check-prefix=ICTXT --check-prefix=ICSUM
+# RUN: llvm-profdata show -ic-targets -counts -text -all-functions %s | FileCheck %s --check-prefix=ICTEXT
+# RUN: llvm-profdata merge -o %t.profdata %s
+# RUN: llvm-profdata show -ic-targets -all-functions %t.profdata | FileCheck %s --check-prefix=IC --check-prefix=ICSUM
+
+foo
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+999000
+359800
+
+foo2
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+1001000
+360200
+
+main
+# Func Hash:
+16650
+# Num Counters:
+4
+# Counter Values:
+2
+2000
+2000000
+999000
+# NumValueKinds
+1
+# Value Kind IPVK_IndirectCallTarget
+0
+# NumSites
+3
+# Values for each site
+0
+2
+foo:100
+foo2:1000
+1
+foo2:20000
+
+#ICTXT: Indirect Call Site Count: 3
+#ICTXT-NEXT: Indirect Target Results:
+#ICTXT-NEXT: [ 1, foo, 100 ]
+#ICTXT-NEXT: [ 1, foo2, 1000 ]
+#ICTXT-NEXT: [ 2, foo2, 20000 ]
+
+#IC: Indirect Call Site Count: 3
+#IC-NEXT: Indirect Target Results:
+#IC-NEXT: [ 1, foo2, 1000 ]
+#IC-NEXT: [ 1, foo, 100 ]
+#IC-NEXT: [ 2, foo2, 20000 ]
+
+#ICTEXT: foo:100
+#ICTEXT-NEXT: foo2:1000
+#ICTEXT-NEXT: 1
+#ICTEXT-NEXT: foo2:20000
+#
+
+bar
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+999000
+359800
+
+#ICSUM: Statistics for indirect call sites profile:
+#ICSUM: Total number of sites: 3
+#ICSUM: Total number of sites with values: 2
+#ICSUM: Total number of profiled values: 3
+#ICSUM: NumTargets, SiteCount
+#ICSUM 1, 1
+#ICSUM 2, 1
diff --git a/test/tools/llvm-profdata/weight-instr.test b/test/tools/llvm-profdata/weight-instr.test
new file mode 100644
index 0000000..927a896
--- /dev/null
+++ b/test/tools/llvm-profdata/weight-instr.test
@@ -0,0 +1,81 @@
+Tests for weighted merge of instrumented profiles.
+
+1- Merge the foo and bar profiles with unity weight and verify the combined output
+RUN: llvm-profdata merge -instr -weighted-input=1,%p/Inputs/weight-instr-bar.profdata -weighted-input=1,%p/Inputs/weight-instr-foo.profdata -o %t
+RUN: llvm-profdata show -instr -all-functions %t > %t.out1
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-1 < %t.out1
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-2 < %t.out1
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-3 < %t.out1
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-4 < %t.out1
+RUN: llvm-profdata merge -instr -weighted-input=1,%p/Inputs/weight-instr-bar.profdata %p/Inputs/weight-instr-foo.profdata -o %t
+RUN: llvm-profdata show -instr -all-functions %t > %t.out2
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-1 < %t.out2
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-2 < %t.out2
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-3 < %t.out2
+RUN: FileCheck %s -check-prefix=1X_1X_WEIGHT --check-prefix=1X_1X_WEIGHT-4 < %t.out2
+1X_1X_WEIGHT: Counters:
+1X_1X_WEIGHT-1: usage:
+1X_1X_WEIGHT-1: Hash: 0x0000000000000000
+1X_1X_WEIGHT-1: Counters: 1
+1X_1X_WEIGHT-1: Function count: 0
+1X_1X_WEIGHT-2: foo:
+1X_1X_WEIGHT-2: Hash: 0x000000000000028a
+1X_1X_WEIGHT-2: Counters: 3
+1X_1X_WEIGHT-2: Function count: 866988873
+1X_1X_WEIGHT-3: bar:
+1X_1X_WEIGHT-3: Hash: 0x000000000000028a
+1X_1X_WEIGHT-3: Counters: 3
+1X_1X_WEIGHT-3: Function count: 866988873
+1X_1X_WEIGHT-4: main:
+1X_1X_WEIGHT-4: Hash: 0x7d31c47ea98f8248
+1X_1X_WEIGHT-4: Counters: 60
+1X_1X_WEIGHT-4: Function count: 2
+1X_1X_WEIGHT: Functions shown: 4
+1X_1X_WEIGHT-NEXT: Total functions: 4
+1X_1X_WEIGHT-NEXT: Maximum function count: 866988873
+1X_1X_WEIGHT-NEXT: Maximum internal block count: 267914296
+
+2- Merge the foo and bar profiles with weight 3x and 5x respectively and verify the combined output
+RUN: llvm-profdata merge -instr -weighted-input=3,%p/Inputs/weight-instr-bar.profdata -weighted-input=5,%p/Inputs/weight-instr-foo.profdata -o %t
+RUN: llvm-profdata show -instr -all-functions %t > %t.out3
+RUN: FileCheck %s -check-prefix=3X_5X_WEIGHT --check-prefix=3X_5X_WEIGHT-1 < %t.out3
+RUN: FileCheck %s -check-prefix=3X_5X_WEIGHT --check-prefix=3X_5X_WEIGHT-2 < %t.out3
+RUN: FileCheck %s -check-prefix=3X_5X_WEIGHT --check-prefix=3X_5X_WEIGHT-3 < %t.out3
+RUN: FileCheck %s -check-prefix=3X_5X_WEIGHT --check-prefix=3X_5X_WEIGHT-4 < %t.out3
+3X_5X_WEIGHT: Counters:
+3X_5X_WEIGHT-1: usage:
+3X_5X_WEIGHT-1: Hash: 0x0000000000000000
+3X_5X_WEIGHT-1: Counters: 1
+3X_5X_WEIGHT-1: Function count: 0
+3X_5X_WEIGHT-2: foo:
+3X_5X_WEIGHT-2: Hash: 0x000000000000028a
+3X_5X_WEIGHT-2: Counters: 3
+3X_5X_WEIGHT-2: Function count: 4334944365
+3X_5X_WEIGHT-3: bar:
+3X_5X_WEIGHT-3: Hash: 0x000000000000028a
+3X_5X_WEIGHT-3: Counters: 3
+3X_5X_WEIGHT-3: Function count: 2600966619
+3X_5X_WEIGHT-4: main:
+3X_5X_WEIGHT-4: Hash: 0x7d31c47ea98f8248
+3X_5X_WEIGHT-4: Counters: 60
+3X_5X_WEIGHT-4: Function count: 8
+3X_5X_WEIGHT: Functions shown: 4
+3X_5X_WEIGHT-NEXT: Total functions: 4
+3X_5X_WEIGHT-NEXT: Maximum function count: 4334944365
+3X_5X_WEIGHT-NEXT: Maximum internal block count: 1339571480
+
+3- Bad merge: invalid weight
+RUN: not llvm-profdata merge -instr -weighted-input=3,%p/Inputs/weight-instr-bar.profdata -weighted-input=0,%p/Inputs/weight-instr-foo.profdata -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -instr -weighted-input=3,%p/Inputs/weight-instr-bar.profdata -weighted-input=0.75,%p/Inputs/weight-instr-foo.profdata -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -instr -weighted-input=3,%p/Inputs/weight-instr-bar.profdata -weighted-input=-5,%p/Inputs/weight-instr-foo.profdata -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -instr -weighted-input=3,%p/Inputs/weight-instr-bar.profdata -weighted-input=,%p/Inputs/weight-instr-foo.profdata -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -instr -weighted-input=3,%p/Inputs/weight-instr-bar.profdata -weighted-input=%p/Inputs/weight-instr-foo.profdata -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+INVALID_WEIGHT: error: Input weight must be a positive integer.
+
+4- Bad merge: input path does not exist
+RUN: not llvm-profdata merge -instr -weighted-input=3,%p/Inputs/does-not-exist.profdata -weighted-input=2,%p/Inputs/does-not-exist-either.profdata -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_INPUT
+INVALID_INPUT: {{.*}}: {{.*}}does-not-exist.profdata: {{[Nn]}}o such file or directory
+
+5- No inputs
+RUN: not llvm-profdata merge -instr -o %t.out 2>&1 | FileCheck %s -check-prefix=NO_INPUT
+NO_INPUT: {{.*}}: No input files specified. See llvm-profdata{{(\.EXE|\.exe)?}} merge -help
diff --git a/test/tools/llvm-profdata/weight-sample.test b/test/tools/llvm-profdata/weight-sample.test
new file mode 100644
index 0000000..635e621
--- /dev/null
+++ b/test/tools/llvm-profdata/weight-sample.test
@@ -0,0 +1,56 @@
+Tests for weighted merge of sample profiles.
+
+1- Merge the foo and bar profiles with unity weight and verify the combined output
+RUN: llvm-profdata merge -sample -text -weighted-input=1,%p/Inputs/weight-sample-bar.proftext -weighted-input=1,%p/Inputs/weight-sample-foo.proftext -o - | FileCheck %s -check-prefix=1X_1X_WEIGHT
+RUN: llvm-profdata merge -sample -text -weighted-input=1,%p/Inputs/weight-sample-bar.proftext %p/Inputs/weight-sample-foo.proftext -o - | FileCheck %s -check-prefix=1X_1X_WEIGHT
+1X_1X_WEIGHT-DAG: foo:1763288:35327
+1X_1X_WEIGHT-DAG: 7: 35327
+1X_1X_WEIGHT-DAG: 8: 35327
+1X_1X_WEIGHT-DAG: 9: 6930
+1X_1X_WEIGHT-DAG: 10: 29341
+1X_1X_WEIGHT-DAG: 11: 11906
+1X_1X_WEIGHT-DAG: 13: 18185 foo:19531
+1X_1X_WEIGHT-DAG: 15: 36458
+1X_1X_WEIGHT-DAG: bar:1772037:35370
+1X_1X_WEIGHT-DAG: 17: 35370
+1X_1X_WEIGHT-DAG: 18: 35370
+1X_1X_WEIGHT-DAG: 19: 7005
+1X_1X_WEIGHT-DAG: 20: 29407
+1X_1X_WEIGHT-DAG: 21: 12170
+1X_1X_WEIGHT-DAG: 23: 18150 bar:19829
+1X_1X_WEIGHT-DAG: 25: 36666
+
+2- Merge the foo and bar profiles with weight 3x and 5x respectively and verify the combined output
+RUN: llvm-profdata merge -sample -text -weighted-input=3,%p/Inputs/weight-sample-bar.proftext -weighted-input=5,%p/Inputs/weight-sample-foo.proftext -o - | FileCheck %s -check-prefix=3X_5X_WEIGHT
+3X_5X_WEIGHT-DAG: foo:8816440:176635
+3X_5X_WEIGHT-DAG: 7: 176635
+3X_5X_WEIGHT-DAG: 8: 176635
+3X_5X_WEIGHT-DAG: 9: 34650
+3X_5X_WEIGHT-DAG: 10: 146705
+3X_5X_WEIGHT-DAG: 11: 59530
+3X_5X_WEIGHT-DAG: 13: 90925 foo:97655
+3X_5X_WEIGHT-DAG: 15: 182290
+3X_5X_WEIGHT-DAG: bar:5316111:106110
+3X_5X_WEIGHT-DAG: 17: 106110
+3X_5X_WEIGHT-DAG: 18: 106110
+3X_5X_WEIGHT-DAG: 19: 21015
+3X_5X_WEIGHT-DAG: 20: 88221
+3X_5X_WEIGHT-DAG: 21: 36510
+3X_5X_WEIGHT-DAG: 23: 54450 bar:59487
+3X_5X_WEIGHT-DAG: 25: 109998
+
+3- Bad merge: invalid weight
+RUN: not llvm-profdata merge -sample -weighted-input=3,%p/Inputs/weight-sample-bar.proftext -weighted-input=0,%p/Inputs/weight-sample-foo.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -sample -weighted-input=3,%p/Inputs/weight-sample-bar.proftext -weighted-input=0.75,%p/Inputs/weight-sample-foo.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -sample -weighted-input=3,%p/Inputs/weight-sample-bar.proftext -weighted-input=-5,%p/Inputs/weight-sample-foo.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -sample -weighted-input=3,%p/Inputs/weight-sample-bar.proftext -weighted-input=,%p/Inputs/weight-sample-foo.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+RUN: not llvm-profdata merge -sample -weighted-input=3,%p/Inputs/weight-sample-bar.proftext -weighted-input=%p/Inputs/weight-sample-foo.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_WEIGHT
+INVALID_WEIGHT: error: Input weight must be a positive integer.
+
+4- Bad merge: input path does not exist
+RUN: not llvm-profdata merge -sample -weighted-input=3,%p/Inputs/does-not-exist.proftext -weighted-input=2,%p/Inputs/does-not-exist-either.proftext -o %t.out 2>&1 | FileCheck %s -check-prefix=INVALID_INPUT
+INVALID_INPUT: {{.*}}: {{.*}}does-not-exist.proftext: {{[Nn]}}o such file or directory
+
+5- No inputs
+RUN: not llvm-profdata merge -sample -o %t.out 2>&1 | FileCheck %s -check-prefix=NO_INPUT
+NO_INPUT: {{.*}}: No input files specified. See llvm-profdata{{(\.EXE|\.exe)?}} merge -help