babeltrace.git
6 months agotests: normalize names of files and more
Philippe Proulx [Sun, 29 Oct 2023 16:32:11 +0000 (12:32 -0400)] 
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>

6 months agoReduce the number of Makefiles in 'doc/'
Michael Jeanson [Wed, 25 Oct 2023 20:58:53 +0000 (16:58 -0400)] 
Reduce the number of Makefiles in 'doc/'

Continue the effort started by Simon to reduce the overall number of
Makefiles to allow for faster parallel builds.

Change-Id: I7a4a8543a2f1e2781f09fbe0bdea2cc0395d239d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11156
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoReduce the number of Makefiles in 'src/'
Michael Jeanson [Tue, 24 Oct 2023 19:18:00 +0000 (15:18 -0400)] 
Reduce the number of Makefiles in 'src/'

Continue the effort started by Simon to reduce the overall number of
Makefiles to allow for faster parallel builds.

Change-Id: I3d87dea9979c09d1a6416c7b9950264a8c4d81dc
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11155
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoReduce the number of Makefiles in 'src/plugins/text'
Michael Jeanson [Tue, 24 Oct 2023 18:56:44 +0000 (14:56 -0400)] 
Reduce the number of Makefiles in 'src/plugins/text'

Continue the effort started by Simon to reduce the overall number of
Makefiles to allow for faster parallel builds. Also reduce the number of
convenience libraries for faster linking.

Change-Id: I1e706eb0bb5d52d0172ab6d0773f861865562158
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11154
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoReduce the number of Makefiles in 'src/plugins/lttng-utils'
Michael Jeanson [Tue, 24 Oct 2023 18:41:24 +0000 (14:41 -0400)] 
Reduce the number of Makefiles in 'src/plugins/lttng-utils'

Continue the effort started by Simon to reduce the overall number of
Makefiles to allow for faster parallel builds.

Change-Id: I339d190fea78fcefd6b3927cccb89db1b4fec6f4
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11153
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoReduce the number of Makefiles in 'src/plugins/common'
Michael Jeanson [Tue, 24 Oct 2023 18:26:20 +0000 (14:26 -0400)] 
Reduce the number of Makefiles in 'src/plugins/common'

Continue the effort started by Simon to reduce the overall number of
Makefiles to allow for faster parallel builds.

Change-Id: Ic90c2c4e60f0af76bb0fde784d3cb64030aa7f44
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11152
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoReduce the number of Makefiles in 'src/plugins/utils'
Michael Jeanson [Tue, 24 Oct 2023 18:14:41 +0000 (14:14 -0400)] 
Reduce the number of Makefiles in 'src/plugins/utils'

Continue the effort started by Simon to reduce the overall number of
Makefiles to allow for faster parallel builds. Also reduce the number of
convenience libraries for faster linking.

Change-Id: I772572c3dc1d2481ec94526a4301d4bb79f9d855
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11151
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoRemove `src/cpp-tester`
Philippe Proulx [Thu, 26 Oct 2023 18:59:15 +0000 (14:59 -0400)] 
Remove `src/cpp-tester`

This was never meant to be added.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I4ba129b99145cceef6f785d07f7c84341754e827
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11157

6 months agoUpdate autoconf archive macros
Michael Jeanson [Mon, 17 Apr 2023 19:18:08 +0000 (15:18 -0400)] 
Update autoconf archive macros

Change-Id: I899d955dd1ff53a7bde9729a13396da7514f35cc
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10342
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agoAdd test to parse lf/crlf metadata
Michael Jeanson [Thu, 19 Oct 2023 17:27:30 +0000 (13:27 -0400)] 
Add test to parse lf/crlf metadata

Unix-like platforms represent line endings in text file with a '\n' or
LF while Windows uses '\r\n' or CRLF. The CTF standard doesn't specify a
canonical representation for metadata files and only requires whitespace.

Test both styles of line endings on all platforms to ensure
interoperability of the produced metadata files.

Change-Id: Ib4080b1d95be2fb0d5844e7772bd6c2832de378a
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11078
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agofix: tests: use a portable invocation of 'sed -i'
Michael Jeanson [Mon, 23 Oct 2023 20:16:34 +0000 (16:16 -0400)] 
fix: tests: use a portable invocation of 'sed -i'

The GNU and BSD sed implementations slightly differ in the handling of
an argument to the '-i' switch to use as a suffix to a backup file. BSD
sed requires an argument while it's optional for GNU sed, if present it
must be placed directly after the switch with no space.

To make both implementations work properly and not create a backup file,
a zero length argument must be placed directly after the switch with no
space.

Change-Id: Ifd2cd5b27df05e3301e527ef1d8e718b434d2236
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11132
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoctf: reduce the number of `Makefile.am`s
Simon Marchi [Tue, 24 Oct 2023 14:39:26 +0000 (10:39 -0400)] 
ctf: reduce the number of `Makefile.am`s

This should help speeding parallel builds a bit, by reducing the time
spent in directories with few source files.  The time necessary to build
the intermediary .la libraries is also non-negligible (at least on
Windows), so having less of those should help.

I kept `common/metadata/Makefile.am`, because it has a lot of complexity
specific to the use of bison, I think it's good to keep it in its own
file.

Change-Id: I6b7a5ca370d6b4481bda3649ab51009e70a0e393
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11137
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoctf: grow stored_values array when necessary
Simon Marchi [Tue, 17 Oct 2023 19:33:37 +0000 (15:33 -0400)] 
ctf: grow stored_values array when necessary

The CTF message iterator accesses the `stored_values` array out of
bounds in the following situation:

 - In the context of a src.ctf.lttng-live source, a ctf_trace_class gets
   created from some metadata.
 - At this point, ctf_trace_class->stored_value_count indicates that a
   certain number of stored values are necessary given the metadata
   parsed up to now.
 - The message iterators are created with `stored_values` arrays of that
   size.
 - The source receives more metadata, which requires more stored
   values.
 - The message iterator reads some event described by the new metadata,
   that requires the use of a stored value.
 - Since the stored value arrays have not been resized to reflect the
   necessary number of stored value considering the new metadata, the
   message iterator tries to store a value past the end of the array.

Fix this by ensuring the `stored_values` array is large enough before
storing a value in it.

Add a test with a hand-crafted trace that replicates the scenario
described in the simplest manner possible:

 - send a bit of metadata
 - send a bit of data that uses that metadata
 - send a bit more metadata (that requires a new stored value)
 - send a bit of data that uses that new metadata

Without the fix, we get (when babeltrace is built in debug mode):

    (╯°□°)╯︵ ┻━┻  /home/smarchi/src/babeltrace/src/plugins/ctf/common/msg-iter/msg-iter.cpp:1865: bfcr_unsigned_int_cb(): Assertion `(uint64_t) int_fc->storing_index < msg_it->stored_values->len` failed.

... showing the out of bounds array access.

Change-Id: I78e3ca57ac6cae1959425df3c8ffdbfeb534f348
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10866
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: add `tests/utils/python/mctf.py`, a text to CTF trace generator
Simon Marchi [Mon, 16 Oct 2023 18:07:03 +0000 (14:07 -0400)] 
tests: add `tests/utils/python/mctf.py`, a text to CTF trace generator

Add `mctf.py`, a utility to generate a test trace from a moultipart file
(see `moultipart.py`).

Any part having the header info `metadata` is written as-is in a file
named `metadata`.  Other parts are considered Normand inputs, and the
output is written to a file of which the name is the exact header info
of the part.  For example:

    --- metadata
    /* CTF 1.8 */
    [...]

    --- stream0
    "Normand input here"

    --- .index/stream0
    "Normand input here too"

Variables and labels are carried from one normand.parse()
call to the other, allowing parts to refer to variables/labels from
previous parts.

All files are written relative to the value of the `--base-dir` option,
or relative to the current working directory if omitted.  Any
nonexistent parent directory is created if needed (like `make -p`).

Add a function in `utils.sh  that runs `mctf.py`.

Change-Id: I345b77ac382f268e8becd553e2e301982d80ced3
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11056
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: add moultipart.py
Simon Marchi [Fri, 22 Sep 2023 20:43:00 +0000 (16:43 -0400)] 
tests: add moultipart.py

Add moultipart.py, a Python module to help read text files meant to be
split in different parts.  A moultipart-compliant file is a succession
of parts, where each part is made of a header line followed with zero or
more lines of content.

A header line consists of `---` optionally followed by a space and some
custom information.

The moultipart module exposes the `parse` function, which takes a TextIO
object and returns a list of Part objects.

For instance, the following input:

    --- Victoria
    Parenteau
    ---
    Taillon
    --- This part is empty
    --- Josianne
    Gervais

results in the following parts:

    [Part('Victoria', 'Parenteau\n', 2),
     Part('', 'Taillon\n', 4),
     Part('This part is empty', '', 6),
     Part('Josianne', 'Gervais\n', 7)]

Change-Id: I50fb88ed6e064c09deaf1d56187415bc26002a14
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10912
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: use /dev/null instead of empty files in src.ctf.lttng-live test
Simon Marchi [Fri, 22 Sep 2023 18:59:33 +0000 (14:59 -0400)] 
tests: use /dev/null instead of empty files in src.ctf.lttng-live test

Instead of creating empty files, use /dev/null.

Change-Id: I4193da1fb60e9bd25df61afde09a7684b6cdf8f7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10906
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: pass trace path prefix down in test_live
Simon Marchi [Thu, 5 Oct 2023 02:28:53 +0000 (22:28 -0400)] 
tests: pass trace path prefix down in test_live

A future test case will need to use a different trace path prefix than
the existing tests.  Add a parameter for that and pass the value down.

Change-Id: I2b95ce098461f32503cafabfc640d99fe120e582
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10919
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: pass live server args down using arrays
Simon Marchi [Wed, 18 Oct 2023 03:23:52 +0000 (23:23 -0400)] 
tests: pass live server args down using arrays

Pass arguments to lttng_live_server.py all the way down using arrays.

Change-Id: I9efd02539fd7c790bb941069bceadb7b7f5315a2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10918
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: move --port-file and --trace-path-prefix arguments up one level
Simon Marchi [Thu, 5 Oct 2023 19:10:34 +0000 (15:10 -0400)] 
tests: move --port-file and --trace-path-prefix arguments up one level

Specify the --port-file and --trace-path-prefix arguments in function
get_cli_output_with_lttng_live_server rather than function
lttng_live_server.

Change-Id: Iddb781b8a085b85468f4148708409c774c79893f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10917
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agocommon: introduce bt_g_array_index
Simon Marchi [Tue, 17 Oct 2023 18:52:38 +0000 (14:52 -0400)] 
common: introduce bt_g_array_index

Introduce bt_g_array_index, a wrapper to g_array_index, that adds a
check that the specified index does not go past the end of the array.

Use BT_ASSERT_DBG, so that it's enabled only in builds with debug mode
enabled.

The difficulty is that g_array_index is expected to yield an lvalue,
since some call sites take the address of what it yields, or assign to
it.  The way I found to make it work is to add a statement expression
that has no effect, and put the BT_ASSERT_DBG in it.

Change-Id: I280c0657ec6f1cadd01328eec79da5cefada5c31
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10905
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agoFix: set proper size when creating new strings
Simon Marchi [Tue, 19 Sep 2023 19:41:11 +0000 (15:41 -0400)] 
Fix: set proper size when creating new strings

After adding a wrapper to g_array_index that validates that accessed
indices don't go past the end of the arrays, I got this:

    (╯°□°)╯︵ ┻━┻  /home/smarchi/src/babeltrace/src/lib/trace-ir/field.c:392: create_string_field(): Assertion `0 < string_field->buf->len` failed.

The problem is that arrays backing string fields are created with:

    string->buf = g_array_sized_new(FALSE, FALSE, sizeof(char), 1);

This g_array_sized_new call reserves space for one element, but doesn't
actually make the length of the array one.  Add a call to
g_array_set_size to fix that.  Fix another occurence of the same bug in
ctf-writer.

Change-Id: I2b90b26c37d70d64bcd825b5b07b204bcbb5baf5
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10904
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: make lttng_live_server.py write temp port filename in same directory
Simon Marchi [Mon, 18 Sep 2023 18:47:44 +0000 (14:47 -0400)] 
tests: make lttng_live_server.py write temp port filename in same directory

When running lttng_live_server.py with `--port-filename yoyoyo`, I get:

    Traceback (most recent call last):
      File "lttng_live_server.py", line 1982, in <module>
        LttngLiveServer(port, port_filename, sessions, max_query_data_response_size)
      File "lttng_live_server.py", line 1716, in __init__
        self._write_port_to_file(port_filename)
      File "lttng_live_server.py", line 1839, in _write_port_to_file
        os.replace(tmp_port_file.name, port_filename)
    OSError: [Errno 18] Invalid cross-device link: '/tmp/tmpe70085jz' -> 'yoyoyo'

Fix this by placing the temporary file in the same directory as its
final location.

Change-Id: Ibe6fee5dc99860ab3cd4464a2f490e05c65df1eb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10901
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: make lttng_live_server.py print session URLs
Simon Marchi [Mon, 18 Sep 2023 18:18:54 +0000 (14:18 -0400)] 
tests: make lttng_live_server.py print session URLs

To help with interactive use, make lttng_live_server.py print session
URLs that you can pass directly to babeltrace.

For instance:

    $ PYTHONPATH=/home/smarchi/src/babeltrace/tests/utils/python /opt/python/3.4.10/bin/python3 lttng_live_server.py --trace-path-prefix /home/smarchi/src/babeltrace/tests/data/ctf-traces  split_metadata.json --port 1245
    Listening on port 1245
    net://localhost:1245/host/hostname/split_metadata

Change-Id: Ib4d806804bfdc00132ec7987c62016ad976b50d2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10900
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: remove isdir/isfile asserts from lttng_live_server.py
Simon Marchi [Tue, 17 Oct 2023 18:51:39 +0000 (14:51 -0400)] 
tests: remove isdir/isfile asserts from lttng_live_server.py

When lttng_live_server.py receives a trace path that doesn't exist
(perhaps because the user forgot to pass a --trace-path-prefix), it
gives:

    Traceback (most recent call last):
      File "lttng_live_server.py", line 1969, in <module>
        trace_path_prefix,
      File "lttng_live_server.py", line 1892, in _session_descriptors_from_path
        traces.append(LttngTrace(path, metadata_sections, beacons))
      File "lttng_live_server.py", line 1044, in __init__
        assert os.path.isdir(trace_dir)
    AssertionError

This is not very helpful, it hides details about the nature of the
problem.  Remove the assert, and let the subsequent open fail, saying
why it failed.  After the patch, it becomes:

    Traceback (most recent call last):
      File "lttng_live_server.py", line 1968, in <module>
trace_path_prefix,
      File "lttng_live_server.py", line 1891, in _session_descriptors_from_path
traces.append(LttngTrace(path, metadata_sections, beacons))
      File "lttng_live_server.py", line 1045, in __init__
self._create_metadata_stream(trace_dir, metadata_sections)
      File "lttng_live_server.py", line 1099, in _create_metadata_stream
metadata_path, config_metadata_sections
      File "lttng_live_server.py", line 974, in _split_metadata_sections
with open(metadata_file_path, "r") as metadata_file:
    FileNotFoundError: [Errno 2] No such file or directory: 'live/split_metadata/metadata'

Remove an isfile assert for the same reason.

Change-Id: If4289515b2c27748dd90209049c623e02c940a03
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10899
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: change lttng_live_server.py's --sessions-filename to be a positional argument
Simon Marchi [Mon, 18 Sep 2023 17:15:58 +0000 (13:15 -0400)] 
tests: change lttng_live_server.py's --sessions-filename to be a positional argument

When running lttng_live_server.py with no arguments, we get:

    Traceback (most recent call last):
      File "lttng_live_server.py", line 1968, in <module>
        trace_path_prefix,
      File "lttng_live_server.py", line 1871, in _session_descriptors_from_path
        with open(sessions_filename, "r") as sessions_file:
    TypeError: invalid file: None

The --sessions-filename argument is effectively mandatory.  Change it to
be a positional argument.

Change-Id: I48e67cbf1da8adfaa87d5024d91a922f9b67a7fd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10898
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: make --port-filename optional in lttng_live_server.py
Simon Marchi [Sat, 23 Sep 2023 02:26:14 +0000 (22:26 -0400)] 
tests: make --port-filename optional in lttng_live_server.py

While port_filename is useful for automation, it isn't essential when
using lttng_live_server.py manually.  Make that argument non-required.

Also, print a message indicating the port used to listen, which is handy
for interactive use.

Change how lttng_live_server.py is invoked to redirect stdout to stderr,
hopefully avoiding messing up the tap output format.

Change-Id: Ie185ced440c51fb1bb8355553f7b4a7725a13542
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10896
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: remove UnexpectedInput from lttng_live_server.py
Simon Marchi [Thu, 21 Sep 2023 16:28:50 +0000 (12:28 -0400)] 
tests: remove UnexpectedInput from lttng_live_server.py

I don't think this exception is useful, versus just raising a
RuntimeError.

The current code catches exceptions at the top-level, logs it (using
logging.error) and prints it to stderr.  I don't think it's useful to
log using logging.error, since it also goes to stderr.  And I don't
think it's useful to manually print the exception.  Instead, let them
escape and let Python print them using its regular uncaught exception
mechanism, which ends up printing them on stderr too.

Change-Id: Ice797d4b672dc5eba7312c4cabb2740806c37a2a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10894
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agotests: add typing annotations to lttng_live_server.py
Simon Marchi [Mon, 18 Sep 2023 19:07:30 +0000 (15:07 -0400)] 
tests: add typing annotations to lttng_live_server.py

Add typing annotations throughout lttng_live_server.py, such that
pyright passes cleanly in strict mode.

Specify in a comment in lttng_live_server.py to run in strict mode, but
disable these two warnings:

 - reportTypeCommentUsage: we need to use the comment form to support
   Python 3.4
 - reportMissingTypeStubs: it would complain about not having a stub
   file for the utils module (although it can inspect utils.py just
   fine)

Note that the sessions_filename variable near the bottom is marked as a
string, even though it's currently an optional argument (so it should be
`str | None`).  But the rest of the code treats it as non-optional.
This is corrected in a subsequent patch that makes the sessions filename
mandatory.

Change the way lttng_live_server.py is launched to use run_python, to
have access to Python modules in tests/utils/python, to have access to
jsonw.py and possible the typing module shim for Python 3.4.

Change-Id: I842f4c696eea7c99932876af26c195bf99d5cfff
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10869
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: add strongly-typed JSON wrappers
Simon Marchi [Thu, 21 Sep 2023 16:29:47 +0000 (12:29 -0400)] 
tests: add strongly-typed JSON wrappers

When using the result of `json.load` as-is, the returned values are not
strongly-typed, so it is up to the code to check that values are of the
expected type.  To facilitate this introduce small wrappers around that,
for objects and arrays, to add automatic type-checking when accessing
children.

    # Obtain the child of an object with type check
    obj: tjson.ObjVal = ...
    child = obj.at("child-key", tjson.BoolVal)

    # Iterate on children of an array with type check
    arr: tjson.ArrayVal = ...
    for integers in arr.iter(tjson.IntVal):
      ...

These expressions throw TypeError if the children are not of the
expected type. `tjson.ArrayVal` and `tjson.ObjVal` are resp. sequence
and mapping types so that you may still use the typical operators to
disable type checking:

    obj: tjson.ObjVal = ...
    child = obj["child-key"]

    arr: tjson.ArrayVal = ...
    for integers in arr:
      ...

The wrappers also help generate relatively precise error messages, by
recording the path to each object, and outputting it in jq filter
format.  For instance:

    TypeError: `.[1].traces[0].path`: expecting a string value

    KeyError: `.[1].traces[0]`: no value has the key `path`

Change-Id: Ic6fbb2de5731851af3b90a476af009315f829665
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10909
Tested-by: jenkins <jenkins@lttng.org>
6 months agosrc.ctf.fs: improve `metadata-info` query error message with non-existent metadata...
Simon Marchi [Thu, 19 Oct 2023 17:25:40 +0000 (13:25 -0400)] 
src.ctf.fs: improve `metadata-info` query error message with non-existent metadata file

A colleague pointed out that the message babeltrace2 outputs when
pointing the `metadata-info` query to a directory without a metadata
file (or a non-existent directory) is not clear as it could be.

    ERROR:    [Babeltrace CLI] (/home/smarchi/src/babeltrace/src/cli/babeltrace2.c:651)
      Failed to query component class: unknown error: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=SOURCE object="metadata-info"
    CAUSED BY [libbabeltrace2] (/home/smarchi/src/babeltrace/src/lib/graph/query-executor.c:234)
      Component class's "query" method failed: query-exec-addr=0x60b000000880, cc-addr=0x60f000000130, cc-type=SOURCE, cc-name="fs", cc-partial-descr="Read CTF traces from the file sy",
      cc-is-frozen=0, cc-so-handle-addr=0x607000000020, cc-so-handle-path="/home/smarchi/build/babeltrace/src/plugins/ctf/babeltrace-plugin-ctf.la", object="metadata-info",
      params-addr=0x606000000500, params-type=MAP, params-element-count=1, log-level=WARNING
    CAUSED BY ['source.ctf.fs'] (/home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/query.cpp:92)
      Cannot open trace metadata: path="yoyoyo".

In the ctf_fs_metadata_open_file function, we could have access to the
errno that explains the failure, but currently don't use it.  Also, it
would be good to tell which file we tried to open exactly.  Make
ctf_fs_metadata_open_file log an error and append an error cause.

The new error stack is the same as the above, with this new cause at the
end:

    CAUSED BY ['source.ctf.fs'] (/home/smarchi/src/babeltrace/src/plugins/ctf/fs-src/metadata.cpp:41)
      Failed to open metadata file: No such file or directory: path="yoyoyo/metadata"

Add a test that validates that this error cause is present in the error
message.

Change-Id: I111848cc72e6f3b2cdfb251914eb337ea02a19f4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11079
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>

6 months agoFix: make gen-version-i.sh work with shallow clones
Simon Marchi [Wed, 18 Oct 2023 21:28:14 +0000 (17:28 -0400)] 
Fix: make gen-version-i.sh work with shallow clones

With a shallow git clone (a clone done with `--depth=1`),
gen-version-i.sh fails with:

    $ TOP_SRCDIR=$PWD ./src/common/gen-version-i.sh
    fatal: No names found, cannot describe anything.

The underlying git command that fails is:

    $ git describe --tags --dirty --abbrev=12
    fatal: No names found, cannot describe anything.

git-describe fails because no tags are available in the shallow clone.
Work around that by using `--always`, which makes git-describe
generate string with only the commit hash as a fallback.   In my
non-shallow clone:

    $ git describe --tags --dirty --abbrev=12 --always
    v1.2.0-3854-g0b538efadd88

And in my shallow clone:

    $ git describe --tags --dirty --abbrev=12 --always
    0b538efadd88

Change-Id: Ie1c15239497bda248c9742e74a12a14af6e32928
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Thomas Applencourt <tapplencourt@anl.gov>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11073
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agofix: test_message_iterator.py hangs on Python 3.12
Simon Marchi [Wed, 18 Oct 2023 19:32:00 +0000 (15:32 -0400)] 
fix: test_message_iterator.py hangs on Python 3.12

Starting with Python 3.12, `None` is immortal: its refcount operations
are NO-OP and sys.getrefcount() will return a static value of UINT_MAX
on 64-bit and UINT_MAX >> 2 on 32-bit.

This basically transform `test_try_again_many_times` in an almost
infinite loop and hangs the testsuite.

Detect this by checking if the refcount on `None` is incremented after
assigning to a variable and skip the test if it's not the case.

See PEP-0683[1] for the gory details.

[1] https://peps.python.org/pep-0683/

Change-Id: Id07658245d524288ce7606cb0a011ad97068dad1
Signed-off-by: Michael Jeanson <mjeanson@debian.org>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10379
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoFix: src.ctf.fs: omitting to add ctf signature
Francis Deslauriers [Thu, 2 Jun 2022 19:46:18 +0000 (15:46 -0400)] 
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>

6 months agotests: fix file comment of plugins/src.ctf.lttng-live/test_live
Simon Marchi [Sun, 31 May 2020 02:24:37 +0000 (22:24 -0400)] 
tests: fix file comment of plugins/src.ctf.lttng-live/test_live

That comment appears to be a copy-paste leftover from a `src.ctf.fs`
test.  Adjust it to make it relevant to that file.

Change-Id: I943cef771d01589ec432a75128860c7c55aed314
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3599
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agofix: python bindings: use stdlib distutils when setuptools is installed
Michael Jeanson [Thu, 15 Jun 2023 17:29:54 +0000 (13:29 -0400)] 
fix: python bindings: use stdlib distutils when setuptools is installed

When the setuptools package is installed, it monkey patches the standard
library distutils even if the user code doesn't import setuptools.

This results in a failure to install the Python agent in a directory
which isn't in the current PYTHONPATH. To allow this, setuptools requires
the '--single-version-externally-managed' options which is not
implemented in distutils.

To resolve this, force the use of distutils for Python < 3.12 even when
setuptools is installed with the 'SETUPTOOLS_USE_DISTUTILS' environment
variable and use the previously mentionned setuptools option with Python
>= 3.12 which doesn't include distutils anymore.

Change-Id: I9e8412021c6ec79b0a9ea38759c475113e4ea018
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10371
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agofix: python bindings: install on Debian python >= 3.10
Michael Jeanson [Tue, 13 Jun 2023 22:22:37 +0000 (18:22 -0400)] 
fix: python bindings: install on Debian python >= 3.10

Starting with Debian's Python 3.10, the default install scheme is
'posix_local' which is a Debian specific scheme based on 'posix_prefix'
but with an added 'local' prefix. This is the default so users doing
system wide manual installations of python modules end up in
'/usr/local'. This interferes with our autotools based install which
already defaults to '/usr/local' and expects a provided prefix to be
used verbatim.

Monkeypatch sysconfig to override this scheme and use 'posix_prefix'
instead.

Change-Id: I41973f6db4966519aa1c7e74a9d1e9b5d90bf7ea
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10343
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agoctf: remove some unused `ctx` parameters in visitor-generate-ir.cpp
Simon Marchi [Mon, 26 Jun 2023 19:29:36 +0000 (15:29 -0400)] 
ctf: remove some unused `ctx` parameters in visitor-generate-ir.cpp

My editor pointed these out.

Change-Id: Ia0c3b244c0037a9a2111f53cfd7fbf2ede7bb2c7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10453
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
6 months agotests: remove unused MyFilter in UserMessageIteratorTestCase.test_try_again_many_times
Simon Marchi [Fri, 16 Jun 2023 20:00:22 +0000 (16:00 -0400)] 
tests: remove unused MyFilter in UserMessageIteratorTestCase.test_try_again_many_times

This MyFilter class (and associated MyFilterIter class) is not used,
remove it.

Change-Id: Ib148361606ac8814145b2924a940e262eb7d4bd7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10380
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
CI-Build: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agoRemove dev-requirements.txt entry for click
Simon Marchi [Tue, 17 Oct 2023 15:30:32 +0000 (11:30 -0400)] 
Remove dev-requirements.txt entry for click

Since we don't use black 22 anymore, this entry for click is not
required anymore.

Change-Id: Icf89fca7c7af6d71bb00c0fc4f6ca1d18e17b653
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11057
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
CI-Build: Michael Jeanson <mjeanson@efficios.com>

6 months agoAdd `tests/utils/python/normand.py` (Normand 0.23)
Philippe Proulx [Thu, 21 Sep 2023 18:16:01 +0000 (14:16 -0400)] 
Add `tests/utils/python/normand.py` (Normand 0.23)

This is an unmodified copy of the `normand.py` module [1], version 0.23.

Normand, an EfficiOS project, is both a template language to generate
binary data and a processor of said language.

`normand.py` is part of the `normand` package, but it's completely
independent, without external dependencies, therefore we can copy it
right here. `normand.py` works with Python 3.4. The module itself offers
a Python 3 API as well as a command-line tool.

We plan to use Normand in Babeltrace 2 to write human-readable and
Git-trackable plain text CTF data streams, and eventually other types of
binary data, for testing purposes.

Although Normand is an EfficiOS project, it's considered an external
project from the point of view of the Babeltrace project. Therefore, we
make Black, isort, and Flake8 ignore it, even though Normand uses the
same settings in its own repository.

[1]: https://github.com/efficios/normand

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I6e8937cf40320c3cf1226c3447f71640ed9f91bf
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10910
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
6 months agotests: use a local `typing` module with Python 3.4 only
Philippe Proulx [Fri, 22 Sep 2023 15:35:22 +0000 (11:35 -0400)] 
tests: use a local `typing` module with Python 3.4 only

This patch changes the strategy to support the `typing` module in tests.

To make it possible to include compatible third-party/portable Python
modules as is, Python needs to find the `typing` module. Python 3.5+
will find it, but Python 3.4 won't.

To fix this:

1. `tests/utils/utils.sh` calls the Python interpreter specified by
   BT_TESTS_PYTHON_BIN to get the Python version.

2. The run_python() function in `tests/utils/utils.sh` adds the
   `tests/utils/python/typing` directory to `PYTHONPATH` if the version
   of Python is 3.4.

3. Move `tests/utils/python/local_typing.py` to
   `tests/utils/python/typing/typing.py`.

4. Remove `tests/utils/python/utils.py` (not needed anymore).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ifc939f617627ff11cd6a7cbf8642c7b33006d303
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10915
Tested-by: jenkins <jenkins@lttng.org>
6 months agoFix: Windows DLL path lookup with Python >= 3.8
Michael Jeanson [Wed, 11 Oct 2023 21:42:30 +0000 (17:42 -0400)] 
Fix: Windows DLL path lookup with Python >= 3.8

Starting with Python 3.8 on Windows [1] the DLLs lookup when loading
native modules was changed to not search PATH like everything else on
this platform. Restore this behavior by doing it manually.

Simon adds: it only started to matter now because MSYS2 dropped a local
patch [2] that retained the old behaviour.

[1]: https://docs.python.org/3/library/os.html#os.add_dll_directory
[2]: https://www.msys2.org/news/#2023-08-06-python-changed-behavior-when-loading-dll-dependencies-of-extension-modules

Change-Id: Id436244a717f440db11c33b6d418f31c7838591d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11043

6 months agotests/utils/utils.sh: add run_python helper function
Philippe Proulx [Fri, 22 Sep 2023 15:33:59 +0000 (11:33 -0400)] 
tests/utils/utils.sh: add run_python helper function

Add a run_python function, which runs the passed command with
`tests/utils/python` in PYTHONPATH.  Re-implement run_python_bt2 on top
of run_python.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I30dcee2e85d581340881bc108e4cc8bbc65ba798
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10914
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
6 months agoconfigure.ac: require Python 3.4+
Philippe Proulx [Fri, 22 Sep 2023 15:46:31 +0000 (11:46 -0400)] 
configure.ac: require Python 3.4+

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iec0fc9ec23016069a30b08bb63c808ed6d3143cb
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10913
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agotests: fix all basic type check issues of lttng_live_server.py
Simon Marchi [Sat, 16 Sep 2023 01:44:44 +0000 (21:44 -0400)] 
tests: fix all basic type check issues of lttng_live_server.py

Do the necessary changes such that this comment passes cleanly:

    $ PYTHONPATH=/home/smarchi/src/babeltrace/tests/utils/python pyright tests/data/plugins/src.ctf.lttng-live/lttng_live_server.py

Pyright pointed out that field _trace_session_state didn't exist, in:

    @property
    def trace_session_state(self):
        return self._trace_session_state

The actual field name is _ts_state.  However, it shows that this
property is never used, so remove it.

Change-Id: I115fe473310ecdb1e2fd2e5d369aae33afe963f1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10893
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agotests/python: add local copy of typing module
Simon Marchi [Fri, 9 Jun 2023 21:01:07 +0000 (17:01 -0400)] 
tests/python: add local copy of typing module

Add a local copy of the typing module [1], in order to be able to use
the typing module features with Python 3.4.

Add notes about the license in the top-level LICENSE file.

Add exclusions to avoid this file being reformatted by black, analyzed
by flake8 and its imports sorted by isort.

Add the tests/utils/python/utils.py with an import
er files will be able to use the
typing module using:

    typing = utils._typing_mod

... and not care where the typing module comes from.

[1] https://raw.githubusercontent.com/python/typing/3.10.0.2/src/typing.py

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I7648e700f7e350acc595004c697a89e1fc97de4a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10892
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agotests: move classes around in lttng_live_server.py
Simon Marchi [Thu, 14 Sep 2023 18:46:56 +0000 (14:46 -0400)] 
tests: move classes around in lttng_live_server.py

In preparation for an upcoming patch, which fixes typing issues in
lttng_live_server.py, move some types around to avoid forward-references
when possible.

Change-Id: If7c14db977fa8b5c5d050badf2d8f1254fb1279a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10870
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agopython: run isort on everything
Simon Marchi [Tue, 19 Sep 2023 18:45:05 +0000 (14:45 -0400)] 
python: run isort on everything

Run isort on the whole repo, to nicely sort Python imports.

Add a mention in CONTRIBUTING.adoc, that all Python imports must be
sorted using the version of isort specified in dev-requirements.txt.

Add `isort ~= 5.12` to dev-requirements.txt.  5.12 is the latest stable
version available on PyPi as of writing.

Tell isort to use its `black` profile, in pyproject.toml, so that
black remains happy.  The details of that profile are here:

  https://pycqa.github.io/isort/docs/configuration/profiles.html

Tell isort to ignore `tests/utils/python/tap`, since it's code copied
from elsewhere.

Use the `length_sort` option, because Philippe prefers it like that.
See:

  https://pycqa.github.io/isort/docs/configuration/custom_sections_and_ordering.html

Change-Id: I8778f908342d0feeb97d4442506113d9252559e7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10871
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agoDocument usage of Black in CONTRIBUTING.adoc
Simon Marchi [Fri, 15 Sep 2023 19:55:20 +0000 (15:55 -0400)] 
Document usage of Black in CONTRIBUTING.adoc

Mention that all Python code must be formatted using Black.

Change-Id: I420c4e5a75b34eae40da83ae09d5fd76d8eddb0f
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10888
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agopython: remove internal `import bt2` imports
Simon Marchi [Mon, 28 Aug 2023 21:01:58 +0000 (17:01 -0400)] 
python: remove internal `import bt2` imports

Standardize the internal imports to import specific modules like this:

    from bt2 import foo as bt2_foo

... instead of importing the complete bt2 package.

Change-Id: I32eb223a8bcfe841020a2aafb976f121dadd8680
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10388
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agopython: move exception types out of __init__.py
Simon Marchi [Mon, 19 Jun 2023 18:47:15 +0000 (14:47 -0400)] 
python: move exception types out of __init__.py

Move exception types defined in __init__.py.

 - Move _MemoryError to error.py
 - Move _IncompleteUserClass to component.py
 - Move the others to utils.py

I initially moved them to a new exceptions.py file, but I think that
it's just fine to move them in the existing files.  But it's a
possibility too, if y'all prefer that.

The goal of this commit is to make it easier to use these types
internally, using the form:

    from bt2 import utils as bt2_utils

    ... use bt2_utils.TryAgain ...

... in order to get rid of the internal `import bt2` imports.

Note that it would be possible to keep the exception types in
__init__.py and do:

    from bt2 import TryAgain

... and then use `TryAgain` in the code, but I think we prefer using a
module qualifier for whatever is imported.

Change-Id: I7d8dbdc28a3a2e3e38093903d622487a45fe7637
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10387
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agopython: standardize intra-bt2 imports
Simon Marchi [Mon, 19 Jun 2023 18:11:04 +0000 (14:11 -0400)] 
python: standardize intra-bt2 imports

A subsequent patch wants to refer to `object` (the Python type), but it
is shadowed by our `from bt2 import object` import.  It seems like a
good time to standardize how we import intra-bt2 modules, to use the
pattern:

    from bt2 import potato as bt2_potato

Note that I didn't add the bt2_ prefix to the native_bt import, since it
would be a bit redundant.

Change-Id: Icdb4339075a1888463c4f84b292deb272ad49943
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10386
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agoBump black to version 23
Simon Marchi [Wed, 15 Mar 2023 19:45:28 +0000 (15:45 -0400)] 
Bump black to version 23

Bump to the latest available black version.

Change-Id: I62360ab9137ab2a5eb7fcc4dbbed913bfacee2e1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/9650
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agoctf: fix formatting in ctf-meta-resolve.cpp
Simon Marchi [Tue, 12 Sep 2023 18:18:56 +0000 (14:18 -0400)] 
ctf: fix formatting in ctf-meta-resolve.cpp

Run tools/format-cpp.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Iea7165c5996b5ce62790ddb9df69e4e8e5014240
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10891
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agocpp-common/bt2/message.hpp: add missing `#include`
Philippe Proulx [Wed, 6 Sep 2023 15:48:38 +0000 (11:48 -0400)] 
cpp-common/bt2/message.hpp: add missing `#include`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I35fe9d7ed01e4272252fb0918371ef5251a90438
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10847
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
7 months agosrc.ctf.fs: add GMappedFileUP
Simon Marchi [Thu, 9 Jun 2022 19:49:39 +0000 (15:49 -0400)] 
src.ctf.fs: add GMappedFileUP

Add GMappedFileUP, a unique_ptr type used to manage the lifetime of a
GMappedFile object.

Change-Id: Ibc47d3c6e052499013cb34782b112ff1e72eab46
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8311
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10846
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add GDirUp
Simon Marchi [Thu, 9 Jun 2022 15:37:51 +0000 (11:37 -0400)] 
cpp-common: add GDirUp

Add GDirUP, a unique_ptr type to manage the lifetime of GDir objects.

Change-Id: I8814db0bec41918203af2f6d43a97a3e8d13c8c1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8294
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10845
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add GStringUP
Simon Marchi [Thu, 9 Jun 2022 15:23:33 +0000 (11:23 -0400)] 
cpp-common: add GStringUP

Add a type to automatically manage the lifetime of GString objects.

Change-Id: I60e08f7d62c290c0194ed0cd62b0d0491b9af2bd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8288
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10844
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add FileUP
Simon Marchi [Sat, 28 May 2022 18:18:17 +0000 (14:18 -0400)] 
cpp-common: add FileUP

Add a unique_ptr type to manage the lifetime of a `FILE *`, with a
custom deleter that calls fclose.

Change-Id: Idded4546d2a709cd0652975ef83c3ad6a0f511bc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8172
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10843
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add GCharUP
Simon Marchi [Sat, 28 May 2022 14:36:08 +0000 (10:36 -0400)] 
cpp-common: add GCharUP

Add GCharUP, a unique_ptr type that wraps a g_char pointer and has a
deleter that calls g_free.  It can be used to provide automatic memory
management of buffers returned by the GLib API.

Change-Id: I9d98be2f972cc008877b55a20eceeb3dce256cdb
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8170
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10842
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add `readFixedLenInt()` function
Francis Deslauriers [Wed, 25 May 2022 15:20:53 +0000 (11:20 -0400)] 
cpp-common: add `readFixedLenInt()` function

This function template reads an integer from a buffer without assuming
its byte order.

For example, this is needed when reading the magic number from a data
buffer of unknown byte order. If needed, the user then has to manually
swap byte order of that integer to get its native byte order

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ia94ee3a3ffc7caaa46a46defead3e23da0a4c2b2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8111
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10841
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add fixed-length integer reading functions
Philippe Proulx [Mon, 25 Apr 2022 15:10:04 +0000 (11:10 -0400)] 
src/cpp-common: add fixed-length integer reading functions

This patch adds `src/cpp-common/read-fixed-len-int.hpp` which offers
function templates to read fixed-length integers from a buffer.

The bt2_common::readFixedLenIntLe() (little endian) and
bt2_common::readFixedLenIntBe() (big endian) function templates accept
one template parameter which is the integral type of the integer to read
(and the return type of the function). For example,
bt2_common::readFixedLenIntLe<std::int32_t>() reads a 32-bit signed
little-endian integer and returns it.

The function templates use bt2_common::littleEndianToNative() and
bt2_common::bigEndianToNative() as needed.

You may combine this with `bt2_common::StdIntT` to have the length in
bits and the signedness as independent template parameters, for
example:

    const auto val = readFixedLenIntBe<StdIntT<16, true>>(myBuf);

which is equivalent to:

    const auto val = readFixedLenIntBe<std::int16_t>(myBuf);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9c684bede60f7b6324a3140c5fd498c21ad513ab
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7939
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10840
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd `src/cpp-common/std-int.hpp`
Philippe Proulx [Thu, 19 May 2022 12:38:05 +0000 (08:38 -0400)] 
Add `src/cpp-common/std-int.hpp`

This new header contains the `StdIntT` trait structure to get the
standard integer type from a length (bits) and a signedness.

For example, `bt2_common::StdIntT<32, true>::Type` is `std::int32_t`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I69fc9ac7e01c2a82e4ad13afa553ef8e8720bd57
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8086
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10839
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add bt2_common::messageTypeStr()
Simon Marchi [Wed, 3 Aug 2022 15:56:15 +0000 (11:56 -0400)] 
cpp-common: add bt2_common::messageTypeStr()

Change-Id: I6967d232922c7b5ad6b35cc100becb9ff8a6b968
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8651
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10838
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: add vectorFastRemove
Simon Marchi [Tue, 28 Jun 2022 18:26:53 +0000 (14:26 -0400)] 
cpp-common: add vectorFastRemove

Add the vectorFastRemove function, in src/cpp-common/vector.hpp, as a
drop-in replacement for g_ptr_array_remove_index_fast, when replacing a
GPtrArray with an std::vector.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: Ibee249fd9a8168d02ad99abf36984bf7edd53b5b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8493
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10837
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agotests: add `--port` option to lttng_live_server.py
Simon Marchi [Thu, 30 Jun 2022 17:15:46 +0000 (13:15 -0400)] 
tests: add `--port` option to lttng_live_server.py

This is useful when testing manually, to force using a specific port.
When not specified, we still use an OS-assigned port, so it doesn't
change the behavior when used by the testsuite.

Change-Id: Ic530bf13ddfa37fa1095c1e52a6c78f284e2c312
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8215
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10836
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: bt2::CommonOptionField::hasField(): use has_value()
Philippe Proulx [Wed, 10 Aug 2022 15:16:05 +0000 (11:16 -0400)] 
Fix: bt2::CommonOptionField::hasField(): use has_value()

Can't convert `nonstd::optional<ConstField>` to `bool` for some reason
in this context.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I539700da37eb0c27944e2f2842b09df8c2b1b023
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10835
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/bt2: field.hpp: Add assignment operator for Enum field
Francis Deslauriers [Wed, 1 Jun 2022 13:27:57 +0000 (09:27 -0400)] 
cpp-common/bt2: field.hpp: Add assignment operator for Enum field

Used to set the value of enumeration fields using integers.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Iaec161ca8e9e0d13770ac4f82a9c5556a1a20001
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8199
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10834
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agocpp-common: Add `bt2::CommonStringField::append()` method
Francis Deslauriers [Tue, 31 May 2022 14:52:15 +0000 (10:52 -0400)] 
cpp-common: Add `bt2::CommonStringField::append()` method

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I42217dd06cf53511718d97839bda4f9d0a0ed784
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8196
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10833
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: message.hpp: add `asDiscardedPackets()` function
Francis Deslauriers [Mon, 30 May 2022 20:00:28 +0000 (16:00 -0400)] 
cpp-common: message.hpp: add `asDiscardedPackets()` function

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I909290879d90806124119b00d91f5ad17d176abc
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8189
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10832
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agotrace-ir.hpp: pass `UuidView` object to `CommonTrace::uuid()` method
Francis Deslauriers [Mon, 30 May 2022 19:58:31 +0000 (15:58 -0400)] 
trace-ir.hpp: pass `UuidView` object to `CommonTrace::uuid()` method

To simplify the code, the ctf::ir::TraceCls returns a Uuid, so accepting
a UuidView here makes it trivial to pass the return of one to the other.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I1f7a8fa51d932d764d77cd8dafe087cbf89f77b7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8188
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10831
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agoFix: trace-ir.hpp: spurious reference on object creation
Francis Deslauriers [Mon, 30 May 2022 19:55:14 +0000 (15:55 -0400)] 
Fix: trace-ir.hpp: spurious reference on object creation

We create a variant field class, which initially has refcount == 1.  We
then call `.shared()`, which creates another reference, bringing the
refcount to 2.

Fix that by using the `Shared::createWithoutRef()` method.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Idfe8184497a00d3192e390017d7717c7ff9a3344
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8187
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10830
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: trace-ir.hpp: no need to provide a bt2::Trace to create a bt2::Trace
Francis Deslauriers [Mon, 30 May 2022 19:28:27 +0000 (15:28 -0400)] 
Fix: trace-ir.hpp: no need to provide a bt2::Trace to create a bt2::Trace

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I3d1af5c8c9057a7a252f2e2a72313cc71bf396f8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8186
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10829
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: field.hpp: various typos
Francis Deslauriers [Mon, 30 May 2022 17:53:46 +0000 (13:53 -0400)] 
Fix: field.hpp: various typos

 * `Common{Unsigned, Signed}IntegerField` is derived by the
   `Common{Unsigned,Signed}EnumerationField` class so can't be final.

 * `CommonSignedIntegerField::value` should be `int64_t`.

 * Calling single precision function instead of double.

 * `CommonStringField::operator=` methods can throw.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ib354f0bd4edc8f625494acedac1052c7f45ec67d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8185
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10828
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agoFix: integer-range-set.hpp: calling `_get_ref()` rather than `_put_ref()`
Francis Deslauriers [Mon, 30 May 2022 17:41:36 +0000 (13:41 -0400)] 
Fix: integer-range-set.hpp: calling `_get_ref()` rather than `_put_ref()`

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ic7c381d7dd7f2c5780f7678e48b76d23e8f3ca00
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8183
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10827
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/bt2: pass wrappers by value instead of by reference
Philippe Proulx [Mon, 30 May 2022 12:08:10 +0000 (08:08 -0400)] 
cpp-common/bt2: pass wrappers by value instead of by reference

This is the convention elsewhere when using those wrappers as they only
contain a single pointer.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I23d73f6447a90372df349cb75afe56db28afc9aa
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8177
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10826
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: add SharedObj::release
Simon Marchi [Sat, 28 May 2022 14:01:44 +0000 (10:01 -0400)] 
cpp-common: add SharedObj::release

It will sometimes be needed to extract the ownership of a lib object
from a SharedObj, and get the underlying lib object pointer.  For
example:

 - The value returned by queries
 - Messages returned by iterators

Add a SharedObj::release method for that.  The return type is a borrowed
object (e.g. bt2::Value::Shared::release returns a bt2::Value), but
conceptually the caller then owns the reference and is responsible for
manually managing it.

After a release, a Shared object becomes invalid, same as when it is moved
from.

Change-Id: Id31855512b8dd3d5223f2e759ff48f81ceadbfbf
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8169
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10825
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/bt2: use classes from `cpp-common/exc.hpp`
Philippe Proulx [Mon, 30 May 2022 11:46:26 +0000 (07:46 -0400)] 
cpp-common/bt2: use classes from `cpp-common/exc.hpp`

This patch:

* Renames `lib-error.hpp` to `exc.hpp` as this could contain non-error
  exceptions in the future.

* Changes `bt2::Error`, `bt2::MemoryError`, and `bt2::OverflowError` to
  be aliases of `bt2_common::Error`, `bt2_common::MemoryError`, and
  `bt2_common::OverflowError`.

  This makes it possible for some code to catch only the common
  `bt2_common` errors to handle both library and user/internal
  exceptions.

  Note that those exceptions don't carry much information themselves;
  they're usually just a signal that an exception occurred, while the
  details are part of the libbabeltrace2 error of the current thread.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5bc1d39c8d978c21604614c68012509edc1776d5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8176
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10824
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd `bt2_common::OverflowError`
Philippe Proulx [Mon, 30 May 2022 11:41:01 +0000 (07:41 -0400)] 
Add `bt2_common::OverflowError`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9c524bed2374b7472e5603740c1c146f49371fe5
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8175
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10823
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: improve C++ UUID utilities
Simon Marchi [Thu, 30 Mar 2023 16:14:09 +0000 (12:14 -0400)] 
src/cpp-common: improve C++ UUID utilities

Philippe Proulx writing below.

This patch improves the C++ common UUID utilities.

Francis wrote the initial version of `bt2_common::Uuid`, and then we
worked together to improve many little things at once, leading to this
patch.

His original message was:

> Add `bt2_common::Uuid`
>
> This patch adds the `bt2_common::Uuid` class which represent UUIDs.
>
> `Uuid` instances can be created from byte array, strings, or
> bt2_common::UuidView objects.
>
> The generate() static method returns a Uuid object with newly
> generated UUID.
>
> The operator UuidView() method returns a bt2_common::UuidView object
> representing the entire content of the UUID.
>
> The data() method returns a const pointer to the underlying
> std::array<>.
>
> The str() method returns a new `std::string` instance containing the
> canonical string representation of the UUID.

The final improvements are:

* Add said `bt2_common::Uuid` class.

  I also added the operator[](), operator=(), isNil(), begin(), and
  end() methods, the `Val` and `ConstIter` aliases, and the fact that
  most of the class relies on creating a `bt2_common::UuidView` to wrap
  itself when needed.

  data() just returns `const Val *`.

* In `bt2_common::UuidView`:

  * Make the class `final`.

  * Add the `Val` and `ConstIter` aliases.

  * Add operator<(): makes it possible to use a `bt2_common::UuidView`
    as an `std::set` value type or as an `std::map` key type, and to use
    it with STL algorithms.

  * Make size() `constexpr`.

  * Rename string() to str() for consistency with internal C++ naming.

  * Add begin() and end().

  * Add operator=() which accepts a UUID pointer.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Id049953aecc51562e5939db546cb7d82bbaf88eb
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10822
Tested-by: jenkins <jenkins@lttng.org>
7 months agoMake `bt2_common::UuidView` final
Philippe Proulx [Mon, 2 May 2022 14:08:03 +0000 (10:08 -0400)] 
Make `bt2_common::UuidView` final

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I79ea919d497065256a445fc0faeb59e4267a466a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7972
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10821
Tested-by: jenkins <jenkins@lttng.org>
7 months agoRename bt2_common::UuidView::string() -> str()
Philippe Proulx [Mon, 2 May 2022 14:07:30 +0000 (10:07 -0400)] 
Rename bt2_common::UuidView::string() -> str()

More consistent with other internal C++ naming.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I552d4941b882215a302d8c02ea17bb018db79c5a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7971
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10820
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd bt2_common::UuidView::operator<()
Philippe Proulx [Mon, 2 May 2022 14:01:54 +0000 (10:01 -0400)] 
Add bt2_common::UuidView::operator<()

Makes it possible to use a `bt2_common::UuidView` as an `std::set` value
type or an `std::map` key type.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I297afa3c4ef00939ca3de659e1e72ced93a3310e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7970
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10819
Tested-by: jenkins <jenkins@lttng.org>
7 months agoMake bt2_common::UuidView::size() `constexpr`
Philippe Proulx [Mon, 2 May 2022 13:59:42 +0000 (09:59 -0400)] 
Make bt2_common::UuidView::size() `constexpr`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iffaae7d39ffa9fffb5c40988f82f5a5d78174115
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7969
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10818
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add bt2_common::align()
Philippe Proulx [Fri, 22 Apr 2022 12:11:22 +0000 (08:11 -0400)] 
src/cpp-common: add bt2_common::align()

This is a templated C++ version of the BT_ALIGN() macro found in
`src/common/align.h`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I0062778831d20cf19fe28bfa82c867473f7cf50b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7928
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10817

7 months agosrc/cpp-common: add bt2_common::safeTo*() and bt2_common::safe*()
Philippe Proulx [Fri, 15 Apr 2022 17:08:10 +0000 (13:08 -0400)] 
src/cpp-common: add bt2_common::safeTo*() and bt2_common::safe*()

This patch adds the following function templates, under the `bt2_common`
namespace, within the new `src/cpp-common/safe-ops.hpp` header:

safeToMul():
    Returns whether or not you can safely multiply two numbers without
    causing an overflow.

safeToAdd():
    Returns whether or not you can safely add two numbers without
    causing an overflow.

safeToSub():
    Returns whether or not you can safely subtract two numbers without
    causing an underflow.

safeMul():
    Multiplies some number by another, asserting that it's safe to do
    so, and returns the result.

safeAdd():
    Adds some number and another, asserting that it's safe to do so, and
    returns the result.

safeSub():
    Subtract some number from another, asserting that it's safe to do
    so, and returns the result.

Those are similar to the existing bt_safe_*() C functions, except that:

* They're function templates, so you can use any numeric type.

* The safeTo*() function templates are `constexpr`.

* They only work with unsigned types; signed types introduce some
  complexity (negative values) which I don't need to deal with right
  now.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I29ed4b51d50ae2507f5580db20452ec6c188ef66
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7916
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10816
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add bt2_common::makeUnique()
Philippe Proulx [Wed, 2 Mar 2022 18:47:25 +0000 (13:47 -0500)] 
src/cpp-common: add bt2_common::makeUnique()

This is our equivalent of std::make_unique() (introduced in C++14) for
C++11.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic58341f7419ac447f83401358ca0884151246dc8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7465
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10815
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add bt2_common::{little,big}ToNative()
Philippe Proulx [Fri, 22 Apr 2022 12:09:21 +0000 (08:09 -0400)] 
src/cpp-common: add bt2_common::{little,big}ToNative()

Those are C++ versions (using overloads) of the {le,be}{16,32,64}toh()
functions found in `src/compat/endian.h`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iab826bb633388d5ce506b4462b7a0417c2c05ad4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7927
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10814
Tested-by: jenkins <jenkins@lttng.org>
7 months agouuid-view.hpp: add missing #include's
Francis Deslauriers [Wed, 23 Feb 2022 15:42:49 +0000 (10:42 -0500)] 
uuid-view.hpp: add missing #include's

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I6299ef75acd765fde29f86046df877720ff8f54d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7376
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10813
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common/Makefile.am: add missing `uuid-view.hpp`
Simon Marchi [Wed, 27 Jul 2022 13:21:11 +0000 (09:21 -0400)] 
src/cpp-common/Makefile.am: add missing `uuid-view.hpp`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Idca1204fc2e53cf42633a3dd977f6883a6d55348
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7407
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10812
Tested-by: jenkins <jenkins@lttng.org>
7 months agologging: remove check for BT_LOG_OUTPUT_LEVEL
Simon Marchi [Wed, 3 Aug 2022 14:42:01 +0000 (10:42 -0400)] 
logging: remove check for BT_LOG_OUTPUT_LEVEL

This helps the case of TUs including headers that do logging, but don't
do logging themselves.

Change-Id: Ia1b51b4d30f120c68f96bcbd2db90adfc8ee98c9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10811
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agosrc/cpp-common: add BT_APPEND_CAUSE*() and BT_CLOG_*() macros
Simon Marchi [Wed, 27 Jul 2022 13:20:50 +0000 (09:20 -0400)] 
src/cpp-common: add BT_APPEND_CAUSE*() and BT_CLOG_*() macros

This patch adds the following files:

`src/cpp-common/cfg-logging.hpp`:
    Offers the following macros:

    BT_CLOG*_EX():
        Logs using a given logging configuration reference.

    BT_CLOG*_STR_EX():
        Logs a literal string using a given logging configuration
        reference.

    BT_CLOG*_ERRNO_EX():
        Logs an errno message using a given logging configuration
        reference.

    BT_CLOG*_MEM_EX():
        Logs memory bytes using a given logging configuration reference.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

    Those macros decide, depending on what's available within the
    provided logging configuration object, how to prefix the complete
    log message.

`src/cpp-common/cfg-error-reporting.hpp`:
    Offers the following macros:

    BT_APPEND_CAUSE_EX():
    BT_APPEND_CAUSE_STR_EX():
    BT_APPEND_CAUSE_ERRNO_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

    Those macros decide, depending on what's available within the
    provided logging configuration object, which
    BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use.

`src/cpp-common/cfg-error-reporting-throw.hpp`:
    Offers the following macros:

    BT_APPEND_CAUSE_AND_THROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and throws an exception.

    BT_APPEND_CAUSE_AND_RETHROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and rethrows.

    BT_STR_APPEND_CAUSE_AND_THROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and throws an exception.

    BT_STR_APPEND_CAUSE_AND_RETHROW_EX():
        Appends a cause to the error of the current thread using a given
        logging configuration reference, and rethrows.

    BT_ERRNO_APPEND_CAUSE_AND_THROW_EX():
        Appends a cause with an errno message to the error of the
        current thread using a given logging configuration reference,
        and throws an exception.

    BT_ERRNO_APPEND_CAUSE_AND_RETHROW_EX():
        Appends a cause with an errno message to the error of the
        current thread using a given logging configuration reference,
        and rethrows.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

`src/cpp-common/cfg-logging-error-reporting.hpp`:
    Offers the following macros:

    BT_CLOGE_APPEND_CAUSE_EX():
        Logs using a given logging configuration reference and appends
        a cause to the error of the current thread.

    BT_CLOGE_STR_APPEND_CAUSE_EX():
        Logs a literal string using a given logging configuration
        reference and appends a cause to the error of the current
        thread.

    BT_CLOGE_ERRNO_APPEND_CAUSE_EX():
        Logs an errno message using a given logging configuration
        reference and appends a cause to the error of the current
        thread.

    BT_CLOGE_MEM_APPEND_CAUSE_EX():
        Logs memory bytes using a given logging configuration reference
        and appends a cause to the error of the current thread.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

    Those macros decide, depending on what's available within the
    provided logging configuration object, which
    BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_*() macro to use.

`src/cpp-common/cfg-logging-error-reporting-throw.hpp`:
    Offers the following macros:

    BT_CLOGE_APPEND_CAUSE_AND_THROW_EX():
        Logs using a given logging configuration reference, appends a
        cause to the error of the current thread, and throws an
        exception.

    BT_CLOGE_APPEND_CAUSE_AND_RETHROW_EX():
        Logs using a given logging configuration reference, appends a
        cause to the error of the current thread, and rethrows.

    BT_CLOGE_STR_APPEND_CAUSE_AND_THROW_EX():
        Logs a literal string using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and throws an exception.

    BT_CLOGE_STR_APPEND_CAUSE_AND_RETHROW_EX():
        Logs a literal string using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and rethrows.

    BT_CLOGE_ERRNO_APPEND_CAUSE_AND_THROW_EX():
        Logs an errno message using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and throws an exception.

    BT_CLOGE_ERRNO_APPEND_CAUSE_AND_RETHROW_EX():
        Logs an errno message using a given logging configuration
        reference, appends a cause to the error of the current thread,
        and rethrows.

    BT_CLOGE_MEM_APPEND_CAUSE_AND_THROW_EX():
        Logs memory bytes using a given logging configuration reference,
        appends a cause to the error of the current thread, and throws
        an exception.

    BT_CLOGE_MEM_APPEND_CAUSE_AND_RETHROW_EX():
        Logs memory bytes using a given logging configuration reference,
        appends a cause to the error of the current thread, and
        rethrows.

    All the macros above also have their variant without the `_EX`
    suffix which uses the logging configuration reference `BT_CLOG_CFG`.

The intended usage is as such:

1. In a header file defining a class, have a logging configuration
   member:

       bt2_common::LogCfg _mLogCfg;

   Make the constructor of the class accept a logging configuration
   reference and copy it to `_mLogCfg`.

2. In the source file which implements the methods of the class, at
   the top of the file, write:

       #define BT_LOG_TAG   "MY/TAG"
       #define BT_CLOG_CFG  _mLogCfg
       #include "cpp-common/cfg-logging-error-reporting-throw.hpp"

3. In any method of the class, when there's an error, call:

       BT_CLOGE_APPEND_CAUSE_AND_THROW(bt2_common::Error,
                                       "Cannot do this and that: code=%d",
                                       code);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I3e689fe612b90be2f8f69288bc7947c727434d5a
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10810
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common: Add common exceptions
Francis Deslauriers [Tue, 19 Apr 2022 20:49:47 +0000 (16:49 -0400)] 
cpp-common: Add common exceptions

Add `bt2_common::{End, Error, MemoryError, TryAgain}` exception classes
to use in in-tree components and elsewhere. Each exception inherits a
C++ standard exception that I believe matches more closely in meaning.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I7335465f2377e032ae9706108708e35d78d38e6e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7918
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10809
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agosrc/cpp-common: add `LogCfg` class
Francis Deslauriers [Fri, 22 Apr 2022 20:47:55 +0000 (16:47 -0400)] 
src/cpp-common: add `LogCfg` class

`LogCfg` is a class to carry around the logging information used by
`BT_LOG*()` macros in the in-tree plugins.

Philippe added:

* Class comment.

* Setting other members when possible (for example, `_mSelfComp` when
  using the self message iterator constructor).

* Use references instead of pointers in constructors because they can't
  be `nullptr`, making it possible to remove some assertions.

* Component class member (because the libbabeltrace2 API has nothing
  to get a self component class from a self component) and
  compClsName() method.

  compClsName() is always available when using the self message
  iterator, component, or component class constructor.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic6980a2bcf74f8b270b0a108efc79f25f0e65d8d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7936
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10808
Tested-by: jenkins <jenkins@lttng.org>
7 months agolib: adjust son dev/non-dev precondition assertions in field-class.c
Simon Marchi [Thu, 17 Feb 2022 04:10:29 +0000 (23:10 -0500)] 
lib: adjust son dev/non-dev precondition assertions in field-class.c

I found some functions using BT_ASSERT_PRE_DEV_FC_NON_NULL followed by
either BT_ASSERT_PRE_FC_HAS_TYPE or BT_ASSERT_PRE_FC_IS_STRUCT (i.e. a
dev followed by a non-dev).  This seems illogical to me.  Either the
function is considered "fast path" and we use the dev versions, either
it's not "fast path" and we use the non-dev versions.

Change a few assertions to be dev.  If some of these functions aren't
actually considered fast path, then I think we should switch the
BT_ASSERT_PRE_DEV_FC_NON_NULLs to be non-dev.

Change-Id: I4f0c1cb0ef1006beddcc688d4e71f37fdb561e15
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7326
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10807
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

7 months agotests: only preload libasan for gcc compilers
Simon Marchi [Fri, 26 Aug 2022 17:50:53 +0000 (13:50 -0400)] 
tests: only preload libasan for gcc compilers

Clang appears to not use an external library for ASan, so we should not
try to preload it when building with clang.

Change-Id: I5cd88007fefcd7b8ad7caaee9155d3d9ea7f463e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10806
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
7 months agocpp-common/uuid-view: use string::operator[] instead of string::data to access intern...
Simon Marchi [Thu, 30 Mar 2023 16:11:19 +0000 (12:11 -0400)] 
cpp-common/uuid-view: use string::operator[] instead of string::data to access internal buffer

Using UuidView::string fails with:

      CXX      ctf-ir.lo
    In file included from /home/smarchi/src/babeltrace/src/cpp-common/bt2/clock-class.hpp:20,
                     from /home/smarchi/src/babeltrace/src/cpp-common/bt2/trace-ir.hpp:19,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.hpp:18,
                     from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.cpp:8:
    /home/smarchi/src/babeltrace/src/cpp-common/uuid-view.hpp: In member function 'std::string bt2_common::UuidView::str() const':
    /home/smarchi/src/babeltrace/src/cpp-common/uuid-view.hpp:57:38: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
       57 |         bt_uuid_to_str(_mUuid, s.data());
          |                                ~~~~~~^~
          |                                      |
          |                                      const char*
    In file included from /home/smarchi/src/babeltrace/src/plugins/ctf/common/src/metadata/ctf-ir.hpp:15:
    /home/smarchi/src/babeltrace/src/common/uuid.h:40:62: note:   initializing argument 2 of 'void bt_uuid_to_str(const uint8_t*, char*)'
       40 | BT_HIDDEN void bt_uuid_to_str(const bt_uuid_t uuid_in, char *str_out);
          |                                                        ~~~~~~^~~~~~~

This is because the data method only has a const version in C++11:

  https://en.cppreference.com/w/cpp/string/basic_string/data

It therefore can't be used to modify the content of the string.  Use
operator[] instead.

Change-Id: I3bd9c9756c4e79856a5f0f0c7d8fa14e19c1eadd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10805
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
7 months agofield-class.hpp: add missing support for user attributes
Philippe Proulx [Fri, 20 May 2022 13:11:40 +0000 (09:11 -0400)] 
field-class.hpp: add missing support for user attributes

This patch adds the missing
bt2::CommonStructureFieldClassMember::userAttributes() and
bt2::CommonVariantFieldClassOption::userAttributes() methods to set and
borrow user attributes of structure field member classes and variant
field class options.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I023e835531753eb928ea5db41b5f429750139af7
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8100
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10804
Tested-by: jenkins <jenkins@lttng.org>
7 months agoAdd bt2::Common{Field,FieldClass,Value,Message}<>::as<>()
Philippe Proulx [Fri, 20 May 2022 01:50:36 +0000 (21:50 -0400)] 
Add bt2::Common{Field,FieldClass,Value,Message}<>::as<>()

Those new as() method templates conceptually cast their object to the
first template parameter. Those are shorthands to use specific types
within a template function, for example:

    template <typename FieldT, typename ValT>
    void g(bt2::Field field, const ValT val)
    {
        // ...
        field.as<FieldT>() = val;
        // ...
    }

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ifc1f49487ac6ef9c143bf4c2faa3373f4eaccd9e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8099
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10803
Tested-by: jenkins <jenkins@lttng.org>
7 months agobt2::internal::BorrowedObj: add static assertions for generic copy ops.
Philippe Proulx [Thu, 19 May 2022 16:22:29 +0000 (12:22 -0400)] 
bt2::internal::BorrowedObj: add static assertions for generic copy ops.

This patch adds static assertions to `borrowed-obj.hpp` so as to make
compiler errors more readable when assigning a const wrapper to a
non-const wrapper, for example:

    bt2::Value v = bt2::ConstMapValue {somePtr};

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ib23d91c6660a478e0ad663abbd141b0a90eaa92d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8091
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10802
Tested-by: jenkins <jenkins@lttng.org>
This page took 0.053005 seconds and 4 git commands to generate.