tests: make auto-source-discovery-grouping test use sink.text.details
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 9 Aug 2019 20:08:37 +0000 (16:08 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 12 Aug 2019 02:19:51 +0000 (22:19 -0400)
This patch changes the way that test component classes for the auto
source discovery grouping CLI test reports the inputs passed to each
instantiated component.

Currently, they print to stdout the input names
in the components' __init__.  That is then check by the test script
(test_auto_source_discovery_grouping).  The
TraceCollectionMessageIterator class in the Python bindings will soon
have the capability to automatically discover source components.
However, it's not practical to use the same test method in Python.

To facilitate this, make the test component classes report the inputs
they receive by sending a stream beginning message, where the stream
name contains the input names.  The eventual Python test will be able to
inspect the stream name to validate that the right inputs were passed to
each component.

Since the information is now passed in messages, the
test_auto_source_discovery_grouping test now uses the details sink.

Change-Id: Ie5c12e390f5b68fb50a6d18c53463860fb7a1c99
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1863
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
tests/cli/convert/test_auto_source_discovery_grouping
tests/data/cli/convert/auto-source-discovery-grouping/bt_plugin_test.py
tests/data/cli/convert/auto-source-discovery-grouping/stdout.expect [new file with mode: 0644]

index d98f689f8268da32ba869bb772ec4e265e91b7bd..d4e9e4c47d645eab97d1adb5cbed1548b113b8a1 100755 (executable)
@@ -44,21 +44,9 @@ else
        dir_sep='/'
 fi
 
-expected_file=$(mktemp -t expected.XXXXXX)
-stderr_expected=/dev/null
+stdout_expected_file="${data_dir}/stdout.expect"
 
-cat > "$expected_file" <<END
-TestSourceABCDE: ABCDE
-TestSourceExt: ${trace_dir}${dir_sep}aaa1, ${trace_dir}${dir_sep}aaa2, ${trace_dir}${dir_sep}aaa3
-TestSourceExt: ${trace_dir}${dir_sep}bbb1, ${trace_dir}${dir_sep}bbb2
-TestSourceExt: ${trace_dir}${dir_sep}ccc1
-TestSourceExt: ${trace_dir}${dir_sep}ccc2
-TestSourceExt: ${trace_dir}${dir_sep}ccc3
-TestSourceExt: ${trace_dir}${dir_sep}ccc4
-TestSourceSomeDir: ${trace_dir}${dir_sep}some-dir
-END
-
-bt_diff_cli_sorted "$expected_file" "$stderr_expected" convert --plugin-path "${plugin_dir}" "ABCDE" "${trace_dir}" some_other_non_opt
+bt_diff_cli "$stdout_expected_file" "/dev/null" \
+       convert --plugin-path "${plugin_dir}" "ABCDE" "${trace_dir}" some_other_non_opt \
+       -c sink.text.details --params='with-metadata=false'
 ok "$?" "sources are auto-discovered"
-
-rm -f "$expected_file"
index e40215d0b162d239034431cb2b0c64016174486e..2495b502099714a72eae152f367713d85cbb2b0a 100644 (file)
@@ -1,16 +1,46 @@
 import bt2
 import os
 
+# Source component classes in this file recognize and group inputs in
+# various ways.  One stream is created by each component, with a name
+# derived from the component class and the inputs.  This is then checked
+# using the `sink.text.details` sink.
+
 
 class TestIter(bt2._UserMessageIterator):
-    pass
+    def __init__(self, output_port):
+        inputs = output_port.user_data['inputs']
+        sc = output_port.user_data['sc']
+        tc = sc.trace_class
+        t = tc()
+        s = t.create_stream(sc, name=self._make_stream_name(inputs))
+
+        self._msgs = [
+            self._create_stream_beginning_message(s),
+            self._create_stream_end_message(s),
+        ]
+
+    def _make_stream_name(self, inputs):
+        comp_cls_name = self._component.__class__.__name__
+        return (
+            comp_cls_name
+            + ': '
+            + ', '.join(sorted([os.path.basename(str(x)) for x in inputs]))
+        )
+
+    def __next__(self):
+        if len(self._msgs) == 0:
+            raise StopIteration
+
+        return self._msgs.pop(0)
 
 
 class Base:
-    @classmethod
-    def _print_params(cls, params):
-        inputs = sorted([str(x) for x in params['inputs']])
-        print('{}: {}'.format(cls.__name__, ', '.join(inputs)))
+    def __init__(self, params):
+        tc = self._create_trace_class()
+        sc = tc.create_stream_class()
+
+        self._add_output_port('out', {'inputs': params['inputs'], 'sc': sc})
 
 
 @bt2.plugin_component_class
@@ -23,7 +53,7 @@ class TestSourceExt(Base, bt2._UserSourceComponent, message_iterator_class=TestI
     """
 
     def __init__(self, params, obj):
-        self._print_params(params)
+        super().__init__(params)
 
     @staticmethod
     def _user_query(priv_query_exec, obj, params, method_obj):
@@ -61,7 +91,7 @@ class TestSourceSomeDir(
     recurse in "some-dir"."""
 
     def __init__(self, params, obj):
-        self._print_params(params)
+        super().__init__(params)
 
     @staticmethod
     def _user_query(priv_query_exec, obj, params, method_obj):
@@ -80,7 +110,7 @@ class TestSourceABCDE(Base, bt2._UserSourceComponent, message_iterator_class=Tes
     """A source that recognizes the arbitrary string input "ABCDE"."""
 
     def __init__(self, params, obj):
-        self._print_params(params)
+        super().__init__(params)
 
     @staticmethod
     def _user_query(priv_query_exec, obj, params, method_obj):
diff --git a/tests/data/cli/convert/auto-source-discovery-grouping/stdout.expect b/tests/data/cli/convert/auto-source-discovery-grouping/stdout.expect
new file mode 100644 (file)
index 0000000..3cfa198
--- /dev/null
@@ -0,0 +1,71 @@
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceABCDE: ABCDE
+  Trace:
+    Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceExt: aaa1, aaa2, aaa3
+  Trace:
+    Stream (ID 0, Class ID 0)
+
+{Trace 2, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceExt: bbb1, bbb2
+  Trace:
+    Stream (ID 0, Class ID 0)
+
+{Trace 3, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceExt: ccc1
+  Trace:
+    Stream (ID 0, Class ID 0)
+
+{Trace 4, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceExt: ccc2
+  Trace:
+    Stream (ID 0, Class ID 0)
+
+{Trace 5, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceExt: ccc3
+  Trace:
+    Stream (ID 0, Class ID 0)
+
+{Trace 6, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceExt: ccc4
+  Trace:
+    Stream (ID 0, Class ID 0)
+
+{Trace 7, Stream class ID 0, Stream ID 0}
+Stream beginning:
+  Name: TestSourceSomeDir: some-dir
+  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
+
+{Trace 2, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 3, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 4, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 5, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 6, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 7, Stream class ID 0, Stream ID 0}
+Stream end
This page took 0.026813 seconds and 4 git commands to generate.