tests: sort mockup chips by number, not by name
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 14 Mar 2017 16:52:24 +0000 (17:52 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 14 Mar 2017 16:52:24 +0000 (17:52 +0100)
If we request more than 9 chips for a test case, we'll run into
a problem: 'gpiochip10' will come before 'gpiochip2' when sorting by
name.

Sort by chip number instead - it's stored as an unsigned integer and
the above situation will not occur.

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

index b28512fa37903801b474e8d7251d9156de3218a8..ffd42314b0516a3acdf9cd5278b0af5efe1b9514 100644 (file)
@@ -292,7 +292,7 @@ static int chipcmp(const void *c1, const void *c2)
        const struct mockup_chip *chip1 = *(const struct mockup_chip **)c1;
        const struct mockup_chip *chip2 = *(const struct mockup_chip **)c2;
 
-       return strcmp(chip1->name, chip2->name);
+       return chip1->number > chip2->number;
 }
 
 static bool devpath_is_mockup(const char *devpath)
@@ -386,7 +386,7 @@ static void test_prepare(struct _gu_chip_descr *descr)
         * order in which the chips were defined in the GU_DEFINE_TEST()
         * macro.
         *
-        * Once all gpiochips are there, sort them by name.
+        * Once all gpiochips are there, sort them by chip number.
         */
        qsort(ctx->chips, ctx->num_chips, sizeof(*ctx->chips), chipcmp);
 }