tests: allow having zero gpio-mockup chips for tests
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 8 Jun 2017 11:24:36 +0000 (13:24 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 8 Jun 2017 11:30:56 +0000 (13:30 +0200)
We may have tests which don't require any gpio-mockup chips to be
present. When an empty array is given as the list of chip line counts,
the gpio-mockup module will not be loaded.

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

index e0dd923b89d6ada2aadbbf92a5052fd0a3b93b44..ae76dfb77b5de80703a27f2f57c74ca6a47167c4 100644 (file)
@@ -644,6 +644,9 @@ static void load_module(struct _test_chip_descr *descr)
        char *modarg;
        int status;
 
+       if (descr->num_chips == 0)
+               return;
+
        modarg = xappend(NULL, "gpio_mockup_ranges=");
        for (i = 0; i < descr->num_chips; i++)
                modarg = xappend(modarg, "-1,%u,", descr->num_lines[i]);
@@ -836,9 +839,11 @@ static void teardown_test(void)
 
        free(globals.test_ctx.chips);
 
-       status = kmod_module_remove_module(globals.module, 0);
-       if (status)
-               die_perr("unable to remove gpio-mockup");
+       if (mockup_loaded()) {
+               status = kmod_module_remove_module(globals.module, 0);
+               if (status)
+                       die_perr("unable to remove gpio-mockup");
+       }
 }
 
 int main(int argc TEST_UNUSED, char **argv)