tests: add a test case for a bad line request
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 2 Mar 2017 10:08:58 +0000 (11:08 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 2 Mar 2017 10:08:58 +0000 (11:08 +0100)
Implement a test case in which we try to request lines from different
GPIO chips in a single bulk object.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/unit/tests-line.c

index 91a81deb0f337fc4c50c27f46afc310f53576632..fc7274ca3870a15477244cf921e350162f6d7dc4 100644 (file)
@@ -131,6 +131,51 @@ GU_DEFINE_TEST(line_request_bulk_output,
               "gpiod_line_request_bulk_output()",
               GU_LINES_UNNAMED, { 8, 8 });
 
+static void line_request_bulk_different_chips(void)
+{
+       GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipA = NULL;
+       GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipB = NULL;
+       struct gpiod_line_request_config req;
+       struct gpiod_line *lineA0 = NULL;
+       struct gpiod_line *lineA1 = NULL;
+       struct gpiod_line *lineB0 = NULL;
+       struct gpiod_line *lineB1 = NULL;
+       struct gpiod_line_bulk bulk;
+       int status;
+
+       chipA = gpiod_chip_open(gu_chip_path(0));
+       chipB = gpiod_chip_open(gu_chip_path(1));
+       GU_ASSERT_NOT_NULL(chipA);
+       GU_ASSERT_NOT_NULL(chipB);
+
+       lineA0 = gpiod_chip_get_line(chipA, 0);
+       lineA1 = gpiod_chip_get_line(chipA, 1);
+       lineB0 = gpiod_chip_get_line(chipB, 0);
+       lineB1 = gpiod_chip_get_line(chipB, 1);
+
+       GU_ASSERT_NOT_NULL(lineA0);
+       GU_ASSERT_NOT_NULL(lineA1);
+       GU_ASSERT_NOT_NULL(lineB0);
+       GU_ASSERT_NOT_NULL(lineB1);
+
+       gpiod_line_bulk_init(&bulk);
+       gpiod_line_bulk_add(&bulk, lineA0);
+       gpiod_line_bulk_add(&bulk, lineA1);
+       gpiod_line_bulk_add(&bulk, lineB0);
+       gpiod_line_bulk_add(&bulk, lineB1);
+
+       req.consumer = "gpiod-unit";
+       req.direction = GPIOD_DIRECTION_INPUT;
+       req.active_state = GPIOD_ACTIVE_STATE_HIGH;
+
+       status = gpiod_line_request_bulk(&bulk, &req, NULL);
+       GU_ASSERT_NOTEQ(status, 0);
+       GU_ASSERT_EQ(gpiod_errno(), GPIOD_EBULKINCOH);
+}
+GU_DEFINE_TEST(line_request_bulk_different_chips,
+              "gpiod_line_request_bulk() different chips",
+              GU_LINES_UNNAMED, { 8, 8 });
+
 static void line_set_value(void)
 {
        GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL;