From: Bartosz Golaszewski Date: Mon, 19 Feb 2018 10:32:41 +0000 (+0100) Subject: core: allow NULL default_vals for output requests X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=12badc212cbc8c29480f64bb556de0989281e8d4;p=qemu-gpiodev%2Flibgpiod.git core: allow NULL default_vals for output requests Explicitly allow default_vals to be NULL for output requests, in which case the actual default values passed to the kernel are set to 0. Add a test case that verifies that this works correctly. Signed-off-by: Bartosz Golaszewski --- diff --git a/src/lib/core.c b/src/lib/core.c index fa276f6..22f247d 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -368,7 +368,9 @@ static int line_request_values(struct gpiod_line_bulk *bulk, gpiod_line_bulk_foreach_line_off(bulk, line, i) { req.lineoffsets[i] = gpiod_line_offset(line); - if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT) + if (config->request_type == + GPIOD_LINE_REQUEST_DIRECTION_OUTPUT && + default_vals) req.default_values[i] = !!default_vals[i]; } diff --git a/tests/tests-line.c b/tests/tests-line.c index 5c1397f..bae3451 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -247,6 +247,44 @@ TEST_DEFINE(line_request_bulk_different_chips, "gpiod_line_request_bulk() - different chips", 0, { 8, 8 }); +static void line_request_null_default_vals_for_output(void) +{ + TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL; + struct gpiod_line_bulk bulk = GPIOD_LINE_BULK_INITIALIZER; + struct gpiod_line *line; + int rv, vals[3]; + + chip = gpiod_chip_open(test_chip_path(0)); + TEST_ASSERT_NOT_NULL(chip); + + line = gpiod_chip_get_line(chip, 0); + gpiod_line_bulk_add(&bulk, line); + line = gpiod_chip_get_line(chip, 1); + gpiod_line_bulk_add(&bulk, line); + line = gpiod_chip_get_line(chip, 2); + gpiod_line_bulk_add(&bulk, line); + + rv = gpiod_line_request_bulk_output(&bulk, TEST_CONSUMER, NULL); + TEST_ASSERT_RET_OK(rv); + + gpiod_line_release_bulk(&bulk); + + rv = gpiod_line_request_bulk_input(&bulk, TEST_CONSUMER); + TEST_ASSERT_RET_OK(rv); + + memset(vals, 0, sizeof(vals)); + + rv = gpiod_line_get_value_bulk(&bulk, vals); + TEST_ASSERT_RET_OK(rv); + + TEST_ASSERT_EQ(vals[0], 0); + TEST_ASSERT_EQ(vals[1], 0); + TEST_ASSERT_EQ(vals[2], 0); +} +TEST_DEFINE(line_request_null_default_vals_for_output, + "gpiod_line_request_bulk() - null default vals for output", + 0, { 8 }); + static void line_set_value(void) { TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL;