From f6fe99dfe1bb8332f522a4269547a674a4fe3594 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 14 Mar 2017 17:52:24 +0100 Subject: [PATCH] tests: sort mockup chips by number, not by name 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 --- tests/unit/gpiod-unit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/gpiod-unit.c b/tests/unit/gpiod-unit.c index b28512f..ffd4231 100644 --- a/tests/unit/gpiod-unit.c +++ b/tests/unit/gpiod-unit.c @@ -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); } -- 2.30.2