Skip to content

Commit

Permalink
tracee_test: Add tests for get_sockaddr_from_buf and move offsets on …
Browse files Browse the repository at this point in the history
…__init__

Signed-off-by: Simarpreet Singh <simar@linux.com>
  • Loading branch information
simar7 committed Nov 5, 2019
1 parent ea9b0ec commit a069238
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test_container_tracer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ctypes
import unittest
import tracee
import start

from tracee.container_tracer import EventMonitor

Expand Down Expand Up @@ -114,6 +116,31 @@ def test_open_flags_to_str(self):
self.assertEqual(test_case["expected"], tracee.container_tracer.open_flags_to_str(test_case["input"]),
test_case["name"])

def test_get_sockaddr_from_buf(self):
self.longMessage = True

em = tracee.container_tracer.EventMonitor(start.parse_args([]))

test_cases = [
{
"name": "unix type socket",
"input": 1,
"expected_sock_type": "AF_UNIX",
"expected_cur_off": 2,
},
{
"name": "unknown type socket",
"input": 123,
"expected_sock_type": "123",
"expected_cur_off": 2,
},
]

for test_case in test_cases:
sockaddr_str = em.get_sockaddr_from_buf(ctypes.c_short(test_case["input"]))
self.assertEqual(test_case["expected_sock_type"], sockaddr_str, "returned sock_type should be equal")
self.assertEqual(test_case["expected_cur_off"], em.cur_off, "current offset should be 2")


if __name__ == '__main__':
unittest.main()
4 changes: 4 additions & 0 deletions tracee/container_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,10 @@ def open_flags_to_str(flags):
class EventMonitor:

def __init__(self, args):
self.start_off = 0
self.cur_off = 0
self.max_off = 0
self.end_off = 0
self.events = list()
self.do_trace = True
self.bpf = None
Expand Down

0 comments on commit a069238

Please sign in to comment.