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
2881f7f3
Commit
2881f7f3
authored
Oct 17, 2018
by
williangaspar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests
parent
38276a11
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
15 deletions
+81
-15
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+12
-13
src/types.cpp
src/types.cpp
+1
-1
src/types.h
src/types.h
+1
-1
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
tests/probe.cpp
tests/probe.cpp
+66
-0
No files found.
src/ast/semantic_analyser.cpp
View file @
2881f7f3
...
...
@@ -677,33 +677,32 @@ void SemanticAnalyser::visit(Predicate &pred)
void
SemanticAnalyser
::
visit
(
AttachPoint
&
ap
)
{
auto
type
=
probetypeName
(
ap
.
provider
);
type
=
type
==
""
?
ap
.
provider
:
type
;
ap
.
provider
=
probetypeName
(
ap
.
provider
);
if
(
type
==
"kprobe"
||
type
==
"kretprobe"
)
{
if
(
ap
.
provider
==
"kprobe"
||
ap
.
provider
==
"kretprobe"
)
{
if
(
ap
.
target
!=
""
)
err_
<<
"kprobes should not have a target"
<<
std
::
endl
;
if
(
ap
.
func
==
""
)
err_
<<
"kprobes should be attached to a function"
<<
std
::
endl
;
}
else
if
(
type
==
"uprobe"
||
type
==
"uretprobe"
)
{
else
if
(
ap
.
provider
==
"uprobe"
||
ap
.
provider
==
"uretprobe"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"uprobes should have a target"
<<
std
::
endl
;
if
(
ap
.
func
==
""
)
err_
<<
"uprobes should be attached to a function"
<<
std
::
endl
;
}
else
if
(
type
==
"usdt"
)
{
else
if
(
ap
.
provider
==
"usdt"
)
{
if
(
ap
.
target
==
""
||
ap
.
func
==
""
)
err_
<<
"usdt probe must have a target"
<<
std
::
endl
;
struct
stat
s
;
if
(
stat
(
ap
.
target
.
c_str
(),
&
s
)
!=
0
)
err_
<<
"usdt target file "
<<
ap
.
target
<<
" does not exist"
<<
std
::
endl
;
}
else
if
(
type
==
"tracepoint"
)
{
else
if
(
ap
.
provider
==
"tracepoint"
)
{
if
(
ap
.
target
==
""
||
ap
.
func
==
""
)
err_
<<
"tracepoint probe must have a target"
<<
std
::
endl
;
}
else
if
(
type
==
"profile"
)
{
else
if
(
ap
.
provider
==
"profile"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"profile probe must have unit of time"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"hz"
&&
...
...
@@ -716,7 +715,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else
if
(
ap
.
freq
<=
0
)
err_
<<
"profile frequency should be a positive integer"
<<
std
::
endl
;
}
else
if
(
type
==
"interval"
)
{
else
if
(
ap
.
provider
==
"interval"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"interval probe must have unit of time"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"ms"
&&
...
...
@@ -725,7 +724,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
if
(
ap
.
func
!=
""
)
err_
<<
"interval probe must have an integer frequency"
<<
std
::
endl
;
}
else
if
(
type
==
"software"
)
{
else
if
(
ap
.
provider
==
"software"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"software probe must have a software event name"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"cpu-clock"
&&
ap
.
target
!=
"cpu"
&&
...
...
@@ -745,7 +744,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else
if
(
ap
.
freq
<
0
)
err_
<<
"software count should be a positive integer"
<<
std
::
endl
;
}
else
if
(
type
==
"hardware"
)
{
else
if
(
ap
.
provider
==
"hardware"
)
{
if
(
ap
.
target
==
""
)
err_
<<
"hardware probe must have a hardware event name"
<<
std
::
endl
;
else
if
(
ap
.
target
!=
"cpu-cycles"
&&
ap
.
target
!=
"cycles"
&&
...
...
@@ -763,16 +762,16 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else
if
(
ap
.
freq
<
0
)
err_
<<
"hardware frequency should be a positive integer"
<<
std
::
endl
;
}
else
if
(
type
==
"BEGIN"
||
type
==
"END"
)
{
else
if
(
ap
.
provider
==
"BEGIN"
||
ap
.
provider
==
"END"
)
{
if
(
ap
.
target
!=
""
||
ap
.
func
!=
""
)
err_
<<
"BEGIN/END probes should not have a target"
<<
std
::
endl
;
if
(
is_final_pass
())
{
if
(
type
==
"BEGIN"
)
{
if
(
ap
.
provider
==
"BEGIN"
)
{
if
(
has_begin_probe_
)
err_
<<
"More than one BEGIN probe defined"
<<
std
::
endl
;
has_begin_probe_
=
true
;
}
if
(
type
==
"END"
)
{
if
(
ap
.
provider
==
"END"
)
{
if
(
has_end_probe_
)
err_
<<
"More than one END probe defined"
<<
std
::
endl
;
has_end_probe_
=
true
;
...
...
src/types.cpp
View file @
2881f7f3
...
...
@@ -70,7 +70,7 @@ std::string probetypeName(const std::string &type)
if
(
type
==
PROBE_LIST
[
i
].
name
||
type
==
PROBE_LIST
[
i
].
abbr
)
return
PROBE_LIST
[
i
].
name
;
}
return
""
;
return
type
;
}
uint64_t
asyncactionint
(
AsyncAction
a
)
...
...
src/types.h
View file @
2881f7f3
...
...
@@ -85,7 +85,7 @@ const ProbeItem PROBE_LIST[] =
{
"kretprobe"
,
"kr"
,
ProbeType
::
kretprobe
},
{
"uprobe"
,
"u"
,
ProbeType
::
uprobe
},
{
"uretprobe"
,
"ur"
,
ProbeType
::
uretprobe
},
{
"usdt"
,
"
usdt
"
,
ProbeType
::
usdt
},
{
"usdt"
,
"
U
"
,
ProbeType
::
usdt
},
{
"BEGIN"
,
"BEGIN"
,
ProbeType
::
uprobe
},
{
"END"
,
"END"
,
ProbeType
::
uprobe
},
{
"tracepoint"
,
"t"
,
ProbeType
::
tracepoint
},
...
...
tests/CMakeLists.txt
View file @
2881f7f3
...
...
@@ -9,6 +9,7 @@ add_executable(bpftrace_test
codegen.cpp
main.cpp
parser.cpp
probe.cpp
semantic_analyser.cpp
tracepoint_format_parser.cpp
utils.cpp
...
...
tests/probe.cpp
0 → 100644
View file @
2881f7f3
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "bpforc.h"
#include "bpftrace.h"
#include "clang_parser.h"
#include "codegen_llvm.h"
#include "driver.h"
#include "fake_map.h"
#include "semantic_analyser.h"
namespace
bpftrace
{
namespace
test
{
namespace
probe
{
using
bpftrace
::
ast
::
AttachPoint
;
using
bpftrace
::
ast
::
AttachPointList
;
using
bpftrace
::
ast
::
Probe
;
void
gen_bytecode
(
const
std
::
string
&
input
,
std
::
stringstream
&
out
)
{
BPFtrace
bpftrace
;
Driver
driver
;
FakeMap
::
next_mapfd_
=
1
;
ASSERT_EQ
(
driver
.
parse_str
(
input
),
0
);
ClangParser
clang
;
clang
.
parse
(
driver
.
root_
,
bpftrace
.
structs_
);
ast
::
SemanticAnalyser
semantics
(
driver
.
root_
,
bpftrace
);
ASSERT_EQ
(
semantics
.
analyse
(),
0
);
ASSERT_EQ
(
semantics
.
create_maps
(
true
),
0
);
ast
::
CodegenLLVM
codegen
(
driver
.
root_
,
bpftrace
);
codegen
.
compile
(
DebugLevel
::
kDebug
,
out
);
}
void
compare_bytecode
(
const
std
::
string
&
input1
,
const
std
::
string
&
input2
)
{
std
::
stringstream
expected_output1
;
std
::
stringstream
expected_output2
;
gen_bytecode
(
input1
,
expected_output1
);
gen_bytecode
(
input2
,
expected_output2
);
EXPECT_EQ
(
expected_output1
.
str
(),
expected_output2
.
str
());
}
TEST
(
probe
,
short_name
)
{
compare_bytecode
(
"tracepoint:a:b { args }"
,
"t:a:b { args }"
);
compare_bytecode
(
"kprobe:f { pid }"
,
"k:f { pid }"
);
compare_bytecode
(
"kretprobe:f { pid }"
,
"kr:f { pid }"
);
compare_bytecode
(
"uprobe:path:f { 1 }"
,
"u:path:f { 1 }"
);
compare_bytecode
(
"profile:hz:997 { 1 }"
,
"p:hz:997 { 1 }"
);
compare_bytecode
(
"hardware:cache-references:1000000 { 1 }"
,
"h:cache-references:1000000 { 1 }"
);
compare_bytecode
(
"software:faults:1000 { 1 }"
,
"s:faults:1000 { 1 }"
);
compare_bytecode
(
"interval:s:1 { 1 }"
,
"i:s:1 { 1 }"
);
}
}
// namespace probe
}
// namespace test
}
// 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