tests: explain the need for qsort()
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 1 Mar 2017 10:12:03 +0000 (11:12 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 1 Mar 2017 10:12:03 +0000 (11:12 +0100)
Add a comment explaining why we need to sort the mockup gpiochip
structures after detecting them with udev.

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

index be47e043fadd990510dd60164f83bfecc62aaa7b..28ee6a36777e8bbaa9a6af03a5c49aeafbe849c5 100644 (file)
@@ -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);
 }