-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use tox to handle virtual env and pytest to as test runner. Add a task in cirrus CI to run them. Signed-off-by: Adrian Moreno <[email protected]>
- Loading branch information
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from retis import * | ||
|
||
import pytest | ||
|
||
|
||
def verify_event(e): | ||
"""Verify the event is valid""" | ||
assert e.__class__ == Event | ||
assert isinstance(e.raw(), dict) | ||
assert isinstance(e.show(), str) | ||
assert "userspace" in e or "kernel" in e | ||
|
||
|
||
def verify_event_reader(r): | ||
assert r.__class__ == EventReader | ||
for e in r: | ||
verify_event(e) | ||
|
||
|
||
def verify_series_reader(r): | ||
assert r.__class__ == SeriesReader | ||
for s in r: | ||
assert s.__class__ == EventSeries | ||
length = len(s) | ||
i = 0 | ||
|
||
for e in s: | ||
verify_event(e) | ||
i += 1 | ||
|
||
assert i == length | ||
|
||
|
||
def test_event_reader(): | ||
"""Test event reader is capable of reading valid events""" | ||
r = EventReader("test_data/test_events.json") | ||
verify_event_reader(r) | ||
|
||
|
||
def test_series_reader(): | ||
"""Test SeriesReader is capable of reading sorted events""" | ||
r = SeriesReader("test_data/test_events_sorted.json") | ||
verify_series_reader(r) | ||
|
||
|
||
def test_event_File(): | ||
"""Test EventFile is capable of reading reader is capable generating | ||
iterators""" | ||
f = EventFile("test_data/test_events.json") | ||
assert not f.sorted() | ||
verify_event_reader(f.iter_events()) | ||
|
||
with pytest.raises(Exception): | ||
f.iter_series() | ||
|
||
sf = EventFile("test_data/test_events_sorted.json") | ||
assert sf.sorted() | ||
verify_series_reader(sf.iter_series()) | ||
|
||
with pytest.raises(Exception): | ||
sf.iter_events() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[{"common":{"smp_id":0,"task":{"comm":"napi/phy0-8197","pid":1360,"tgid":1360},"timestamp":23868643385999},"kernel":{"probe_type":"kprobe","symbol":"tcp_v4_rcv"},"skb":{},"skb-tracking":{"orig_head":18446616568293939200,"skb":18446616546229617920,"timestamp":23868643385999},"tracking":{"idx":0,"skb":{"orig_head":18446616568293939200,"skb":18446616546229617920,"timestamp":23868643385999}}}] | ||
[{"common":{"smp_id":2,"task":{"comm":"napi/phy0-8197","pid":1360,"tgid":1360},"timestamp":23868955262984},"kernel":{"probe_type":"raw_tracepoint","symbol":"openvswitch:ovs_dp_upcall"},"ovs":{"cmd":1,"cpu":1,"event_type":"upcall","port":3366920467},"skb":{},"skb-tracking":{"orig_head":18446616576100907520,"skb":18446616546107689472,"timestamp":23868955262984},"tracking":{"idx":0,"skb":{"orig_head":18446616576100907520,"skb":18446616546107689472,"timestamp":23868955262984}}},{"common":{"smp_id":3,"task":{"comm":"napi/phy0-8197","pid":1360,"tgid":1360},"timestamp":23868955276361},"kernel":{"probe_type":"kretprobe","symbol":"ovs_dp_upcall"},"ovs":{"event_type":"upcall_return","ret":0,"upcall_cpu":1,"upcall_ts":23868955262984},"skb":{},"skb-tracking":{"orig_head":18446616576100907520,"skb":18446616546107689472,"timestamp":23868955262984},"tracking":{"idx":1,"skb":{"orig_head":18446616576100907520,"skb":18446616546107689472,"timestamp":23868955262984}}}] | ||
[{"common":{"smp_id":0,"task":{"comm":"napi/phy0-8197","pid":1360,"tgid":1360},"timestamp":23868955449721},"kernel":{"probe_type":"raw_tracepoint","symbol":"skb:kfree_skb"},"skb":{},"skb-drop":{"drop_reason":"NO_SOCKET"},"skb-tracking":{"orig_head":18446616575285769216,"skb":18446616552502694400,"timestamp":23868955437572},"tracking":{"idx":0,"skb":{"orig_head":18446616575285769216,"skb":18446616552502694400,"timestamp":23868955437572}}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[tox] | ||
requires = | ||
tox>=4 | ||
env_list = py{38,39,310,311,312} | ||
|
||
[testenv] | ||
description = Run unit tests | ||
deps = | ||
pytest>=7 | ||
maturin>=1.7 | ||
commands = | ||
pytest {posargs:pytests} |