libgpiod v2: rewrite tests for the C library
Subsystems (2)
v2 cover libgpiod v2: rewrite tests for the C library
This series contains two patches that continue the work on libgpiod v2 API, a patch adding a switch to the configure script that allows to compile in gcov profiling into the test executable and finally a big patch that replaces the old test suite for libgpiod v1 based on gpio-mockup with a one covering around 95% of the libgpiod v2 code based on the upcoming gpio-sim module.
Bartosz Golaszewski (4):
line-request: don't accept NULL line config
line-config: expose the override logic to users
build: add a configure option for enabling gcov profiling
tests: rewrite core C tests using libgpiosim
.gitignore | 4 + configure.ac | 18 +- include/gpiod.h | 514 ++++++++++------ lib/Makefile.am | 1 + lib/line-config.c | 731 ++++++++++++++--------- tests/Makefile.am | 21 +- tests/gpiod-test-helpers.c | 49 ++ tests/gpiod-test-helpers.h | 131 ++++ tests/gpiod-test-sim.c | 303 ++++++++++ tests/gpiod-test-sim.h | 42 ++ tests/gpiod-test.c | 233 +------- tests/gpiod-test.h | 81 +-- tests/gpiosim/gpiosim.c | 1 + tests/mockup/Makefile.am | 11 - tests/mockup/gpio-mockup.c | 496 ---------------- tests/mockup/gpio-mockup.h | 36 -- tests/tests-chip.c | 282 ++++----- tests/tests-edge-event.c | 420 +++++++++++++ tests/tests-event.c | 908 ---------------------------- tests/tests-info-event.c | 301 ++++++++++ tests/tests-line-config.c | 408 +++++++++++++ tests/tests-line-info.c | 316 ++++++++++ tests/tests-line-request.c | 421 +++++++++++++ tests/tests-line.c | 1091 ---------------------------------- tests/tests-misc.c | 86 ++- tests/tests-request-config.c | 90 +++ tools/gpioget.c | 6 +- tools/gpiomon.c | 6 +- tools/gpioset.c | 9 +- 29 files changed, 3544 insertions(+), 3472 deletions(-) create mode 100644 tests/gpiod-test-helpers.c create mode 100644 tests/gpiod-test-helpers.h create mode 100644 tests/gpiod-test-sim.c create mode 100644 tests/gpiod-test-sim.h delete mode 100644 tests/mockup/Makefile.am delete mode 100644 tests/mockup/gpio-mockup.c delete mode 100644 tests/mockup/gpio-mockup.h create mode 100644 tests/tests-edge-event.c delete mode 100644 tests/tests-event.c create mode 100644 tests/tests-info-event.c create mode 100644 tests/tests-line-config.c create mode 100644 tests/tests-line-info.c create mode 100644 tests/tests-line-request.c delete mode 100644 tests/tests-line.c create mode 100644 tests/tests-request-config.c
Signature · 1 line
2.30.1
PATCH v2 1/4 line-request: don't accept NULL line config
While it was initially agreed that NULL line_config passed to gpiod_chip_request_lines() would result in lines being requested with default config (just like a newly created struct gpiod_line_config), I believe this is unintuitive in the context of all other functions in the C library not being NULL-aware (as advertised in one of the first paragraphs of the documentation) and should be changed to make both config structures mandatory.
This is C after all and it should be both explicit and spartan. :)
--- include/gpiod.h | 4 +--- lib/line-config.c | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-)
include/gpiod.h +1 -3
@@ -173,11 +173,9 @@ int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name);* @brief Request a set of lines for exclusive usage. * @param chip GPIO chip object. * @param req_cfg Request config object. -* @param line_cfg Line config object. May be NULL. +* @param line_cfg Line config object. * @return New line request object or NULL if an error occurred. The request * must be released by the caller using ::gpiod_line_request_release. -* @note If line_cfg is NULL, lines will be requested in input mode with no -* additional parameters set. */ struct gpiod_line_request * gpiod_chip_request_lines(struct gpiod_chip *chip,
lib/line-config.c +0 -5
@@ -903,11 +903,6 @@ int gpiod_line_config_to_kernel(struct gpiod_line_config *config,uint64_t mask, values;int ret; -if (!config) { - cfgbuf->flags =GPIO_V2_LINE_FLAG_INPUT ; -return 0 ; - } -if (config->too_complex) goto err_2big;
Signature · 1 line
2.30.1
Re: [libgpiod v2][PATCH 1/4] line-request: don't accept NULL line config
Quoted 10 lines · Bartosz Golaszewski
While it was initially agreed that NULL
line_configpassed togpiod_chip_request_lines()would result in lines being requested with default config (just like a newly created structgpiod_line_config), I believe this is unintuitive in the context of all other functions in the C library not being NULL-aware (as advertised in one of the first paragraphs of the documentation) and should be changed to make both config structures mandatory.This is C after all and it should be both explicit and spartan. :)
Fair enough.
Quoted 42 lines
Signed-off-by Bartosz Golaszewski <[email protected]>--- include/gpiod.h | 4 +--- lib/line-config.c | 5 ----- 2 files changed, 1 insertion(+), 8 deletions(-)include/gpiod.h +1
-3@@ -173,11 +173,9 @@ int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name);* @brief Request a set of lines for exclusive usage. * @param chip GPIO chip object. * @param req_cfg Request config object. -* @param line_cfg Line config object. May be NULL. +* @param line_cfg Line config object. * @return New line request object or NULL if an error occurred. The request * must be released by the caller using ::gpiod_line_request_release. -* @note If line_cfg is NULL, lines will be requested in input mode with no -* additional parameters set. */ struct gpiod_line_request * gpiod_chip_request_lines(struct gpiod_chip *chip,lib/line-config.c +0
-5@@ -903,11 +903,6 @@ int gpiod_line_config_to_kernel(struct gpiod_line_config *config,uint64_t mask, values;int ret; -if (!config) { - cfgbuf->flags =GPIO_V2_LINE_FLAG_INPUT ; -return 0 ; - } -if (config->too_complex) goto err_2big;Signature · 1 line
2.30.1
PATCH v2 2/4 line-config: expose the override logic to users
In reply to Bartosz GolaszewskiWe've already added getters for line-config but without exposing some parts of the internal logic of the object, the user can't really get the full picture and inspect the contents. This patch reworks the accessors further by providing access to the underlying override mechanism.
For every setting, we expose a getter and setter for the default value as well as a set of four functions for setting, getting, clearing and checking per-offset overrides.
An override can initially have the same value as the defaults but will retain the overridden value should the defaults change.
We also complete the API by providing functions that allow to identify offsets for which at least one setting is overriden.
This way the caller can fully inspect the line_config and high-level language bindings can provide stringification methods.
While at it: we fix a couple bugs in the implementation of struct line_config.
--- include/gpiod.h | 510 +++++++++++++++++++++----------- lib/line-config.c | 726 +++++++++++++++++++++++++++++----------------- tools/gpioget.c | 6 +- tools/gpiomon.c | 6 +- tools/gpioset.c | 9 +- 5 files changed, 813 insertions(+), 444 deletions(-)
include/gpiod.h +341 -169
@@ -450,12 +450,38 @@ gpiod_info_event_get_line_info(struct gpiod_info_event *event);* * The line-config object stores the configuration for lines that can be used * in two cases: when making a line request and when reconfiguring a set of -* already requested lines. The mutators for the line request don't return -* errors. If the set of options is too complex to be translated into kernel -* uAPI structures - the error will be returned at the time of the request or -* reconfiguration. If an invalid value was passed to any of the getters - the -* default value will be silently used instead. Each option can be set -* globally, for a single line offset or for multiple line offsets. +* already requested lines. +* +* A new line-config object is instantiated containing a set of sane defaults +* for all supported configuration settings. Those defaults can be modified by +* the caller. Default values can be overridden by applying different values +* for specific line offsets. When making a request or reconfiguring an +* existing one, the overridden settings for specific offsets will be taken +* into account first and for every other offset and setting the defaults will +* be used. +* +* For every setting, the mutators come in three flavors: one setting the +* default value (to which we fallback for every offset not explicitly +* overridden), one setting an override for a single offset and one that +* overrides settings for a subset of offsets. +* +* The mutators don't return errors. If the set of options is too complex to +* be translated into kernel uAPI structures - the error will be returned at +* the time of the request or reconfiguration. If an invalid value was passed +* to any of the mutators - the default value will be silently used instead. +* +* We also expose getters - these come in two flavors for every settings: one +* that returns the value that would have been used for given offset if the +* request was made at this moment and one that always returns the default +* value. +* +* It's important to not think of the offsets used in the offset->value mapping +* as linked to actual hardware offsets of the lines exposed by a GPIO chip as +* config objects live separately from any chips and are only analyzed at the +* time the request is being made. +* +* For simple cases the offsets can be entirely ignored when preparing the +* line configuration. */ /**
@@ -480,329 +506,424 @@ void gpiod_line_config_free(struct gpiod_line_config *config);void gpiod_line_config_reset (struct gpiod_line_config *config);/** -* @brief Set the direction of all lines. +* @brief Set the default direction setting. * @param config Line config object. * @param direction New direction. */ -void gpiod_line_config_set_direction (struct gpiod_line_config *config, -int direction); +void gpiod_line_config_set_direction_default (struct gpiod_line_config *config, +int direction);/** -* @brief Set the direction for a single line at given offset. +* @brief Set the direction override at given offset. * @param config Line config object. * @param direction New direction. -* @param offset Offset of the line for which to set the direction. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_direction_offset (struct gpiod_line_config *config, -int direction,unsigned int offset); +void gpiod_line_config_set_direction_override (struct gpiod_line_config *config, +int direction, +unsigned int offset);/** -* @brief Set the direction for a subset of lines. +* @brief Clear the direction override at given offset. * @param config Line config object. -* @param direction New direction. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the direction. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void gpiod_line_config_set_direction_subset (struct gpiod_line_config *config, -int direction, -unsigned int num_offsets, -const unsigned int *offsets); +void +gpiod_line_config_clear_direction_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the direction setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if direction is overridden at this offset, false otherwise. +*/ +bool gpiod_line_config_direction_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the direction setting for a given line. +* @brief Get the default direction setting. +* @param config Line config object. +* @return Direction setting that would have been used for any non-overridden +* offset. +*/ +int gpiod_line_config_get_direction_default (struct gpiod_line_config *config); + +/** +* @brief Get the direction setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the direction setting. * @return Direction setting that would have been used for given offset if the * config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_direction (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_direction_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set the edge event detection for all lines. +* @brief Set the default edge event detection. * @param config Line config object. * @param edge Type of edge events to detect. */ -void gpiod_line_config_set_edge_detection (struct gpiod_line_config *config, -int edge); +void +gpiod_line_config_set_edge_detection_default (struct gpiod_line_config *config, +int edge);/** -* @brief Set the edge event detection for a single line at given offset. +* @brief Set the edge detection override at given offset. * @param config Line config object. -* @param edge Type of edge events to detect. -* @param offset Offset of the line for which to set the edge detection. +* @param edge New edge detection setting. +* @param offset Offset of the line for which to set the override. */ void -gpiod_line_config_set_edge_detection_offset (struct gpiod_line_config *config, -int edge,unsigned int offset); +gpiod_line_config_set_edge_detection_override (struct gpiod_line_config *config, +int edge,unsigned int offset);/** -* @brief Set the edge event detection for a subset of lines. +* @brief Clear the edge detection override at given offset. * @param config Line config object. -* @param edge Type of edge events to detect. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the edge detection. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ void -gpiod_line_config_set_edge_detection_subset (struct gpiod_line_config *config, -int edge,unsigned int num_offsets, -const unsigned int *offsets); +gpiod_line_config_clear_edge_detection_override ( +struct gpiod_line_config *config,unsigned int offset); + +/** +* @brief Check if the edge detection setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if edge detection is overridden at this offset, false otherwise. +*/ +bool +gpiod_line_config_edge_detection_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the edge event detection setting for a given line. +* @brief Get the default edge detection setting. +* @param config Line config object. +* @return Edge detection setting that would have been used for any offset not +* assigned its own direction value. +*/ +int +gpiod_line_config_get_edge_detection_default (struct gpiod_line_config *config); + +/** +* @brief Get the edge event detection setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the edge event detection setting. * @return Edge event detection setting that would have been used for given * offset if the config object was used in a request at the time of * the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_edge_detection (struct gpiod_line_config *config, -unsigned int offset); +int +gpiod_line_config_get_edge_detection_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set the bias of all lines. +* @brief Set the default bias setting. * @param config Line config object. * @param bias New bias. */ -void gpiod_line_config_set_bias (struct gpiod_line_config *config,int bias); +void gpiod_line_config_set_bias_default (struct gpiod_line_config *config, +int bias);/** -* @brief Set the bias for a single line at given offset. +* @brief Set the bias override at given offset. * @param config Line config object. -* @param bias New bias. -* @param offset Offset of the line for which to set the bias. +* @param bias New bias setting. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_bias_offset (struct gpiod_line_config *config, -int bias,unsigned int offset); +void gpiod_line_config_set_bias_override (struct gpiod_line_config *config, +int bias,unsigned int offset);/** -* @brief Set the bias for a subset of lines. +* @brief Clear the bias override at given offset. * @param config Line config object. -* @param bias New bias. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the bias. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. +*/ +void gpiod_line_config_clear_bias_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the bias setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if bias is overridden at this offset, false otherwise. +*/ +bool gpiod_line_config_bias_is_overridden (struct gpiod_line_config *config, +unsigned int offset); +/** +* @brief Get the default bias setting. +* @param config Line config object. +* @return Bias setting that would have been used for any offset not assigned +* its own direction value. */ -void gpiod_line_config_set_bias_subset (struct gpiod_line_config *config, -int bias,unsigned int num_offsets, -const unsigned int *offsets); +int gpiod_line_config_get_bias_default (struct gpiod_line_config *config);/** -* @brief Get the bias setting for a given line. +* @brief Get the bias setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the bias setting. * @return Bias setting that would have been used for given offset if the * config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_bias (struct gpiod_line_config *config, +int gpiod_line_config_get_bias_offset (struct gpiod_line_config *config,unsigned int offset);/** -* @brief Set the drive of all lines. +* @brief Set the default drive setting. * @param config Line config object. * @param drive New drive. */ -void gpiod_line_config_set_drive (struct gpiod_line_config *config,int drive); +void gpiod_line_config_set_drive_default (struct gpiod_line_config *config, +int drive);/** -* @brief Set the drive for a single line at given offset. +* @brief Set the drive override at given offset. * @param config Line config object. -* @param drive New drive. -* @param offset Offset of the line for which to set the drive. +* @param drive New drive setting. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_drive_offset (struct gpiod_line_config *config, -int drive,unsigned int offset); +void gpiod_line_config_set_drive_override (struct gpiod_line_config *config, +int drive,unsigned int offset);/** -* @brief Set the drive for a subset of lines. +* @brief Clear the drive override at given offset. * @param config Line config object. -* @param drive New drive. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the drive. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void gpiod_line_config_set_drive_subset (struct gpiod_line_config *config, -int drive,unsigned int num_offsets, -const unsigned int *offsets); +void gpiod_line_config_clear_drive_override (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the drive setting for a given line. +* @brief Check if the drive setting is overridden at given offset. * @param config Line config object. -* @param offset Line offset for which to read the drive setting. -* @return Drive setting that would have been used for given offset if the -* config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. +* @param offset Offset of the line for which to check the override. +* @return True if drive is overridden at this offset, false otherwise. */ -int gpiod_line_config_get_drive (struct gpiod_line_config *config, -unsigned int offset); +bool gpiod_line_config_drive_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set all lines as active-low. +* @brief Get the default drive setting. * @param config Line config object. +* @return Drive setting that would have been used for any offset not assigned +* its own direction value. */ -void gpiod_line_config_set_active_low (struct gpiod_line_config *config); +int gpiod_line_config_get_drive_default (struct gpiod_line_config *config);/** -* @brief Set a single line as active-low. +* @brief Get the drive setting for a given offset. * @param config Line config object. -* @param offset Offset of the line for which to set the active setting. +* @param offset Line offset for which to read the drive setting. +* @return Drive setting that would have been used for given offset if the +* config object was used in a request at the time of the call. */ -void gpiod_line_config_set_active_low_offset (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_drive_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set a subset of lines as active-low. +* @brief Set lines to active-low by default. * @param config Line config object. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the active setting. +* @param active_low New active-low setting. */ -void gpiod_line_config_set_active_low_subset (struct gpiod_line_config *config, -unsigned int num_offsets, -const unsigned int *offsets); +void gpiod_line_config_set_active_low_default (struct gpiod_line_config *config, +bool active_low);/** -* @brief Check if the line at given offset was configured as active-low. +* @brief Override the active-low setting at given offset. * @param config Line config object. -* @param offset Line offset for which to read the active-low setting. -* @return Active-low setting that would have been used for given offset if the -* config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. +* @param active_low New active-low setting. +* @param offset Offset of the line for which to set the override. */ -bool gpiod_line_config_get_active_low (struct gpiod_line_config *config, -unsigned int offset); +void gpiod_line_config_set_active_low_override (struct gpiod_line_config *config, +bool active_low, +unsigned int offset);/** -* @brief Set all lines as active-high. +* @brief Clear the active-low override at given offset. * @param config Line config object. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void gpiod_line_config_set_active_high (struct gpiod_line_config *config); +void +gpiod_line_config_clear_active_low_override (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set a single line as active-high. +* @brief Check if the active-low setting is overridden at given offset. * @param config Line config object. -* @param offset Offset of the line for which to set the active setting. +* @param offset Offset of the line for which to check the override. +* @return True if active-low is overridden at this offset, false otherwise. */ -void gpiod_line_config_set_active_high_offset (struct gpiod_line_config *config, -unsigned int offset); +bool +gpiod_line_config_active_low_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set a subset of lines as active-high. +* @brief Check if active-low is the default setting. * @param config Line config object. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the active setting. +* @return Active-low setting that would have been used for any offset not +* assigned its own value. */ -void gpiod_line_config_set_active_high_subset (struct gpiod_line_config *config, -unsigned int num_offsets, -const unsigned int *offsets); +bool gpiod_line_config_get_active_low_default (struct gpiod_line_config *config);/** -* @brief Set the debounce period for all lines. +* @brief Check if the line at given offset was configured as active-low. * @param config Line config object. -* @param period New debounce period. Disables debouncing if 0. +* @param offset Line offset for which to read the active-low setting. +* @return Active-low setting that would have been used for given offset if the +* config object was used in a request at the time of the call. */ -void gpiod_line_config_set_debounce_period_us (struct gpiod_line_config *config, -unsigned long period); +bool gpiod_line_config_get_active_low_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set the debounce period for a single line at given offset. +* @brief Set the default debounce period. * @param config Line config object. * @param period New debounce period. Disables debouncing if 0. -* @param offset Offset of the line for which to set the debounce period. +*/ +void gpiod_line_config_set_debounce_period_us_default ( +struct gpiod_line_config *config,unsigned long period); + +/** +* @brief Override the debounce period setting at given offset. +* @param config Line config object. +* @param period New debounce period in microseconds. +* @param offset Offset of the line for which to set the override. */ void -gpiod_line_config_set_debounce_period_us_offset ( +gpiod_line_config_set_debounce_period_us_override (struct gpiod_line_config *config,unsigned long period,unsigned int offset);/** -* @brief Set the debounce period for a subset of lines. +* @brief Clear the debounce period override at given offset. * @param config Line config object. -* @param period New debounce period. Disables debouncing if 0. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the debounce period. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void -gpiod_line_config_set_debounce_period_us_subset ( +void gpiod_line_config_clear_debounce_period_us_override (struct gpiod_line_config *config, -unsigned long period, -unsigned int num_offsets, -const unsigned int *offsets); +unsigned int offset); + +/** +* @brief Check if the debounce period setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if debounce period is overridden at this offset, false +* otherwise. +*/ +bool gpiod_line_config_debounce_period_us_is_overridden ( +struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Get the default debounce period. +* @param config Line config object. +* @return Debounce period that would have been used for any offset not +* assigned its own debounce period. 0 if not debouncing is disabled. +*/ +unsigned long gpiod_line_config_get_debounce_period_us_default ( +struct gpiod_line_config *config);/** -* @brief Get the debounce period for a given line. +* @brief Get the debounce period for a given offset. * @param config Line config object. * @param offset Line offset for which to read the debounce period. * @return Debounce period that would have been used for given offset if the -* config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. +* config object was used in a request at the time of the call. 0 if +* debouncing is disabled. */ unsigned long -gpiod_line_config_get_debounce_us_period (struct gpiod_line_config *config, -unsigned int offset); +gpiod_line_config_get_debounce_period_us_offset ( +struct gpiod_line_config *config,unsigned int offset);/** -* @brief Set the event timestamp clock for all lines. +* @brief Set the default event timestamp clock. * @param config Line config object. * @param clock New clock to use. */ -void gpiod_line_config_set_event_clock (struct gpiod_line_config *config, -int clock); +void gpiod_line_config_set_event_clock_default (struct gpiod_line_config *config, +int clock);/** -* @brief Set the event clock for a single line at given offset. +* @brief Override the event clock setting at given offset. * @param config Line config object. * @param clock New event clock to use. -* @param offset Offset of the line for which to set the event clock type. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_event_clock_offset (struct gpiod_line_config *config, -int clock,unsigned int offset); +void +gpiod_line_config_set_event_clock_override (struct gpiod_line_config *config, +int clock,unsigned int offset);/** -* @brief Set the event clock for a subset of lines. +* @brief Clear the event clock override at given offset. * @param config Line config object. -* @param clock New event clock to use. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the event clock type. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. +*/ +void +gpiod_line_config_clear_event_clock_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the event clock setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if event clock period is overridden at this offset, false +* otherwise. */ -void gpiod_line_config_set_event_clock_subset (struct gpiod_line_config *config, -int clock, -unsigned int num_offsets, -const unsigned int *offsets); +bool +gpiod_line_config_event_clock_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the event clock setting for a given line. +* @brief Get the default event clock setting. +* @param config Line config object. +* @return Event clock setting that would have been used for any offset not +* assigned its own direction value. +*/ +int gpiod_line_config_get_event_clock_default (struct gpiod_line_config *config); + +/** +* @brief Get the event clock setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the event clock setting. * @return Event clock setting that would have been used for given offset if * the config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_event_clock (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_event_clock_offset (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Set the default output value. +* @param config Line config object. +* @param value New value. +*/ +void +gpiod_line_config_set_output_value_default (struct gpiod_line_config *config, +int value);/** -* @brief Set the output value for a single offset. +* @brief Override the output value for a single offset. * @param config Line config object. * @param offset Offset of the line. * @param value Output value to set. */ -void gpiod_line_config_set_output_value (struct gpiod_line_config *config, -unsigned int offset,int value); +void +gpiod_line_config_set_output_value_override (struct gpiod_line_config *config, +unsigned int offset,int value);/** -* @brief Set the output values for a set of offsets. +* @brief Override the output values for multiple offsets. * @param config Line config object. -* @param num_values Number of offsets for which to set values. -* @param offsets Array of line offsets to set values for. +* @param num_values Number of offsets for which to override values. +* @param offsets Array of line offsets to override values for. * @param values Array of output values associated with the offsets passed in * the previous argument. */
@@ -811,14 +932,65 @@ void gpiod_line_config_set_output_values(struct gpiod_line_config *config,const unsigned int *offsets, const int *values); +/** +* @brief Clear the output value override at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. +*/ +void +gpiod_line_config_clear_output_value_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the output value is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if output value period is overridden at this offset, false +* otherwise. +*/ +bool +gpiod_line_config_output_value_is_overridden (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Get the default output value. +* @param config Line config object. +* @return Output value that would have been used for any offset not +* assigned its own output value. +*/ +int +gpiod_line_config_get_output_value_default (struct gpiod_line_config *config); +/** * @brief Get the output value configured for a given line. * @param config Line config object. * @param offset Line offset for which to read the value. -* @return 1 or 0 if the value was configured for this line, -1 otherwise. +* @return Output value that would have been used for given offset if the +* config object was used in a request at the time of the call. */ -int gpiod_line_config_get_output_value (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_output_value_offset (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Get the number of offsets for which this config object contains +* at least one setting that is different from the defaults. +* @param config Line config object. +* @return Number of offsets with at least one overridden setting. +*/ +unsigned int +gpiod_line_config_get_num_overridden_offsets (struct gpiod_line_config *config); + +/** +* @brief Get the offsets for which this config object contains at least one +* setting that is different from the defaults. +* @param config Line config object. +* @param offsets Array to store the offsets. Must hold at least the number +* of offsets returned by +* ::gpiod_line_config_get_num_overridden_offsets. +*/ +void gpiod_line_config_get_overridden_offsets (struct gpiod_line_config *config, +unsigned int *offsets);/** * @}
lib/line-config.c +461 -265
1,060 lines not on this page · raw message
tools/gpioget.c +3 -3
@@ -110,13 +110,13 @@ int main(int argc, char **argv)if (!line_cfg)die_perror ("unable to allocate the line config structure" ); -gpiod_line_config_set_direction (line_cfg, direction); +gpiod_line_config_set_direction_default (line_cfg, direction);if (bias) -gpiod_line_config_set_bias (line_cfg, bias); +gpiod_line_config_set_bias_default (line_cfg, bias);if (active_low) -gpiod_line_config_set_active_low (line_cfg); +gpiod_line_config_set_active_low_default (line_cfg, true); req_cfg =gpiod_request_config_new ();if (!req_cfg)
tools/gpiomon.c +3 -3
@@ -259,10 +259,10 @@ int main(int argc, char **argv)die_perror ("unable to allocate the line config structure" );if (bias) -gpiod_line_config_set_bias (line_cfg, bias); +gpiod_line_config_set_bias_default (line_cfg, bias);if (active_low) -gpiod_line_config_set_active_low (line_cfg); -gpiod_line_config_set_edge_detection (line_cfg, edge); +gpiod_line_config_set_active_low_default (line_cfg, true); +gpiod_line_config_set_edge_detection_default (line_cfg, edge); req_cfg =gpiod_request_config_new ();if (!req_cfg)
tools/gpioset.c +5 -4
@@ -296,12 +296,13 @@ int main(int argc, char **argv)die_perror ("unable to allocate the line config structure" );if (bias) -gpiod_line_config_set_bias (line_cfg, bias); +gpiod_line_config_set_bias_default (line_cfg, bias);if (drive) -gpiod_line_config_set_drive (line_cfg, drive); +gpiod_line_config_set_drive_default (line_cfg, drive);if (active_low) -gpiod_line_config_set_active_low (line_cfg); -gpiod_line_config_set_direction (line_cfg,GPIOD_LINE_DIRECTION_OUTPUT ); +gpiod_line_config_set_active_low_default (line_cfg, true); +gpiod_line_config_set_direction_default (line_cfg, +GPIOD_LINE_DIRECTION_OUTPUT );gpiod_line_config_set_output_values (line_cfg, num_lines, offsets, values);
Signature · 1 line
2.30.1
Re: [libgpiod v2][PATCH 2/4] line-config: expose the override logic to users
Quoted 50 lines · Bartosz Golaszewski
We've already added getters for line-config but without exposing some parts of the internal logic of the object, the user can't really get the full picture and inspect the contents. This patch reworks the accessors further by providing access to the underlying override mechanism.
For every setting, we expose a getter and setter for the default value as well as a set of four functions for setting, getting, clearing and checking per-offset overrides.
An override can initially have the same value as the defaults but will retain the overridden value should the defaults change.
We also complete the API by providing functions that allow to identify offsets for which at least one setting is overriden.
This way the caller can fully inspect the
line_configand high-level language bindings can provide stringification methods.While at it: we fix a couple bugs in the implementation of struct
line_config.Signed-off-by Bartosz Golaszewski <[email protected]>--- include/gpiod.h | 510 +++++++++++++++++++++----------- lib/line-config.c | 726 +++++++++++++++++++++++++++++----------------- tools/gpioget.c | 6 +- tools/gpiomon.c | 6 +- tools/gpioset.c | 9 +- 5 files changed, 813 insertions(+), 444 deletions(-)include/gpiod.h +5
-6@@ -450,12 +450,38 @@ gpiod_info_event_get_line_info(struct gpiod_info_event *event);* * The line-config object stores the configuration for lines that can be used * in two cases: when making a line request and when reconfiguring a set of -* already requested lines. The mutators for the line request don't return -* errors. If the set of options is too complex to be translated into kernel -* uAPI structures - the error will be returned at the time of the request or -* reconfiguration. If an invalid value was passed to any of the getters - the -* default value will be silently used instead. Each option can be set -* globally, for a single line offset or for multiple line offsets. +* already requested lines. +* +* A new line-config object is instantiated containing a set of sane defaults +* for all supported configuration settings. Those defaults can be modified by +* the caller. Default values can be overridden by applying different values
include/gpiod.h gpiod_info_event_get_line_info(struct gpiod_info_event *event); · line 467
Quoted 10 lines
include/gpiod.h +10
-0+* for specific line offsets. When making a request or reconfiguring an +* existing one, the overridden settings for specific offsets will be taken +* into account first and for every other offset and setting the defaults will +* be used. +* +* For every setting, the mutators come in three flavors: one setting the +* default value (to which we fallback for every offset not explicitly +* overridden), one setting an override for a single offset and one that +* overrides settings for a subset of offsets. +*
The subset flavour has been removed.
And you don't describe the clear flavour.
include/gpiod.h gpiod_info_event_get_line_info(struct gpiod_info_event *event); · line 477
Quoted 10 lines
include/gpiod.h +10
-0+* The mutators don't return errors. If the set of options is too complex to +* be translated into kernel uAPI structures - the error will be returned at +* the time of the request or reconfiguration. If an invalid value was passed +* to any of the mutators - the default value will be silently used instead. +* +* We also expose getters - these come in two flavors for every settings: one +* that returns the value that would have been used for given offset if the +* request was made at this moment and one that always returns the default +* value. +*
What about the is_overridden check?
include/gpiod.h gpiod_info_event_get_line_info(struct gpiod_info_event *event); · line 482
Quoted 5 lines
include/gpiod.h +5
-0+* It's important to not think of the offsets used in the offset->value mapping +* as linked to actual hardware offsets of the lines exposed by a GPIO chip as +* config objects live separately from any chips and are only analyzed at the +* time the request is being made. +*
I find this paragraph confusing, which is especially worrying as it starts with "It's important". You are trying to reiterate that operations on the config object are only manipulating the config object in memory and are not applied to hardware until the request/reconfigure?
Cos I read it as meaning there is some difference between the offsets used in line_config and the offsets on the chip. And there isn't.
include/gpiod.h gpiod_info_event_get_line_info(struct gpiod_info_event *event); · line 486
Quoted 4 lines
include/gpiod.h +2
-0+* For simple cases the offsets can be entirely ignored when preparing the +* line configuration. */
"simple cases" being where all lines have the same configuration so you can just use the default setters.
So say that instead of "simple cases", which is open to interpretation.
Cheers,
Kent.
Quoted 1,666 lines
include/gpiod.h +309
-163/** @@ -480,329 +506,424 @@ void gpiod_line_config_free(struct gpiod_line_config *config);void gpiod_line_config_reset (struct gpiod_line_config *config);/** -* @brief Set the direction of all lines. +* @brief Set the default direction setting. * @param config Line config object. * @param direction New direction. */ -void gpiod_line_config_set_direction (struct gpiod_line_config *config, -int direction); +void gpiod_line_config_set_direction_default (struct gpiod_line_config *config, +int direction);/** -* @brief Set the direction for a single line at given offset. +* @brief Set the direction override at given offset. * @param config Line config object. * @param direction New direction. -* @param offset Offset of the line for which to set the direction. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_direction_offset (struct gpiod_line_config *config, -int direction,unsigned int offset); +void gpiod_line_config_set_direction_override (struct gpiod_line_config *config, +int direction, +unsigned int offset);/** -* @brief Set the direction for a subset of lines. +* @brief Clear the direction override at given offset. * @param config Line config object. -* @param direction New direction. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the direction. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void gpiod_line_config_set_direction_subset (struct gpiod_line_config *config, -int direction, -unsigned int num_offsets, -const unsigned int *offsets); +void +gpiod_line_config_clear_direction_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the direction setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if direction is overridden at this offset, false otherwise. +*/ +bool gpiod_line_config_direction_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the direction setting for a given line. +* @brief Get the default direction setting. +* @param config Line config object. +* @return Direction setting that would have been used for any non-overridden +* offset. +*/ +int gpiod_line_config_get_direction_default (struct gpiod_line_config *config); + +/** +* @brief Get the direction setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the direction setting. * @return Direction setting that would have been used for given offset if the * config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_direction (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_direction_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set the edge event detection for all lines. +* @brief Set the default edge event detection. * @param config Line config object. * @param edge Type of edge events to detect. */ -void gpiod_line_config_set_edge_detection (struct gpiod_line_config *config, -int edge); +void +gpiod_line_config_set_edge_detection_default (struct gpiod_line_config *config, +int edge);/** -* @brief Set the edge event detection for a single line at given offset. +* @brief Set the edge detection override at given offset. * @param config Line config object. -* @param edge Type of edge events to detect. -* @param offset Offset of the line for which to set the edge detection. +* @param edge New edge detection setting. +* @param offset Offset of the line for which to set the override. */ void -gpiod_line_config_set_edge_detection_offset (struct gpiod_line_config *config, -int edge,unsigned int offset); +gpiod_line_config_set_edge_detection_override (struct gpiod_line_config *config, +int edge,unsigned int offset);/** -* @brief Set the edge event detection for a subset of lines. +* @brief Clear the edge detection override at given offset. * @param config Line config object. -* @param edge Type of edge events to detect. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the edge detection. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ void -gpiod_line_config_set_edge_detection_subset (struct gpiod_line_config *config, -int edge,unsigned int num_offsets, -const unsigned int *offsets); +gpiod_line_config_clear_edge_detection_override ( +struct gpiod_line_config *config,unsigned int offset); + +/** +* @brief Check if the edge detection setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if edge detection is overridden at this offset, false otherwise. +*/ +bool +gpiod_line_config_edge_detection_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the edge event detection setting for a given line. +* @brief Get the default edge detection setting. +* @param config Line config object. +* @return Edge detection setting that would have been used for any offset not +* assigned its own direction value. +*/ +int +gpiod_line_config_get_edge_detection_default (struct gpiod_line_config *config); + +/** +* @brief Get the edge event detection setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the edge event detection setting. * @return Edge event detection setting that would have been used for given * offset if the config object was used in a request at the time of * the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_edge_detection (struct gpiod_line_config *config, -unsigned int offset); +int +gpiod_line_config_get_edge_detection_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set the bias of all lines. +* @brief Set the default bias setting. * @param config Line config object. * @param bias New bias. */ -void gpiod_line_config_set_bias (struct gpiod_line_config *config,int bias); +void gpiod_line_config_set_bias_default (struct gpiod_line_config *config, +int bias);/** -* @brief Set the bias for a single line at given offset. +* @brief Set the bias override at given offset. * @param config Line config object. -* @param bias New bias. -* @param offset Offset of the line for which to set the bias. +* @param bias New bias setting. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_bias_offset (struct gpiod_line_config *config, -int bias,unsigned int offset); +void gpiod_line_config_set_bias_override (struct gpiod_line_config *config, +int bias,unsigned int offset);/** -* @brief Set the bias for a subset of lines. +* @brief Clear the bias override at given offset. * @param config Line config object. -* @param bias New bias. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the bias. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. +*/ +void gpiod_line_config_clear_bias_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the bias setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if bias is overridden at this offset, false otherwise. +*/ +bool gpiod_line_config_bias_is_overridden (struct gpiod_line_config *config, +unsigned int offset); +/** +* @brief Get the default bias setting. +* @param config Line config object. +* @return Bias setting that would have been used for any offset not assigned +* its own direction value. */ -void gpiod_line_config_set_bias_subset (struct gpiod_line_config *config, -int bias,unsigned int num_offsets, -const unsigned int *offsets); +int gpiod_line_config_get_bias_default (struct gpiod_line_config *config);/** -* @brief Get the bias setting for a given line. +* @brief Get the bias setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the bias setting. * @return Bias setting that would have been used for given offset if the * config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_bias (struct gpiod_line_config *config, +int gpiod_line_config_get_bias_offset (struct gpiod_line_config *config,unsigned int offset);/** -* @brief Set the drive of all lines. +* @brief Set the default drive setting. * @param config Line config object. * @param drive New drive. */ -void gpiod_line_config_set_drive (struct gpiod_line_config *config,int drive); +void gpiod_line_config_set_drive_default (struct gpiod_line_config *config, +int drive);/** -* @brief Set the drive for a single line at given offset. +* @brief Set the drive override at given offset. * @param config Line config object. -* @param drive New drive. -* @param offset Offset of the line for which to set the drive. +* @param drive New drive setting. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_drive_offset (struct gpiod_line_config *config, -int drive,unsigned int offset); +void gpiod_line_config_set_drive_override (struct gpiod_line_config *config, +int drive,unsigned int offset);/** -* @brief Set the drive for a subset of lines. +* @brief Clear the drive override at given offset. * @param config Line config object. -* @param drive New drive. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the drive. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void gpiod_line_config_set_drive_subset (struct gpiod_line_config *config, -int drive,unsigned int num_offsets, -const unsigned int *offsets); +void gpiod_line_config_clear_drive_override (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the drive setting for a given line. +* @brief Check if the drive setting is overridden at given offset. * @param config Line config object. -* @param offset Line offset for which to read the drive setting. -* @return Drive setting that would have been used for given offset if the -* config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. +* @param offset Offset of the line for which to check the override. +* @return True if drive is overridden at this offset, false otherwise. */ -int gpiod_line_config_get_drive (struct gpiod_line_config *config, -unsigned int offset); +bool gpiod_line_config_drive_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set all lines as active-low. +* @brief Get the default drive setting. * @param config Line config object. +* @return Drive setting that would have been used for any offset not assigned +* its own direction value. */ -void gpiod_line_config_set_active_low (struct gpiod_line_config *config); +int gpiod_line_config_get_drive_default (struct gpiod_line_config *config);/** -* @brief Set a single line as active-low. +* @brief Get the drive setting for a given offset. * @param config Line config object. -* @param offset Offset of the line for which to set the active setting. +* @param offset Line offset for which to read the drive setting. +* @return Drive setting that would have been used for given offset if the +* config object was used in a request at the time of the call. */ -void gpiod_line_config_set_active_low_offset (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_drive_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set a subset of lines as active-low. +* @brief Set lines to active-low by default. * @param config Line config object. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the active setting. +* @param active_low New active-low setting. */ -void gpiod_line_config_set_active_low_subset (struct gpiod_line_config *config, -unsigned int num_offsets, -const unsigned int *offsets); +void gpiod_line_config_set_active_low_default (struct gpiod_line_config *config, +bool active_low);/** -* @brief Check if the line at given offset was configured as active-low. +* @brief Override the active-low setting at given offset. * @param config Line config object. -* @param offset Line offset for which to read the active-low setting. -* @return Active-low setting that would have been used for given offset if the -* config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. +* @param active_low New active-low setting. +* @param offset Offset of the line for which to set the override. */ -bool gpiod_line_config_get_active_low (struct gpiod_line_config *config, -unsigned int offset); +void gpiod_line_config_set_active_low_override (struct gpiod_line_config *config, +bool active_low, +unsigned int offset);/** -* @brief Set all lines as active-high. +* @brief Clear the active-low override at given offset. * @param config Line config object. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void gpiod_line_config_set_active_high (struct gpiod_line_config *config); +void +gpiod_line_config_clear_active_low_override (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set a single line as active-high. +* @brief Check if the active-low setting is overridden at given offset. * @param config Line config object. -* @param offset Offset of the line for which to set the active setting. +* @param offset Offset of the line for which to check the override. +* @return True if active-low is overridden at this offset, false otherwise. */ -void gpiod_line_config_set_active_high_offset (struct gpiod_line_config *config, -unsigned int offset); +bool +gpiod_line_config_active_low_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set a subset of lines as active-high. +* @brief Check if active-low is the default setting. * @param config Line config object. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the active setting. +* @return Active-low setting that would have been used for any offset not +* assigned its own value. */ -void gpiod_line_config_set_active_high_subset (struct gpiod_line_config *config, -unsigned int num_offsets, -const unsigned int *offsets); +bool gpiod_line_config_get_active_low_default (struct gpiod_line_config *config);/** -* @brief Set the debounce period for all lines. +* @brief Check if the line at given offset was configured as active-low. * @param config Line config object. -* @param period New debounce period. Disables debouncing if 0. +* @param offset Line offset for which to read the active-low setting. +* @return Active-low setting that would have been used for given offset if the +* config object was used in a request at the time of the call. */ -void gpiod_line_config_set_debounce_period_us (struct gpiod_line_config *config, -unsigned long period); +bool gpiod_line_config_get_active_low_offset (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Set the debounce period for a single line at given offset. +* @brief Set the default debounce period. * @param config Line config object. * @param period New debounce period. Disables debouncing if 0. -* @param offset Offset of the line for which to set the debounce period. +*/ +void gpiod_line_config_set_debounce_period_us_default ( +struct gpiod_line_config *config,unsigned long period); + +/** +* @brief Override the debounce period setting at given offset. +* @param config Line config object. +* @param period New debounce period in microseconds. +* @param offset Offset of the line for which to set the override. */ void -gpiod_line_config_set_debounce_period_us_offset ( +gpiod_line_config_set_debounce_period_us_override (struct gpiod_line_config *config,unsigned long period,unsigned int offset);/** -* @brief Set the debounce period for a subset of lines. +* @brief Clear the debounce period override at given offset. * @param config Line config object. -* @param period New debounce period. Disables debouncing if 0. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the debounce period. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. */ -void -gpiod_line_config_set_debounce_period_us_subset ( +void gpiod_line_config_clear_debounce_period_us_override (struct gpiod_line_config *config, -unsigned long period, -unsigned int num_offsets, -const unsigned int *offsets); +unsigned int offset); + +/** +* @brief Check if the debounce period setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if debounce period is overridden at this offset, false +* otherwise. +*/ +bool gpiod_line_config_debounce_period_us_is_overridden ( +struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Get the default debounce period. +* @param config Line config object. +* @return Debounce period that would have been used for any offset not +* assigned its own debounce period. 0 if not debouncing is disabled. +*/ +unsigned long gpiod_line_config_get_debounce_period_us_default ( +struct gpiod_line_config *config);/** -* @brief Get the debounce period for a given line. +* @brief Get the debounce period for a given offset. * @param config Line config object. * @param offset Line offset for which to read the debounce period. * @return Debounce period that would have been used for given offset if the -* config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. +* config object was used in a request at the time of the call. 0 if +* debouncing is disabled. */ unsigned long -gpiod_line_config_get_debounce_us_period (struct gpiod_line_config *config, -unsigned int offset); +gpiod_line_config_get_debounce_period_us_offset ( +struct gpiod_line_config *config,unsigned int offset);/** -* @brief Set the event timestamp clock for all lines. +* @brief Set the default event timestamp clock. * @param config Line config object. * @param clock New clock to use. */ -void gpiod_line_config_set_event_clock (struct gpiod_line_config *config, -int clock); +void gpiod_line_config_set_event_clock_default (struct gpiod_line_config *config, +int clock);/** -* @brief Set the event clock for a single line at given offset. +* @brief Override the event clock setting at given offset. * @param config Line config object. * @param clock New event clock to use. -* @param offset Offset of the line for which to set the event clock type. +* @param offset Offset of the line for which to set the override. */ -void gpiod_line_config_set_event_clock_offset (struct gpiod_line_config *config, -int clock,unsigned int offset); +void +gpiod_line_config_set_event_clock_override (struct gpiod_line_config *config, +int clock,unsigned int offset);/** -* @brief Set the event clock for a subset of lines. +* @brief Clear the event clock override at given offset. * @param config Line config object. -* @param clock New event clock to use. -* @param num_offsets Number of offsets in the array. -* @param offsets Array of line offsets for which to set the event clock type. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. +*/ +void +gpiod_line_config_clear_event_clock_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the event clock setting is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if event clock period is overridden at this offset, false +* otherwise. */ -void gpiod_line_config_set_event_clock_subset (struct gpiod_line_config *config, -int clock, -unsigned int num_offsets, -const unsigned int *offsets); +bool +gpiod_line_config_event_clock_is_overridden (struct gpiod_line_config *config, +unsigned int offset);/** -* @brief Get the event clock setting for a given line. +* @brief Get the default event clock setting. +* @param config Line config object. +* @return Event clock setting that would have been used for any offset not +* assigned its own direction value. +*/ +int gpiod_line_config_get_event_clock_default (struct gpiod_line_config *config); + +/** +* @brief Get the event clock setting for a given offset. * @param config Line config object. * @param offset Line offset for which to read the event clock setting. * @return Event clock setting that would have been used for given offset if * the config object was used in a request at the time of the call. -* @note If an offset is used for which no config was provided, the function -* will return the global default value. */ -int gpiod_line_config_get_event_clock (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_event_clock_offset (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Set the default output value. +* @param config Line config object. +* @param value New value. +*/ +void +gpiod_line_config_set_output_value_default (struct gpiod_line_config *config, +int value);/** -* @brief Set the output value for a single offset. +* @brief Override the output value for a single offset. * @param config Line config object. * @param offset Offset of the line. * @param value Output value to set. */ -void gpiod_line_config_set_output_value (struct gpiod_line_config *config, -unsigned int offset,int value); +void +gpiod_line_config_set_output_value_override (struct gpiod_line_config *config, +unsigned int offset,int value);/** -* @brief Set the output values for a set of offsets. +* @brief Override the output values for multiple offsets. * @param config Line config object. -* @param num_values Number of offsets for which to set values. -* @param offsets Array of line offsets to set values for. +* @param num_values Number of offsets for which to override values. +* @param offsets Array of line offsets to override values for. * @param values Array of output values associated with the offsets passed in * the previous argument. */ @@ -811,14 +932,65 @@ void gpiod_line_config_set_output_values(struct gpiod_line_config *config,const unsigned int *offsets, const int *values); +/** +* @brief Clear the output value override at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to clear the override. +* @note Does nothing if no override is set for this line. +*/ +void +gpiod_line_config_clear_output_value_override (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Check if the output value is overridden at given offset. +* @param config Line config object. +* @param offset Offset of the line for which to check the override. +* @return True if output value period is overridden at this offset, false +* otherwise. +*/ +bool +gpiod_line_config_output_value_is_overridden (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Get the default output value. +* @param config Line config object. +* @return Output value that would have been used for any offset not +* assigned its own output value. +*/ +int +gpiod_line_config_get_output_value_default (struct gpiod_line_config *config); +/** * @brief Get the output value configured for a given line. * @param config Line config object. * @param offset Line offset for which to read the value. -* @return 1 or 0 if the value was configured for this line, -1 otherwise. +* @return Output value that would have been used for given offset if the +* config object was used in a request at the time of the call. */ -int gpiod_line_config_get_output_value (struct gpiod_line_config *config, -unsigned int offset); +int gpiod_line_config_get_output_value_offset (struct gpiod_line_config *config, +unsigned int offset); + +/** +* @brief Get the number of offsets for which this config object contains +* at least one setting that is different from the defaults. +* @param config Line config object. +* @return Number of offsets with at least one overridden setting. +*/ +unsigned int +gpiod_line_config_get_num_overridden_offsets (struct gpiod_line_config *config); + +/** +* @brief Get the offsets for which this config object contains at least one +* setting that is different from the defaults. +* @param config Line config object. +* @param offsets Array to store the offsets. Must hold at least the number +* of offsets returned by +* ::gpiod_line_config_get_num_overridden_offsets. +*/ +void gpiod_line_config_get_overridden_offsets (struct gpiod_line_config *config, +unsigned int *offsets);/** * @} lib/line-config.c +432
-244@@ -18,6 +18,7 @@ struct base_config { bool active_low : 1; unsigned int clock : 2;unsigned long debounce_period_us; + unsigned int value : 1; }GPIOD_PACKED ;#define OVERRIDE_FLAG_DIRECTION GPIOD_BIT(0)@@ -27,6 +28,7 @@ struct base_config {#define OVERRIDE_FLAG_ACTIVE_LOW GPIOD_BIT(4)#define OVERRIDE_FLAG_CLOCK GPIOD_BIT(5)#define OVERRIDE_FLAG_DEBOUNCE_PERIOD GPIOD_BIT(6) +#define OVERRIDE_FLAG_OUTPUT_VALUE GPIOD_BIT(7)/* * Config overriding the defaults for a single line offset. Only flagged @@ -35,16 +37,13 @@ struct base_config {struct override_config {struct base_config base;unsigned int offset; -bool value_set :1 ; -unsigned int value :1 ; -unsigned int override_flags :7 ; +unsigned int override_flags :8 ; }GPIOD_PACKED ;struct gpiod_line_config {bool too_complex;struct base_config defaults;struct override_config overrides[GPIO_V2_LINES_MAX ]; -unsigned int num_overrides; };static void init_base_config (struct base_config *config)@@ -58,6 +57,17 @@ static void init_base_config(struct base_config *config) config->debounce_period_us =0 ; } +static void init_override_config (struct override_config *override) +{ + override->override_flags =0 ; +init_base_config (&override->base); +} + +static bool override_used (struct override_config *override) +{ +return !!override->override_flags; +} + GPIOD_API struct gpiod_line_config *gpiod_line_config_new(void) {struct gpiod_line_config *config;@@ -82,8 +92,8 @@ GPIOD_API void gpiod_line_config_reset(struct gpiod_line_config *config)memset (config,0 ,sizeof (*config));init_base_config (&config->defaults); -for (i =0 ; i <GPIO_V2_LINE_NUM_ATTRS_MAX ; i++) -init_base_config (&config->overrides[i].base); +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) +init_override_config (&config->overrides[i]); } static struct override_config *@@ -92,7 +102,7 @@ get_override_by_offset(struct gpiod_line_config *config, unsigned int offset)struct override_config *override;unsigned int i; -for (i =0 ; i < config->num_overrides; i++) { +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { override = &config->overrides[i];if (override->offset == offset)@@ -103,19 +113,24 @@ get_override_by_offset(struct gpiod_line_config *config, unsigned int offset) }static struct override_config * -get_new_override (struct gpiod_line_config *config,unsigned int offset) +get_free_override (struct gpiod_line_config *config,unsigned int offset) {struct override_config *override; +unsigned int i; -if (config->num_overrides ==GPIO_V2_LINES_MAX ) { - config->too_complex = true; -return NULL ; - } +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { + override = &config->overrides[i]; - override = &config->overrides[config->num_overrides++]; - override->offset = offset; +if (override->override_flags) +continue ; -return override; + override->offset = offset; +return override; + } + +/* No more free overrides. */ + config->too_complex = true; +return NULL ; } static struct override_config *@@ -129,7 +144,7 @@ get_override_config_for_writing(struct gpiod_line_config *config, override =get_override_by_offset (config, offset);if (!override) { - override =get_new_override (config, offset); + override =get_free_override (config, offset);if (!override)return NULL ; }@@ -139,7 +154,7 @@ get_override_config_for_writing(struct gpiod_line_config *config,static struct base_config *get_base_config_for_reading (struct gpiod_line_config *config, -unsigned int offset,unsigned int flag) +unsigned int offset,unsigned int flag) {struct override_config *override;@@ -150,6 +165,35 @@ get_base_config_for_reading(struct gpiod_line_config *config,return &config->defaults; } +static void clear_override (struct gpiod_line_config *config, +unsigned int offset,int flag) +{ +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return ; + +if (override->override_flags & flag) { + override->override_flags &= ~flag; + +if (!override->override_flags) +init_override_config (override); + } +} + +static bool check_override (struct gpiod_line_config *config, +unsigned int offset,int flag) +{ +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return false; + +return override->override_flags & flag; +} +static void set_direction (struct base_config *config,int direction) {switch (direction) {@@ -165,38 +209,49 @@ static void set_direction(struct base_config *config, int direction) } GPIOD_API void -gpiod_line_config_set_direction (struct gpiod_line_config *config,int direction) +gpiod_line_config_set_direction_default (struct gpiod_line_config *config, +int direction) {set_direction (&config->defaults, direction); } GPIOD_API void -gpiod_line_config_set_direction_offset (struct gpiod_line_config *config, +gpiod_line_config_set_direction_override (struct gpiod_line_config *config,int direction,unsigned int offset) { -gpiod_line_config_set_direction_subset (config, direction,1 , &offset); +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return ; + +set_direction (&override->base, direction); + override->override_flags |=OVERRIDE_FLAG_DIRECTION ; } GPIOD_API void -gpiod_line_config_set_direction_subset (struct gpiod_line_config *config, -int direction,unsigned int num_offsets, -const unsigned int *offsets) +gpiod_line_config_clear_direction_override (struct gpiod_line_config *config, +unsigned int offset) { -struct override_config *override; -unsigned int i; +clear_override (config, offset,OVERRIDE_FLAG_DIRECTION ); +} -for (i =0 ; i < num_offsets; i++) { - override =get_override_config_for_writing (config, offsets[i]); -if (!override) -return ; +GPIOD_API bool +gpiod_line_config_direction_is_overridden (struct gpiod_line_config *config, +unsigned int offset) +{ +return check_override (config, offset,OVERRIDE_FLAG_DIRECTION ); +} -set_direction (&override->base, direction); - override->override_flags |=OVERRIDE_FLAG_DIRECTION ; - } +GPIOD_API int +gpiod_line_config_get_direction_default (struct gpiod_line_config *config) +{ +return config->defaults.direction; } -GPIOD_API int gpiod_line_config_get_direction(struct gpiod_line_config *config, -unsigned int offset) +GPIOD_API int +gpiod_line_config_get_direction_offset (struct gpiod_line_config *config, +unsigned int offset) {struct base_config *base;@@ -222,39 +277,49 @@ static void set_edge_detection(struct base_config *config, int edge) } GPIOD_API void -gpiod_line_config_set_edge_detection (struct gpiod_line_config *config,int edge) +gpiod_line_config_set_edge_detection_default (struct gpiod_line_config *config, +int edge) {set_edge_detection (&config->defaults, edge); } GPIOD_API void -gpiod_line_config_set_edge_detection_offset (struct gpiod_line_config *config, -int edge,unsigned int offset) +gpiod_line_config_set_edge_detection_override (struct gpiod_line_config *config, +int edge,unsigned int offset) { -gpiod_line_config_set_edge_detection_subset (config, edge,1 , &offset); +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return ; + +set_edge_detection (&override->base, edge); + override->override_flags |=OVERRIDE_FLAG_EDGE ; } GPIOD_API void -gpiod_line_config_set_edge_detection_subset (struct gpiod_line_config *config, -int edge,unsigned int num_offsets, -const unsigned int *offsets) +gpiod_line_config_clear_edge_detection_override ( +struct gpiod_line_config *config,unsigned int offset) { -struct override_config *override; -unsigned int i; +clear_override (config, offset,OVERRIDE_FLAG_EDGE ); +} -for (i =0 ; i < num_offsets; i++) { - override =get_override_config_for_writing (config, offsets[i]); -if (!override) -return ; +GPIOD_API bool +gpiod_line_config_edge_detection_is_overridden (struct gpiod_line_config *config, +unsigned int offset) +{ +return check_override (config, offset,OVERRIDE_FLAG_EDGE ); +} -set_edge_detection (&override->base, edge); - override->override_flags |=OVERRIDE_FLAG_EDGE ; - } +GPIOD_API int +gpiod_line_config_get_edge_detection_default (struct gpiod_line_config *config) +{ +return config->defaults.edge; } GPIOD_API int -gpiod_line_config_get_edge_detection (struct gpiod_line_config *config, -unsigned int offset) +gpiod_line_config_get_edge_detection_offset (struct gpiod_line_config *config, +unsigned int offset) {struct base_config *base;@@ -279,38 +344,48 @@ static void set_bias(struct base_config *config, int bias) } GPIOD_API void -gpiod_line_config_set_bias (struct gpiod_line_config *config,int bias) +gpiod_line_config_set_bias_default (struct gpiod_line_config *config,int bias) {set_bias (&config->defaults, bias); } GPIOD_API void -gpiod_line_config_set_bias_offset (struct gpiod_line_config *config, +gpiod_line_config_set_bias_override (struct gpiod_line_config *config,int bias,unsigned int offset) { -gpiod_line_config_set_bias_subset (config, bias,1 , &offset); +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return ; + +set_bias (&override->base, bias); + override->override_flags |=OVERRIDE_FLAG_BIAS ; } GPIOD_API void -gpiod_line_config_set_bias_subset (struct gpiod_line_config *config, -int bias,unsigned int num_offsets, -const unsigned int *offsets) +gpiod_line_config_clear_bias_override (struct gpiod_line_config *config, +unsigned int offset) { -struct override_config *override; -unsigned int i; +clear_override (config, offset,OVERRIDE_FLAG_BIAS ); +} -for (i =0 ; i < num_offsets; i++) { - override =get_override_config_for_writing (config, offsets[i]); -if (!override) -return ; +GPIOD_API bool +gpiod_line_config_bias_is_overridden (struct gpiod_line_config *config, +unsigned int offset) +{ +return check_override (config, offset,OVERRIDE_FLAG_BIAS ); +} -set_bias (&override->base, bias); - override->override_flags |=OVERRIDE_FLAG_BIAS ; - } +GPIOD_API int +gpiod_line_config_get_bias_default (struct gpiod_line_config *config) +{ +return config->defaults.bias; } -GPIOD_API int gpiod_line_config_get_bias(struct gpiod_line_config *config, -unsigned int offset) +GPIOD_API int +gpiod_line_config_get_bias_offset (struct gpiod_line_config *config, +unsigned int offset) {struct base_config *base;@@ -334,38 +409,48 @@ static void set_drive(struct base_config *config, int drive) } GPIOD_API void -gpiod_line_config_set_drive (struct gpiod_line_config *config,int drive) +gpiod_line_config_set_drive_default (struct gpiod_line_config *config,int drive) {set_drive (&config->defaults, drive); } GPIOD_API void -gpiod_line_config_set_drive_offset (struct gpiod_line_config *config, -int drive,unsigned int offset) +gpiod_line_config_set_drive_override (struct gpiod_line_config *config, +int drive,unsigned int offset) { -gpiod_line_config_set_drive_subset (config, drive,1 , &offset); +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return ; + +set_drive (&override->base, drive); + override->override_flags |=OVERRIDE_FLAG_DRIVE ; } GPIOD_API void -gpiod_line_config_set_drive_subset (struct gpiod_line_config *config, -int drive,unsigned int num_offsets, -const unsigned int *offsets) +gpiod_line_config_clear_drive_override (struct gpiod_line_config *config, +unsigned int offset) { -struct override_config *override; -unsigned int i; +clear_override (config, offset,OVERRIDE_FLAG_DRIVE ); +} -for (i =0 ; i < num_offsets; i++) { - override =get_override_config_for_writing (config, offsets[i]); -if (!override) -return ; +GPIOD_API bool +gpiod_line_config_drive_is_overridden (struct gpiod_line_config *config, +unsigned int offset) +{ +return check_override (config, offset,OVERRIDE_FLAG_DRIVE ); +} -set_drive (&override->base, drive); - override->override_flags |=OVERRIDE_FLAG_DRIVE ; - } +GPIOD_API int +gpiod_line_config_get_drive_default (struct gpiod_line_config *config) +{ +return config->defaults.drive; } -GPIOD_API int gpiod_line_config_get_drive(struct gpiod_line_config *config, -unsigned int offset) +GPIOD_API int +gpiod_line_config_get_drive_offset (struct gpiod_line_config *config, +unsigned int offset) {struct base_config *base;@@ -375,49 +460,50 @@ GPIOD_API int gpiod_line_config_get_drive(struct gpiod_line_config *config, } GPIOD_API void -gpiod_line_config_set_active_low (struct gpiod_line_config *config) +gpiod_line_config_set_active_low_default (struct gpiod_line_config *config, +bool active_low) { - config->defaults.active_low = true; + config->defaults.active_low = active_low; } GPIOD_API void -gpiod_line_config_set_active_low_offset (struct gpiod_line_config *config, -unsigned int offset) -{ -gpiod_line_config_set_active_low_subset (config,1 , &offset); -} - -static void -gpiod_line_config_set_active_setting (struct gpiod_line_config *config, -unsigned int num_offsets, -const unsigned int *offsets, -bool active_low) +gpiod_line_config_set_active_low_override (struct gpiod_line_config *config, +bool active_low, +unsigned int offset) {struct override_config *override; -unsigned int i; -for (i =0 ; i < num_offsets; i++) { - override =get_override_config_for_writing (config, offsets[i]); -if (!override) -return ; + override =get_override_config_for_writing (config, offset); +if (!override) +return ; - override->base.active_low = active_low; - override->override_flags |=OVERRIDE_FLAG_ACTIVE_LOW ; - } + override->base.active_low = active_low; + override->override_flags |=OVERRIDE_FLAG_ACTIVE_LOW ; } GPIOD_API void -gpiod_line_config_set_active_low_subset (struct gpiod_line_config *config, -unsigned int num_offsets, -const unsigned int *offsets) +gpiod_line_config_clear_active_low_override (struct gpiod_line_config *config, +unsigned int offset) { -gpiod_line_config_set_active_setting (config, - num_offsets, offsets, true); +clear_override (config, offset,OVERRIDE_FLAG_ACTIVE_LOW ); } GPIOD_API bool -gpiod_line_config_get_active_low (struct gpiod_line_config *config, -unsigned int offset) +gpiod_line_config_active_low_is_overridden (struct gpiod_line_config *config, +unsigned int offset) +{ +return check_override (config, offset,OVERRIDE_FLAG_ACTIVE_LOW ); +} + +GPIOD_API bool +gpiod_line_config_get_active_low_default (struct gpiod_line_config *config) +{ +return config->defaults.active_low; +} + +GPIOD_API bool +gpiod_line_config_get_active_low_offset (struct gpiod_line_config *config, +unsigned int offset) {struct base_config *base;@@ -428,69 +514,52 @@ gpiod_line_config_get_active_low(struct gpiod_line_config *config, } GPIOD_API void -gpiod_line_config_set_active_high (struct gpiod_line_config *config) +gpiod_line_config_set_debounce_period_us_default ( +struct gpiod_line_config *config,unsigned long period) { - config->defaults.active_low = false; + config->defaults.debounce_period_us = period; } GPIOD_API void -gpiod_line_config_set_active_high_offset (struct gpiod_line_config *config, -unsigned int offset) +gpiod_line_config_set_debounce_period_us_override ( +struct gpiod_line_config *config, +unsigned long period, +unsigned int offset) { -gpiod_line_config_set_active_high_subset (config,1 , &offset); -} +struct override_config *override; -GPIOD_API void -gpiod_line_config_set_active_high_subset (struct gpiod_line_config *config, -unsigned int num_offsets, -const unsigned int *offsets) -{ -gpiod_line_config_set_active_setting (config, - num_offsets, offsets, false); -} + override =get_override_config_for_writing (config, offset); +if (!override) +return ; -GPIOD_API void -gpiod_line_config_set_debounce_period_us (struct gpiod_line_config *config, -unsigned long period) -{ - config->defaults.debounce_period_us = period; + override->base.debounce_period_us = period; + override->override_flags |=OVERRIDE_FLAG_DEBOUNCE_PERIOD ; } -GPIOD_API void -gpiod_line_config_set_debounce_period_us_offset ( +GPIOD_API void gpiod_line_config_clear_debounce_period_us_override(struct gpiod_line_config *config, -unsigned long period,unsigned int offset) { -gpiod_line_config_set_debounce_period_us_subset (config, period, -1 , &offset); +clear_override (config, offset,OVERRIDE_FLAG_DEBOUNCE_PERIOD ); } -GPIOD_API void -gpiod_line_config_set_debounce_period_us_subset ( +GPIOD_API bool gpiod_line_config_debounce_period_us_is_overridden(struct gpiod_line_config *config, -unsigned long period, -unsigned int num_offsets, -const unsigned int *offsets) +unsigned int offset) { -struct override_config *override; -unsigned int i, offset; - -for (i =0 ; i < num_offsets; i++) { - offset = offsets[i]; - - override =get_override_config_for_writing (config, offset); -if (!override) -return ; +return check_override (config, offset,OVERRIDE_FLAG_DEBOUNCE_PERIOD ); +} - override->base.debounce_period_us = period; - override->override_flags |=OVERRIDE_FLAG_DEBOUNCE_PERIOD ; - } +GPIOD_API unsigned long +gpiod_line_config_get_debounce_period_us_default ( +struct gpiod_line_config *config) +{ +return config->defaults.debounce_period_us; }GPIOD_API unsigned long -gpiod_line_config_get_debounce_us_period (struct gpiod_line_config *config, -unsigned int offset) +gpiod_line_config_get_debounce_period_us_offset ( +struct gpiod_line_config *config,unsigned int offset) {struct base_config *base;@@ -514,38 +583,49 @@ static void set_event_clock(struct base_config *config, int clock) } GPIOD_API void -gpiod_line_config_set_event_clock (struct gpiod_line_config *config,int clock) +gpiod_line_config_set_event_clock_default (struct gpiod_line_config *config, +int clock) {set_event_clock (&config->defaults, clock); } GPIOD_API void -gpiod_line_config_set_event_clock_offset (struct gpiod_line_config *config, -int clock,unsigned int offset) +gpiod_line_config_set_event_clock_override (struct gpiod_line_config *config, +int clock,unsigned int offset) { -gpiod_line_config_set_event_clock_subset (config, clock,1 , &offset); +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return ; + +set_event_clock (&override->base, clock); + override->override_flags |=OVERRIDE_FLAG_CLOCK ; } GPIOD_API void -gpiod_line_config_set_event_clock_subset (struct gpiod_line_config *config, -int clock,unsigned int num_offsets, -const unsigned int *offsets) +gpiod_line_config_clear_event_clock_override (struct gpiod_line_config *config, +unsigned int offset) { -struct override_config *override; -unsigned int i; +clear_override (config, offset,OVERRIDE_FLAG_CLOCK ); +} -for (i =0 ; i < num_offsets; i++) { - override =get_override_config_for_writing (config, offsets[i]); -if (!override) -return ; +GPIOD_API bool +gpiod_line_config_event_clock_is_overridden (struct gpiod_line_config *config, +unsigned int offset) +{ +return check_override (config, offset,OVERRIDE_FLAG_CLOCK ); +} -set_event_clock (&override->base, clock); - } +GPIOD_API int +gpiod_line_config_get_event_clock_default (struct gpiod_line_config *config) +{ +return config->defaults.clock; } GPIOD_API int -gpiod_line_config_get_event_clock (struct gpiod_line_config *config, -unsigned int offset) +gpiod_line_config_get_event_clock_offset (struct gpiod_line_config *config, +unsigned int offset) {struct base_config *base;@@ -554,17 +634,25 @@ gpiod_line_config_get_event_clock(struct gpiod_line_config *config,return base->clock; } -static void set_output_value (struct override_config *override,int value) +GPIOD_API void +gpiod_line_config_set_output_value_default (struct gpiod_line_config *config, +int value) { - override->value = !!value; - override->value_set = true; + config->defaults.value = value; } GPIOD_API void -gpiod_line_config_set_output_value (struct gpiod_line_config *config, -unsigned int offset,int value) +gpiod_line_config_set_output_value_override (struct gpiod_line_config *config, +unsigned int offset,int value) { -gpiod_line_config_set_output_values (config,1 , &offset, &value); +struct override_config *override; + + override =get_override_config_for_writing (config, offset); +if (!override) +return ; + + override->base.value = !!value; + override->override_flags |=OVERRIDE_FLAG_OUTPUT_VALUE ; }GPIOD_API void@@ -573,36 +661,103 @@ gpiod_line_config_set_output_values(struct gpiod_line_config *config,const unsigned int *offsets, const int *values) { - struct override_config *override; -unsigned int i, offset, val; + unsigned int i; -for (i =0 ; i < num_values; i++) { - offset = offsets[i]; - val = values[i]; +for (i =0 ; i < num_values; i++) +gpiod_line_config_set_output_value_override (config, + offsets[i], + values[i]); +} - override =get_override_by_offset (config, offset); -if (!override) { - override =get_new_override (config, offset); -if (!override) -return ; - } +GPIOD_API void +gpiod_line_config_clear_output_value_override (struct gpiod_line_config *config, +unsigned int offset) +{ +clear_override (config, offset,OVERRIDE_FLAG_OUTPUT_VALUE ); +} -set_output_value (override, val); - } +GPIOD_API bool +gpiod_line_config_output_value_is_overridden (struct gpiod_line_config *config, +unsigned int offset) +{ +return check_override (config, offset,OVERRIDE_FLAG_OUTPUT_VALUE ); } GPIOD_API int -gpiod_line_config_get_output_value (struct gpiod_line_config *config, -unsigned int offset) +gpiod_line_config_get_output_value_default (struct gpiod_line_config *config) +{ +return config->defaults.value; +} + +GPIOD_API int +gpiod_line_config_get_output_value_offset (struct gpiod_line_config *config, +unsigned int offset) {struct override_config *override; override =get_override_by_offset (config, offset); -if (override && override->value_set) -return override->value; +if (override && (override->override_flags &OVERRIDE_FLAG_OUTPUT_VALUE )) +return override->base.value; - errno =ENXIO ; -return -1 ; +return config->defaults.value; +} + +static bool base_config_flags_are_equal (struct base_config *base, +struct override_config *override) +{ +if (((override->override_flags &OVERRIDE_FLAG_DIRECTION ) && + base->direction != override->base.direction) || + ((override->override_flags &OVERRIDE_FLAG_EDGE ) && + base->edge != override->base.edge) || + ((override->override_flags &OVERRIDE_FLAG_DRIVE ) && + base->drive != override->base.drive) || + ((override->override_flags &OVERRIDE_FLAG_BIAS ) && + base->bias != override->base.bias) || + ((override->override_flags &OVERRIDE_FLAG_ACTIVE_LOW ) && + base->active_low != override->base.active_low) || + ((override->override_flags &OVERRIDE_FLAG_CLOCK ) && + base->clock != override->base.clock)) +return false; + +return true; +} + +static bool base_debounce_period_is_equal (struct base_config *base, +struct override_config *override) +{ +if ((override->override_flags &OVERRIDE_FLAG_DEBOUNCE_PERIOD ) && + base->debounce_period_us != override->base.debounce_period_us) +return false; + +return true; +} + +GPIOD_API unsigned int +gpiod_line_config_get_num_overridden_offsets (struct gpiod_line_config *config) +{ +unsigned int i, ret =0 ; + +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { +if (override_used (&config->overrides[i])) + ret++; + } + +return ret; +} + +GPIOD_API void +gpiod_line_config_get_overridden_offsets (struct gpiod_line_config *config, +unsigned int *offsets) +{ +struct override_config *override; +unsigned int i, j; + +for (i =0 , j =0 ; i <GPIO_V2_LINES_MAX ; i++) { + override = &config->overrides[i]; + +if (override_used (override)) + offsets[j++] = override->offset; + } }static uint64_t make_kernel_flags (const struct base_config *config)@@ -695,10 +850,36 @@ static int set_kernel_output_values(uint64_t *mask, uint64_t *vals,gpiod_line_mask_zero (mask);gpiod_line_mask_zero (vals); -for (i =0 ; i < config->num_overrides; i++) { - override = &config->overrides[i]; +if (config->defaults.direction ==GPIOD_LINE_DIRECTION_OUTPUT ) { +/* +* Default direction is output - assign the default output +* value to all lines. Overrides that may set some lines to +* input will be handled later and may re-assign the output +* values. +*/ +for (i =0 ; i < num_lines; i++) { +gpiod_line_mask_set_bit (mask, i); +gpiod_line_mask_assign_bit (vals, i, + config->defaults.value); + } + }else { +/* +* Default output value is not output. Iterate over overrides +* and set the default output value for those that override the +* direction to output. Don't touch the ones which override +* the output value. +*/ +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { + override = &config->overrides[i]; + +if (override->base.direction != +GPIOD_LINE_DIRECTION_OUTPUT || + !(override->override_flags & +OVERRIDE_FLAG_DIRECTION ) || + (override->override_flags & +OVERRIDE_FLAG_OUTPUT_VALUE )) +continue ; -if (override->value_set) { idx =find_bitmap_index (override->offset, num_lines, offsets);if (idx <0 ) {@@ -708,31 +889,36 @@ static int set_kernel_output_values(uint64_t *mask, uint64_t *vals,gpiod_line_mask_set_bit (mask, idx);gpiod_line_mask_assign_bit (vals, idx, - !!override->value); + !!config->defaults.value); } } -return 0 ; -} +/* +* Finally iterate over the overrides again and set the overridden +* output values. +*/ +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { + override = &config->overrides[i]; -static bool base_config_flags_are_equal (struct base_config *base, -struct override_config *override) -{ -if (((override->override_flags &OVERRIDE_FLAG_DIRECTION ) && - base->direction != override->base.direction) || - ((override->override_flags &OVERRIDE_FLAG_EDGE ) && - base->edge != override->base.edge) || - ((override->override_flags &OVERRIDE_FLAG_DRIVE ) && - base->drive != override->base.drive) || - ((override->override_flags &OVERRIDE_FLAG_BIAS ) && - base->bias != override->base.bias) || - ((override->override_flags &OVERRIDE_FLAG_ACTIVE_LOW ) && - base->active_low != override->base.active_low) || - ((override->override_flags &OVERRIDE_FLAG_CLOCK ) && - base->clock != override->base.clock)) -return false; +if (!(override->override_flags &OVERRIDE_FLAG_OUTPUT_VALUE )) +continue ; -return true; +if (config->defaults.direction !=GPIOD_LINE_DIRECTION_OUTPUT && + (!(override->override_flags &OVERRIDE_FLAG_DIRECTION ) || + override->base.direction !=GPIOD_LINE_DIRECTION_OUTPUT )) +continue ; + + idx =find_bitmap_index (override->offset, num_lines, offsets); +if (idx <0 ) { + errno =EINVAL ; +return -1 ; + } + +gpiod_line_mask_set_bit (mask, idx); +gpiod_line_mask_assign_bit (vals, idx, !!override->base.value); + } + +return 0 ; } static bool override_config_flags_are_equal(struct override_config *a,@@ -771,16 +957,6 @@ static void set_base_config_flags(struct gpio_v2_line_attribute *attr, attr->flags =make_kernel_flags (&base); } -static bool base_debounce_period_is_equal (struct base_config *base, -struct override_config *override) -{ -if ((override->override_flags &OVERRIDE_FLAG_DEBOUNCE_PERIOD ) && - base->debounce_period_us != override->base.debounce_period_us) -return false; - -return true; -} -static bool override_config_debounce_period_is_equal (struct override_config *a,struct override_config *b) {@@ -804,19 +980,23 @@ set_base_config_debounce_period(struct gpio_v2_line_attribute *attr,static int set_kernel_attr_mask (uint64_t *out,const uint64_t *in,unsigned int num_lines,const unsigned int *offsets, -const struct gpiod_line_config *config) +struct gpiod_line_config *config) { +struct override_config *override;unsigned int i, j;int off;gpiod_line_mask_zero (out); -for (i =0 ; i < config->num_overrides; i++) { -if (!gpiod_line_mask_test_bit (in, i)) +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { + override = &config->overrides[i]; + +if (!override_used (override) || + !gpiod_line_mask_test_bit (in, i))continue ;for (j =0 , off =-1 ; j < num_lines; j++) { -if (offsets[j] == config->overrides[i].offset) { +if (offsets[j] == override->offset) { off = j;break ; }@@ -852,11 +1032,18 @@ static int process_overrides(struct gpiod_line_config *config,struct override_config *current, *next;unsigned int i, j; -for (i =0 ; i < config->num_overrides; i++) { -if (gpiod_line_mask_test_bit (&processed, i)) +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { + current = &config->overrides[i]; + +if (!override_used (current) || +gpiod_line_mask_test_bit (&processed, i))continue ; - current = &config->overrides[i]; +if (*attr_idx ==GPIO_V2_LINE_NUM_ATTRS_MAX ) { + errno =E2BIG ; +return -1 ; + } +gpiod_line_mask_set_bit (&processed, i);if (defaults_equal_func (&config->defaults, current))@@ -865,12 +1052,13 @@ static int process_overrides(struct gpiod_line_config *config, marked =0 ;gpiod_line_mask_set_bit (&marked, i); -for (j = i +1 ; j < config->num_overrides; j++) { -if (gpiod_line_mask_test_bit (&processed, j)) -continue ; - +for (j = i +1 ; j <GPIO_V2_LINES_MAX ; j++) { next = &config->overrides[j]; +if (!override_used (next) || +gpiod_line_mask_test_bit (&processed, j)) +continue ; +if (override_equal_func (current, next)) {gpiod_line_mask_set_bit (&marked, j);gpiod_line_mask_set_bit (&processed, j);
lib/line-config.c static int process_overrides(struct gpiod_line_config *config, · line 1071
Quoted 10 lines
lib/line-config.c +0
-4@@ -878,10 +1066,6 @@ static int process_overrides(struct gpiod_line_config *config, } attr = &cfgbuf->attrs[(*attr_idx)++]; -if (*attr_idx ==GPIO_V2_LINE_NUM_ATTRS_MAX ) { - errno =E2BIG ; -return -1 ; - }set_kernel_attr_mask (&mask, &marked, num_lines, offsets, config);
Ignored return value in the only place set_kernel_attr_mask() is called. If you aren't going to use the return value then set_kernel_attr_mask() should skip over overrides for lines not in offsets, else you are quietly truncating your config.
OTOH, if you want a strict "all lines in config must be in offsets" policy then you need to check the return.
And set_kernel_output_values() behaviour should be consistent, either way.
Document the behaviour in gpiod_line_request_reconfigure_lines() and gpiod_chip_request_lines() and add corresponding test cases.
Cheers,
Kent.
Quoted 135 lines
lib/line-config.c +29
-17@@ -892,14 +1076,31 @@ static int process_overrides(struct gpiod_line_config *config,return 0 ; } +static bool has_at_least_one_output_direction (struct gpiod_line_config *config) +{ +struct override_config *override; +unsigned int i; + +if (config->defaults.direction ==GPIOD_LINE_DIRECTION_OUTPUT ) +return true; + +for (i =0 ; i <GPIO_V2_LINES_MAX ; i++) { + override = &config->overrides[i]; + +if (override->base.direction ==GPIOD_LINE_DIRECTION_OUTPUT ) +return true; + } + +return false; +} +int gpiod_line_config_to_kernel (struct gpiod_line_config *config,struct gpio_v2_line_config *cfgbuf,unsigned int num_lines,const unsigned int *offsets) {struct gpio_v2_line_config_attribute *attr; -struct override_config *override; -unsigned int attr_idx =0 , i; +unsigned int attr_idx =0 ;uint64_t mask, values;int ret;@@ -907,26 +1108,21 @@ int gpiod_line_config_to_kernel(struct gpiod_line_config *config, goto err_2big;/* -* First check if we have at least one default output value configured. +* First check if we have at least one line configured in output mode. * If so, let's take one attribute for the default values. */ -for (i =0 ; i < config->num_overrides; i++) { - override = &config->overrides[i]; - -if (override->value_set) { - attr = &cfgbuf->attrs[attr_idx++]; - attr->attr.id =GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES ; +if (has_at_least_one_output_direction (config)) { + attr = &cfgbuf->attrs[attr_idx++]; + attr->attr.id =GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES ; - ret =set_kernel_output_values (&mask, &values, config, - num_lines, offsets); -if (ret) -return ret; + ret =set_kernel_output_values (&mask, &values, config, + num_lines, offsets); +if (ret) +return ret; - attr->attr.values = values; - attr->mask = mask; + attr->attr.values = values; + attr->mask = mask; -break ; - } }/* If we have a default debounce period - use another attribute. */ tools/gpioget.c +3
-3@@ -110,13 +110,13 @@ int main(int argc, char **argv)if (!line_cfg)die_perror ("unable to allocate the line config structure" ); -gpiod_line_config_set_direction (line_cfg, direction); +gpiod_line_config_set_direction_default (line_cfg, direction);if (bias) -gpiod_line_config_set_bias (line_cfg, bias); +gpiod_line_config_set_bias_default (line_cfg, bias);if (active_low) -gpiod_line_config_set_active_low (line_cfg); +gpiod_line_config_set_active_low_default (line_cfg, true); req_cfg =gpiod_request_config_new ();if (!req_cfg)tools/gpiomon.c +3
-3@@ -259,10 +259,10 @@ int main(int argc, char **argv)die_perror ("unable to allocate the line config structure" );if (bias) -gpiod_line_config_set_bias (line_cfg, bias); +gpiod_line_config_set_bias_default (line_cfg, bias);if (active_low) -gpiod_line_config_set_active_low (line_cfg); -gpiod_line_config_set_edge_detection (line_cfg, edge); +gpiod_line_config_set_active_low_default (line_cfg, true); +gpiod_line_config_set_edge_detection_default (line_cfg, edge); req_cfg =gpiod_request_config_new ();if (!req_cfg)tools/gpioset.c +5
-4@@ -296,12 +296,13 @@ int main(int argc, char **argv)die_perror ("unable to allocate the line config structure" );if (bias) -gpiod_line_config_set_bias (line_cfg, bias); +gpiod_line_config_set_bias_default (line_cfg, bias);if (drive) -gpiod_line_config_set_drive (line_cfg, drive); +gpiod_line_config_set_drive_default (line_cfg, drive);if (active_low) -gpiod_line_config_set_active_low (line_cfg); -gpiod_line_config_set_direction (line_cfg,GPIOD_LINE_DIRECTION_OUTPUT ); +gpiod_line_config_set_active_low_default (line_cfg, true); +gpiod_line_config_set_direction_default (line_cfg, +GPIOD_LINE_DIRECTION_OUTPUT );gpiod_line_config_set_output_values (line_cfg, num_lines, offsets, values);Signature · 1 line
2.30.1
PATCH v2 3/4 build: add a configure option for enabling gcov profiling
In reply to Bartosz GolaszewskiAdd a configure switch that adds the relevant gcov options to the compiler flags for the core library and tests.
--- .gitignore | 4 ++++ configure.ac | 10 ++++++++++ lib/Makefile.am | 1 + tests/Makefile.am | 1 + 4 files changed, 16 insertions(+)
.gitignore +4 -0
@@ -29,3 +29,7 @@ libtool *-libtool m4/ stamp-h1 + +# profiling +*.gcda +*.gcno
configure.ac +10 -0
@@ -122,6 +122,16 @@ AC_ARG_ENABLE([tests], [with_tests=false]) AM_CONDITIONAL([WITH_TESTS], [test "x$with_tests" = xtrue]) +AC_ARG_ENABLE([profiling], + [AS_HELP_STRING([--enable-profiling], + [enable gcov profiling on the core library and tests [default=no]])], + [if test "x$enableval" = xyes; then with_profiling=true; fi], + [with_profiling=false]) +if test "x$with_profiling" = xtrue +then + AC_SUBST(PROFILING_FLAGS, ["-fprofile-arcs -ftest-coverage"]) +fi + AC_DEFUN([FUNC_NOT_FOUND_TESTS], [ERR_NOT_FOUND([$1()], [tests])])
lib/Makefile.am +1 -0
@@ -17,6 +17,7 @@ libgpiod_la_SOURCES = chip.c \ libgpiod_la_CFLAGS = -Wall -Wextra -g -std=gnu89 libgpiod_la_CFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/ libgpiod_la_CFLAGS += -include $(top_builddir)/config.h +libgpiod_la_CFLAGS += $(PROFILING_FLAGS) libgpiod_la_LDFLAGS = -version-info $(subst .,:,$(ABI_VERSION)) pkgconfigdir = $(libdir)/pkgconfig
tests/Makefile.am +1 -0
@@ -7,6 +7,7 @@ AM_CFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/tests/gpiosim/ AM_CFLAGS += -include $(top_builddir)/config.h AM_CFLAGS += -Wall -Wextra -g -std=gnu89 $(GLIB_CFLAGS) AM_CFLAGS += -DG_LOG_DOMAIN=\"gpiod-test\" +AM_CFLAGS += $(PROFILING_FLAGS) AM_LDFLAGS = -pthread LDADD = $(top_builddir)/lib/libgpiod.la LDADD += $(top_builddir)/tests/gpiosim/libgpiosim.la
Signature · 1 line
2.30.1
PATCH v2 4/4 tests: rewrite core C tests using libgpiosim
In reply to Bartosz GolaszewskiThis replaces the old tests for the C API v1 based on gpio-mockup with a test suite based on gpio-sim that covers around 95% of the libgpiod v2 codebase.
The test harness has been rebuilt and shrank significantly as well. The libgpiosim API has been wrapped in a gobject interface.
--- configure.ac | 8 +- tests/Makefile.am | 20 +- tests/gpiod-test-helpers.c | 49 ++ tests/gpiod-test-helpers.h | 131 ++++ tests/gpiod-test-sim.c | 303 ++++++++++ tests/gpiod-test-sim.h | 42 ++ tests/gpiod-test.c | 233 +------- tests/gpiod-test.h | 81 +-- tests/gpiosim/gpiosim.c | 1 + tests/mockup/Makefile.am | 11 - tests/mockup/gpio-mockup.c | 496 ---------------- tests/mockup/gpio-mockup.h | 36 -- tests/tests-chip.c | 282 ++++----- tests/tests-edge-event.c | 420 +++++++++++++ tests/tests-event.c | 908 ---------------------------- tests/tests-info-event.c | 301 ++++++++++ tests/tests-line-config.c | 408 +++++++++++++ tests/tests-line-info.c | 316 ++++++++++ tests/tests-line-request.c | 421 +++++++++++++ tests/tests-line.c | 1091 ---------------------------------- tests/tests-misc.c | 86 ++- tests/tests-request-config.c | 90 +++ 22 files changed, 2714 insertions(+), 3020 deletions(-) create mode 100644 tests/gpiod-test-helpers.c create mode 100644 tests/gpiod-test-helpers.h create mode 100644 tests/gpiod-test-sim.c create mode 100644 tests/gpiod-test-sim.h delete mode 100644 tests/mockup/Makefile.am delete mode 100644 tests/mockup/gpio-mockup.c delete mode 100644 tests/mockup/gpio-mockup.h create mode 100644 tests/tests-edge-event.c delete mode 100644 tests/tests-event.c create mode 100644 tests/tests-info-event.c create mode 100644 tests/tests-line-config.c create mode 100644 tests/tests-line-info.c create mode 100644 tests/tests-line-request.c delete mode 100644 tests/tests-line.c create mode 100644 tests/tests-request-config.c
configure.ac +3 -5
@@ -28,9 +28,8 @@ AC_SUBST(VERSION_STR, [$PACKAGE_VERSION$EXTRA_VERSION]) AC_SUBST(ABI_VERSION, [4.1.2]) # Have a separate ABI version for C++ bindings: AC_SUBST(ABI_CXX_VERSION, [2.1.1]) -# ABI version for libgpiomockup (we need this since it can be installed if we +# ABI version for libgpiosim (we need this since it can be installed if we # enable install-tests). -AC_SUBST(ABI_MOCKUP_VERSION, [0.1.0]) AC_SUBST(ABI_GPIOSIM_VERSION, [0.1.0]) AC_CONFIG_AUX_DIR([autostuff])
@@ -137,14 +136,14 @@ AC_DEFUN([FUNC_NOT_FOUND_TESTS], if test "x$with_tests" = xtrue then - # For libgpiomockup & libgpiosim + # For libgpiosim AC_CHECK_FUNC([qsort], [], [FUNC_NOT_FOUND_TESTS([qsort])]) PKG_CHECK_MODULES([KMOD], [libkmod >= 18]) - PKG_CHECK_MODULES([UDEV], [libudev >= 215]) PKG_CHECK_MODULES([MOUNT], [mount >= 2.33.1]) # For core library tests PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.50]) + PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.50]) if test "x$with_tools" = xtrue then
@@ -235,7 +234,6 @@ AC_CONFIG_FILES([Makefile lib/libgpiod.pc tools/Makefile tests/Makefile - tests/mockup/Makefile tests/gpiosim/Makefile bindings/cxx/libgpiodcxx.pc bindings/Makefile
tests/Makefile.am +14 -6
@@ -1,24 +1,32 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2017-2022 Bartosz Golaszewski <[email protected]> -SUBDIRS = mockup gpiosim +SUBDIRS = gpiosim AM_CFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/tests/gpiosim/ AM_CFLAGS += -include $(top_builddir)/config.h -AM_CFLAGS += -Wall -Wextra -g -std=gnu89 $(GLIB_CFLAGS) +AM_CFLAGS += -Wall -Wextra -g -std=gnu89 $(GLIB_CFLAGS) $(GOBJECT_CFLAGS) AM_CFLAGS += -DG_LOG_DOMAIN=\"gpiod-test\" AM_CFLAGS += $(PROFILING_FLAGS) AM_LDFLAGS = -pthread LDADD = $(top_builddir)/lib/libgpiod.la LDADD += $(top_builddir)/tests/gpiosim/libgpiosim.la -LDADD += $(GLIB_LIBS) +LDADD += $(GLIB_LIBS) $(GOBJECT_LIBS) bin_PROGRAMS = gpiod-test gpiod_test_SOURCES = \ gpiod-test.c \ gpiod-test.h \ + gpiod-test-helpers.c \ + gpiod-test-helpers.h \ + gpiod-test-sim.c \ + gpiod-test-sim.h \ tests-chip.c \ - tests-event.c \ - tests-line.c \ - tests-misc.c + tests-edge-event.c \ + tests-info-event.c \ + tests-line-config.c \ + tests-line-info.c \ + tests-line-request.c \ + tests-misc.c \ + tests-request-config.c
tests/gpiod-test-helpers.c new file +49 -0
49 lines not on this page · raw message
tests/gpiod-test-helpers.h new file +131 -0
131 lines not on this page · raw message
tests/gpiod-test-sim.c new file +303 -0
303 lines not on this page · raw message
tests/gpiod-test-sim.h new file +42 -0
42 lines not on this page · raw message
tests/gpiod-test.c +9 -224
276 lines not on this page · raw message
tests/gpiod-test.h +15 -66
101 lines not on this page · raw message
tests/gpiosim/gpiosim.c +1 -0
@@ -736,6 +736,7 @@ static void bank_release(struct refcount *ref)unsigned int i;char buf[64 ]; +/* FIXME should be based on dirent because num_lines can change. */ for (i =0 ; i < bank->num_lines; i++) {snprintf (buf,sizeof (buf),"line%u/hog" , i);unlinkat (bank->cfs_dir_fd, buf,AT_REMOVEDIR );
tests/mockup/Makefile.am deleted +0 -11
@@ -1,11 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -lib_LTLIBRARIES = libgpiomockup.la - -libgpiomockup_la_SOURCES = gpio-mockup.c gpio-mockup.h -libgpiomockup_la_CFLAGS = -Wall -Wextra -g -fvisibility=hidden -std=gnu89 -libgpiomockup_la_CFLAGS += -include $(top_builddir)/config.h -libgpiomockup_la_CFLAGS += $(KMOD_CFLAGS) $(UDEV_CFLAGS) -libgpiomockup_la_LDFLAGS = -version-info $(subst .,:,$(ABI_MOCKUP_VERSION)) -libgpiomockup_la_LDFLAGS += $(KMOD_LIBS) $(UDEV_LIBS)
tests/mockup/gpio-mockup.c deleted +0 -496
496 lines not on this page · raw message
tests/mockup/gpio-mockup.h deleted +0 -36
@@ -1,36 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> */ - -#ifndef __GPIO_MOCKUP_H__ -#define __GPIO_MOCKUP_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -struct gpio_mockup ; - -#define GPIO_MOCKUP_FLAG_NAMED_LINES (1 << 0) - -struct gpio_mockup *gpio_mockup_new (void ); -void gpio_mockup_ref (struct gpio_mockup *ctx); -void gpio_mockup_unref (struct gpio_mockup *ctx); - -int gpio_mockup_probe (struct gpio_mockup *ctx,unsigned int num_chips, -const unsigned int *chip_sizes,int flags); -int gpio_mockup_remove (struct gpio_mockup *ctx); - -const char *gpio_mockup_chip_name (struct gpio_mockup *ctx,unsigned int idx); -const char *gpio_mockup_chip_path (struct gpio_mockup *ctx,unsigned int idx); -int gpio_mockup_chip_num (struct gpio_mockup *ctx,unsigned int idx); - -int gpio_mockup_get_value (struct gpio_mockup *ctx, -unsigned int chip_idx,unsigned int line_offset); -int gpio_mockup_set_pull (struct gpio_mockup *ctx,unsigned int chip_idx, -unsigned int line_offset,int pull); - -#ifdef __cplusplus -}/* extern "C" */ -#endif - -#endif /* __GPIO_MOCKUP_H__ */
tests/tests-chip.c +112 -170
341 lines not on this page · raw message
tests/tests-edge-event.c new file +420 -0
420 lines not on this page · raw message
tests/tests-event.c deleted +0 -908
716 lines not on this page · raw message
tests/tests-info-event.c new file +301 -0
301 lines not on this page · raw message
tests/tests-line-config.c new file +408 -0
408 lines not on this page · raw message
tests/tests-line-info.c new file +316 -0
316 lines not on this page · raw message
tests/tests-line-request.c new file +421 -0
421 lines not on this page · raw message
tests/tests-line.c deleted +0 -1091
1,091 lines not on this page · raw message
tests/tests-misc.c +79 -7
86 lines not on this page · raw message
tests/tests-request-config.c new file +90 -0
90 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.30.1
Part of the diff is not shown here. View the raw message.