Add parameter validation utility
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 4 Oct 2019 20:16:47 +0000 (16:16 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 11 Oct 2019 14:50:09 +0000 (10:50 -0400)
commitd0d4e0ed487ea23aaf0d023513c0a4d86901b79b
tree28b71748ca96d8af9cfa19aab857b0a798436673
parentdeb34b1f2c9e32a082d219b2d80b017fd0fa0fc6
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.025205 seconds and 4 git commands to generate.