From: Bartosz Golaszewski Date: Wed, 14 Nov 2018 10:15:30 +0000 (+0100) Subject: treewide: unify naming of local variables representing return values X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=acdd77c639d3f50a826d9f2467c04b79ed4d3ff4;p=qemu-gpiodev%2Flibgpiod.git treewide: unify naming of local variables representing return values For integers representing simple return values of various functions use the name 'rv' everywhere. Signed-off-by: Bartosz Golaszewski --- diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index 6cd8011..fb1243f 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -123,14 +123,14 @@ PyDoc_STRVAR(gpiod_LineEvent_get_type_doc, PyObject *gpiod_LineEvent_get_type(gpiod_LineEventObject *self) { - int ret; + int rv; if (self->event.event_type == GPIOD_LINE_EVENT_RISING_EDGE) - ret = gpiod_RISING_EDGE; + rv = gpiod_RISING_EDGE; else - ret = gpiod_FALLING_EDGE; + rv = gpiod_FALLING_EDGE; - return Py_BuildValue("I", ret); + return Py_BuildValue("I", rv); } PyDoc_STRVAR(gpiod_LineEvent_get_sec_doc, diff --git a/src/lib/core.c b/src/lib/core.c index 4f273e3..7c4f0bf 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -145,7 +145,7 @@ struct gpiod_chip *gpiod_chip_open(const char *path) { struct gpiochip_info info; struct gpiod_chip *chip; - int status, fd; + int rv, fd; fd = open(path, O_RDWR | O_CLOEXEC); if (fd < 0) @@ -167,8 +167,8 @@ struct gpiod_chip *gpiod_chip_open(const char *path) memset(chip, 0, sizeof(*chip)); memset(&info, 0, sizeof(info)); - status = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &info); - if (status < 0) + rv = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &info); + if (rv < 0) goto err_free_chip; chip->fd = fd; @@ -240,7 +240,7 @@ struct gpiod_line * gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset) { struct gpiod_line *line; - int status; + int rv; if (offset >= chip->num_lines) { errno = EINVAL; @@ -270,8 +270,8 @@ gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset) line = chip->lines[offset]; } - status = gpiod_line_update(line); - if (status < 0) + rv = gpiod_line_update(line); + if (rv < 0) return NULL; return line; @@ -322,10 +322,10 @@ static int line_get_fd(struct gpiod_line *line) static void line_maybe_update(struct gpiod_line *line) { - int status; + int rv; - status = gpiod_line_update(line); - if (status < 0) + rv = gpiod_line_update(line); + if (rv < 0) line->up_to_date = false; } @@ -679,13 +679,13 @@ bool gpiod_line_is_free(struct gpiod_line *line) int gpiod_line_get_value(struct gpiod_line *line) { struct gpiod_line_bulk bulk; - int status, value; + int rv, value; gpiod_line_bulk_init(&bulk); gpiod_line_bulk_add(&bulk, line); - status = gpiod_line_get_value_bulk(&bulk, &value); - if (status < 0) + rv = gpiod_line_get_value_bulk(&bulk, &value); + if (rv < 0) return -1; return value; @@ -696,7 +696,7 @@ int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values) struct gpiohandle_data data; struct gpiod_line *first; unsigned int i; - int status, fd; + int rv, fd; if (!line_bulk_same_chip(bulk) || !line_bulk_all_requested(bulk)) return -1; @@ -707,8 +707,8 @@ int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values) fd = line_get_fd(first); - status = ioctl(fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); - if (status < 0) + rv = ioctl(fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); + if (rv < 0) return -1; for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) @@ -732,7 +732,7 @@ int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, const int *values) struct gpiohandle_data data; struct gpiod_line *line; unsigned int i; - int status, fd; + int rv, fd; if (!line_bulk_same_chip(bulk) || !line_bulk_all_requested(bulk)) return -1; @@ -745,8 +745,8 @@ int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, const int *values) line = gpiod_line_bulk_get_line(bulk, 0); fd = line_get_fd(line); - status = ioctl(fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data); - if (status < 0) + rv = ioctl(fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data); + if (rv < 0) return -1; return 0; diff --git a/src/lib/ctxless.c b/src/lib/ctxless.c index 0009504..17f255f 100644 --- a/src/lib/ctxless.c +++ b/src/lib/ctxless.c @@ -17,12 +17,12 @@ int gpiod_ctxless_get_value(const char *device, unsigned int offset, bool active_low, const char *consumer) { - int value, status; + int value, rv; - status = gpiod_ctxless_get_value_multiple(device, &offset, &value, - 1, active_low, consumer); - if (status < 0) - return status; + rv = gpiod_ctxless_get_value_multiple(device, &offset, &value, + 1, active_low, consumer); + if (rv < 0) + return rv; return value; } @@ -35,7 +35,7 @@ int gpiod_ctxless_get_value_multiple(const char *device, struct gpiod_line_bulk bulk; struct gpiod_chip *chip; struct gpiod_line *line; - int status, flags; + int rv, flags; unsigned int i; if (num_lines > GPIOD_LINE_BULK_MAX_LINES) { @@ -61,18 +61,18 @@ int gpiod_ctxless_get_value_multiple(const char *device, flags = active_low ? GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW : 0; - status = gpiod_line_request_bulk_input_flags(&bulk, consumer, flags); - if (status < 0) { + rv = gpiod_line_request_bulk_input_flags(&bulk, consumer, flags); + if (rv < 0) { gpiod_chip_close(chip); return -1; } memset(values, 0, sizeof(*values) * num_lines); - status = gpiod_line_get_value_bulk(&bulk, values); + rv = gpiod_line_get_value_bulk(&bulk, values); gpiod_chip_close(chip); - return status; + return rv; } int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value, @@ -92,8 +92,8 @@ int gpiod_ctxless_set_value_multiple(const char *device, struct gpiod_line_bulk bulk; struct gpiod_chip *chip; struct gpiod_line *line; - int status, flags; unsigned int i; + int rv, flags; if (num_lines > GPIOD_LINE_BULK_MAX_LINES) { errno = EINVAL; @@ -118,9 +118,9 @@ int gpiod_ctxless_set_value_multiple(const char *device, flags = active_low ? GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW : 0; - status = gpiod_line_request_bulk_output_flags(&bulk, consumer, - flags, values); - if (status < 0) { + rv = gpiod_line_request_bulk_output_flags(&bulk, consumer, + flags, values); + if (rv < 0) { gpiod_chip_close(chip); return -1; } diff --git a/src/lib/helpers.c b/src/lib/helpers.c index 80b8eff..9beea3a 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -30,10 +30,10 @@ struct gpiod_chip *gpiod_chip_open_by_name(const char *name) { struct gpiod_chip *chip; char *path; - int status; + int rv; - status = asprintf(&path, "/dev/%s", name); - if (status < 0) + rv = asprintf(&path, "/dev/%s", name); + if (rv < 0) return NULL; chip = gpiod_chip_open(path); @@ -46,10 +46,10 @@ struct gpiod_chip *gpiod_chip_open_by_number(unsigned int num) { struct gpiod_chip *chip; char *path; - int status; + int rv; - status = asprintf(&path, "/dev/gpiochip%u", num); - if (!status) + rv = asprintf(&path, "/dev/gpiochip%u", num); + if (!rv) return NULL; chip = gpiod_chip_open(path); diff --git a/src/tools/gpioget.c b/src/tools/gpioget.c index b468c05..d942c07 100644 --- a/src/tools/gpioget.c +++ b/src/tools/gpioget.c @@ -37,7 +37,7 @@ static void print_help(void) int main(int argc, char **argv) { unsigned int *offsets, i, num_lines; - int *values, optc, opti, status; + int *values, optc, opti, rv; bool active_low = false; char *device, *end; @@ -86,10 +86,10 @@ int main(int argc, char **argv) die("invalid GPIO offset: %s", argv[i + 1]); } - status = gpiod_ctxless_get_value_multiple(device, offsets, values, - num_lines, active_low, - "gpioget"); - if (status < 0) + rv = gpiod_ctxless_get_value_multiple(device, offsets, values, + num_lines, active_low, + "gpioget"); + if (rv < 0) die_perror("error reading GPIO values"); for (i = 0; i < num_lines; i++) { diff --git a/src/tools/gpioinfo.c b/src/tools/gpioinfo.c index e631e1c..73dc4e5 100644 --- a/src/tools/gpioinfo.c +++ b/src/tools/gpioinfo.c @@ -60,12 +60,12 @@ static PRINTF(3, 4) void prinfo(bool *of, char *buf, *buffmt = NULL; size_t len; va_list va; - int status; + int rv; va_start(va, fmt); - status = vasprintf(&buf, fmt, va); + rv = vasprintf(&buf, fmt, va); va_end(va); - if (status < 0) + if (rv < 0) die("vasprintf: %s\n", strerror(errno)); len = strlen(buf) - 1; @@ -74,8 +74,8 @@ static PRINTF(3, 4) void prinfo(bool *of, *of = true; printf("%s", buf); } else { - status = asprintf(&buffmt, "%%%us", prlen); - if (status < 0) + rv = asprintf(&buffmt, "%%%us", prlen); + if (rv < 0) die("asprintf: %s\n", strerror(errno)); printf(buffmt, buf); diff --git a/src/tools/gpiomon.c b/src/tools/gpiomon.c index c13ab38..5dfb388 100644 --- a/src/tools/gpiomon.c +++ b/src/tools/gpiomon.c @@ -141,7 +141,7 @@ static int poll_callback(unsigned int num_lines, { struct pollfd pfds[GPIOD_LINE_BULK_MAX_LINES + 1]; struct mon_ctx *ctx = data; - int cnt, ts, ret; + int cnt, ts, rv; unsigned int i; for (i = 0; i < num_lines; i++) { @@ -160,12 +160,12 @@ static int poll_callback(unsigned int num_lines, else if (cnt == 0) return GPIOD_CTXLESS_EVENT_POLL_RET_TIMEOUT; - ret = cnt; + rv = cnt; for (i = 0; i < num_lines; i++) { if (pfds[i].revents) { fds[i].event = true; if (!--cnt) - return ret; + return rv; } } @@ -243,7 +243,7 @@ int main(int argc, char **argv) unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES], num_lines = 0, offset; bool active_low = false, watch_rising = false, watch_falling = false; struct timespec timeout = { 10, 0 }; - int optc, opti, ret, i, event_type; + int optc, opti, rv, i, event_type; struct mon_ctx ctx; char *end; @@ -315,12 +315,12 @@ int main(int argc, char **argv) ctx.sigfd = make_signalfd(); - ret = gpiod_ctxless_event_monitor_multiple(argv[0], event_type, - offsets, num_lines, - active_low, "gpiomon", - &timeout, poll_callback, - event_callback, &ctx); - if (ret) + rv = gpiod_ctxless_event_monitor_multiple(argv[0], event_type, + offsets, num_lines, + active_low, "gpiomon", + &timeout, poll_callback, + event_callback, &ctx); + if (rv) die_perror("error waiting for events"); return EXIT_SUCCESS; diff --git a/src/tools/gpioset.c b/src/tools/gpioset.c index fb012fa..0678373 100644 --- a/src/tools/gpioset.c +++ b/src/tools/gpioset.c @@ -63,11 +63,11 @@ struct callback_data { static void maybe_daemonize(bool daemonize) { - int status; + int rv; if (daemonize) { - status = daemon(0, 0); - if (status < 0) + rv = daemon(0, 0); + if (rv < 0) die("unable to daemonize: %s", strerror(errno)); } } @@ -88,16 +88,16 @@ static void wait_time(void *data) static void wait_signal(void *data) { struct callback_data *cbdata = data; - int sigfd, status; struct pollfd pfd; sigset_t sigmask; + int sigfd, rv; sigemptyset(&sigmask); sigaddset(&sigmask, SIGTERM); sigaddset(&sigmask, SIGINT); - status = sigprocmask(SIG_BLOCK, &sigmask, NULL); - if (status < 0) + rv = sigprocmask(SIG_BLOCK, &sigmask, NULL); + if (rv < 0) die("error blocking signals: %s", strerror(errno)); sigfd = signalfd(-1, &sigmask, 0); @@ -111,10 +111,10 @@ static void wait_signal(void *data) maybe_daemonize(cbdata->daemonize); for (;;) { - status = poll(&pfd, 1, 1000 /* one second */); - if (status < 0) + rv = poll(&pfd, 1, 1000 /* one second */); + if (rv < 0) die("error polling for signals: %s", strerror(errno)); - else if (status > 0) + else if (rv > 0) break; } @@ -176,7 +176,7 @@ int main(int argc, char **argv) { const struct mode_mapping *mode = &modes[MODE_EXIT]; unsigned int *offsets, num_lines, i; - int *values, status, optc, opti; + int *values, rv, optc, opti; struct callback_data cbdata; bool active_low = false; char *device, *end; @@ -251,8 +251,8 @@ int main(int argc, char **argv) die("out of memory"); for (i = 0; i < num_lines; i++) { - status = sscanf(argv[i + 1], "%u=%d", &offsets[i], &values[i]); - if (status != 2) + rv = sscanf(argv[i + 1], "%u=%d", &offsets[i], &values[i]); + if (rv != 2) die("invalid offset<->value mapping: %s", argv[i + 1]); if (values[i] != 0 && values[i] != 1) @@ -262,11 +262,10 @@ int main(int argc, char **argv) die("invalid offset: %s", argv[i + 1]); } - status = gpiod_ctxless_set_value_multiple(device, offsets, values, - num_lines, active_low, - "gpioset", mode->callback, - &cbdata); - if (status < 0) + rv = gpiod_ctxless_set_value_multiple(device, offsets, values, + num_lines, active_low, "gpioset", + mode->callback, &cbdata); + if (rv < 0) die_perror("error setting the GPIO line values"); free(offsets); diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 0177301..8083f1c 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -172,11 +172,11 @@ static TEST_PRINTF(1, 2) void err(const char *fmt, ...) static void die_test_cleanup(void) { struct gpiotool_proc *proc = &globals.test_ctx.tool_proc; - int status; + int rv; if (proc->running) { kill(proc->pid, SIGKILL); - waitpid(proc->pid, &status, 0); + waitpid(proc->pid, &rv, 0); } if (globals.test_ctx.running) @@ -257,12 +257,12 @@ static TEST_PRINTF(2, 3) char *xappend(char *str, const char *fmt, ...) { char *new, *ret; va_list va; - int status; + int rv; va_start(va, fmt); - status = vasprintf(&new, fmt, va); + rv = vasprintf(&new, fmt, va); va_end(va); - if (status < 0) + if (rv < 0) die_perr("vasprintf"); if (!str) @@ -357,7 +357,7 @@ static void *event_worker(void *data TEST_UNUSED) struct event_thread *ev = &globals.test_ctx.event; struct timeval tv_now, tv_add, tv_res; struct timespec ts; - int status, i, fd; + int rv, i, fd; char *path; ssize_t rd; char buf; @@ -376,8 +376,8 @@ static void *event_worker(void *data TEST_UNUSED) ts.tv_sec = tv_res.tv_sec; ts.tv_nsec = tv_res.tv_usec * 1000; - status = pthread_cond_timedwait(&ev->cond, &ev->lock, &ts); - if (status == ETIMEDOUT) { + rv = pthread_cond_timedwait(&ev->cond, &ev->lock, &ts); + if (rv == ETIMEDOUT) { path = xappend(NULL, "/sys/kernel/debug/gpio-mockup-event/gpio-mockup-%c/%u", 'A' + ev->chip_index, ev->line_offset); @@ -400,9 +400,9 @@ static void *event_worker(void *data TEST_UNUSED) die_perr("error writing to gpio event file"); else if (rd != 1) die("invalid write size to gpio event file"); - } else if (status != 0) { + } else if (rv != 0) { die("error waiting for conditional variable: %s", - strerror(status)); + strerror(rv)); } event_unlock(); @@ -413,22 +413,22 @@ static void *event_worker(void *data TEST_UNUSED) static void gpiotool_proc_make_pipes(int *in_fds, int *out_fds, int *err_fds) { - int status, i, *fds[3]; + int rv, i, *fds[3]; fds[0] = in_fds; fds[1] = out_fds; fds[2] = err_fds; for (i = 0; i < 3; i++) { - status = pipe(fds[i]); - if (status < 0) + rv = pipe(fds[i]); + if (rv < 0) die_perr("unable to create a pipe"); } } static void gpiotool_proc_dup_fds(int in_fd, int out_fd, int err_fd) { - int old_fds[3], new_fds[3], i, status; + int old_fds[3], new_fds[3], i, rv; old_fds[0] = in_fd; old_fds[1] = out_fd; @@ -439,8 +439,8 @@ static void gpiotool_proc_dup_fds(int in_fd, int out_fd, int err_fd) new_fds[2] = STDERR_FILENO; for (i = 0; i < 3; i++) { - status = dup2(old_fds[i], new_fds[i]); - if (status < 0) + rv = dup2(old_fds[i], new_fds[i]); + if (rv < 0) die_perr("unable to duplicate a file descriptor"); close(old_fds[i]); @@ -529,7 +529,7 @@ void test_tool_stdin_write(const char *fmt, ...) void test_tool_run(char *tool, ...) { - int in_fds[2], out_fds[2], err_fds[2], status; + int in_fds[2], out_fds[2], err_fds[2], rv; struct gpiotool_proc *proc; sigset_t sigmask; char *path; @@ -549,15 +549,15 @@ void test_tool_run(char *tool, ...) gpiotool_proc_make_pipes(in_fds, out_fds, err_fds); path = gpiotool_proc_get_path(tool); - status = access(path, R_OK | X_OK); - if (status) + rv = access(path, R_OK | X_OK); + if (rv) die_perr("unable to execute '%s'", path); sigemptyset(&sigmask); sigaddset(&sigmask, SIGCHLD); - status = sigprocmask(SIG_BLOCK, &sigmask, NULL); - if (status) + rv = sigprocmask(SIG_BLOCK, &sigmask, NULL); + if (rv) die_perr("unable to block SIGCHLD"); proc->sig_fd = signalfd(-1, &sigmask, 0); @@ -617,8 +617,8 @@ void test_tool_wait(void) struct gpiotool_proc *proc; struct pollfd pfd; sigset_t sigmask; - int status; ssize_t rd; + int rv; proc = &globals.test_ctx.tool_proc; @@ -628,10 +628,10 @@ void test_tool_wait(void) pfd.fd = proc->sig_fd; pfd.events = POLLIN | POLLPRI; - status = poll(&pfd, 1, 5000); - if (status == 0) + rv = poll(&pfd, 1, 5000); + if (rv == 0) die("tool program is taking too long to terminate"); - else if (status < 0) + else if (rv < 0) die_perr("error when polling the signalfd"); rd = read(proc->sig_fd, &sinfo, sizeof(sinfo)); @@ -644,8 +644,8 @@ void test_tool_wait(void) sigemptyset(&sigmask); sigaddset(&sigmask, SIGCHLD); - status = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); - if (status) + rv = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + if (rv) die_perr("unable to unblock SIGCHLD"); gpiotool_readall(proc->stdout_fd, &proc->stdout); @@ -736,7 +736,7 @@ bad_version: static void check_gpio_mockup(void) { const char *modpath; - int status; + int rv; msg("checking gpio-mockup availability"); @@ -744,9 +744,9 @@ static void check_gpio_mockup(void) if (!globals.module_ctx) die_perr("error creating kernel module context"); - status = kmod_module_new_from_name(globals.module_ctx, - "gpio-mockup", &globals.module); - if (status) + rv = kmod_module_new_from_name(globals.module_ctx, + "gpio-mockup", &globals.module); + if (rv) die_perr("error allocating module info"); /* First see if we can find the module. */ @@ -755,14 +755,14 @@ static void check_gpio_mockup(void) die("the gpio-mockup module does not exist in the system or is built into the kernel"); /* Then see if we can freely load and unload it. */ - status = kmod_module_probe_insert_module(globals.module, 0, - "gpio_mockup_ranges=-1,4", - NULL, NULL, NULL); - if (status) + rv = kmod_module_probe_insert_module(globals.module, 0, + "gpio_mockup_ranges=-1,4", + NULL, NULL, NULL); + if (rv) die_perr("unable to load gpio-mockup"); - status = kmod_module_remove_module(globals.module, 0); - if (status) + rv = kmod_module_remove_module(globals.module, 0); + if (rv) die_perr("unable to remove gpio-mockup"); msg("gpio-mockup ok"); @@ -772,7 +772,7 @@ static void load_module(struct _test_chip_descr *descr) { unsigned int i; char *modarg; - int status; + int rv; if (descr->num_chips == 0) return; @@ -785,9 +785,9 @@ static void load_module(struct _test_chip_descr *descr) if (descr->flags & TEST_FLAG_NAMED_LINES) modarg = xappend(modarg, " gpio_mockup_named_lines"); - status = kmod_module_probe_insert_module(globals.module, 0, - modarg, NULL, NULL, NULL); - if (status) + rv = kmod_module_probe_insert_module(globals.module, 0, + modarg, NULL, NULL, NULL); + if (rv) die_perr("unable to load gpio-mockup"); free(modarg); @@ -818,7 +818,7 @@ static void prepare_test(struct _test_chip_descr *descr) struct udev_device *dev; struct udev *udev_ctx; struct pollfd pfd; - int status; + int rv; ctx = &globals.test_ctx; memset(ctx, 0, sizeof(*ctx)); @@ -840,13 +840,13 @@ static void prepare_test(struct _test_chip_descr *descr) if (!monitor) die_perr("error creating udev monitor"); - status = udev_monitor_filter_add_match_subsystem_devtype(monitor, - "gpio", NULL); - if (status < 0) + rv = udev_monitor_filter_add_match_subsystem_devtype(monitor, + "gpio", NULL); + if (rv < 0) die_perr("error adding udev filters"); - status = udev_monitor_enable_receiving(monitor); - if (status < 0) + rv = udev_monitor_enable_receiving(monitor); + if (rv < 0) die_perr("error enabling udev event receiving"); load_module(descr); @@ -855,10 +855,10 @@ static void prepare_test(struct _test_chip_descr *descr) pfd.events = POLLIN | POLLPRI; while (ctx->num_chips > detected) { - status = poll(&pfd, 1, 5000); - if (status < 0) + rv = poll(&pfd, 1, 5000); + if (rv < 0) die_perr("error polling for uevents"); - else if (status == 0) + else if (rv == 0) die("timeout waiting for gpiochips"); dev = udev_monitor_receive_device(monitor); @@ -880,8 +880,8 @@ static void prepare_test(struct _test_chip_descr *descr) chip = xzalloc(sizeof(*chip)); chip->name = xstrdup(sysname); chip->path = xstrdup(devnode); - status = sscanf(sysname, "gpiochip%u", &chip->number); - if (status != 1) + rv = sscanf(sysname, "gpiochip%u", &chip->number); + if (rv != 1) die("unable to determine chip number"); ctx->chips[detected++] = chip; @@ -937,7 +937,7 @@ static void teardown_test(void) struct mockup_chip *chip; struct event_thread *ev; unsigned int i; - int status; + int rv; event_lock(); ev = &globals.test_ctx.event; @@ -947,10 +947,10 @@ static void teardown_test(void) pthread_cond_broadcast(&ev->cond); event_unlock(); - status = pthread_join(globals.test_ctx.event.thread_id, NULL); - if (status != 0) + rv = pthread_join(globals.test_ctx.event.thread_id, NULL); + if (rv != 0) die("error joining event thread: %s", - strerror(status)); + strerror(rv)); pthread_mutex_destroy(&globals.test_ctx.event.lock); pthread_cond_destroy(&globals.test_ctx.event.cond); @@ -981,8 +981,8 @@ static void teardown_test(void) free(globals.test_ctx.custom_str); if (mockup_loaded()) { - status = kmod_module_remove_module(globals.module, 0); - if (status) + rv = kmod_module_remove_module(globals.module, 0); + if (rv) die_perr("unable to remove gpio-mockup"); } } @@ -1089,13 +1089,13 @@ void _test_register(struct _test_case *test) void _test_print_failed(const char *fmt, ...) { - int status; va_list va; + int rv; va_start(va, fmt); - status = vasprintf(&globals.test_ctx.failed_msg, fmt, va); + rv = vasprintf(&globals.test_ctx.failed_msg, fmt, va); va_end(va); - if (status < 0) + if (rv < 0) die_perr("vasprintf"); globals.test_ctx.test_failed = true; @@ -1105,16 +1105,15 @@ void test_set_event(unsigned int chip_index, unsigned int line_offset, int event_type, unsigned int freq) { struct event_thread *ev = &globals.test_ctx.event; - int status; + int rv; event_lock(); if (!ev->running) { - status = pthread_create(&ev->thread_id, NULL, - event_worker, NULL); - if (status != 0) + rv = pthread_create(&ev->thread_id, NULL, event_worker, NULL); + if (rv != 0) die("error creating event thread: %s", - strerror(status)); + strerror(rv)); ev->running = true; } diff --git a/tests/tests-ctxless.c b/tests/tests-ctxless.c index ea9403d..4daab48 100644 --- a/tests/tests-ctxless.c +++ b/tests/tests-ctxless.c @@ -13,19 +13,19 @@ static void ctxless_set_get_value(void) { - int ret; + int rv; - ret = gpiod_ctxless_get_value(test_chip_name(0), 3, - false, TEST_CONSUMER); - TEST_ASSERT_EQ(ret, 0); + rv = gpiod_ctxless_get_value(test_chip_name(0), 3, + false, TEST_CONSUMER); + TEST_ASSERT_EQ(rv, 0); - ret = gpiod_ctxless_set_value(test_chip_name(0), 3, 1, - false, TEST_CONSUMER, NULL, NULL); - TEST_ASSERT_RET_OK(ret); + rv = gpiod_ctxless_set_value(test_chip_name(0), 3, 1, + false, TEST_CONSUMER, NULL, NULL); + TEST_ASSERT_RET_OK(rv); - ret = gpiod_ctxless_get_value(test_chip_name(0), 3, - false, TEST_CONSUMER); - TEST_ASSERT_EQ(ret, 1); + rv = gpiod_ctxless_get_value(test_chip_name(0), 3, + false, TEST_CONSUMER); + TEST_ASSERT_EQ(rv, 1); } TEST_DEFINE(ctxless_set_get_value, "ctxless set/get value - single line", @@ -89,13 +89,13 @@ TEST_DEFINE(ctxless_set_get_value_multiple, static void ctxless_get_value_multiple_max_lines(void) { unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES + 1]; - int values[GPIOD_LINE_BULK_MAX_LINES + 1], ret; + int values[GPIOD_LINE_BULK_MAX_LINES + 1], rv; - ret = gpiod_ctxless_get_value_multiple(test_chip_name(0), offsets, - values, - GPIOD_LINE_BULK_MAX_LINES + 1, - false, TEST_CONSUMER); - TEST_ASSERT_NOTEQ(ret, 0); + rv = gpiod_ctxless_get_value_multiple(test_chip_name(0), offsets, + values, + GPIOD_LINE_BULK_MAX_LINES + 1, + false, TEST_CONSUMER); + TEST_ASSERT_NOTEQ(rv, 0); TEST_ASSERT_ERRNO_IS(EINVAL); } TEST_DEFINE(ctxless_get_value_multiple_max_lines, @@ -105,14 +105,14 @@ TEST_DEFINE(ctxless_get_value_multiple_max_lines, static void ctxless_set_value_multiple_max_lines(void) { unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES + 1]; - int values[GPIOD_LINE_BULK_MAX_LINES + 1], ret; - - ret = gpiod_ctxless_set_value_multiple(test_chip_name(0), offsets, - values, - GPIOD_LINE_BULK_MAX_LINES + 1, - false, TEST_CONSUMER, - NULL, NULL); - TEST_ASSERT_NOTEQ(ret, 0); + int values[GPIOD_LINE_BULK_MAX_LINES + 1], rv; + + rv = gpiod_ctxless_set_value_multiple(test_chip_name(0), offsets, + values, + GPIOD_LINE_BULK_MAX_LINES + 1, + false, TEST_CONSUMER, + NULL, NULL); + TEST_ASSERT_NOTEQ(rv, 0); TEST_ASSERT_ERRNO_IS(EINVAL); } TEST_DEFINE(ctxless_set_value_multiple_max_lines, @@ -146,16 +146,16 @@ static void ctxless_event_monitor(void) { struct ctxless_event_data evdata = { false, false, 0, 0 }; struct timespec ts = { 1, 0 }; - int status; + int rv; test_set_event(0, 3, TEST_EVENT_ALTERNATING, 100); - status = gpiod_ctxless_event_monitor(test_chip_name(0), - GPIOD_CTXLESS_EVENT_BOTH_EDGES, - 3, false, TEST_CONSUMER, &ts, - NULL, ctxless_event_cb, &evdata); + rv = gpiod_ctxless_event_monitor(test_chip_name(0), + GPIOD_CTXLESS_EVENT_BOTH_EDGES, + 3, false, TEST_CONSUMER, &ts, + NULL, ctxless_event_cb, &evdata); - TEST_ASSERT_RET_OK(status); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT(evdata.got_rising_edge); TEST_ASSERT(evdata.got_falling_edge); TEST_ASSERT_EQ(evdata.count, 2); @@ -193,7 +193,7 @@ static void ctxless_event_monitor_multiple(void) struct ctxless_event_data evdata = { false, false, 0, 0 }; struct timespec ts = { 1, 0 }; unsigned int offsets[4]; - int status; + int rv; offsets[0] = 2; offsets[1] = 3; @@ -202,13 +202,13 @@ static void ctxless_event_monitor_multiple(void) test_set_event(0, 3, TEST_EVENT_ALTERNATING, 100); - status = gpiod_ctxless_event_monitor_multiple( + rv = gpiod_ctxless_event_monitor_multiple( test_chip_name(0), GPIOD_CTXLESS_EVENT_BOTH_EDGES, offsets, 4, false, TEST_CONSUMER, &ts, NULL, ctxless_event_cb, &evdata); - TEST_ASSERT_RET_OK(status); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT(evdata.got_rising_edge); TEST_ASSERT(evdata.got_falling_edge); TEST_ASSERT_EQ(evdata.count, 2); diff --git a/tests/tests-line.c b/tests/tests-line.c index 1b73b86..1385381 100644 --- a/tests/tests-line.c +++ b/tests/tests-line.c @@ -16,7 +16,7 @@ static void line_request_output(void) TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line_0; struct gpiod_line *line_1; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -26,10 +26,10 @@ static void line_request_output(void) TEST_ASSERT_NOT_NULL(line_0); TEST_ASSERT_NOT_NULL(line_1); - status = gpiod_line_request_output(line_0, TEST_CONSUMER, 0); - TEST_ASSERT_RET_OK(status); - status = gpiod_line_request_output(line_1, TEST_CONSUMER, 1); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_output(line_0, TEST_CONSUMER, 0); + TEST_ASSERT_RET_OK(rv); + rv = gpiod_line_request_output(line_1, TEST_CONSUMER, 1); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(gpiod_line_get_value(line_0), 0); TEST_ASSERT_EQ(gpiod_line_get_value(line_1), 1); @@ -42,7 +42,7 @@ static void line_request_already_requested(void) { TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -50,11 +50,11 @@ static void line_request_already_requested(void) line = gpiod_chip_get_line(chip, 0); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_request_input(line, TEST_CONSUMER); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_input(line, TEST_CONSUMER); + TEST_ASSERT_RET_OK(rv); - status = gpiod_line_request_input(line, TEST_CONSUMER); - TEST_ASSERT_NOTEQ(status, 0); + rv = gpiod_line_request_input(line, TEST_CONSUMER); + TEST_ASSERT_NOTEQ(rv, 0); TEST_ASSERT_ERRNO_IS(EBUSY); } TEST_DEFINE(line_request_already_requested, @@ -65,7 +65,7 @@ static void line_consumer(void) { TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -75,8 +75,8 @@ static void line_consumer(void) TEST_ASSERT_NULL(gpiod_line_consumer(line)); - status = gpiod_line_request_input(line, TEST_CONSUMER); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_input(line, TEST_CONSUMER); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT(!gpiod_line_needs_update(line)); TEST_ASSERT_STR_EQ(gpiod_line_consumer(line), TEST_CONSUMER); @@ -89,7 +89,7 @@ static void line_consumer_long_string(void) { TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -99,9 +99,9 @@ static void line_consumer_long_string(void) TEST_ASSERT_NULL(gpiod_line_consumer(line)); - status = gpiod_line_request_input(line, - "consumer string over 32 characters long"); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_input(line, + "consumer string over 32 characters long"); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT(!gpiod_line_needs_update(line)); TEST_ASSERT_STR_EQ(gpiod_line_consumer(line), @@ -127,7 +127,7 @@ static void line_request_bulk_output(void) struct gpiod_line *lineB2; struct gpiod_line *lineB3; int valA[4], valB[4]; - int status; + int rv; chipA = gpiod_chip_open(test_chip_path(0)); chipB = gpiod_chip_open(test_chip_path(1)); @@ -167,28 +167,28 @@ static void line_request_bulk_output(void) valA[1] = 0; valA[2] = 0; valA[3] = 1; - status = gpiod_line_request_bulk_output(&bulkA, TEST_CONSUMER, valA); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_bulk_output(&bulkA, TEST_CONSUMER, valA); + TEST_ASSERT_RET_OK(rv); valB[0] = 0; valB[1] = 1; valB[2] = 0; valB[3] = 1; - status = gpiod_line_request_bulk_output(&bulkB, TEST_CONSUMER, valB); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_bulk_output(&bulkB, TEST_CONSUMER, valB); + TEST_ASSERT_RET_OK(rv); memset(valA, 0, sizeof(valA)); memset(valB, 0, sizeof(valB)); - status = gpiod_line_get_value_bulk(&bulkA, valA); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_get_value_bulk(&bulkA, valA); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(valA[0], 1); TEST_ASSERT_EQ(valA[1], 0); TEST_ASSERT_EQ(valA[2], 0); TEST_ASSERT_EQ(valA[3], 1); - status = gpiod_line_get_value_bulk(&bulkB, valB); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_get_value_bulk(&bulkB, valB); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(valB[0], 0); TEST_ASSERT_EQ(valB[1], 1); TEST_ASSERT_EQ(valB[2], 0); @@ -208,7 +208,7 @@ static void line_request_bulk_different_chips(void) struct gpiod_line *lineA1; struct gpiod_line *lineB0; struct gpiod_line *lineB1; - int status; + int rv; chipA = gpiod_chip_open(test_chip_path(0)); chipB = gpiod_chip_open(test_chip_path(1)); @@ -235,8 +235,8 @@ static void line_request_bulk_different_chips(void) req.request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT; req.flags = GPIOD_LINE_ACTIVE_STATE_HIGH; - status = gpiod_line_request_bulk(&bulk, &req, NULL); - TEST_ASSERT_NOTEQ(status, 0); + rv = gpiod_line_request_bulk(&bulk, &req, NULL); + TEST_ASSERT_NOTEQ(rv, 0); TEST_ASSERT_ERRNO_IS(EINVAL); } TEST_DEFINE(line_request_bulk_different_chips, @@ -285,7 +285,7 @@ static void line_set_value(void) { TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -293,8 +293,8 @@ static void line_set_value(void) line = gpiod_chip_get_line(chip, 2); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_request_output(line, TEST_CONSUMER, 0); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_output(line, TEST_CONSUMER, 0); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_RET_OK(gpiod_line_set_value(line, 1)); TEST_ASSERT_EQ(gpiod_line_get_value(line), 1); @@ -425,7 +425,7 @@ static void line_direction(void) { TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -433,15 +433,15 @@ static void line_direction(void) line = gpiod_chip_get_line(chip, 5); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_request_output(line, TEST_CONSUMER, 0); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_output(line, TEST_CONSUMER, 0); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(gpiod_line_direction(line), GPIOD_LINE_DIRECTION_OUTPUT); gpiod_line_release(line); - status = gpiod_line_request_input(line, TEST_CONSUMER); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_input(line, TEST_CONSUMER); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(gpiod_line_direction(line), GPIOD_LINE_DIRECTION_INPUT); } @@ -453,7 +453,7 @@ static void line_active_state(void) { TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -461,17 +461,17 @@ static void line_active_state(void) line = gpiod_chip_get_line(chip, 5); TEST_ASSERT_NOT_NULL(line); - status = gpiod_line_request_input(line, TEST_CONSUMER); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request_input(line, TEST_CONSUMER); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(gpiod_line_active_state(line), GPIOD_LINE_ACTIVE_STATE_HIGH); gpiod_line_release(line); - status = gpiod_line_request_input_flags(line, TEST_CONSUMER, + rv = gpiod_line_request_input_flags(line, TEST_CONSUMER, GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW); - TEST_ASSERT_RET_OK(status); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT_EQ(gpiod_line_direction(line), GPIOD_LINE_DIRECTION_INPUT); } @@ -484,7 +484,7 @@ static void line_misc_flags(void) TEST_CLEANUP_CHIP struct gpiod_chip *chip = NULL; struct gpiod_line_request_config config; struct gpiod_line *line; - int status; + int rv; chip = gpiod_chip_open(test_chip_path(0)); TEST_ASSERT_NOT_NULL(chip); @@ -500,8 +500,8 @@ static void line_misc_flags(void) config.consumer = TEST_CONSUMER; config.flags = GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN; - status = gpiod_line_request(line, &config, 0); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request(line, &config, 0); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT(gpiod_line_is_used(line)); TEST_ASSERT(gpiod_line_is_open_drain(line)); @@ -511,8 +511,8 @@ static void line_misc_flags(void) config.flags = GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE; - status = gpiod_line_request(line, &config, 0); - TEST_ASSERT_RET_OK(status); + rv = gpiod_line_request(line, &config, 0); + TEST_ASSERT_RET_OK(rv); TEST_ASSERT(gpiod_line_is_used(line)); TEST_ASSERT_FALSE(gpiod_line_is_open_drain(line));