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 43 44 45 46 47 48
|
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2019 EfficiOS Inc.
#
import os
import time
import signal
import bt2
bt2.register_plugin(__name__, "test-exit-status")
class StatusIter(bt2._UserMessageIterator):
def __init__(self, config, output_port):
self.case = output_port.user_data["case"]
def __next__(self):
if self.case == "STOP":
raise bt2.Stop()
if self.case == "INTERRUPTED":
os.kill(os.getpid(), signal.SIGINT)
# Wait until the graph is in the interrupted state.
timeout_s = 10
for _ in range(timeout_s * 10):
if self._is_interrupted:
raise bt2.TryAgain()
time.sleep(0.1)
raise Exception(
"{} was not interrupted after {} seconds".format(
self.__class__.__name__, timeout_s
)
)
elif self.case == "ERROR":
raise TypeError("Raising type error")
else:
raise ValueError("Invalid parameter")
@bt2.plugin_component_class
class StatusSrc(bt2._UserSourceComponent, message_iterator_class=StatusIter):
def __init__(self, config, params, obj):
self._add_output_port("out", {"case": params["case"]})
|