# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-# Test log level options are applied to sources auto-discovered by the convert
-# command.
+# Test how log level options are applied to sources auto-discovered by the
+# convert command.
if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
dir_ab="${data_dir}/dir-ab"
expected_file=$(mktemp -t expected.XXXXXX)
-stderr_expected=/dev/null
-print_log_level="--params print=\"log-level\""
+print_log_level="--params what=\"log-level\""
+details_sink=("-c" "sink.text.details" "--params=with-metadata=false")
debug=2
trace=1
# Apply log level to two components from one non-option argument.
cat > "$expected_file" <<END
-TestSourceA: ${debug}
-TestSourceB: ${debug}
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ${debug}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ${debug}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_ab}" --log-level DEBUG ${print_log_level}
+ "${dir_ab}" --log-level DEBUG ${print_log_level} \
+ ${details_sink[@]}
ok "$?" "apply log level to two components from one non-option argument"
# Apply log level to two components from two distinct non-option arguments.
cat > "$expected_file" <<END
-TestSourceA: ${debug}
-TestSourceB: ${trace}
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ${debug}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ${trace}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_a}" --log-level DEBUG ${print_log_level} "${dir_b}" --log-level TRACE ${print_log_level}
+ "${dir_a}" --log-level DEBUG ${print_log_level} "${dir_b}" --log-level TRACE ${print_log_level} \
+ ${details_sink[@]}
ok "$?" "apply log level to two non-option arguments"
# Apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (1).
cat > "$expected_file" <<END
-TestSourceA: ${trace}
-TestSourceB: ${trace}
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ${trace}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ${trace}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_a}" --log-level DEBUG ${print_log_level} "${dir_ab}" --log-level TRACE ${print_log_level}
+ "${dir_a}" --log-level DEBUG ${print_log_level} "${dir_ab}" --log-level TRACE ${print_log_level} \
+ ${details_sink[@]}
ok "$?" "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (1)"
# Apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (2).
cat > "$expected_file" <<END
-TestSourceA: ${trace}
-TestSourceB: ${debug}
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ${trace}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ${debug}
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_ab}" --log-level DEBUG ${print_log_level} "${dir_a}" --log-level TRACE ${print_log_level}
+ "${dir_ab}" --log-level DEBUG ${print_log_level} "${dir_a}" --log-level TRACE ${print_log_level} \
+ ${details_sink[@]}
ok "$?" "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (2)"
rm -f "$expected_file"
dir_ab="${data_dir}/dir-ab"
expected_file=$(mktemp -t expected.XXXXXX)
-stderr_expected=/dev/null
-print_test_params="--params print=\"test-params\""
+print_test_params="--params what=\"test-params\""
+details_sink=("-c" "sink.text.details" "--params=with-metadata=false")
# Apply params to two components from one non-option argument.
cat > "$expected_file" <<END
-TestSourceA: ('test-allo', 'madame')
-TestSourceB: ('test-allo', 'madame')
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ('test-allo', 'madame')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ('test-allo', 'madame')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_ab}" --params 'test-allo="madame"' ${print_test_params}
+ "${dir_ab}" --params 'test-allo="madame"' ${print_test_params} \
+ ${details_sink[@]}
ok "$?" "apply params to two components from one non-option argument"
# Apply params to two components from two distinct non-option arguments.
cat > "$expected_file" <<END
-TestSourceA: ('test-allo', 'madame')
-TestSourceB: ('test-bonjour', 'monsieur')
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ('test-allo', 'madame')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ('test-bonjour', 'monsieur')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_a}" --params 'test-allo="madame"' ${print_test_params} "${dir_b}" --params 'test-bonjour="monsieur"' ${print_test_params}
+ "${dir_a}" --params 'test-allo="madame"' ${print_test_params} "${dir_b}" --params 'test-bonjour="monsieur"' ${print_test_params} \
+ ${details_sink[@]}
ok "$?" "apply params to two non-option arguments"
# Apply params to one component coming from one non-option argument and one component coming from two non-option arguments (1).
cat > "$expected_file" <<END
-TestSourceA: ('test-allo', 'madame'), ('test-bonjour', 'monsieur')
-TestSourceB: ('test-bonjour', 'monsieur')
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ('test-allo', 'madame'), ('test-bonjour', 'monsieur')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ('test-bonjour', 'monsieur')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_a}" --params 'test-allo="madame"' ${print_test_params} "${dir_ab}" --params 'test-bonjour="monsieur"' ${print_test_params}
+ "${dir_a}" --params 'test-allo="madame"' ${print_test_params} "${dir_ab}" --params 'test-bonjour="monsieur"' ${print_test_params} \
+ ${details_sink[@]}
ok "$?" "apply params to one component coming from one non-option argument and one component coming from two non-option arguments (1)"
# Apply params to one component coming from one non-option argument and one component coming from two non-option arguments (2).
cat > "$expected_file" <<END
-TestSourceA: ('test-bonjour', 'monsieur'), ('test-salut', 'les amis')
-TestSourceB: ('test-bonjour', 'madame'), ('test-salut', 'les amis')
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceA: ('test-bonjour', 'monsieur'), ('test-salut', 'les amis')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceB: ('test-bonjour', 'madame'), ('test-salut', 'les amis')
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
END
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" \
+bt_diff_cli "$expected_file" "/dev/null" \
convert --plugin-path "${plugin_dir}" \
- "${dir_ab}" --params 'test-bonjour="madame",test-salut="les amis"' ${print_test_params} "${dir_a}" --params 'test-bonjour="monsieur"' ${print_test_params}
+ "${dir_ab}" --params 'test-bonjour="madame",test-salut="les amis"' ${print_test_params} "${dir_a}" --params 'test-bonjour="monsieur"' ${print_test_params} \
+ ${details_sink[@]}
ok "$?" "apply params to one component coming from one non-option argument and one component coming from two non-option arguments (2)"
rm -f "$expected_file"
import bt2
import os
-# This file defines source component classes that can print (depending the on
-# the `print` param):
+# This file defines source component classes to help verify the parameters an
+# log levels passed to components. Each component creates one stream, with a
+# name derived from either:
#
-# - Parameter names and values, for parameter whose name starts with `test-`.
-# - Component log levels as integers
+# - the received params that start with `test-`
+# - the received log level
+#
+# The `what` parameter determines what is used.
class TestIter(bt2._UserMessageIterator):
- pass
+ def __init__(self, output_port):
+ params = output_port.user_data['params']
+ comp_cls_name = self._component.__class__.__name__
-class Base:
- @classmethod
- def _print_test_params(cls, params):
- items = sorted([str(x) for x in params.items() if x[0].startswith('test-')])
- print('{}: {}'.format(cls.__name__, ', '.join(items)))
-
- def _print_log_level(self):
- cls_name = self.__class__.__name__
- log_level = self.logging_level
- print('{}: {}'.format(cls_name, log_level))
-
- def _print_info(self, params):
- what = params['print']
- if what == 'test-params':
- self._print_test_params(params)
- elif what == 'log-level':
- self._print_log_level()
+ if params['what'] == 'test-params':
+ items = sorted([str(x) for x in params.items() if x[0].startswith('test-')])
+ stream_name = '{}: {}'.format(comp_cls_name, ', '.join(items))
+ elif params['what'] == 'log-level':
+ log_level = self._component.logging_level
+ stream_name = '{}: {}'.format(comp_cls_name, log_level)
else:
assert False
+ sc = output_port.user_data['sc']
+ tc = sc.trace_class
+ t = tc()
+ s = t.create_stream(sc, name=stream_name)
+
+ self._msgs = [
+ self._create_stream_beginning_message(s),
+ self._create_stream_end_message(s),
+ ]
+
+ def __next__(self):
+ if len(self._msgs) == 0:
+ raise StopIteration
+
+ return self._msgs.pop(0)
+
+
+class Base:
+ def __init__(self, params):
+ tc = self._create_trace_class()
+ sc = tc.create_stream_class()
+
+ self._add_output_port('out', {'params': params, 'sc': sc})
+
@bt2.plugin_component_class
class TestSourceA(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
- def __init__(self, params):
- self._print_info(params)
+ def __init__(self, params, obj):
+ super().__init__(params)
@staticmethod
def _user_query(priv_query_exec, obj, params, method_obj):
@bt2.plugin_component_class
class TestSourceB(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
- def __init__(self, params):
- self._print_info(params)
+ def __init__(self, params, obj):
+ super().__init__(params)
@staticmethod
def _user_query(priv_query_exec, obj, params, method_obj):