tests: gpioinfo: don't use static names for GPIO chips
authorBartosz Golaszewski <bartekgola@gmail.com>
Sat, 4 Nov 2017 21:37:38 +0000 (22:37 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Sat, 4 Nov 2017 22:17:45 +0000 (23:17 +0100)
We need to construct the pattern strings using the names supplied by
the testing framework - otherwise we may end up getting false
negatives from these test cases if the chip layout in the system is
different than expected.

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

index c75cbb2c7ff0b1627299e80f156a3ac08c5a3812..d94c4b2d4aff9bd66b467050e2c6da2c78c26a31 100644 (file)
 
 static void gpioinfo_dump_all_chips(void)
 {
+       TEST_CLEANUP(test_free_str) char *ptrn_line0 = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_line1 = NULL;
+       int rv0, rv1;
+
+       rv0 = asprintf(&ptrn_line0, "%s - 4 lines:", test_chip_name(0));
+       rv1 = asprintf(&ptrn_line1, "%s - 8 lines:", test_chip_name(1));
+       TEST_ASSERT(rv0 > 0);
+       TEST_ASSERT(rv1 > 0);
+
        test_tool_run("gpioinfo", (char *)NULL);
        test_tool_wait();
 
        TEST_ASSERT(test_tool_exited());
        TEST_ASSERT_RET_OK(test_tool_exit_status());
        TEST_ASSERT_NOT_NULL(test_tool_stdout());
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip0 - 4 lines:");
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip1 - 8 lines:");
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line0);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line1);
        TEST_ASSERT_REGEX_MATCH(test_tool_stdout(),
                                "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+output\\s+active-high");
        TEST_ASSERT_REGEX_MATCH(test_tool_stdout(),
@@ -36,14 +45,20 @@ TEST_DEFINE(gpioinfo_dump_all_chips,
 static void gpioinfo_dump_all_chips_one_exported(void)
 {
        TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL;
-       TEST_CLEANUP(test_free_str) char *ptrn = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_line0 = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_line1 = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_lineinfo = NULL;
        struct gpiod_line *line;
-       int rv;
+       int rv0, rv1, rv2;
 
-       rv = asprintf(&ptrn,
+       rv0 = asprintf(&ptrn_line0, "%s - 4 lines:", test_chip_name(0));
+       rv1 = asprintf(&ptrn_line1, "%s - 8 lines:", test_chip_name(1));
+       rv2 = asprintf(&ptrn_lineinfo,
                      "\\s+line\\s+7:\\s+unnamed\\s+\\\"%s\\\"\\s+input\\s+active-low",
                      TEST_CONSUMER);
-       TEST_ASSERT(rv > 0);
+       TEST_ASSERT(rv0 > 0);
+       TEST_ASSERT(rv1 > 0);
+       TEST_ASSERT(rv2 > 0);
 
        chip = gpiod_chip_open(test_chip_path(1));
        TEST_ASSERT_NOT_NULL(chip);
@@ -51,9 +66,9 @@ static void gpioinfo_dump_all_chips_one_exported(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       rv = gpiod_line_request_input_flags(line, TEST_CONSUMER,
+       rv2 = gpiod_line_request_input_flags(line, TEST_CONSUMER,
                                            GPIOD_LINE_REQUEST_ACTIVE_LOW);
-       TEST_ASSERT_RET_OK(rv);
+       TEST_ASSERT_RET_OK(rv2);
 
        test_tool_run("gpioinfo", (char *)NULL);
        test_tool_wait();
@@ -61,11 +76,11 @@ static void gpioinfo_dump_all_chips_one_exported(void)
        TEST_ASSERT(test_tool_exited());
        TEST_ASSERT_RET_OK(test_tool_exit_status());
        TEST_ASSERT_NOT_NULL(test_tool_stdout());
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip0 - 4 lines:");
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip1 - 8 lines:");
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line0);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line1);
        TEST_ASSERT_REGEX_MATCH(test_tool_stdout(),
                                "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+output\\s+active-high");
-       TEST_ASSERT_REGEX_MATCH(test_tool_stdout(), ptrn);
+       TEST_ASSERT_REGEX_MATCH(test_tool_stdout(), ptrn_lineinfo);
 }
 TEST_DEFINE(gpioinfo_dump_all_chips_one_exported,
            "tools: gpioinfo - dump all chips (one line exported)",
@@ -73,14 +88,23 @@ TEST_DEFINE(gpioinfo_dump_all_chips_one_exported,
 
 static void gpioinfo_dump_one_chip(void)
 {
+       TEST_CLEANUP(test_free_str) char *ptrn_line0 = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_line1 = NULL;
+       int rv0, rv1;
+
+       rv0 = asprintf(&ptrn_line0, "%s - 8 lines:", test_chip_name(0));
+       rv1 = asprintf(&ptrn_line1, "%s - 4 lines:", test_chip_name(1));
+       TEST_ASSERT(rv0 > 0);
+       TEST_ASSERT(rv1 > 0);
+
        test_tool_run("gpioinfo", test_chip_name(1), (char *)NULL);
        test_tool_wait();
 
        TEST_ASSERT(test_tool_exited());
        TEST_ASSERT_RET_OK(test_tool_exit_status());
        TEST_ASSERT_NOT_NULL(test_tool_stdout());
-       TEST_ASSERT_STR_NOTCONT(test_tool_stdout(), "gpiochip0 - 8 lines:");
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip1 - 4 lines:");
+       TEST_ASSERT_STR_NOTCONT(test_tool_stdout(), ptrn_line0);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line1);
        TEST_ASSERT_REGEX_MATCH(test_tool_stdout(),
                                "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+output\\s+active-high");
        TEST_ASSERT_REGEX_NOMATCH(test_tool_stdout(),
@@ -92,6 +116,21 @@ TEST_DEFINE(gpioinfo_dump_one_chip,
 
 static void gpioinfo_dump_all_but_one_chip(void)
 {
+       TEST_CLEANUP(test_free_str) char *ptrn_line0 = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_line1 = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_line2 = NULL;
+       TEST_CLEANUP(test_free_str) char *ptrn_line3 = NULL;
+       int rv0, rv1, rv2, rv3;
+
+       rv0 = asprintf(&ptrn_line0, "%s - 4 lines:", test_chip_name(0));
+       rv1 = asprintf(&ptrn_line1, "%s - 4 lines:", test_chip_name(1));
+       rv2 = asprintf(&ptrn_line2, "%s - 8 lines:", test_chip_name(2));
+       rv3 = asprintf(&ptrn_line3, "%s - 4 lines:", test_chip_name(3));
+       TEST_ASSERT(rv0 > 0);
+       TEST_ASSERT(rv1 > 0);
+       TEST_ASSERT(rv2 > 0);
+       TEST_ASSERT(rv3 > 0);
+
        test_tool_run("gpioinfo", test_chip_name(0),
                      test_chip_name(1), test_chip_name(3), (char *)NULL);
        test_tool_wait();
@@ -99,10 +138,10 @@ static void gpioinfo_dump_all_but_one_chip(void)
        TEST_ASSERT(test_tool_exited());
        TEST_ASSERT_RET_OK(test_tool_exit_status());
        TEST_ASSERT_NOT_NULL(test_tool_stdout());
-       TEST_ASSERT_STR_NOTCONT(test_tool_stdout(), "gpiochip2 - 8 lines:");
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip0 - 4 lines:");
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip1 - 4 lines:");
-       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip3 - 4 lines:");
+       TEST_ASSERT_STR_NOTCONT(test_tool_stdout(), ptrn_line2);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line0);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line1);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), ptrn_line3);
        TEST_ASSERT_REGEX_MATCH(test_tool_stdout(),
                                "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+output\\s+active-high");
        TEST_ASSERT_REGEX_NOMATCH(test_tool_stdout(),