Blame SOURCES/rhbz1643997.0003-stapbpf-assembler-WIP-2-testcases-no-driver-so-far.patch

132810
From df2e44cd4a35c0cbba528e1d5821d5cd14cb7a87 Mon Sep 17 00:00:00 2001
132810
From: Serhei Makarov <smakarov@redhat.com>
132810
Date: Mon, 1 Oct 2018 15:39:00 -0400
132810
Subject: [PATCH 03/32] stapbpf assembler WIP #2 :: testcases (no driver so
132810
 far)
132810
132810
---
132810
 testsuite/systemtap.bpf/asm_tests/branch.stp    | 22 ++++++++++++++++++++++
132810
 testsuite/systemtap.bpf/asm_tests/err_token.stp | 21 +++++++++++++++++++++
132810
 testsuite/systemtap.bpf/asm_tests/leniency.stp  | 17 +++++++++++++++++
132810
 testsuite/systemtap.bpf/asm_tests/simple.stp    | 11 +++++++++++
132810
 4 files changed, 71 insertions(+)
132810
 create mode 100644 testsuite/systemtap.bpf/asm_tests/branch.stp
132810
 create mode 100644 testsuite/systemtap.bpf/asm_tests/err_token.stp
132810
 create mode 100644 testsuite/systemtap.bpf/asm_tests/leniency.stp
132810
 create mode 100644 testsuite/systemtap.bpf/asm_tests/simple.stp
132810
132810
diff --git a/testsuite/systemtap.bpf/asm_tests/branch.stp b/testsuite/systemtap.bpf/asm_tests/branch.stp
132810
new file mode 100644
132810
index 000000000..aa22bf195
132810
--- /dev/null
132810
+++ b/testsuite/systemtap.bpf/asm_tests/branch.stp
132810
@@ -0,0 +1,22 @@
132810
+function foo:long (x:long) %{ /* bpf */ /* pure */
132810
+  /* if x <= 10 then 50 else 100 */
132810
+  0xd5, $x, -, _bar, 10; /* jsle $x, 10, _bar */
132810
+  0xb7, $$, -, -, 100; /* mov $$, 100 */
132810
+  0x05, -, -, _done, -; /* ja _done; */
132810
+  label, _bar;
132810
+  0xb7, $$, -, -, 50; /* mov $$, 50 */
132810
+  label, _done;
132810
+  /* 0xbf, $$, $$, -, -; /* dummy op */
132810
+%}
132810
+
132810
+function bar:long (x:long) {
132810
+  if (x <= 10) return 50 else return 100
132810
+}
132810
+
132810
+probe begin {
132810
+  printf("foo(1)=%d should be %d\n", foo(1), bar(1))
132810
+  printf("foo(8)=%d should be %d\n", foo(8), bar(8))
132810
+  printf("foo(15)=%d should be %d\n", foo(15), bar(15))
132810
+  exit()
132810
+}
132810
+
132810
diff --git a/testsuite/systemtap.bpf/asm_tests/err_token.stp b/testsuite/systemtap.bpf/asm_tests/err_token.stp
132810
new file mode 100644
132810
index 000000000..b9f8bd866
132810
--- /dev/null
132810
+++ b/testsuite/systemtap.bpf/asm_tests/err_token.stp
132810
@@ -0,0 +1,21 @@
132810
+function foo:long (x:long) %{ /* bpf */ /* pure */
132810
+  /* if x <= 10 then 50 else 100 */
132810
+  0xd5, $x, -, _bar, 10; /* jsle $x, 10, _bar */
132810
+  0xb7, $$, -, -, 100; /* mov $$, 100 */
132810
+  florb, -, -, _done, -; /* TRIGGER ERROR */
132810
+  label, _bar;
132810
+  0xb7, $$, -, -, 50; /* mov $$, 50 */
132810
+  label, _done;
132810
+  /* 0xbf, $$, $$, -, -; /* dummy op */
132810
+%}
132810
+
132810
+function bar:long (x:long) {
132810
+  if (x <= 10) return 50 else return 100
132810
+}
132810
+
132810
+probe begin {
132810
+  printf("foo(1)=%d should be %d\n", foo(1), bar(1))
132810
+  printf("foo(8)=%d should be %d\n", foo(8), bar(8))
132810
+  printf("foo(15)=%d should be %d\n", foo(15), bar(15))
132810
+  exit()
132810
+}
132810
diff --git a/testsuite/systemtap.bpf/asm_tests/leniency.stp b/testsuite/systemtap.bpf/asm_tests/leniency.stp
132810
new file mode 100644
132810
index 000000000..939061158
132810
--- /dev/null
132810
+++ b/testsuite/systemtap.bpf/asm_tests/leniency.stp
132810
@@ -0,0 +1,17 @@
132810
+function foo:long (x:long) %{ /* bpf */ /* pure */
132810
+  /* if x < 10 then 17 else 16 */
132810
+  0xa5, $x, -, _bar, 10; /* jlt $x, 10, _bar */
132810
+  0xb7, $this is an "!!ide\nt!!"   believe it or not, -, -, 16; /* mov $t, 0 */
132810
+  0xbf, $$, $thisisan"!!ide\nt!!"believeitornot, -, -; /* mov $$, $t */
132810
+  0x05, -, -, _done, -; /* ja _done; */
132810
+  label, _bar;
132810
+  0xb7, $$, -, -, 17; /* mov $$, 1 */
132810
+  label, _done;
132810
+%}
132810
+
132810
+probe begin {
132810
+  printf("foo(1)=%d\n", foo(1))
132810
+  printf("foo(15)=%d\n", foo(15))
132810
+  exit()
132810
+}
132810
+
132810
diff --git a/testsuite/systemtap.bpf/asm_tests/simple.stp b/testsuite/systemtap.bpf/asm_tests/simple.stp
132810
new file mode 100644
132810
index 000000000..693219d15
132810
--- /dev/null
132810
+++ b/testsuite/systemtap.bpf/asm_tests/simple.stp
132810
@@ -0,0 +1,11 @@
132810
+function foo:long (x:long) %{ /* bpf */ /* pure */
132810
+  /* compute 100-x */
132810
+  0xb7, $$, -, -, 100; /* mov $$, ee */
132810
+  0x1f, $$, $x, -, -; /* sub $$, $x */
132810
+%}
132810
+
132810
+probe begin {
132810
+  printf("foo(1)=%d\n", foo(1))
132810
+  printf("foo(15)=%d\n", foo(15))
132810
+  exit()
132810
+}
132810
-- 
132810
2.14.5
132810