|
|
132810 |
From 6411e53fe729a987a300274f6b15fd88b737367d Mon Sep 17 00:00:00 2001
|
|
|
132810 |
From: Serhei Makarov <smakarov@redhat.com>
|
|
|
132810 |
Date: Tue, 16 Oct 2018 18:13:47 -0400
|
|
|
132810 |
Subject: [PATCH 04/32] stapbpf assembler WIP #3 :: additional assembly test
|
|
|
132810 |
cases
|
|
|
132810 |
|
|
|
132810 |
---
|
|
|
132810 |
testsuite/systemtap.bpf/asm_tests/err_alloc.stp | 10 ++++++++++
|
|
|
132810 |
testsuite/systemtap.bpf/asm_tests/err_numeric.stp | 18 ++++++++++++++++++
|
|
|
132810 |
testsuite/systemtap.bpf/asm_tests/simple.stp | 6 +++---
|
|
|
132810 |
testsuite/systemtap.bpf/asm_tests/string.stp | 22 ++++++++++++++++++++++
|
|
|
132810 |
testsuite/systemtap.bpf/asm_tests/temporary.stp | 14 ++++++++++++++
|
|
|
132810 |
5 files changed, 67 insertions(+), 3 deletions(-)
|
|
|
132810 |
create mode 100644 testsuite/systemtap.bpf/asm_tests/err_alloc.stp
|
|
|
132810 |
create mode 100644 testsuite/systemtap.bpf/asm_tests/err_numeric.stp
|
|
|
132810 |
create mode 100644 testsuite/systemtap.bpf/asm_tests/string.stp
|
|
|
132810 |
create mode 100644 testsuite/systemtap.bpf/asm_tests/temporary.stp
|
|
|
132810 |
|
|
|
132810 |
diff --git a/testsuite/systemtap.bpf/asm_tests/err_alloc.stp b/testsuite/systemtap.bpf/asm_tests/err_alloc.stp
|
|
|
132810 |
new file mode 100644
|
|
|
132810 |
index 000000000..6778a52e2
|
|
|
132810 |
--- /dev/null
|
|
|
132810 |
+++ b/testsuite/systemtap.bpf/asm_tests/err_alloc.stp
|
|
|
132810 |
@@ -0,0 +1,10 @@
|
|
|
132810 |
+function foo:long (x:long) %{ /* bpf */ /* pure */
|
|
|
132810 |
+ alloc "not a register", BPF_MAXSTRINGLEN; /* SHOULD ERROR */
|
|
|
132810 |
+ 0xbf, $$, "fifty", -, -; /* mov $$, "fifty" */
|
|
|
132810 |
+%}
|
|
|
132810 |
+
|
|
|
132810 |
+
|
|
|
132810 |
+probe begin {
|
|
|
132810 |
+ printf("foo(1)=%d should be fifty\n", foo(1))
|
|
|
132810 |
+ exit()
|
|
|
132810 |
+}
|
|
|
132810 |
diff --git a/testsuite/systemtap.bpf/asm_tests/err_numeric.stp b/testsuite/systemtap.bpf/asm_tests/err_numeric.stp
|
|
|
132810 |
new file mode 100644
|
|
|
132810 |
index 000000000..9428e5704
|
|
|
132810 |
--- /dev/null
|
|
|
132810 |
+++ b/testsuite/systemtap.bpf/asm_tests/err_numeric.stp
|
|
|
132810 |
@@ -0,0 +1,18 @@
|
|
|
132810 |
+function foo:long (x:long) %{ /* bpf */ /* pure */
|
|
|
132810 |
+ /* verify refusal to accept gibberish */
|
|
|
132810 |
+ 0xd33333333333333333333333333333333333333333333333333333333333333333333333333334db33f, $x, -, _bar, 10; /* XTREAM opcode */
|
|
|
132810 |
+ /* 0xb7, $$, -, huirgishvirguwishgiburg, 100; /* XTREAM 3rd arg */
|
|
|
132810 |
+ /* 0xb7, $$, -, -, borkborkborkborkbork; /* XTREAM 4th arg */
|
|
|
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/simple.stp b/testsuite/systemtap.bpf/asm_tests/simple.stp
|
|
|
132810 |
index 693219d15..17184a139 100644
|
|
|
132810 |
--- a/testsuite/systemtap.bpf/asm_tests/simple.stp
|
|
|
132810 |
+++ b/testsuite/systemtap.bpf/asm_tests/simple.stp
|
|
|
132810 |
@@ -1,11 +1,11 @@
|
|
|
132810 |
function foo:long (x:long) %{ /* bpf */ /* pure */
|
|
|
132810 |
/* compute 100-x */
|
|
|
132810 |
- 0xb7, $$, -, -, 100; /* mov $$, ee */
|
|
|
132810 |
+ 0xb7, $$, -, -, 100; /* mov $$, 100 */
|
|
|
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 |
+ printf("foo(1)=%d, should be 99\n", foo(1))
|
|
|
132810 |
+ printf("foo(15)=%d, should be 85\n", foo(15))
|
|
|
132810 |
exit()
|
|
|
132810 |
}
|
|
|
132810 |
diff --git a/testsuite/systemtap.bpf/asm_tests/string.stp b/testsuite/systemtap.bpf/asm_tests/string.stp
|
|
|
132810 |
new file mode 100644
|
|
|
132810 |
index 000000000..dce665c14
|
|
|
132810 |
--- /dev/null
|
|
|
132810 |
+++ b/testsuite/systemtap.bpf/asm_tests/string.stp
|
|
|
132810 |
@@ -0,0 +1,22 @@
|
|
|
132810 |
+function foo:long (x:long) %{ /* bpf */ /* pure */
|
|
|
132810 |
+ /* if x <= 10 then "fifty" else "one-hundred" */
|
|
|
132810 |
+ 0xd5, $x, -, _bar, 10; /* jsle $x, 10, _bar */
|
|
|
132810 |
+ 0xbf, $$, "one-hundred", -, -; /* mov $$, "one-hundred" */
|
|
|
132810 |
+ 0x05, -, -, _done, -; /* ja _done; */
|
|
|
132810 |
+ label, _bar;
|
|
|
132810 |
+ 0xbf, $$, "fifty", -, -; /* mov $$, "fifty" */
|
|
|
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/temporary.stp b/testsuite/systemtap.bpf/asm_tests/temporary.stp
|
|
|
132810 |
new file mode 100644
|
|
|
132810 |
index 000000000..153c759ba
|
|
|
132810 |
--- /dev/null
|
|
|
132810 |
+++ b/testsuite/systemtap.bpf/asm_tests/temporary.stp
|
|
|
132810 |
@@ -0,0 +1,14 @@
|
|
|
132810 |
+function foo:long (x:long) %{ /* bpf */ /* pure */
|
|
|
132810 |
+ /* compute (100-x)*(x+2) */
|
|
|
132810 |
+ 0xb7, $$, -, -, 100; /* mov $$, 100 */
|
|
|
132810 |
+ 0x1f, $$, $x, -, -; /* sub $$, $x */
|
|
|
132810 |
+ 0xbf, $tmp, $x, -, -; /* mov $tmp, $x */
|
|
|
132810 |
+ 0x07, $tmp, -, -, 2; /* add $tmp, 2 */
|
|
|
132810 |
+ 0x2f, $$, $tmp, -, -; /* mul $$, $tmp */
|
|
|
132810 |
+%}
|
|
|
132810 |
+
|
|
|
132810 |
+probe begin {
|
|
|
132810 |
+ printf("foo(1)=%d, should be 99*3=297\n", foo(1))
|
|
|
132810 |
+ printf("foo(15)=%d, should be 85*18=1530\n", foo(15))
|
|
|
132810 |
+ exit()
|
|
|
132810 |
+}
|
|
|
132810 |
--
|
|
|
132810 |
2.14.5
|
|
|
132810 |
|