From ace8eef246fd977c8185240c5cf69b866071ae6f Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 16 May 2017 13:30:05 +0200 Subject: [PATCH] tests: tweak the event worker The event worker thread should only inject another line event if pthread_cond_timedwait() returned -ETIMEDOUT. If it returned 0, then the main thread called pthread_cond_broadcast() and either requested the worker thread to terminate or to change the event configuration. In both cases we should not inject an event. Signed-off-by: Bartosz Golaszewski --- tests/gpiod-test.c | 49 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index bccf02f..b28c079 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -284,32 +284,33 @@ static void * event_worker(void *data TEST_UNUSED) ts.tv_nsec = tv_res.tv_usec * 1000; status = pthread_cond_timedwait(&ev->cond, &ev->lock, &ts); - if (status != 0 && status != ETIMEDOUT) + if (status == ETIMEDOUT) { + path = xappend(NULL, + "/sys/kernel/debug/gpio-mockup-event/gpio-mockup-%c/%u", + 'A' + ev->chip_index, ev->line_offset); + + fd = open(path, O_RDWR); + free(path); + if (fd < 0) + die_perr("error opening gpio event file"); + + if (ev->event_type == TEST_EVENT_RISING) + buf = '1'; + else if (ev->event_type == TEST_EVENT_FALLING) + buf = '0'; + else + buf = i % 2 == 0 ? '1' : '0'; + + rd = write(fd, &buf, 1); + close(fd); + if (rd < 0) + die_perr("error writing to gpio event file"); + else if (rd != 1) + die("invalid write size to gpio event file"); + } else if (status != 0) { die("error waiting for conditional variable: %s", strerror(status)); - - path = xappend(NULL, - "/sys/kernel/debug/gpio-mockup-event/gpio-mockup-%c/%u", - 'A' + ev->chip_index, ev->line_offset); - - fd = open(path, O_RDWR); - free(path); - if (fd < 0) - die_perr("error opening gpio event file"); - - if (ev->event_type == TEST_EVENT_RISING) - buf = '1'; - else if (ev->event_type == TEST_EVENT_FALLING) - buf = '0'; - else - buf = i % 2 == 0 ? '1' : '0'; - - rd = write(fd, &buf, 1); - close(fd); - if (rd < 0) - die_perr("error writing to gpio event file"); - else if (rd != 1) - die("invalid write size to gpio event file"); + } event_unlock(); } -- 2.30.2