-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdtrace_ctypes_test.py
More file actions
42 lines (30 loc) · 864 Bytes
/
Copy pathdtrace_ctypes_test.py
File metadata and controls
42 lines (30 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Unittest for ctypes based consumer.
"""
__author__ = 'tmetsch'
import unittest
from ctypes import c_char_p
from dtrace_ctypes import consumer
SCRIPT = 'dtrace:::BEGIN {trace("Hello World");}'
class TestDTraceConsumer(unittest.TestCase):
"""
Tests ctypes based DTrace consumer.
"""
def setUp(self):
self.out = b''
self.consumer = consumer.DTraceConsumer(out_func=self._get_output)
def test_run_for_success(self):
"""
Test for success.
"""
self.consumer.run(SCRIPT)
def test_run_for_sanity(self):
"""
Test for sanity.
"""
self.consumer.run(SCRIPT)
self.assertEqual(self.out, b'Hello World')
def _get_output(self, data, _arg):
tmp = c_char_p(data.contents.dtbda_buffered).value.strip()
self.out += tmp
return 0