bt2: add interrupter support
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 20 Jul 2019 22:47:17 +0000 (18:47 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 24 Jul 2019 14:17:16 +0000 (10:17 -0400)
This patch wraps the library's interrupter API within the `bt2` Python
package.

Tests are added to verify the new API.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4d81759d1eaeac0b8036b8cbe9a4fd46ec57cbf1
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1734

src/bindings/python/bt2/Makefile.am
src/bindings/python/bt2/bt2/__init__.py.in
src/bindings/python/bt2/bt2/interrupter.py [new file with mode: 0644]
src/bindings/python/bt2/bt2/native_bt.i
src/bindings/python/bt2/bt2/native_bt_interrupter.i [new file with mode: 0644]
tests/Makefile.am
tests/bindings/python/bt2/test_interrupter.py [new file with mode: 0644]

index c8719d66b5e753cc6315bc18a040af9c361147a8..2816279a00cea9665f7724e65848649457fc910f 100644 (file)
@@ -9,18 +9,18 @@ SWIG_INTERFACE_FILES =                                        \
        bt2/native_bt.i                                 \
        bt2/native_bt_clock_class.i                     \
        bt2/native_bt_clock_snapshot.i                  \
-       bt2/native_bt_component_class.i                 \
        bt2/native_bt_component.i                       \
+       bt2/native_bt_component_class.i                 \
        bt2/native_bt_connection.i                      \
        bt2/native_bt_error.i                           \
-       bt2/native_bt_event_class.i                     \
        bt2/native_bt_event.i                           \
+       bt2/native_bt_event_class.i                     \
+       bt2/native_bt_field.i                           \
        bt2/native_bt_field_class.i                     \
        bt2/native_bt_field_path.i                      \
-       bt2/native_bt_field.i                           \
        bt2/native_bt_graph.i                           \
        bt2/native_bt_integer_range_set.i               \
-       bt2/native_bt.i                                 \
+       bt2/native_bt_interrupter.i                     \
        bt2/native_bt_logging.i                         \
        bt2/native_bt_message.i                         \
        bt2/native_bt_message_iterator.i                \
@@ -28,10 +28,10 @@ SWIG_INTERFACE_FILES =                                      \
        bt2/native_bt_plugin.i                          \
        bt2/native_bt_port.i                            \
        bt2/native_bt_query_exec.i                      \
-       bt2/native_bt_stream_class.i                    \
        bt2/native_bt_stream.i                          \
-       bt2/native_bt_trace_class.i                     \
+       bt2/native_bt_stream_class.i                    \
        bt2/native_bt_trace.i                           \
+       bt2/native_bt_trace_class.i                     \
        bt2/native_bt_value.i                           \
        bt2/native_bt_version.i
 
@@ -46,24 +46,25 @@ STATIC_BINDINGS_DEPS =                                      \
        bt2/component.py                                \
        bt2/connection.py                               \
        bt2/error.py                                    \
-       bt2/event_class.py                              \
        bt2/event.py                                    \
+       bt2/event_class.py                              \
        bt2/field.py                                    \
        bt2/field_class.py                              \
        bt2/field_path.py                               \
        bt2/graph.py                                    \
        bt2/integer_range_set.py                        \
+       bt2/interrupter.py                              \
        bt2/logging.py                                  \
-       bt2/message_iterator.py                         \
        bt2/message.py                                  \
+       bt2/message_iterator.py                         \
        bt2/object.py                                   \
        bt2/packet.py                                   \
        bt2/plugin.py                                   \
        bt2/port.py                                     \
        bt2/py_plugin.py                                \
        bt2/query_executor.py                           \
-       bt2/stream_class.py                             \
        bt2/stream.py                                   \
+       bt2/stream_class.py                             \
        bt2/trace.py                                    \
        bt2/trace_class.py                              \
        bt2/trace_collection_message_iterator.py        \
index 7d63b697d88bdda6378b669e582485f92391b8ca..a801446ce44b1acde318fcd556e38c238f66dcd6 100644 (file)
@@ -23,6 +23,7 @@
 __version__ = '@PACKAGE_VERSION@'
 
 
+from bt2.interrupter import *
 from bt2.clock_class import *
 from bt2.clock_snapshot import *
 from bt2.component import *
diff --git a/src/bindings/python/bt2/bt2/interrupter.py b/src/bindings/python/bt2/bt2/interrupter.py
new file mode 100644 (file)
index 0000000..9c9868d
--- /dev/null
@@ -0,0 +1,49 @@
+# The MIT License (MIT)
+#
+# Copyright (c) 2019 Philippe Proulx <pproulx@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+from bt2 import native_bt, object
+
+
+class Interrupter(object._SharedObject):
+    _get_ref = staticmethod(native_bt.interrupter_get_ref)
+    _put_ref = staticmethod(native_bt.interrupter_put_ref)
+
+    def __init__(self):
+        ptr = native_bt.interrupter_create()
+
+        if ptr is None:
+            raise bt2.CreationError('cannot create interrupter object')
+
+        super().__init__(ptr)
+
+    @property
+    def is_set(self):
+        return bool(native_bt.interrupter_is_set(self._ptr))
+
+    def __bool__(self):
+        return self.is_set
+
+    def set(self):
+        native_bt.interrupter_set(self._ptr)
+
+    def reset(self):
+        native_bt.interrupter_reset(self._ptr)
index d27e4279ade8103799e043c0d29af120c4070242..7b032b17bfbac3b3e994414b7ddf67b945007e59 100644 (file)
@@ -209,6 +209,8 @@ typedef int bt_bool;
 %include "native_bt_field_class.i"
 %include "native_bt_field_path.i"
 %include "native_bt_graph.i"
+%include "native_bt_integer_range_set.i"
+%include "native_bt_interrupter.i"
 %include "native_bt_logging.i"
 %include "native_bt_message.i"
 %include "native_bt_message_iterator.i"
@@ -216,7 +218,6 @@ typedef int bt_bool;
 %include "native_bt_plugin.i"
 %include "native_bt_port.i"
 %include "native_bt_query_exec.i"
-%include "native_bt_integer_range_set.i"
 %include "native_bt_stream.i"
 %include "native_bt_stream_class.i"
 %include "native_bt_trace.i"
diff --git a/src/bindings/python/bt2/bt2/native_bt_interrupter.i b/src/bindings/python/bt2/bt2/native_bt_interrupter.i
new file mode 100644 (file)
index 0000000..4399144
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+%include <babeltrace2/graph/interrupter.h>
+%include <babeltrace2/graph/interrupter-const.h>
index 7ed754157910d84454677b04032e76241bfe196f..00c003b49cf5ed1a47b72ed3f2df95710c73d723 100644 (file)
@@ -16,6 +16,7 @@ dist_check_SCRIPTS = \
        bindings/python/bt2/test_field.py \
        bindings/python/bt2/test_graph.py \
        bindings/python/bt2/test_integer_range_set.py \
+       bindings/python/bt2/test_interrupter.py \
        bindings/python/bt2/test_message_iterator.py \
        bindings/python/bt2/test_message.py \
        bindings/python/bt2/test_packet.py \
diff --git a/tests/bindings/python/bt2/test_interrupter.py b/tests/bindings/python/bt2/test_interrupter.py
new file mode 100644 (file)
index 0000000..5c11f03
--- /dev/null
@@ -0,0 +1,47 @@
+#
+# Copyright (C) 2019 EfficiOS Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; only version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+import bt2
+import unittest
+
+
+class InterrupterTestCase(unittest.TestCase):
+    def setUp(self):
+        self._interrupter = bt2.Interrupter()
+
+    def test_create(self):
+        self.assertFalse(self._interrupter.is_set)
+
+    def test_is_set(self):
+        self.assertFalse(self._interrupter.is_set)
+
+    def test_bool(self):
+        self.assertFalse(self._interrupter)
+        self._interrupter.set()
+        self.assertTrue(self._interrupter)
+
+    def test_set(self):
+        self.assertFalse(self._interrupter)
+        self._interrupter.set()
+        self.assertTrue(self._interrupter)
+
+    def test_reset(self):
+        self._interrupter.set()
+        self.assertTrue(self._interrupter)
+        self._interrupter.reset()
+        self.assertFalse(self._interrupter)
This page took 0.028091 seconds and 4 git commands to generate.