2024-01-13 07:27:25 +00:00
|
|
|
|
2024-01-14 07:50:23 +00:00
|
|
|
'''
|
|
|
|
The tests in this file are samples drawn from
|
|
|
|
https://lwn.net/Articles/806002/.
|
|
|
|
'''
|
2024-01-13 07:27:25 +00:00
|
|
|
|
2024-01-16 01:08:01 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from xbc import loads_xbc
|
|
|
|
|
2024-01-13 07:27:25 +00:00
|
|
|
def test_01():
|
2024-01-16 01:08:01 +00:00
|
|
|
'Key/value example.'
|
|
|
|
i = '''feature.option.foo = 1
|
2024-01-14 07:50:23 +00:00
|
|
|
feature.option.bar = 2'''
|
2024-01-16 01:08:01 +00:00
|
|
|
d = {
|
|
|
|
'feature.option': False,
|
|
|
|
'feature': False,
|
|
|
|
'feature.option.foo': '1',
|
|
|
|
'feature.option.bar': '2'
|
|
|
|
}
|
|
|
|
assert loads_xbc(i) == d
|
2024-01-13 07:27:25 +00:00
|
|
|
|
|
|
|
def test_02():
|
2024-01-16 01:08:01 +00:00
|
|
|
'Block example.'
|
|
|
|
i = '''feature.option {
|
|
|
|
foo = 1
|
|
|
|
bar = 2
|
2024-01-14 07:50:23 +00:00
|
|
|
}'''
|
2024-01-16 01:08:01 +00:00
|
|
|
d = {
|
|
|
|
'feature.option': False,
|
|
|
|
'feature': False,
|
|
|
|
'feature.option.foo': '1',
|
|
|
|
'feature.option.bar': '2'
|
|
|
|
}
|
|
|
|
assert loads_xbc(i) == d
|
2024-01-13 07:27:25 +00:00
|
|
|
|
|
|
|
def test_03():
|
2024-01-16 01:08:01 +00:00
|
|
|
'Array example.'
|
|
|
|
i = 'feature.options = "foo", "bar"'
|
|
|
|
d = {
|
|
|
|
'feature': False,
|
|
|
|
'feature.options': ['foo', 'bar']
|
|
|
|
}
|
|
|
|
assert loads_xbc(i) == d
|
2024-01-13 07:27:25 +00:00
|
|
|
|
|
|
|
def test_10():
|
2024-01-16 01:08:01 +00:00
|
|
|
'Compact example.'
|
|
|
|
i = 'feature.option{foo=1;bar=2}'
|
|
|
|
d = {
|
|
|
|
'feature.option': False,
|
|
|
|
'feature': False,
|
|
|
|
'feature.option.foo': '1',
|
|
|
|
'feature.option.bar': '2'
|
|
|
|
}
|
|
|
|
assert loads_xbc(i) == d
|
2024-01-13 07:27:25 +00:00
|
|
|
|
|
|
|
def test_11():
|
2024-01-16 01:08:01 +00:00
|
|
|
'Example of a possible configuration.'
|
|
|
|
i = '''ftrace.event {
|
|
|
|
task.task_newtask {
|
|
|
|
filter = "pid < 128"
|
|
|
|
enable
|
|
|
|
}
|
|
|
|
kprobes.vfs_read {
|
|
|
|
probes = "vfs_read $arg1 $arg2"
|
|
|
|
filter = "common_pid < 200"
|
|
|
|
enable
|
|
|
|
}
|
|
|
|
synthetic.initcall_latency {
|
|
|
|
fields = "unsigned long func", "u64 lat"
|
|
|
|
actions = "hist:keys=func.sym,lat:vals=lat:sort=lat"
|
|
|
|
}
|
|
|
|
initcall.initcall_start {
|
|
|
|
actions = "hist:keys=func:ts0=common_timestamp.usecs"
|
|
|
|
}
|
|
|
|
initcall.initcall_finish {
|
|
|
|
actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)"
|
|
|
|
}
|
2024-01-14 07:50:23 +00:00
|
|
|
}'''
|
2024-01-16 01:08:01 +00:00
|
|
|
d = {
|
|
|
|
'ftrace': False,
|
|
|
|
'ftrace.event': False,
|
|
|
|
'ftrace.event.task': False,
|
|
|
|
'ftrace.event.task.task_newtask': False,
|
|
|
|
'ftrace.event.task.task_newtask.filter': "pid < 128",
|
|
|
|
'ftrace.event.task.task_newtask.enable': True,
|
|
|
|
'ftrace.event.kprobes': False,
|
|
|
|
'ftrace.event.kprobes.vfs_read': False,
|
|
|
|
'ftrace.event.kprobes.vfs_read.probes': "vfs_read $arg1 $arg2",
|
|
|
|
'ftrace.event.kprobes.vfs_read.filter': "common_pid < 200",
|
|
|
|
'ftrace.event.kprobes.vfs_read.enable': True,
|
|
|
|
'ftrace.event.synthetic': False,
|
|
|
|
'ftrace.event.synthetic.initcall_latency': False,
|
|
|
|
'ftrace.event.synthetic.initcall_latency.fields': ["unsigned long func", "u64 lat"],
|
|
|
|
'ftrace.event.synthetic.initcall_latency.actions':
|
|
|
|
"hist:keys=func.sym,lat:vals=lat:sort=lat",
|
|
|
|
'ftrace.event.initcall': False,
|
|
|
|
'ftrace.event.initcall.initcall_start': False,
|
|
|
|
'ftrace.event.initcall.initcall_start.actions':
|
|
|
|
"hist:keys=func:ts0=common_timestamp.usecs",
|
|
|
|
'ftrace.event.initcall.initcall_finish': False,
|
|
|
|
'ftrace.event.initcall.initcall_finish.actions':
|
|
|
|
"hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(" +
|
|
|
|
"initcall.initcall_start).initcall_latency(func,$lat)"
|
|
|
|
}
|
|
|
|
assert loads_xbc(i) == d
|
2024-01-13 07:27:25 +00:00
|
|
|
|
|
|
|
def test_12():
|
2024-01-16 01:08:01 +00:00
|
|
|
'Another example of a possible configuration.'
|
|
|
|
i = '''ftrace.event.synthetic.initcall_latency {
|
|
|
|
fields = "unsigned long func", "u64 lat"
|
|
|
|
hist {
|
|
|
|
from {
|
|
|
|
event = initcall.initcall_start
|
|
|
|
key = func
|
|
|
|
assigns = "ts0=common_timestamp.usecs"
|
|
|
|
}
|
|
|
|
to {
|
|
|
|
event = initcall.initcall_finish
|
|
|
|
key = func
|
|
|
|
assigns = "lat=common_timestamp.usecs-$ts0"
|
|
|
|
onmatch = func, $lat
|
|
|
|
}
|
|
|
|
keys = func.sym, lat
|
|
|
|
vals = lat
|
|
|
|
sort = lat
|
|
|
|
}
|
2024-01-14 07:50:23 +00:00
|
|
|
}'''
|
2024-01-16 01:08:01 +00:00
|
|
|
d = {
|
|
|
|
'ftrace': False,
|
|
|
|
'ftrace.event': False,
|
|
|
|
'ftrace.event.synthetic': False,
|
|
|
|
'ftrace.event.synthetic.initcall_latency': False,
|
|
|
|
'ftrace.event.synthetic.initcall_latency.fields': ["unsigned long func", "u64 lat"],
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist': False,
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.from': False,
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.from.event': 'initcall.initcall_start',
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.from.key': 'func',
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.from.assigns': "ts0=common_timestamp.usecs",
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.to': False,
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.to.event': 'initcall.initcall_finish',
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.to.key': 'func',
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.to.assigns':
|
|
|
|
"lat=common_timestamp.usecs-$ts0",
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.to.onmatch': ['func', '$lat'],
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.keys': ['func.sym', 'lat'],
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.vals': 'lat',
|
|
|
|
'ftrace.event.synthetic.initcall_latency.hist.sort': 'lat'
|
|
|
|
}
|
|
|
|
assert loads_xbc(i) == d
|