Reduce the number of Makefiles in 'doc/'
[babeltrace.git] / tests / data / cli / exit_status / bt_plugin_test_cli_exit_status.py
CommitLineData
0235b0db
MJ
1# SPDX-License-Identifier: GPL-2.0-only
2#
3# Copyright (C) 2019 EfficiOS Inc.
4#
5
b5cd7d65
FD
6import os
7import time
5995b304
SM
8import signal
9
10import bt2
b5cd7d65
FD
11
12bt2.register_plugin(__name__, "test_exit_status")
13
14
15class StatusIter(bt2._UserMessageIterator):
16 def __init__(self, config, output_port):
f5567ea8 17 self.case = output_port.user_data["case"]
b5cd7d65
FD
18
19 def __next__(self):
20 if self.case == "STOP":
21 raise bt2.Stop()
22 if self.case == "INTERRUPTED":
23 os.kill(os.getpid(), signal.SIGINT)
24
25 # Wait until the graph is in the interrupted state.
26 timeout_s = 10
27 for _ in range(timeout_s * 10):
28 if self._is_interrupted:
29 raise bt2.TryAgain()
30
31 time.sleep(0.1)
32
33 raise Exception(
f5567ea8 34 "{} was not interrupted after {} seconds".format(
b5cd7d65
FD
35 self.__class__.__name__, timeout_s
36 )
37 )
38
39 elif self.case == "ERROR":
40 raise TypeError("Raising type error")
41 else:
42 raise ValueError("Invalid parameter")
43
44
45@bt2.plugin_component_class
46class StatusSrc(bt2._UserSourceComponent, message_iterator_class=StatusIter):
47 def __init__(self, config, params, obj):
f5567ea8 48 self._add_output_port("out", {"case": params["case"]})
This page took 0.041181 seconds and 4 git commands to generate.