barectf.git
3 years agoconfigs/succeed/**/*.yaml: remove useless YAML document end
Philippe Proulx [Thu, 24 Sep 2020 17:46:47 +0000 (13:46 -0400)] 
configs/succeed/**/*.yaml: remove useless YAML document end

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agodocs: yaml: put static/dynamic array FT obj. C types example in partial
Philippe Proulx [Thu, 24 Sep 2020 17:33:51 +0000 (13:33 -0400)] 
docs: yaml: put static/dynamic array FT obj. C types example in partial

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agodocs: {static,dyn}-array-ft-obj.adoc: use example block
Philippe Proulx [Thu, 24 Sep 2020 17:31:33 +0000 (13:31 -0400)] 
docs: {static,dyn}-array-ft-obj.adoc: use example block

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoFix: YAML: force enumeration FT objects to have at least one mapping
Philippe Proulx [Thu, 24 Sep 2020 17:23:34 +0000 (13:23 -0400)] 
Fix: YAML: force enumeration FT objects to have at least one mapping

As per CTF 1.8.3:

> Enumerations need to contain at least one entry.

Before this patch, ythose were legal:

    class: uenum
    size: 8

    class: uenum
    size: 8
    mappings: {}

    class: uenum
    size: 8
    mappings:
      A: []

CTF consumers would not like the resulting metadata stream. For
example, Babeltrace 2.1.0-rc1 [v1.2.0-3520-g73f74ae1f]:

    09-24 13:26:41.740 80492 80492 E PLUGIN/CTF/META/PARSER yyerror@parser.y:925 At line 109 in metadata stream: syntax error, unexpected CTF_RBRAC: token="}"
    09-24 13:26:41.740 80492 80492 E PLUGIN/CTF/META/DECODER ctf_metadata_decoder_append_content@decoder.c:280 [N/A] Cannot create the metadata AST out of the metadata text: mdec-addr=0x559dd9546a10
    09-24 13:26:41.740 80492 80492 W PLUGIN/SRC.CTF.FS/QUERY support_info_query@query.c:459 cannot append metadata content: metadata-decoder-status=-2
    09-24 13:26:41.741 80492 80492 W LIB/QUERY-EXECUTOR bt_query_executor_query@query-executor.c:231 Component class's "query" method failed: query-exec-addr=0x559dd9548070, cc-addr=0x559dd95233e0, cc-type=SOURCE, cc-name="fs", cc-partial-descr="Read CTF traces from the file sy", cc-is-frozen=0, cc-so-handle-addr=0x559dd9522770, cc-so-handle-path="lib/babeltrace2/plugins/babeltrace-plugin-ctf.so", object="babeltrace.support-info", params-addr=0x559dd9545f10, params-type=MAP, params-element-count=2, log-level=WARNING
    09-24 13:26:41.741 80492 80492 E CLI-CFG-SRC-AUTO-DISC support_info_query_all_sources@autodisc.c:493 babeltrace.support-info query failed.
    09-24 13:26:41.741 80492 80492 E CLI main@babeltrace2.c:2644 Command-line error: retcode=1

    ERROR:    [Babeltrace CLI] (babeltrace2.c:2644)
      Command-line error: retcode=1
    CAUSED BY [Source auto-discovery] (autodisc.c:493)
      babeltrace.support-info query failed.
    CAUSED BY [libbabeltrace2] (query-executor.c:231)
      Component class's "query" method failed: query-exec-addr=0x559dd9548070, cc-addr=0x559dd95233e0, cc-type=SOURCE, cc-name="fs", cc-partial-descr="Read CTF traces from
      the file sy", cc-is-frozen=0, cc-so-handle-addr=0x559dd9522770, cc-so-handle-path="babeltrace2/plugins/babeltrace-plugin-ctf.so",
      object="babeltrace.support-info", params-addr=0x559dd9545f10, params-type=MAP, params-element-count=2, log-level=WARNING

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf/templates: use `loop.last` instead of hack in `barectf/cgen.py`
Philippe Proulx [Thu, 24 Sep 2020 16:11:08 +0000 (12:11 -0400)] 
barectf/templates: use `loop.last` instead of hack in `barectf/cgen.py`

This patch removes the raw text replacement at the end of
_CodeGen.gen_src() (`barectf/cgen.py`).

Instead, to avoid empty lines before `}`, Jinja 2 templates only
output an empty line it's not the loop's last iteration:

    {% if not loop.last %}{{ '\n' }}{% endif %}

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotest-platform.h: do not include `barectf.h`: forward-declare context
Philippe Proulx [Thu, 24 Sep 2020 16:09:28 +0000 (12:09 -0400)] 
test-platform.h: do not include `barectf.h`: forward-declare context

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoYAML files: remove empty line after `%YAML 1.2` directive
Philippe Proulx [Thu, 24 Sep 2020 15:41:40 +0000 (11:41 -0400)] 
YAML files: remove empty line after `%YAML 1.2` directive

It's more common not to have one. At least the specification's
examples [1] do not have any.

[1]: https://yaml.org/spec/1.2/spec.html

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotests/tracing: use a base trace type YAML file
Philippe Proulx [Thu, 24 Sep 2020 15:33:07 +0000 (11:33 -0400)] 
tests/tracing: use a base trace type YAML file

This patch adds `tests/tracing/support/base.yaml` as a base YAML trace
type object for test configuration files to include.

`tests/tracing/conftest.py` is changed to add `tests/tracing/support` to
the barectf inclusion search directories and to only consider YAML files
in `tests/tracing/configs/succeed` (`tests/tracing/support/base.yaml` is
not a test).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agodocs: example.adoc: use file names as heading titles
Philippe Proulx [Thu, 24 Sep 2020 14:14:35 +0000 (10:14 -0400)] 
docs: example.adoc: use file names as heading titles

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agomodules/platform/pages/example.adoc: add a list of other examples
Philippe Proulx [Thu, 24 Sep 2020 13:59:23 +0000 (09:59 -0400)] 
modules/platform/pages/example.adoc: add a list of other examples

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agodocs: add missing `build` module
Philippe Proulx [Thu, 24 Sep 2020 14:02:20 +0000 (10:02 -0400)] 
docs: add missing `build` module

This was not added because the root `.gitignore` file contained `build/`
(fixed by 4dd70d0 (".gitignore: simplify")).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years ago.gitignore: simplify
Philippe Proulx [Thu, 24 Sep 2020 14:08:37 +0000 (10:08 -0400)] 
.gitignore: simplify

This patch removes lines from the root `.gitignore` file which were
useless for the barectf project.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotest-platform.c: write_packet(): use `const size_t`
Philippe Proulx [Thu, 24 Sep 2020 11:32:13 +0000 (07:32 -0400)] 
test-platform.c: write_packet(): use `const size_t`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agodocs/modules/ROOT/pages/index.adoc: add internal links
Philippe Proulx [Thu, 24 Sep 2020 11:19:04 +0000 (07:19 -0400)] 
docs/modules/ROOT/pages/index.adoc: add internal links

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoDocument barectf 3
Philippe Proulx [Thu, 24 Sep 2020 00:01:30 +0000 (20:01 -0400)] 
Document barectf 3

This patch adds the complete documentation of barectf 3 (upcoming major
release of the project).

The new `docs` directory is an Antora [1] documentation component
version. You can include it in an Antora site.

All the pages are written in AsciiDoc (Asciidoctor version).

Some contents were copied (and adapted) from the barectf wiki [2], but
most of the pages feature brand new text. The logo and diagrams are also
refreshed.

I'm removing the `barectf` CLI tool's manual page (`doc/man`) as it's
now documented in `docs/modules/cli/pages/usage.adoc`. Having the CLI
documented within the whole project's documentation makes it possible to
have critical links to and from other parts of it. This is to the
advantage of the reader.

[1]: https://antora.org/
[2]: https://github.com/efficios/barectf/wiki

3 years agobarectf_platform_linux_fs_init(): accept DS file path, not trace dir.
Philippe Proulx [Thu, 24 Sep 2020 02:45:24 +0000 (22:45 -0400)] 
barectf_platform_linux_fs_init(): accept DS file path, not trace dir.

This patch changes the Linux FS platform's
barectf_platform_linux_fs_init() function so that it accepts the data
stream file path instead of its trace directory.

This makes it possible to initialize many Linux FS platform contexts for
the same trace, each one targeting a distinct data stream file.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-platform-linux-fs.c: write_packet(): use `const size_t`
Philippe Proulx [Thu, 24 Sep 2020 02:37:13 +0000 (22:37 -0400)] 
barectf-platform-linux-fs.c: write_packet(): use `const size_t`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-platform-linux-fs.c: rename missing `ctx` -> `platform_ctx`
Philippe Proulx [Thu, 24 Sep 2020 02:36:38 +0000 (22:36 -0400)] 
barectf-platform-linux-fs.c: rename missing `ctx` -> `platform_ctx`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agopoetry.lock: update
Philippe Proulx [Thu, 24 Sep 2020 02:25:23 +0000 (22:25 -0400)] 
poetry.lock: update

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agopyproject.toml: update description
Philippe Proulx [Thu, 24 Sep 2020 02:24:21 +0000 (22:24 -0400)] 
pyproject.toml: update description

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf/templates/c: name `void *` context parameters `vctx`
Philippe Proulx [Wed, 23 Sep 2020 23:59:49 +0000 (19:59 -0400)] 
barectf/templates/c: name `void *` context parameters `vctx`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf.h.j2: add barectf_packet_buf_addr()
Philippe Proulx [Wed, 23 Sep 2020 22:20:07 +0000 (18:20 -0400)] 
barectf.h.j2: add barectf_packet_buf_addr()

barectf_packet_buf_addr() is an alias of barectf_packet_buf().

This is more in line with the barectf_packet_set_buf() function which
sets both the buffer's address and size.

This change helps document the platform API.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf.h.j2: add barectf_discarded_event_records_count()
Philippe Proulx [Wed, 23 Sep 2020 22:18:08 +0000 (18:18 -0400)] 
barectf.h.j2: add barectf_discarded_event_records_count()

barectf_discarded_event_records_count() is an alias of
barectf_packet_events_discarded().

The count of discarded event records is not related to the current
packet; it's a data stream variable.

This change helps document the platform API.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf.h.j2: rename "clock callbacks" -> "clock source callbacks"
Philippe Proulx [Wed, 23 Sep 2020 22:17:28 +0000 (18:17 -0400)] 
barectf.h.j2: rename "clock callbacks" -> "clock source callbacks"

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf/templates/c: rename "back-end" -> "back end"
Philippe Proulx [Wed, 23 Sep 2020 22:17:07 +0000 (18:17 -0400)] 
barectf/templates/c: rename "back-end" -> "back end"

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoStandardize root field type prefixes
Philippe Proulx [Wed, 23 Sep 2020 14:51:05 +0000 (10:51 -0400)] 
Standardize root field type prefixes

This patch changes `cgen.py` and what depends on it so that:

* `_RootFtPrefixes` attribute names always begin with `P` (packet) or
  `ER` (event record).

* `_RootFtPrefixes` attribute values for event record prefixes do not
  begin with `er`.

  The C source context where this is used indicates that it's an event
  record field, so `er` is redundant.

  This also makes the documentation easier to understand.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoAdd missing `serialize-write-timestamp-statements.j2` file
Philippe Proulx [Mon, 21 Sep 2020 23:29:14 +0000 (19:29 -0400)] 
Add missing `serialize-write-timestamp-statements.j2` file

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoEnable discarded event records snapshot FT DST feature by default
Philippe Proulx [Mon, 21 Sep 2020 23:26:49 +0000 (19:26 -0400)] 
Enable discarded event records snapshot FT DST feature by default

This patch changes `config.py` (API) and the v3 YAML parser to make
the discarded event records snapshot field type (data stream type)
feature enabled by default.

This feature is nice to have, only adds an integer field to each packet,
and doesn't require anything from the user.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoRename "time" -> "timestamp" (terminology)
Philippe Proulx [Mon, 21 Sep 2020 21:04:36 +0000 (17:04 -0400)] 
Rename "time" -> "timestamp" (terminology)

This patch renames the "time" concept to "timestamp" throughout.

The term "timestamp" is better to describe what used to be named "time",
for example a packet's beginning and end timestamps, and an event
record's timestamp.

"Time" has many definitions, one of which is duration, whereas the
only definition of "timestamp" in Antidote 10 is:

> a printed or stamped mark indicating a time or date of an event

which is pretty accurate.

Which is also why the timestamp members are named `timestamp_begin`,
`timestamp_end`, and `timestamp` in CTF 1.8.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoRename "target byte order" -> "native byte order"
Philippe Proulx [Fri, 18 Sep 2020 19:32:20 +0000 (15:32 -0400)] 
Rename "target byte order" -> "native byte order"

Going back to the CTF terminology.

From the trace type's perspective, I believe this term is better. I
think it's also easier to understand when reading the documentation.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoconfig.py: move target byte order property from config. to trace type
Philippe Proulx [Fri, 18 Sep 2020 19:27:12 +0000 (15:27 -0400)] 
config.py: move target byte order property from config. to trace type

This property is part of the trace type, as it's related to the byte
order of bit array field types which are all part of the trace type.

Also it's a CTF concept, not a barectf concept.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agopoetry.lock: update
Philippe Proulx [Fri, 18 Sep 2020 17:01:11 +0000 (13:01 -0400)] 
poetry.lock: update

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years ago.gitignore: ignore generated HTML READMEs
Philippe Proulx [Fri, 18 Sep 2020 17:00:44 +0000 (13:00 -0400)] 
.gitignore: ignore generated HTML READMEs

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoUse YAML 1.2 throughout
Philippe Proulx [Fri, 18 Sep 2020 16:56:41 +0000 (12:56 -0400)] 
Use YAML 1.2 throughout

The `yes` and `no` boolean values do not exist in YAML 1.2 [1].

Change all of them for `true` and `false`.

Also, in `tests/tracing/configs` and in
`examples/linux-fs-simple/config.yaml`, add the explicit `%YAML 1.2`
directive to indicate that it's a YAML 1.2 document.

[1]: https://yaml.org/spec/1.2/spec.html#id2805071

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoRemove `CHANGELOG.md`
Philippe Proulx [Thu, 17 Sep 2020 14:42:10 +0000 (10:42 -0400)] 
Remove `CHANGELOG.md`

This is the change log of barectf 2.

For barectf 3, the change log will be part of the documentation.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-tracepoint.h: improve quality
Philippe Proulx [Thu, 17 Sep 2020 13:13:18 +0000 (09:13 -0400)] 
barectf-tracepoint.h: improve quality

Changes:

* Reflow header comment to fit 72 columns.

* Capitalize comments.

* Use updated `barectf.h` definition names (`_BARECTF_IDENTIFIER_PREFIX`
  and `_BARECTF_DEFAULT_DATA_STREAM_TYPE_NAME`).

* Check for `BARECTF_TRACEPOINT_DATA_STREAM_TYPE_NAME` as an alternative
  to `BARECTF_TRACEPOINT_STREAM` (for consistency).

* Rework error messages.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf.h.j2: use more accurate definition names
Philippe Proulx [Thu, 17 Sep 2020 13:12:06 +0000 (09:12 -0400)] 
barectf.h.j2: use more accurate definition names

Leaving the old definitions to avoid breaking anything.

The updated names are:

`_BARECTF_PREFIX`:
    `_BARECTF_IDENTIFIER_PREFIX`

`_BARECTF_DEFAULT_STREAM`:
    `_BARECTF_DEFAULT_DATA_STREAM_TYPE_NAME`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoexamples/linux-fs-simple: use `trace` as trace directory, not `ctf`
Philippe Proulx [Thu, 17 Sep 2020 04:09:02 +0000 (00:09 -0400)] 
examples/linux-fs-simple: use `trace` as trace directory, not `ctf`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoexamples/linux-fs-simple: convert README to Asciidoctor and improve it
Philippe Proulx [Thu, 17 Sep 2020 04:05:44 +0000 (00:05 -0400)] 
examples/linux-fs-simple: convert README to Asciidoctor and improve it

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agolinux-fs-simple/config.yaml: convert to v3 format
Philippe Proulx [Thu, 17 Sep 2020 03:59:58 +0000 (23:59 -0400)] 
linux-fs-simple/config.yaml: convert to v3 format

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agolinux-fs-simple.c: improve quality
Philippe Proulx [Thu, 17 Sep 2020 03:58:27 +0000 (23:58 -0400)] 
linux-fs-simple.c: improve quality

Changes:

* Remove unneeded included headers.
* Remove unneeded TO_VOID_PTR() macro.
* Use `const` where possible.
* Use single return points.
* Capitalize comments.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agolinux-fs-simple/Makefile: remove nonexistent `view` from `.PHONY`
Philippe Proulx [Thu, 17 Sep 2020 03:57:22 +0000 (23:57 -0400)] 
linux-fs-simple/Makefile: remove nonexistent `view` from `.PHONY`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-platform-linux-fs.c: improve quality
Philippe Proulx [Thu, 17 Sep 2020 01:19:39 +0000 (21:19 -0400)] 
barectf-platform-linux-fs.c: improve quality

Changes:

* Remove unneeded included headers.
* Remove unneeded TO_VOID_PTR() macro.
* Use `const` where possible.
* Use single return points.
* Rename platform context variables to `platform_ctx`.
* Capitalize comments.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-platform-linux-fs.*: remove header titles
Philippe Proulx [Thu, 17 Sep 2020 01:08:36 +0000 (21:08 -0400)] 
barectf-platform-linux-fs.*: remove header titles

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoexamples/linux-fs-simple, platforms/linux-fs: use double quotes to include
Philippe Proulx [Thu, 17 Sep 2020 01:05:32 +0000 (21:05 -0400)] 
examples/linux-fs-simple, platforms/linux-fs: use double quotes to include

    #include "barectf.h"

is more permissive than

    #include <barectf.h>

You don't need to add `-I.` to search the same directory.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-platform-linux-fs.*: update copyright years
Philippe Proulx [Thu, 17 Sep 2020 01:00:44 +0000 (21:00 -0400)] 
barectf-platform-linux-fs.*: update copyright years

Also reflow the license headers to fit 72 columns.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-platform-linux-fs.h: remove function documentation
Philippe Proulx [Thu, 17 Sep 2020 01:00:12 +0000 (21:00 -0400)] 
barectf-platform-linux-fs.h: remove function documentation

This is now in the local `README.adoc` file.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf-platform-linux-fs.c: use `CLOCK_REALTIME`
Philippe Proulx [Thu, 17 Sep 2020 00:57:52 +0000 (20:57 -0400)] 
barectf-platform-linux-fs.c: use `CLOCK_REALTIME`

Although this clock source can go back, the result is more friendly than
using `CLOCK_MONOTONIC` and having to set the clock type's offset
manually or getting invalid event record times.

I believe this is acceptable considering the demonstration purpose of
this platform.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoplatforms/linux-fs: remove `README.md`, write a better `README.adoc`
Philippe Proulx [Thu, 17 Sep 2020 00:57:16 +0000 (20:57 -0400)] 
platforms/linux-fs: remove `README.md`, write a better `README.adoc`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoMove `doc/examples` to `examples`
Philippe Proulx [Thu, 17 Sep 2020 00:09:49 +0000 (20:09 -0400)] 
Move `doc/examples` to `examples`

I'm planning to remove the `doc` directory, writing the documentation
within the `docs` directory.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoRemove Parallella platform and examples
Philippe Proulx [Thu, 17 Sep 2020 00:05:49 +0000 (20:05 -0400)] 
Remove Parallella platform and examples

It's very hard to test and to integrate in a CI.

Also, the Epiphany repositories are not updated since 3-4 years [1].

[1]: https://github.com/adapteva

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoRename "event type" -> "event record type", "stream type" -> "data stream type"
Philippe Proulx [Wed, 16 Sep 2020 23:36:59 +0000 (19:36 -0400)] 
Rename "event type" -> "event record type", "stream type" -> "data stream type"

This matches an eventual CTF 2 terminology and makes writing the barectf
documentation easier, as a data stream type describes data streams and
an event record type describes event records. An event record is what
the tracer records for an occurring event.

Throughout the code, for names, variables, and file names:

* `dst` means "data stream type".
* `ds` means "data stream".
* `ert` means "event record type".
* `er` means "event record".

The v3 YAML schemas are modified accordingly.

This patch also renames "discarded events counter" to "discarded event
records counter snapshot", as this field is a snapshot of the per-data
stream counter.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoAdd dynamic array tracing tests
Philippe Proulx [Thu, 10 Sep 2020 21:32:50 +0000 (17:32 -0400)] 
Add dynamic array tracing tests

The new tests are modified copies of static array tracing tests as a
dynamic array field can contain the same fields as a static array field.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoRemoved unused `tests/conftest.py`
Philippe Proulx [Thu, 10 Sep 2020 20:54:58 +0000 (16:54 -0400)] 
Removed unused `tests/conftest.py`

Used to contain the yaml_cfg_path() fixture; not needed anymore since
b1c5cbc ("tests/config/yaml: use pytest_collect_file() hook for YAML
files") and 816fefd ("tests/tracing: use pytest_collect_file() hook for
YAML files").

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotests/tracing/support/test-platform.c: clear buffer at every packet opening
Philippe Proulx [Thu, 10 Sep 2020 19:01:56 +0000 (15:01 -0400)] 
tests/tracing/support/test-platform.c: clear buffer at every packet opening

This ensures that there's no garbage data left in the buffer between
packets.

It's not triggering any failure currently because all the tests in
`tests/tracing` produce a single packet.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotracing/src/succeed/static-array: update copyright notice's year
Philippe Proulx [Thu, 10 Sep 2020 19:01:36 +0000 (15:01 -0400)] 
tracing/src/succeed/static-array: update copyright notice's year

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agosrc/succeed/static-array: add missing `const` qualifiers
Philippe Proulx [Thu, 10 Sep 2020 18:58:14 +0000 (14:58 -0400)] 
src/succeed/static-array: add missing `const` qualifiers

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotests/tracing: use pytest_collect_file() hook for YAML files
Philippe Proulx [Thu, 10 Sep 2020 18:41:12 +0000 (14:41 -0400)] 
tests/tracing: use pytest_collect_file() hook for YAML files

This patch applies the same strategy as b1c5cbc ("tests/config/yaml: use
pytest_collect_file() hook for YAML files") to `tests/tracing`.

This patch changes `tests/tracing/conftest.py` so that it implements a
pytest_collect_file() Pytest hook to create Pytest file and item objects
for each barectf YAML configuration file found in the `configs`
directory. Thanks to the base name of this YAML file,
pytest_collect_file() automatically finds the corresponding
test-specific C source and expectation files.

This makes is possible to remove `test_succeed_static_array.py` and
avoid duplication and mismatches between existing YAML files and
available test functions.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotests/config/yaml: use pytest_collect_file() hook for YAML files
Philippe Proulx [Thu, 10 Sep 2020 04:06:41 +0000 (00:06 -0400)] 
tests/config/yaml: use pytest_collect_file() hook for YAML files

This patch changes `tests/config/yaml/conftest.py` so that it implements
a pytest_collect_file() Pytest hook to create Pytest file and item
objects for each failing barectf YAML configuration file found.

This makes is possible to remove all `test_fail_*.py` files and avoid
duplication and mismatches between existing YAML files and available
test functions.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoconfig.py, tsdl182gen.py: fix Mypy/Pylint errors
Philippe Proulx [Thu, 10 Sep 2020 01:36:54 +0000 (21:36 -0400)] 
config.py, tsdl182gen.py: fix Mypy/Pylint errors

3 years agoAdd static array tracing tests
Philippe Proulx [Wed, 9 Sep 2020 23:35:11 +0000 (19:35 -0400)] 
Add static array tracing tests

This patch adds static array tracing tests, also adding the testing
infrastructure for other such tests.

In `tests/tracing`, the test functions of `test_succeed_static_array.py`
use the tracing_succeed_test() fixture as found in
`tests/tracing/conftest.py`.

tracing_succeed_test() does the following:

 1. Creates a temporary directory with the tmpdir() fixture.

 2. Automatically finds the paths, based on the test's module and
    function names, of:

    * A YAML configuration file.

    * A test-specific C source file.

    * Two expectation files (one for the metadata stream and one for the
      data stream).

 3. Creates a barectf configuration from the YAML file found in 2.

 4. Generates the C code files using the barectf configuration of 3.,
    writing the files to the temporary directory of 1.

 5. Generates the metadata stream using the barectf configuration of 3.,
    stripping some variable version and generation date lines.

    This step does not write any file to the file system.

 6. Copies the files in the `tests/tracing/support` directory to the
    temporary directory of 1.

    `test-platform.c` and `test-platform.h` form the barectf platform
    for all the tracing tests.

 7. Copies the test-specific C source file found in 2. as `test.c` to
    the temporary directory of 1.

 8. Executes `make` in the temporary directory of 1.

 9. Executes `./test` in the temporary directory of 1.

10. Reads the produced data stream file (`stream` in the temporary
    directory of 1.) and compares it with the data stream expectation
    file found in 2.

11. Compares the metadata stream contents of 5. with the metadata stream
    expectation file found in 2.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoSimplify current tests
Philippe Proulx [Wed, 9 Sep 2020 22:02:17 +0000 (18:02 -0400)] 
Simplify current tests

This patch:

* Adds the global yaml_cfg_path() fixture which returns the path to an
  hypothetical barectf YAML configuration file based on the test's
  module file and function names.

* Updates the config_fail_test() fixture to only use yaml_cfg_path()

* Updates all the test functions to only use config_fail_test() and call
  it without parameters.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoFix: include/3/stdreal.yaml: `align` -> `alignment`
Philippe Proulx [Thu, 10 Sep 2020 01:14:22 +0000 (21:14 -0400)] 
Fix: include/3/stdreal.yaml: `align` -> `alignment`

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoAdd user dynamic array field support
Philippe Proulx [Wed, 9 Sep 2020 20:50:51 +0000 (16:50 -0400)] 
Add user dynamic array field support

This patch adds support for user dynamic array fields.

The element field type of a user dynamic array field type can be any of
the following:

* Bit array field type.
* String field type.
* Static array field type.

Note that it _cannot_ be another dynamic array field type.

The new `barectf.DynamicArrayFieldType` represents a dynamic array field
type. Its constructor accepts a length field type. As of this version,
this length field type must be within the same immediate structure field
type and before it.

The YAML ways to specify a dynamic array field type are:

barectf 2 configuration:
    class: array
    length: dynamic
    element-type:
      ...

barectf 3 configuration:
    class: dynamic-array
    element-field-type:
      ...

Note that in YAML, you don't specify the length field type: the parser
automatically creates a 32-bit, byte-aligned unsigned integer field type
before which, for a dynamic array field type named `a`, has the name
`__a_len`. This also becomes part of the corresponding tracing function
parameter's name.

In the future, I can add a `length-field-type` property to a barectf 3
YAML dynamic array field type to point to an anterior unsigned integer
field type using some kind of reference, for example:

    class: structure
    members:
      - my_length: uint16
      - my_array:
          field-type:
            class: dynamic-array
            length-field-type-name: my_length
            element-field-type:
              ...

This would make it possible for more than one dynamic array fields
to use the same length field, for example:

    class: structure
    members:
      - my_length: uint16
      - my_uint_array:
          field-type:
            class: dynamic-array
            length-field-type-name: my_length
            element-field-type: uint8
      - my_string_array:
          field-type:
            class: dynamic-array
            length-field-type-name: my_length
            element-field-type: string

The constructor of `barectf.StructureFieldType` calls
_set_dyn_array_ft_length_ft_member_names() which, for each member having
a dynamic array field type:

* Sets its `_length_ft_member_name` attribute to the name of the
  structure field type member having its length field type.

* Sets its length field type's `_is_len` attribute to `True`.

I consider those as hacks, but considering the current constraints, it
makes parts of the (barectf) code easier to implement and maintain.

The C code generation approach is similar to the static array field
case. The `*-write-static-array-statements.j2` templates are renamed to
`*-write-array-statements.j2` and use the `length_src` variable as the
loop's length's value. `*-write-static-array-statements.j2` and the new
`*-write-dynamic-array-statements.j2` set `length_src` before including
`*-write-array-statements.j2`.

To make things easier, barectf now systematically generates alignment
statements if the alignment is greater than one. This could be optimized
again in the future, considering arrays this time. The
`_WriteOp.offset_in_byte` optimization still exists, although as soon as
it's not statically known, it's now `None` and
`serialize-write-bit-array-statements.j2` uses the safe, dynamic
`ctx->at % 8` expression. try_create_align_op() does this, more or less:

    If `self._offset_in_byte` is not currently known and the requested
    alignment is 8:
      Set `self._offset_in_byte` to 0.
    Else:
      If we're currently within an array operation:
        Reset `self._offset_in_byte`.
      Else:
        If `self._offset_in_byte` is currently known:
          Align `self._offset_in_byte` with the requested alignment.

This ensures that each array field's element is aligned before being
written.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoconfig.py: UnsignedIntegerFieldType.__init__(): forward `**kwargs` too
Philippe Proulx [Wed, 9 Sep 2020 20:43:41 +0000 (16:43 -0400)] 
config.py: UnsignedIntegerFieldType.__init__(): forward `**kwargs` too

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoAdd user static array field support (with recursion)
Philippe Proulx [Wed, 9 Sep 2020 15:00:12 +0000 (11:00 -0400)] 
Add user static array field support (with recursion)

This patch adds support for user static array fields.

The element field type of a user static array field type can be any of
the following:

* Bit array field type.
* String field type.
* Static array field type.

The generated serializing C code does not assume anything about the
memory layout of a user array: it iterates each item to serialize them
individually.

For example, consider the following TSDL field type:

    class: static-array
    length: 3
    element-field-type:
      class: unsigned-integer
      size: 16

The tracing function's parameter's C type for the corresponding field is
`const uint16_t *`. Assuming the parameter's name is `a`, the
serialization function accesses `a[0]`, `a[1]`, and `a[2]`; it doesn't
copy large blocks of memory as is. This is because we don't know the
target architecture's alignment constraints and general memory layout.

For:

    class: static-array
    length: 3
    element-field-type:
      class: string

the parameter's C type is `const char * const *`.

Note that a pointed C type is always `const`, so the `barectf.h` user
might need to cast accordingly if her own C types miss such `const`
qualifiers. Here's another example:

    class: static-array
    length: 2
    element-field-type:
      class: static-array
      length: 3
      element-field-type:
        class: unsigned-integer
        size: 8

This becomes `const uint8_t * const *`.

As of this patch, a tracing function uses `uint32_t` as the loop index
type. I believe this will be enough for barectf's use cases. It could
(should) also be based on the static array field type's length.

Each loop is isolated within its own C scope. The loop index variable
names are `i`, then `j`, then `k`, then `k1`, then `k2`, and so on.

Notable changes
===============
`cgen.py`:
    * Add a level property to operation objects.

      This is the static array nesting level.

    * _OpBuilder._build_for_ft(): handle user static array field types.

      A user static array field type leads to an "align" operation
      (possibly) and its element field type's operation, all within a
      compound operation.

      The name of the element field type's operation is the C array
      subscript with the right index variable name, for example `[i]`.

      The packet header's UUID field type still has its special case.

    * Add _loop_var_name() function which returns the name of a loop
      index variable name based on a level (0 is `i`, 1 is `j`, and so
      on).

    * Add general template filter `loop_var_name` which is
      _loop_var_name().

    * Add general template filter `op_src_var_name` which returns an
      operation's source variable name.

      This used to be the op_src() macro in `c/common.j2`, but with
      array subscript names, it's too ugly for the Jinja 2 language.

    * _CodeGen._ft_c_type(): handle static array field types (return a
      `_PointerCType` object).

`config_parse_v3.py`:
    Accept user static array field types.

Existing templates:
    Remove op_src(); use the `op_src_var_name` filter instead.

`serialize-write-static-array-statements.j2`,
`size-write-static-array-statements.j2`:
    New templates to serialize and compute the size of static array
    fields.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoFix: config.py: implement _ArrayFieldType.size_is_dynamic()
Philippe Proulx [Wed, 9 Sep 2020 14:15:25 +0000 (10:15 -0400)] 
Fix: config.py: implement _ArrayFieldType.size_is_dynamic()

An array field type's size is dynamic if its element field type is.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoserialize-write-bit-array-statements.j2: increment position within scope
Philippe Proulx [Wed, 9 Sep 2020 01:52:42 +0000 (21:52 -0400)] 
serialize-write-bit-array-statements.j2: increment position within scope

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agocgen.py: use C type classes for _CodeGen._ft_c_type()
Philippe Proulx [Wed, 9 Sep 2020 01:21:33 +0000 (21:21 -0400)] 
cgen.py: use C type classes for _CodeGen._ft_c_type()

This patch introduces new classes to represent C types in `cgen.py`.

The C type class hierarchy is:

    _CType
      _ArithCType
      _PointerCType

A `_PointerCType` object contains another `_CType` object.

You can get the string representation of a C type object with its
__str__() method.

A C type constructor's `is_const` parameter controls whether or not the
_value_ is const. For example:

`const char *`:
    `_PointerCType` containing a const `_ArithCType`.

`const char * const`:
    Const `_PointerCType` containing a const `_ArithCType`.

_CodeGen._ft_c_type() now returns a `_CType` object instead of a string.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoFix: barectf/include/3: remove `byte-order` properties
Philippe Proulx [Tue, 8 Sep 2020 23:52:51 +0000 (19:52 -0400)] 
Fix: barectf/include/3: remove `byte-order` properties

Removed in 4c91e76 ("config.py: remove bit array field type's byte order
property"), so this should not be here.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoFix: size-write-struct-statements.j2: use `ev_type`, not `event_type`
Philippe Proulx [Tue, 8 Sep 2020 20:21:39 +0000 (16:21 -0400)] 
Fix: size-write-struct-statements.j2: use `ev_type`, not `event_type`

3 years agoconfig_parse_v2.py: fix typing issue
Philippe Proulx [Tue, 8 Sep 2020 20:19:02 +0000 (16:19 -0400)] 
config_parse_v2.py: fix typing issue

Reported by mypy 0.782.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agostruct-ft.j2: use a single line for array indices
Philippe Proulx [Tue, 8 Sep 2020 20:15:31 +0000 (16:15 -0400)] 
struct-ft.j2: use a single line for array indices

Still readable and less weird in my opinion.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agocgen.py, templates: use new `_CompoundOp` for structure fields
Philippe Proulx [Tue, 8 Sep 2020 20:05:42 +0000 (16:05 -0400)] 
cgen.py, templates: use new `_CompoundOp` for structure fields

This patch adds the `_CompoundOp` class which inherits `_Op`. It also
makes `_AlignOp` and `_WriteOp` inherit a new `_LeadOf` class. The final
operation class hierarchy is:

    _Op
      _CompoundOp
      _LeafOp
        _AlignOp
        _WriteOp

A compound operation is a simple container of suboperations (compound or
leaf). It is expected that a compound field type leads to a compound
operation.

As of this version, the only "real" compound field type is the structure
field type.

`_OpsBuilder` becomes `_OpBuilder` and does not accumulate operations
anymore: it still has a state, but its build_for_root_ft() method
returns a `_CompoundOp` object for a given root structure field type.

The returned compound operation can contain an "align" operation for the
structure field itself as its first suboperation.

Because an `_OpBuilder` doesn't accumulate operations anymore, there's
no need to copy operations anymore.

For a structure field type, _OpBuilder._build_for_ft() returns a single
compound operation having the new serialization and size templates
`serialize-write-struct-statements.j2` and
`size-write-struct-statements.j2`. Those templates contain a C comment
and a simple loop to render the appropriate template for each
suboperation, forwarding the `stream_type` and `ev_type` context
variables.

`barectf.c.j2` is changed to render a single template for any compound
operation. This removes many loops.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agopoetry.lock: update
Philippe Proulx [Tue, 8 Sep 2020 17:05:48 +0000 (13:05 -0400)] 
poetry.lock: update

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoserialize-write-bit-array-statements.j2: use memcpy() when possible
Philippe Proulx [Tue, 8 Sep 2020 16:49:14 +0000 (12:49 -0400)] 
serialize-write-bit-array-statements.j2: use memcpy() when possible

To write a bit array field within a serialization function, you can use
memcpy() directly when all of the following conditions are satisfied:

* The field type's size is 8, 16, 32, or 64.

* The field type's alignment is a multiple of 8.

* The field type's byte order is the target byte order; always the case
  since 4c91e76 ("config.py: remove bit array field type's byte order
  property").

With recent compilers, using bt_bitfield_write_*() vs. memcpy() with
`-O2` gives the same result.

For example, consider this C code:

    const uint8_t *data;

    void with_bitfield(size_t offset, int val)
    {
        bt_bitfield_write_le(&data[offset], 0, sizeof(val) * 8, int, val);
    }

    void with_memcpy(size_t offset, int val)
    {
        memcpy(&data[offset], &val, sizeof(val));
    }

On x86-64, this gets compiled to:

GCC 10.2:
    with_bitfield:
            mov     rax, QWORD PTR data[rip]
            mov     DWORD PTR [rax+rdi], esi
            ret
    with_memcpy:
            mov     rax, QWORD PTR data[rip]
            mov     DWORD PTR [rax+rdi], esi
            ret

Clang 10.0:
    with_bitfield:                          # @with_bitfield
            mov     rax, qword ptr [rip + data]
            mov     dword ptr [rax + rdi], esi
            ret
    with_memcpy:                            # @with_memcpy
            mov     rax, qword ptr [rip + data]
            mov     dword ptr [rax + rdi], esi
            ret

GCC 7.3:
    with_bitfield:
            add     rdi, QWORD PTR data[rip]
            mov     eax, esi
            mov     BYTE PTR [rdi], sil
            mov     BYTE PTR [rdi+1], ah
            sar     esi, 24
            sar     eax, 16
            mov     BYTE PTR [rdi+3], sil
            mov     BYTE PTR [rdi+2], al
            ret
    with_memcpy:
            mov     rax, QWORD PTR data[rip]
            mov     DWORD PTR [rax+rdi], esi
            ret

GCC 4.9.4:
    with_bitfield:
            add     rdi, QWORD PTR data[rip]
            mov     eax, esi
            sar     eax, 8
            mov     BYTE PTR [rdi+1], al
            mov     eax, esi
            mov     BYTE PTR [rdi], sil
            sar     eax, 16
            sar     esi, 24
            mov     BYTE PTR [rdi+2], al
            mov     BYTE PTR [rdi+3], sil
            ret
    with_memcpy:
            mov     rax, QWORD PTR data[rip]
            mov     DWORD PTR [rax+rdi], esi
            ret

Clang 3.0:
    with_bitfield:                          # @with_bitfield
            mov     EAX, ESI
            mov     RCX, QWORD PTR [RIP + data]
            mov     BYTE PTR [RCX + RDI], AL
            mov     BYTE PTR [RCX + RDI + 1], AH  # NOREX
            mov     EDX, EAX
            shr     EDX, 16
            mov     BYTE PTR [RCX + RDI + 2], DL
            shr     EAX, 24
            mov     BYTE PTR [RCX + RDI + 3], AL
            ret

    with_memcpy:                            # @with_memcpy
            mov     RAX, QWORD PTR [RIP + data]
            mov     DWORD PTR [RAX + RDI], ESI
            ret

Because barectf targets embedded and bare metal environments, it's
possible that its user uses an older compiler. Therefore, this patch
changes `serialize-write-bit-array-statements.j2` to prefer memcpy()
when possible as it's very common for memcpy() to get replaced with a
compiler built-in to generate faster code when the copy size is static
(which is always the case for barectf bit array fields).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoserialize-write-time-statements.j2: capitalize C comment
Philippe Proulx [Tue, 8 Sep 2020 16:48:54 +0000 (12:48 -0400)] 
serialize-write-time-statements.j2: capitalize C comment

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobitfield.h.j2: keep a single version for the target byte order
Philippe Proulx [Tue, 8 Sep 2020 16:37:28 +0000 (12:37 -0400)] 
bitfield.h.j2: keep a single version for the target byte order

Because all bit array fields use the target byte order since 4c91e76
("config.py: remove bit array field type's byte order property"), we
don't need both little-endian and big-endian versions of the
`bitfield.h` macros.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoconfig.py: remove bit array field type's byte order property
Philippe Proulx [Tue, 8 Sep 2020 16:16:05 +0000 (12:16 -0400)] 
config.py: remove bit array field type's byte order property

This patch removes the byte order property from the `_BitArrayFieldType`
class.

Instead, barectf always uses the configuration's target byte order.

As of this version of barectf, where all integral tracing function
parameters are copies, it makes no sense, for example, for a
little-endian CPU to write big-endian data.

The `byte-order` property is also removed in barectf 3 YAML field types.
I'm keeping it in barectf 2 YAML field types for backward compatibility,
but it's ignored now.

From a CTF consumer's perspective, this patch doesn't cause a noticeable
change: the decoded integral value is the same whatever the byte order.

From the barectf API's perspective, it makes the configuration objects
simpler. This patch effectively reverts 7fffc7d ("config: replace trace
type's default BO with configuration's target BO").

It is possible that barectf needs specific bit array field type byte
orders in the future, for example to copy some user payload as is
instead of copying each field; when this time comes, we can reintroduce
the property, adding a way to mark a bit array field type's byte order
as "target" (which would be the default), for example:

    my_ft = barectf.RealFieldType(32,
                                  byte_order=barectf.TARGET_BYTE_ORDER)

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotemplates: rename "licence" -> "license"
Philippe Proulx [Fri, 4 Sep 2020 20:31:03 +0000 (16:31 -0400)] 
templates: rename "licence" -> "license"

Unintentional French.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobitfield.h.j2: restore `bitfield.h`'s original copyright
Philippe Proulx [Fri, 4 Sep 2020 20:28:09 +0000 (16:28 -0400)] 
bitfield.h.j2: restore `bitfield.h`'s original copyright

In e72875e ("templates: commonize the licence header"), I made the
mistake to overwrite `bitfield.h`'s original copyright with mine, so
restore this.

The new `licence-header-footer.j2` template is the bottom part of any
license header.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobitfield.h.j2: remove `_BYTE_ORDER` definition; set relevant macros
Philippe Proulx [Fri, 4 Sep 2020 20:23:07 +0000 (16:23 -0400)] 
bitfield.h.j2: remove `_BYTE_ORDER` definition; set relevant macros

Now that a barectf configuration contains the target byte order, we can
set the relevant macros directly in `bitfield.h.j2`, and therefore
remove the `_BYTE_ORDER` definition.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf: fix Flake8 errors
Philippe Proulx [Fri, 4 Sep 2020 02:03:52 +0000 (22:03 -0400)] 
barectf: fix Flake8 errors

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoconfig_parse_v3.py: fix Pylint errors/warnings
Philippe Proulx [Fri, 4 Sep 2020 01:53:16 +0000 (21:53 -0400)] 
config_parse_v3.py: fix Pylint errors/warnings

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf.c.j2: remove superfluous empty line
Philippe Proulx [Fri, 4 Sep 2020 01:45:31 +0000 (21:45 -0400)] 
barectf.c.j2: remove superfluous empty line

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agocgen.py: _CodeGen.gen_src(): remove ugly empty lines before `}`
Philippe Proulx [Fri, 4 Sep 2020 01:41:44 +0000 (21:41 -0400)] 
cgen.py: _CodeGen.gen_src(): remove ugly empty lines before `}`

Jinja 2 makes it hard to have multiple contiguous blocks delimited with
empty lines when using a for loop, while not also having an empty line
at the end.

Therefore, we often get something like this:

    /* Serialize payload */
    {
        /* Align for payload structure */
        _ALIGN(ctx->at, 32);

        /* Write `value` field */
        bt_bitfield_write_le(&ctx->buf[_BITS_TO_BYTES(ctx->at)],
            uint8_t, 0, 32, uint32_t,
            (uint32_t) p_value);
        ctx->at += 32;

    }

This empty line before `}` is really ugly, so use a regex substitution
to fix this.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoconfig: replace trace type's default BO with configuration's target BO
Philippe Proulx [Fri, 4 Sep 2020 01:06:03 +0000 (21:06 -0400)] 
config: replace trace type's default BO with configuration's target BO

This patch removes the `default_byte_order` property from the
`barectf.TraceType` class.

Instead of having this helper, a configuration now has a mandatory
`target_byte_order` property.

Because of the trace type's default byte order role in
`barectf-bitfield.h`, it's more fundamental than a mere "default": it's
actually the byte order you expect the target system to have. In other
words, you could not make the trace type's default byte order big-endian
to when your target system is a little-endian machine: the bit array
serialization process will fail at tracing time. Therefore I found that
the "default byte order" term was misleading.

This change brings a challenge, however: when you don't specify a group
of stream type or trace type features, or when you specify
`barectf.DEFAULT_FIELD_TYPE` for a given feature field type, which byte
order should the automatically created integer field type(s) have?

My solution is to add an optional default byte order parameter to each
constructor which _could_ create an integer field type (recursively). As
soon as this is going to happen, the default byte order must not be
`None`. For example, when you create a `barectf.StreamTypeEventFeatures`
object, you can use `barectf.DEFAULT_FIELD_TYPE`, but you must also pass
a default byte order:

    features = barectf.StreamTypeEventFeatures(barectf.DEFAULT_FIELD_TYPE,
                                               default_byte_order=barectf.ByteOrder.LITTLE_ENDIAN)

This can also be when you create a stream type or a trace type, as if
you don't pass any feature object, then the constructor creates one for
you, which eventually creates default field types. For example:

    trace_type = barectf.TraceType(my_stream_types,
                                   default_byte_order=barectf.ByteOrder.BIG_ENDIAN)

This design is not super elegant, but it's a compromise for the
constructors to have everything they need to create full integer field
types. This is also why the `byte_order` property of a bit array field
type is now mandatory; there's no (peculiar) temporary state where it
remains `None` until the complete trace type exists.

I thought about making the target byte order little-endian by default,
for example, but considering that barectf is used to generate tracers
for embedded and bare-metal systems, I found that solution too
indiscriminate.

In a barectf 3 YAML configuration file:

* The trace type's `$default-byte-order` is removed.

* There's a new, mandatory `target-byte-order` configuration property.

* You can still not specify any bit array field type byte order: the
  parser uses the configuration's target byte order in that case.

A barectf 2 YAML trace type's `byte-order` property (which is already
mandatory) is copied as the v3 configuration node's `target-byte-order`
property.

`bitfield.h.j2` and `metadata.j2` are changed to use the configuration's
target byte order instead of the trace type's default byte order.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoFix: _effective_config_file(): get root node to have the YAML tag
Philippe Proulx [Fri, 4 Sep 2020 01:03:02 +0000 (21:03 -0400)] 
Fix: _effective_config_file(): get root node to have the YAML tag

The `config_node` property of a `config_parse_v3._Parser` object returns
an ordered dict; what we want for _yaml_dump() to write the barectf 3
YAML tag is a `_ConfigNodeV3` which is (now) the
`config_parse_common.root_node` property.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoUse pytest as the testing system instead of Bats
Philippe Proulx [Thu, 3 Sep 2020 20:50:57 +0000 (16:50 -0400)] 
Use pytest as the testing system instead of Bats

pytest has several benefits:

* The tests are written in Python, so I can directly import `barectf`
  and use the package to make barectf operations instead of using the
  CLI.

  Therefore I can test the package itself.

  Also, there's a single Python interpreter instance, so you don't pay
  the Python boot up cost for each test.

* With `pytest-xdist` (also a new dev dependency), you can run tests
  in parallel, for example:

      $ poetry run py.test -v -n4 tests

* It's very well known by the Python community, whereas Bats is not that
  popular.

All in all, this makes the testing process really faster (15 seconds on
my machine; used to be 1m45). It's also somewhat more enjoyable to write
Python code than Bash code to create new tests.

This patch only converts current tests using Bats to pytest.

`tests/config/yaml/conftest.py` defines a pytest fixture named
`config_fail_test`. A test receiving this fixture gets a function which
accepts a `request` fixture as well as a relative path to a YAML file
(from the test file's directory), without the `.yaml` extension. The
testing function uses the barectf API directly to try to create a
configuration from the YAML file, ensuring that
`barectf._ConfigurationParseError` is raised in the process.

`tests/config/yaml/2/test_pass_everything.py` does what
`tests/config/2/pass/everything/pass.bats` used to do, using Python's
`subprocess` module to run the C compiler and `nm` (both of which you
can override with the `CC` and `NM` environment variables).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf: fix Flake8 errors
Philippe Proulx [Thu, 3 Sep 2020 20:45:06 +0000 (16:45 -0400)] 
barectf: fix Flake8 errors

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoREADME.md: indicate that this README might be incorrect before v3
Philippe Proulx [Thu, 3 Sep 2020 20:38:59 +0000 (16:38 -0400)] 
README.md: indicate that this README might be incorrect before v3

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agotox.ini: add `mypy` environment
Philippe Proulx [Thu, 3 Sep 2020 19:10:25 +0000 (15:10 -0400)] 
tox.ini: add `mypy` environment

`pyproject.toml` has the `mypy` dev dependency; tox uses it.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoUse Poetry to manage Pylint dev dependency
Philippe Proulx [Thu, 3 Sep 2020 19:07:49 +0000 (15:07 -0400)] 
Use Poetry to manage Pylint dev dependency

Trying not to have both tox and Poetry manage dev dependencies.

tox always runs `poetry install` and then runs a command installed by
Poetry.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoUse Poetry to manage Flake8 dev dependency
Philippe Proulx [Thu, 3 Sep 2020 19:03:58 +0000 (15:03 -0400)] 
Use Poetry to manage Flake8 dev dependency

Trying not to have both tox and Poetry managing dev dependencies.

tox always runs `poetry install` and then runs a command installed by
Poetry.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agopoetry.lock: update
Philippe Proulx [Thu, 3 Sep 2020 17:23:59 +0000 (13:23 -0400)] 
poetry.lock: update

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agocodegen.py, cgen.py: fix Pylint errors/warnings
Philippe Proulx [Thu, 3 Sep 2020 17:19:01 +0000 (13:19 -0400)] 
codegen.py, cgen.py: fix Pylint errors/warnings

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agocgen.py: add type hints
Philippe Proulx [Thu, 3 Sep 2020 17:16:42 +0000 (13:16 -0400)] 
cgen.py: add type hints

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agocodegen.py: add type hints
Philippe Proulx [Thu, 3 Sep 2020 16:09:18 +0000 (12:09 -0400)] 
codegen.py: add type hints

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agoReorganize JSON schemas under `barectf/schemas/config`
Philippe Proulx [Thu, 3 Sep 2020 16:03:35 +0000 (12:03 -0400)] 
Reorganize JSON schemas under `barectf/schemas/config`

Instead of:

    2/
      config/
    3/
      config/
    common/
      config/

Use:

    config/
      2/
      3/
      common/

This requires less inodes.

On a more serious note, barectf might have schemas for other things than
configuration in the future, so all the existing schemas currently
really belong to the configuration domain.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
3 years agobarectf.c.j2: use single return points
Philippe Proulx [Thu, 3 Sep 2020 15:55:32 +0000 (11:55 -0400)] 
barectf.c.j2: use single return points

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
This page took 0.045026 seconds and 4 git commands to generate.