From: Bartosz Golaszewski Date: Wed, 1 Mar 2017 10:12:03 +0000 (+0100) Subject: tests: explain the need for qsort() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=9189bc89b88913c9d531a6b9593777bb1eb7a103;p=qemu-gpiodev%2Flibgpiod.git tests: explain the need for qsort() Add a comment explaining why we need to sort the mockup gpiochip structures after detecting them with udev. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/unit/gpiod-unit.c b/tests/unit/gpiod-unit.c index be47e04..28ee6a3 100644 --- a/tests/unit/gpiod-unit.c +++ b/tests/unit/gpiod-unit.c @@ -326,6 +326,15 @@ static void test_prepare(struct _gu_chip_descr *descr) udev_monitor_unref(monitor); udev_unref(udev_ctx); + /* + * We can't assume that the order in which the mockup gpiochip + * devices are created will be deterministic, yet we want the + * index passed to the gu_chip_*() functions to correspond with the + * order in which the chips were defined in the GU_DEFINE_TEST() + * macro. + * + * Once all gpiochips are there, sort them by name. + */ qsort(ctx->chips, ctx->num_chips, sizeof(*ctx->chips), chipcmp); }