tests: add `src.ctf.fs` single field testing framework
authorOlivier Dion <odion@efficios.com>
Wed, 18 Oct 2023 15:02:30 +0000 (11:02 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 7 Feb 2024 20:45:48 +0000 (15:45 -0500)
commit10ba5f69235e1dc943a716ecf6db3ee62463e066
treee77c93a9fb330c50484b168336f820de86c1196f
parent6b24dae4bd55ea0e2254e2a2ceb4b419fa48781e
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>
12 files changed:
tests/Makefile.am
tests/data/plugins/src.ctf.fs/field/bt_plugin_test_text.py [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/field/ctf-1/pass-fixed-len-uint-32-be.mp [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/field/ctf-1/pass-fixed-len-uint-32-le.mp [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/field/ctf-1/pass-static-len-array-of-struct.mp [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/field/ctf-1/pass-struct-empty.mp [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/field/ctf-1/pass-struct.mp [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/field/ctf-1/pass-variant.mp [new file with mode: 0644]
tests/data/plugins/src.ctf.fs/field/data_from_mp.py [new file with mode: 0644]
tests/plugins/src.ctf.fs/Makefile.am
tests/plugins/src.ctf.fs/field/test-field.sh [new file with mode: 0755]
tests/utils/utils.sh
This page took 0.032997 seconds and 4 git commands to generate.