cpp-common/bt2c: add `format_as()` functions for `Uuid` and `UuidView` Change-Id: I6530144e78d6aa10dedb320b90a4c208aa572e9d Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/12138 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org>
tests/plugins/flt.utils.muxer: add test for clock (in)compatibility cases Add a test for the various clock class incompatibility cases checked by the `MsgIter::_makeSureClkClsIsExpected` method in the `flt.utils.muxer` component class. The scenarios are equivalent to the triggers in `tests/lib/conds/conds-trigger.cpp`, used to test the preconditions in the library. Since the scenarios are equivalent, it would probably be possible to share some code with that file, but I haven't tried it. In essence, for each scenario, the test creates a graph where a muxer component receives two messages with incompatible clock configurations. The test expects that an exception is thrown, and checks whether the root cause contains an expected string. Change-Id: I8bd98fa52719ab2cedb7cbb09310a560b437eb28 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/12005 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org>
tests: add `src.ctf.fs` single field testing framework This patch adds a framework to test the decoding of single CTF 1.8 fields by a `src.ctf.fs` component. Single CTF 1.8 field tests reside as moultipart documents (see `tests/utils/python/moultipart.py`) in `tests/data/plugins/src.ctf.fs/field/ctf-1`. The new `test-field.sh` script does the following, for each `pass-*.mp` file found in `tests/data/plugins/src.ctf.fs/field/ctf-1`: 1. Creates a temporary directory TD to hold a CTF 1.8 trace (`TD/trace`) and an expectation file (`TD/expect`). 2. Runs `data_from_mp.py` on the moultipart document, also passing TD. This script splits the moultipart document to produce `TD/trace` and `TD/expect`. The expected parts are, in this order: a) A TSDL field class (metadata), without any field name, for example: integer { size = 32; byte_order = be; } If you need to test the decoding of an array field, you may use `@` in this part to indicate to `data_from_mp.py` where the field name goes, for example: string @[23] b) A Normand [1] text representing the exact data of an instance of a). c) What you expect the `sink.test-text.single` component to print when it receives an event message containing what a `src.ctf.fs` component decoded from `TD/trace`. `sink.test-text.single` prints exactly the value of b) with a YAML-like format. 3. Runs something like this, keeping the standard output text: $ babeltrace2 -c sink.test-text.single "TD/trace" 4. Compares the result of step 3 with `TD/expect` using bt_diff(). Now it becomes easy to test regular and corner cases of our CTF 1.8 decoding by adding new files to `tests/data/plugins/src.ctf.fs/field/ctf-1`. As initial examples, `tests/data/plugins/src.ctf.fs/field/ctf-1` contains a few single field tests already. Philippe changes: • Made some style adjustments to the original patch. • Using `mktemp -d` instead of `mktemp --directory` because macOS doesn't seem to know the latter. • In `utils.sh`, changed bt_diff() to use the new bt_remove_cr_inline() to remove CR characters from both files because this is the first time the test generates both files. Leaving bt_remove_cr() as is because another test uses it directly. • In the _print_field() function of `bt_plugin_test_text.py`: ‣ Changed parts of the strategy to fix some rendering bugs. ‣ Using int() for an integer field to avoid printing enum. labels. ‣ Added the empty structure field special case. ‣ Added comments with output examples. • In `data_from_mp.py`: ‣ Added lots of useful TSDL type aliases available to any CTF 1 single field test. ‣ Made the default Normand byte order little-endian since it's also the default TSDL byte order in _make_ctf_1_metadata(). • In `test-field.sh`, using a hard-coded test count. See the Gerrit discussion [2] for the rationale. • Added more initial tests in `tests/data/plugins/src.ctf.fs/field/ctf-1`. [1]: https://github.com/efficios/normand [2]: https://review.lttng.org/c/babeltrace/+/11149 Change-Id: I7539b46d49200b5e75fe3525401b47b8ff418f6c Signed-off-by: Olivier Dion <odion@efficios.com> Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/11149 Tested-by: jenkins <jenkins@lttng.org>
cpp-common/bt2c: add CStringView equality and non-equality operators Add `operator==` and `operator!=` functions to check equality or non-equality between `CStringView` and another `CStringView`, `const char *` and `std::string`. Add a test to exercise those. Change-Id: I2463966aae50792bb3e21ae65f9f124b08114499 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/11681 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests: rename lib plugins test files Standardize the names for this test a bit. Change-Id: I2d70332ed6f25505aac36be7da7a1bdb63da72b6 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/11678 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org>
tests: normalize names of files and more The current naming situation is somewhat of a mess in the `tests` directory, making it difficult to deduce (or write) a convention. Use hyphens to separate words as much as possible, following what we usually like for source file names (see `tree src`). Pretty much the only things remaining with underscores are Python file names because of the `import` constraints and because it's Python's own convention. Also make all shell scripts have the `.sh` extension. This makes any worthy editor highlight the shell syntax correctly and tells you immediately it's not a compiled ("binary") executable. I'd prefer `.bash` for Bash code, but I don't think we need to go as far. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I43cd279d78c240a7e3686ad8afd6759bad9f575f Reviewed-on: https://review.lttng.org/c/babeltrace/+/11170 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Simon Marchi <simon.marchi@efficios.com> CI-Build: Simon Marchi <simon.marchi@efficios.com>
Fix: src.ctf.fs: omitting to add ctf signature When depacketizing a metadata stream we may need to add the CTF 1.8 signature at the beginning of the file if it's absent. This fixes a regression introduces by commit: commit 06be99464988953e390114337ccdd20622fb50d1 Author: Philippe Proulx <eeppeliteloop@gmail.com> Date: Tue Jul 9 19:40:45 2019 -0400 ctf: refactor metadata decoder to always have an instance This regression was not caught earlier because the test case for that feature was disabled. This commit reintroduces that behaviour and enables the test case. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Change-Id: I3621a7f8a21ffe51f29dfa344f30039fdf5d16c4 Reviewed-on: https://review.lttng.org/c/babeltrace/+/8204 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> CI-Build: Simon Marchi <simon.marchi@efficios.com>
tests: add bt_field_string_clear test Add a test for bt_field_string_clear, exercising the fix done in commit 0022a87819b0 ("Fix: clear_string_field(): set first character to 0"). The test sets the field to a non-empty value, clears it with bt_field_string_clear, and verifies that the value returned by bt_field_string_get_value is an empty string, and that the length returned by bt_field_string_get_length is 0. When reverting 0022a87819b0, the test gives: 1..2 not ok 1 - string field is empty # Failed test (/home/smarchi/src/babeltrace/tests/lib/test_fields.cpp:operator()() at line 36) ok 2 - string field length is 0 # Looks like you failed 1 test of 2. Change-Id: I46800a93a7290fe72618081efdc5cdcd944c8567 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/10068 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org>
Add a single generated env file to the test suite Regroup all the configure detected values relevant to the test suite in a single generated file. This file will be automatically sourced by the test suite in most scenarios but can also be sourced in the shell of a user. * All user overridable variables start with 'BT_TESTS_'. * The priority for variables is : Environment -> env.sh -> utils.sh (defaults). * A user can source 'env.sh', override some of the values and manually run test scripts. * The test suite can run without an 'env.sh' file present. Scenarios: * Manually running tests in an in-tree build: The test suite sources 'env.sh' relative to itself, no environment variables required. * Manually running tests in an out-of-tree build: The user sets BT_TESTS_BUILDDIR in its environment or sources 'env.sh'. * Running the test suite with 'make check' in either builds: The Makefile sets BT_TESTS_BUILDDIR in the environment which allows the test suite to source env.sh in either in-tree or out-of-tree builds. Change-Id: I1ba3775ea3d724345cab769af9b2efc22ee53585 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/6314 Reviewed-by: Simon Marchi <simon.marchi@efficios.com> CI-Build: Simon Marchi <simon.marchi@efficios.com> Tested-by: jenkins <jenkins@lttng.org>
Fix: sink.ctf.fs: fix logic of make_unique_stream_file_name The logic in make_unique_stream_file_name is wrong. It tries names as long as the candidate exists _and_ is named "metadata". The intent here is that we keep trying names as long as the candidate name names an already existing file _or_ is named "metadata". So the && should be a ||. The impact of this bug is that if two streams have the same name, they'll write to the same file, with troubling consequences (see bug 1279 [1]). Add a test where `sink.ctf.fs` writes a trace with two streams with the same name, and one stream named "metadata". [1] https://bugs.lttng.org/issues/1279 Change-Id: Ifaa30459574229aa5e607095f65033d2caae188f Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/4483 Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Fix: sink.ctf.fs: remove spurious directory level when using assume-single-trace The behavior of `sink.ctf.fs` with the `assume-single-trace=true` parameter does not match the documentation nor the comments in the code. The man page says: If the assume-single-trace parameter is true, then the output trace path to use for the single input trace is the directory specified by the path parameter. What I understand from this is that if you pass `path=/tmp/yo`, that should produce the `/tmp/yo/metadata` file and the data files alongside it. The documentation on the `fs_sink_comp::assume_single_trace` says: /* * True if the component assumes that it will only write a * single CTF trace (which can contain one or more data * streams). This makes the component write the stream files * directly in the output directory (`output_dir_path` above). */ bool assume_single_trace; The `output_dir_path` would contain `/tmp/yo`, in the previous example, so that confirms the previous assumption. The actual behavior is that the sink puts the trace in an extra `trace` directory, in `/tmp/yo/trace`. We end up with the `trace` relative trace path (relative to the base output directory) because `make_trace_path_rel` returns an empty string when `assume_single_trace` is true and `sanitize_trace_path` replaces it with `trace`. When using `assume-single-trace=true`, we should not deal with a relative trace path, as the trace is output directly in the base output directory. We also don't want to run the path in `make_unique_trace_path`, as the trace should be output in the base directory specified by the user, not another directory. Anyway, if the user specifies an existing directory, `sink.ctf.fs` will initially error out with: Single trace mode, but output path exists: output-path="/tmp/yo" Although that's a TOCTOU bug, two babeltrace instances could both check at the same time that the same output directory does not exist, and both write in the same directory. That would not be good. Change-Id: Ib2415420eabbc096a920d113863993161105e90a Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/4480 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org>
Tests: sink.text.pretty: Add unit tests for enum fields printing Adds a Python component class who creates an event class with an enum field that contains the enumeration described by the test caller. The script iterator has a single event with a value also sent in parameter. The tests themselves are run from a bash script, for signed/unsigned values. This commit also renames the existing `test_pretty` test file to `test_pretty_python` to control all future Python tests for the `sink.text.pretty` component class. Change-Id: I3f631224dd3bdf21dbb2ef2d233c9f2dc8da43fa Signed-off-by: Geneviève Bastien <gbastien@versatic.net> Reviewed-on: https://review.lttng.org/c/babeltrace/+/3149 CI-Build: Francis Deslauriers <francis.deslauriers@efficios.com> Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests: add libbabeltrace2 pre/postcondition testing infrastructure This patch adds a basic libbabeltrace2 pre/postcondition testing infrastructure to the project. When a libbabeltrace2 public function precondition or postcondition is not satisfied, the function logs a FATAL-level message which indicates what's wrong and then aborts. Slow path functions check such conditions unconditionally, while fast path functions check them only in developer mode. Testing that a libbabeltrace2 function catches an unsatisfied pre/postcondition and reports it is not straightforward: the library aborts the program, so we can't use the usual approach because the test program itself would abort. The solution brought by this patch is the following process in `tests/lib/conds`: 1. The `conds-triggers.c` program contains all the pre/postcondition failure triggering instructions to test, one condition per function. Each triggering function triggers a single pre/postcondition check. It is expected that the function actually aborts. main() calls ppc_main(), an internal utility, with its command-line arguments and an array of condition trigger descriptors. Each condition trigger descriptor has: * A condition type: precondition or postcondition. * The ID of the condition to trigger. * A name suffix. * A condition triggering function. Each condition trigger descriptor has a unique name: its condition ID and an optional name suffix. As of this patch, the PPC_TRIGGER_*_RUN_IN_COMP_CLS_INIT() macros create condition trigger descriptors of which the function runs within a component class initialization function (accepts a `bt_self_component *` parameter). This is often needed as many libbabeltrace2 functions are only accessible through a self component (all the trace IR API, for example). ppc_main() handles two command-line subcommands: `list`: Prints a JSON array of objects which represent the triggering descriptors, for example (output for this patch): [ { "cond-id": "pre:field-class-integer-set-field-value-range:valid-n", "name": "pre:field-class-integer-set-field-value-range:valid-n-0" }, { "cond-id": "pre:field-class-integer-set-field-value-range:valid-n", "name": "pre:field-class-integer-set-field-value-range:valid-n-gt-64" }, { "cond-id": "pre:field-class-integer-set-field-value-range:not-null:field-class", "name": "pre:field-class-integer-set-field-value-range:not-null:field-class" } ] `run INDEX`: Runs the condition triggering function for the descriptor at index `INDEX` in the `list` array. It is expected that this command aborts. 2. `test_conds` is a Bash script which only does this: reldir=lib/conds export BT_TESTS_LIB_CONDS_TRIGGER_BIN="$BT_TESTS_BUILDDIR/$reldir/conds-triggers" if [ "$BT_OS_TYPE" = "mingw" ]; then BT_TESTS_LIB_CONDS_TRIGGER_BIN="$BT_TESTS_LIB_CONDS_TRIGGER_BIN.exe" fi run_python_bt2_test "$BT_TESTS_SRCDIR/$reldir" test.py In other words, it runs the Python TAP test runner to discover and run tests in `test.py`. This script is part of the `make check` test set. 3. In `test.py`, a function: a) Runs `conds-triggers list` and decodes the output to get the list of available condition trigger descriptors. This step also validates the regular expressions and checks that there are no duplicate descriptor names. b) For each condition trigger descriptor, creates and adds a test to its single test case class which: I. Executes `conds-triggers run INDEX` as a subprocess, where `INDEX` is the descriptor's index. II. Reads the complete process's standard error. III. Asserts that the process aborts (`SIGABRT` signal). This seems to be only possible on a POSIX system with the `subprocess.Popen` API. IV. Asserts that the standard error (II) contains the descriptor's condition ID. All this is only enabled if, at configuration time: * Python 3 is available. * The Babeltrace 2 developer mode is enabled (`BABELTRACE_DEV_MODE=1`). This patch's `conds-triggers.c` includes two precondition triggering functions to confirm that everything works as expected: trigger_fc_int_set_field_value_range_n_0(): When calling bt_field_class_integer_set_field_value_range(), the parameter `N` cannot be greater than 64. trigger_fc_int_set_field_value_range_n_gt_64(): When calling bt_field_class_integer_set_field_value_range(), the parameter `N` cannot be 0. trigger_fc_int_set_field_value_range_null(): When calling bt_field_class_integer_set_field_value_range(), the field class cannot be `NULL`. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Change-Id: I70713d690f7dbfeac5804e6cfcec989242823611 Reviewed-on: https://review.lttng.org/c/babeltrace/+/3401
Fix: sink.text.pretty: check that port is connected before creating message iterator sink.text.pretty does not check if its input port is connected before trying to create a message iterator on it. This can lead to a precondition assertion failure. It can be reproduced with this Python snippet. import bt2 g = bt2.Graph() g.add_component(bt2.find_plugin('text').sink_component_classes['pretty'], 'snk') g.run() The assertion failure we get is: 04-14 11:35:27.339 1231815 1231815 F LIB/MSG-ITER create_self_component_input_port_message_iterator@iterator.c:295 Babeltrace 2 library precondition not satisfied; error is: 04-14 11:35:27.339 1231815 1231815 F LIB/MSG-ITER create_self_component_input_port_message_iterator@iterator.c:295 Input port is not connected: port-addr=0x607000001d70, port-type=INPUT, port-name="in" 04-14 11:35:27.339 1231815 1231815 F LIB/MSG-ITER create_self_component_input_port_message_iterator@iterator.c:295 Aborting... ./tests/utils/../utils/utils.sh: line 283: 1231815 Aborted (core dumped) env "${env_args[@]}" "$@" Add a check and return an error if that happens instead. A corresponding test is also added. Change-Id: Ibeed94cd6ece543817fe8a765a69cb52bbaaba76 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/3403 Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org>
Move to kernel style SPDX license identifiers The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. See https://spdx.org/ids-how for details. Change-Id: I7c25a3bc48ee328500a604cb276877d4cadfa997 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/3227 CI-Build: Philippe Proulx <eeppeliteloop@gmail.com> Tested-by: jenkins <jenkins@lttng.org> Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Use argpar from upstream Now that argpar is maintained in a separate repository, sync the code with it and remove tests from this code base. The code was sync'ed with the argpar repository at commit: f46b510674785c70781a3de06c02888faded5db9 (HEAD -> master, Strip trailing spaces Change-Id: Ie805db224f2d3890decbed26a1c80c105d083293 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/2616
tests: add test for list-plugins CLI command The test provides a custom Python plugin, then checks for a corresponding entry in the "list-plugins" output. Change-Id: I65fff2d4d22f21a89fa1ad7e747c5e15677212b9 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/2421 Tested-by: jenkins <jenkins@lttng.org>
tests: test removing a destruction listener from a destruction listener This patch adds a test to verify that removing a trace or trace class destruction listener from an object from within a destruction listener of that same object works correctly. It tests 3 scenarions: - A destruction listener removing itself. - A destruction listener removing a destruction listener that was already called. - A destruction listener removing a destruction listener that is not yet called. This assumes that destruction listeners are called in the order in which there were added. In the third scenario (removing a destruction listener that is not yet called), the result is that the removed listener won't get called. Change-Id: I49de9b662b3c1f77ca1c9f84c2c3575a8616cc10 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/2429 Tested-by: jenkins <jenkins@lttng.org>
src.ctf.fs: sort inputs paths Sort input paths to make the behavior of the component more deterministic. For example, when there are duplicated packets in the trace and we pick one copy, this will ensure that we always process the data stream files in the same order, and that we always pick the same copy of the packet. In practice, this will reduce the chances of observing different behaviors on different platforms where glib reports the files of a trace in different orders. A test is added to verify that the choice of which copy of a packet to choose, in case a packet is present in multiple copies, is independent from the order of the inputs paths passed to the component. Change-Id: I034ba8c909e76a1e89589e1f0e0f37512c9d88bf Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Reviewed-on: https://review.lttng.org/c/babeltrace/+/2396