Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
5f5d147a
Commit
5f5d147a
authored
Jun 28, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parser tests
parent
fb2f33a6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
160 additions
and
10 deletions
+160
-10
src/main.cpp
src/main.cpp
+1
-1
src/printer.cpp
src/printer.cpp
+0
-2
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
tests/parser.cpp
tests/parser.cpp
+158
-7
No files found.
src/main.cpp
View file @
5f5d147a
...
...
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
if
(
debug
)
{
ast
::
Printer
p
=
bpftrace
::
ast
::
Printer
(
std
::
cout
);
ast
::
Printer
p
(
std
::
cout
);
driver
.
root_
->
accept
(
p
);
}
...
...
src/printer.cpp
View file @
5f5d147a
...
...
@@ -67,9 +67,7 @@ void Printer::visit(Unop &unop)
void
Printer
::
visit
(
ExprStatement
&
expr
)
{
++
depth_
;
expr
.
expr
->
accept
(
*
this
);
--
depth_
;
}
void
Printer
::
visit
(
AssignMapStatement
&
assignment
)
...
...
tests/CMakeLists.txt
View file @
5f5d147a
...
...
@@ -15,6 +15,7 @@ add_executable(bpftrace_test
${
CMAKE_SOURCE_DIR
}
/src/driver.cpp
${
CMAKE_SOURCE_DIR
}
/src/map.cpp
${
CMAKE_SOURCE_DIR
}
/src/mapkey.cpp
${
CMAKE_SOURCE_DIR
}
/src/printer.cpp
${
CMAKE_SOURCE_DIR
}
/src/semantic_analyser.cpp
${
CMAKE_SOURCE_DIR
}
/src/types.cpp
)
...
...
tests/parser.cpp
View file @
5f5d147a
#include <sstream>
#include "gtest/gtest.h"
#include "driver.h"
#include "printer.h"
namespace
bpftrace
{
TEST
(
Parser
,
test0
)
using
Printer
=
ast
::
Printer
;
void
test
(
const
std
::
string
&
input
,
const
std
::
string
&
output
)
{
Driver
driver
;
std
::
string
s
=
"kprobe:sys_open { @x = 1; }"
;
EXPECT_EQ
(
driver
.
parse_str
(
s
),
0
);
ASSERT_EQ
(
driver
.
parse_str
(
input
),
0
);
std
::
ostringstream
out
;
Printer
printer
(
out
);
driver
.
root_
->
accept
(
printer
);
EXPECT_EQ
(
output
,
out
.
str
());
}
TEST
(
Parser
,
test1
)
TEST
(
Parser
,
map_assign
)
{
Driver
driver
;
std
::
string
s
=
"kprobe:sys_open { @x = 1; }"
;
EXPECT_EQ
(
driver
.
parse_str
(
s
),
0
);
test
(
"kprobe:sys_open { @x = 1; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" int: 1
\n
"
);
test
(
"kprobe:sys_open { @x = @y; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" map: @y
\n
"
);
test
(
"kprobe:sys_open { @x = mybuiltin; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" builtin: mybuiltin
\n
"
);
test
(
"kprobe:sys_open { @x = myfunc(); }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" call: myfunc
\n
"
);
}
TEST
(
Parser
,
map_key
)
{
test
(
"kprobe:sys_open { @x[0] = 1; @x[0,1,2] = 1; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" int: 0
\n
"
" int: 1
\n
"
" =
\n
"
" map: @x
\n
"
" int: 0
\n
"
" int: 1
\n
"
" int: 2
\n
"
" int: 1
\n
"
);
test
(
"kprobe:sys_open { @x[@a] = 1; @x[@a,@b,@c] = 1; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" map: @a
\n
"
" int: 1
\n
"
" =
\n
"
" map: @x
\n
"
" map: @a
\n
"
" map: @b
\n
"
" map: @c
\n
"
" int: 1
\n
"
);
test
(
"kprobe:sys_open { @x[b1] = 1; @x[b1,b2,b3] = 1; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" builtin: b1
\n
"
" int: 1
\n
"
" =
\n
"
" map: @x
\n
"
" builtin: b1
\n
"
" builtin: b2
\n
"
" builtin: b3
\n
"
" int: 1
\n
"
);
}
TEST
(
Parser
,
predicate
)
{
test
(
"kprobe:sys_open / @x / { 1; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" pred
\n
"
" map: @x
\n
"
" int: 1
\n
"
);
}
TEST
(
Parser
,
predicate_containing_division
)
{
test
(
"kprobe:sys_open /100/25/ { 1; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" pred
\n
"
" /
\n
"
" int: 100
\n
"
" int: 25
\n
"
" int: 1
\n
"
);
}
TEST
(
Parser
,
expressions
)
{
test
(
"kprobe:sys_open / 1 <= 2 && (9 - 4 == 5*10 || ~0) || poop /
\n
"
"{
\n
"
" 1;
\n
"
"}"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" pred
\n
"
" ||
\n
"
" &&
\n
"
" <=
\n
"
" int: 1
\n
"
" int: 2
\n
"
" ||
\n
"
" ==
\n
"
" -
\n
"
" int: 9
\n
"
" int: 4
\n
"
" *
\n
"
" int: 5
\n
"
" int: 10
\n
"
" ~
\n
"
" int: 0
\n
"
" builtin: poop
\n
"
" int: 1
\n
"
);
}
TEST
(
Parser
,
call
)
{
test
(
"kprobe:sys_open { @x = foo(); @y = bar(1,2,3); }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" =
\n
"
" map: @x
\n
"
" call: foo
\n
"
" =
\n
"
" map: @y
\n
"
" call: bar
\n
"
" int: 1
\n
"
" int: 2
\n
"
" int: 3
\n
"
);
}
TEST
(
Parser
,
multiple_probes
)
{
test
(
"kprobe:sys_open { 1; } kretprobe:sys_open { 2; }"
,
"Program
\n
"
" kprobe:sys_open
\n
"
" int: 1
\n
"
" kretprobe:sys_open
\n
"
" int: 2
\n
"
);
}
}
// namespace bpftrace
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment