Blame SOURCES/rhbz1643997.0001-testsuite-systemtap.bpf-diagnose-a-bug-in-print_form.patch

132810
From 16e9cfa909a183d8e61142d80575189408a2a244 Mon Sep 17 00:00:00 2001
132810
From: Serhei Makarov <smakarov@redhat.com>
132810
Date: Wed, 24 Oct 2018 15:56:44 -0400
132810
Subject: [PATCH 01/32] testsuite/systemtap.bpf :: diagnose a bug in
132810
 print_format("%s%s", ...)
132810
132810
---
132810
 testsuite/systemtap.bpf/asm_tests/string-basic.stp | 19 ++++++++++
132810
 testsuite/systemtap.bpf/bpf_tests/string3.stp      | 44 ++++++++++++++++++++++
132810
 2 files changed, 63 insertions(+)
132810
 create mode 100644 testsuite/systemtap.bpf/asm_tests/string-basic.stp
132810
 create mode 100644 testsuite/systemtap.bpf/bpf_tests/string3.stp
132810
132810
diff --git a/testsuite/systemtap.bpf/asm_tests/string-basic.stp b/testsuite/systemtap.bpf/asm_tests/string-basic.stp
132810
new file mode 100644
132810
index 000000000..7377e4399
132810
--- /dev/null
132810
+++ b/testsuite/systemtap.bpf/asm_tests/string-basic.stp
132810
@@ -0,0 +1,19 @@
132810
+/* narrowing down a bug that turned out unrelated to assembly */
132810
+function foo:string() %{ /* bpf */ /* pure */
132810
+  0xbf, $$, "test", -, -;
132810
+%}
132810
+
132810
+probe begin {
132810
+  printf("U %s %s\n", foo(), "test"/*bar (5)*/)
132810
+}
132810
+
132810
+probe kernel.function("vfs_read") {
132810
+  printf("K 1 %s\n", foo()) // <- this worked
132810
+  printf("K 2 %s\n", "test") // <- this worked
132810
+  printf("K 3 %s %s\n", foo(), "test") // <- this didn't
132810
+  printf("K 4 %s %s\n", "test", "test") // <- this didn't
132810
+  printf("K 5 %s %s\n", foo(), foo()) // <- this didn't
132810
+  printf("K 6 %s", "test") printf(" %s\n", "test") // <- this did
132810
+  printf("K %d %s\n", 7, "test") // <- this did
132810
+  exit()
132810
+}
132810
diff --git a/testsuite/systemtap.bpf/bpf_tests/string3.stp b/testsuite/systemtap.bpf/bpf_tests/string3.stp
132810
new file mode 100644
132810
index 000000000..cf6ec071d
132810
--- /dev/null
132810
+++ b/testsuite/systemtap.bpf/bpf_tests/string3.stp
132810
@@ -0,0 +1,44 @@
132810
+// stapbpf string manipulation -- store string in global from kernel space
132810
+// XXX: the 'locking' scheme here is kind of dumb but it seems to work
132810
+
132810
+global counter = 0
132810
+global var
132810
+global tab1
132810
+global tab2
132810
+
132810
+@define test_print
132810
+%(
132810
+  /* Test multiple %s in one printf */
132810
+  printf("[")
132810
+  printf("%s%s%s", "str0", var, tab1[17])
132810
+  printf("%s]", tab2["key"])
132810
+%)
132810
+
132810
+probe begin {
132810
+  printf("BEGIN")
132810
+}
132810
+
132810
+probe kernel.function("vfs_read") {
132810
+  if (counter == 0) {
132810
+    var = "str1"
132810
+    tab1[17] = "str2"
132810
+    tab2["key"] = "str3"
132810
+    printf("probe0")
132810
+    @test_print
132810
+    counter = 1
132810
+  }
132810
+}
132810
+
132810
+probe kernel.function("vfs_read") {
132810
+  if (counter == 1) {
132810
+    printf("probe1")
132810
+    @test_print
132810
+    exit()
132810
+  }
132810
+}
132810
+
132810
+probe end {
132810
+  printf("end")
132810
+  @test_print
132810
+  printf("END\n")
132810
+}
132810
-- 
132810
2.14.5
132810