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
41096840
Commit
41096840
authored
Jul 01, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update semantic analyer tests to parse an input string into an AST first
parent
5f5d147a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
45 deletions
+20
-45
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+20
-45
No files found.
tests/semantic_analyser.cpp
View file @
41096840
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "bpftrace.h"
#include "
parser.tab.h
h"
#include "
driver.
h"
#include "semantic_analyser.h"
namespace
bpftrace
{
...
...
@@ -11,61 +11,36 @@ public:
MOCK_METHOD1
(
add_probe
,
int
(
ast
::
Probe
&
p
));
};
namespace
ast
{
using
::
testing
::
_
;
TEST
(
semantic_analyser
,
probe_count
)
void
test
(
BPFtrace
&
bpftrace
,
const
std
::
string
&
input
,
int
result
=
0
)
{
MockBPFtrace
bpftrace
;
EXPECT_CALL
(
bpftrace
,
add_probe
(
_
)).
Times
(
2
);
Driver
driver
;
ASSERT_EQ
(
driver
.
parse_str
(
input
),
0
);
// kprobe:kprobe { 123; }
// kprobe:kprobe { 123; }
Integer
expr
(
123
);
ExprStatement
stmt
(
&
expr
);
StatementList
stmts
=
{
&
stmt
};
std
::
string
str
=
"kprobe"
;
Probe
p1
(
str
,
str
,
&
stmts
);
Probe
p2
(
str
,
str
,
&
stmts
);
ProbeList
pl
=
{
&
p1
,
&
p2
};
Program
root
(
&
pl
);
bpftrace
::
ast
::
SemanticAnalyser
semantics
(
&
root
,
bpftrace
);
semantics
.
analyse
();
std
::
ostringstream
out
;
ast
::
SemanticAnalyser
semantics
(
driver
.
root_
,
bpftrace
,
out
);
EXPECT_EQ
(
semantics
.
analyse
(),
result
);
}
TEST
(
semantic_analyser
,
undefined_map
)
void
test
(
const
std
::
string
&
input
,
int
result
=
0
)
{
BPFtrace
bpftrace
;
test
(
bpftrace
,
input
,
result
);
}
// kprobe:kprobe / @mymap1 == 123 / { 123; }
std
::
string
str
=
"kprobe"
;
std
::
string
mapstr1
=
"mymap1"
;
Integer
myint
(
123
);
Map
map1
(
mapstr1
);
Binop
binop
(
&
map1
,
bpftrace
::
Parser
::
token
::
EQ
,
&
myint
);
Predicate
pred
(
&
binop
);
ExprStatement
stmt
(
&
myint
);
StatementList
stmts
=
{
&
stmt
};
Probe
p
(
str
,
str
,
&
pred
,
&
stmts
);
ProbeList
pl
=
{
&
p
};
Program
root
(
&
pl
);
std
::
ostringstream
out1
;
bpftrace
::
ast
::
SemanticAnalyser
semantics1
(
&
root
,
bpftrace
,
out1
);
EXPECT_EQ
(
semantics1
.
analyse
(),
10
);
TEST
(
semantic_analyser
,
probe_count
)
{
MockBPFtrace
bpftrace
;
EXPECT_CALL
(
bpftrace
,
add_probe
(
_
)).
Times
(
2
);
// kprobe:kprobe / @mymap1 == 123 / { 123; @mymap1 = @mymap2; }
std
::
string
mapstr2
=
"mymap2"
;
Map
map2
(
mapstr2
);
AssignMapStatement
assign
(
&
map1
,
&
map2
);
stmts
.
push_back
(
&
assign
);
test
(
bpftrace
,
"a:b { 1; } c:d { 1; }"
);
}
std
::
ostringstream
out2
;
bpftrace
::
ast
::
SemanticAnalyser
semantics2
(
&
root
,
bpftrace
,
out2
);
EXPECT_EQ
(
semantics2
.
analyse
(),
10
);
TEST
(
semantic_analyser
,
undefined_map
)
{
test
(
"a:b / @mymap == 123 / { 456; }"
,
10
);
test
(
"a:b / @mymap1 == 1234 / { 1234; @mymap1 = @mymap2; }"
,
10
);
}
}
// namespace ast
}
// 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