From 9189bc89b88913c9d531a6b9593777bb1eb7a103 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 1 Mar 2017 11:12:03 +0100 Subject: [PATCH] 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 --- tests/unit/gpiod-unit.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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); } -- 2.30.2