Add parameter validation utility
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 4 Oct 2019 20:16:47 +0000 (16:16 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 17 Oct 2019 16:13:26 +0000 (12:13 -0400)
commitb7fa35fce415b33207a9eba111069ed31ef122a0
tree00ec390c144cd8a4e4b8e1ceefc28d3215d4bc74
parentabb3ec0723e65c1c624178312367dff584cec214
Add parameter validation utility

This patch adds a utility to help component classes validate the
parameters they receive (either for component initialization or query).

The definition of what constitutes valid parameters for a component
class is done by filling C structures describing each expected value
(see included test for examples).

Since this is made for parameter validation, and not general-purpose
value validation, the entry point bt_param_validation_validate assumes
that the root value is a map (and is therefore validated as a map, as
described below).

For parameters that have simple validation rules, it is enough to fill
the `type` field of bt_param_validation_value_descr, and perhaps the
additional fields associated to the type.

For array values, the description includes the minimum and maximum sizes
the array can have (use BT_PARAM_VALIDATION_INFINITE if there's no max).
It also includes a pointer to the description of its element values.

For map values, the description includes a list of possible map entries.
For each entry, we have the key, whether the entry is mandatory and the
description of the value.

For string values, the description may include a list of choices.  If it
does, the string value must be in this list.

For parameters that have more complex validation rules, for example
parameters whose value can be of different types, it is possible to set
the `validation_func` field.  If it is set, this function will be called
and is responsible for validating the value.

If the validation fails, an error message is produced, which includes
the full scope where the error occured (again, see the test for an
example).

Change-Id: If729415fdd8ce97fa94b79e8bf79461e46ebf2bc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2119
Tested-by: jenkins <jenkins@lttng.org>
configure.ac
src/param-parse/param-parse.h
src/plugins/common/Makefile.am
src/plugins/common/param-validation/Makefile.am [new file with mode: 0644]
src/plugins/common/param-validation/param-validation.c [new file with mode: 0644]
src/plugins/common/param-validation/param-validation.h [new file with mode: 0644]
tests/Makefile.am
tests/param-validation/Makefile.am [new file with mode: 0644]
tests/param-validation/test_param_validation.c [new file with mode: 0644]
This page took 0.024972 seconds and 4 git commands to generate.