tests: make auto-source-discovery-{log_level,params} tests use sink.text.details
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 9 Aug 2019 21:17:35 +0000 (17:17 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 12 Aug 2019 02:19:51 +0000 (22:19 -0400)
For the same rationale as the previous patch, change how the test
component classes for test_auto_source_discovery_params and
test_auto_source_discovery_log_level report what they receive from a
print to stdout to stream name.

Change-Id: I62405ccd1fbdbe708fbec5dacc52894d4060dfb0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1864
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
tests/cli/convert/test_auto_source_discovery_log_level
tests/cli/convert/test_auto_source_discovery_params
tests/data/cli/convert/auto-source-discovery-params-log-level/bt_plugin_test.py

index 6d2430e4d790d729e91ec92c6c7a3ec1e4df8ae3..5e79b01345fcaf5177165d6d5e497102275f2da8 100755 (executable)
@@ -15,8 +15,8 @@
 # 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"
@@ -38,55 +38,119 @@ dir_b="${data_dir}/dir-b"
 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"
index 26ed6492be1820b7dd016f3f850213b22bb9555a..53a9ecbdada59c2ede7377c6e40ddbd704ad1293 100755 (executable)
@@ -38,52 +38,116 @@ dir_b="${data_dir}/dir-b"
 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"
index dc7f4e69940a953a117bb5d1d37d2cc35030aea6..a1ac699454bef32ec8937e49a789e1a381e0c942 100644 (file)
@@ -1,42 +1,60 @@
 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):
@@ -58,8 +76,8 @@ class TestSourceA(Base, bt2._UserSourceComponent, message_iterator_class=TestIte
 
 @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):
This page took 0.029732 seconds and 4 git commands to generate.