diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 545f0304c..072d0275c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,6 +22,11 @@ if (WIN32) set(LIBIIO_RC ${CMAKE_CURRENT_BINARY_DIR}/properties.rc) configure_file(../properties.rc.cmakein ${LIBIIO_RC} @ONLY) endif() + +if (CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIIO_CHECK_RET") +endif() + add_executable(iio_genxml iio_genxml.c ${GETOPT_C_FILE} ${LIBIIO_RC}) add_executable(iio_info iio_info.c ${GETOPT_C_FILE} ${LIBIIO_RC}) add_executable(iio_attr iio_attr.c gen_code.c ${GETOPT_C_FILE} ${LIBIIO_RC}) diff --git a/tests/iio_adi_xflow_check.c b/tests/iio_adi_xflow_check.c index 569895d12..ee9aeea5c 100644 --- a/tests/iio_adi_xflow_check.c +++ b/tests/iio_adi_xflow_check.c @@ -126,7 +126,11 @@ static void *monitor_thread_fn(void *data) sleep(1); /* Clear all status bits */ - iio_device_reg_write(dev, 0x80000088, 0x6); + ret = iio_device_reg_write(dev, 0x80000088, 0x6); + if (ret) { + fprintf(stderr, "Failed to clearn DMA status register: %s\n", + strerror(-ret)); + } while (app_running) { ret = iio_device_reg_read(dev, 0x80000088, &val); @@ -145,8 +149,12 @@ static void *monitor_thread_fn(void *data) } /* Clear bits */ - if (val) - iio_device_reg_write(dev, 0x80000088, val); + if (val) { + ret = iio_device_reg_write(dev, 0x80000088, val); + if (ret) + fprintf(stderr, "Failed to clearn DMA status register: %s\n", + strerror(-ret)); + } sleep(1); } diff --git a/tests/iio_attr.c b/tests/iio_attr.c index 70f11d9fb..cec667ce4 100644 --- a/tests/iio_attr.c +++ b/tests/iio_attr.c @@ -650,11 +650,20 @@ int main(int argc, char **argv) for (i = 0; i < nb_ctx_attrs; i++) { const char *key, *value; + ssize_t ret; - iio_context_get_attr(ctx, i, &key, &value); - if (!attr_index || str_match(key, argv[attr_index], ignore_case)) { - printf("%s: %s\n", key, value); - gen_context_attr(key); + ret = iio_context_get_attr(ctx, i, &key, &value); + if (!ret) { + if (!attr_index || str_match(key, argv[attr_index], ignore_case)) { + printf("%s: %s\n", key, value); + gen_context_attr(key); + } + } else { + char *buf = xmalloc(BUF_SIZE); + iio_strerror(errno, buf, BUF_SIZE); + fprintf(stderr, "Unable to get context attributes: %s (%zd)\n", + buf, ret); + free(buf); } } } diff --git a/tests/iio_info.c b/tests/iio_info.c index 20af48319..3222d310b 100644 --- a/tests/iio_info.c +++ b/tests/iio_info.c @@ -106,7 +106,9 @@ static void scan(void) ret = iio_scan_context_get_info_list(ctx, &info); if (ret < 0) { - fprintf(stderr, "Unable to scan: %li\n", (long) ret); + char err_str[1024]; + iio_strerror(-ret, err_str, sizeof(err_str)); + fprintf(stderr, "Unable to scan: %s (%zd)\n", err_str, ret); goto err_free_ctx; } @@ -295,8 +297,11 @@ int main(int argc, char **argv) if (!ret) printf("Backend version: %u.%u (git tag: %s)\n", major, minor, git_tag); - else - fprintf(stderr, "Unable to get backend version: %i\n", ret); + else { + char err_str[1024]; + iio_strerror(-ret, err_str, sizeof(err_str)); + fprintf(stderr, "Unable to get backend version: %s (%i)\n", err_str, ret); + } printf("Backend description string: %s\n", iio_context_get_description(ctx)); @@ -308,8 +313,15 @@ int main(int argc, char **argv) for (i = 0; i < nb_ctx_attrs; i++) { const char *key, *value; - iio_context_get_attr(ctx, i, &key, &value); - printf("\t%s: %s\n", key, value); + ret = iio_context_get_attr(ctx, i, &key, &value); + if (ret == 0) + printf("\t%s: %s\n", key, value); + else { + char err_str[1024]; + iio_strerror(-ret, err_str, sizeof(err_str)); + fprintf(stderr, "\tUnable to read IIO context attributes: %s (%i)\n", + err_str, ret); + } } unsigned int nb_devices = iio_context_get_devices_count(ctx); @@ -467,6 +479,11 @@ int main(int argc, char **argv) iio_device_get_id(trig), name ? name : ""); } + } else if (ret == -ENOENT) { + printf("\t\tNo trigger on this device\n"); + } else if (ret < 0) { + iio_strerror(-ret, buf, BUF_SIZE); + printf("ERROR: checking for trigger : %s (%i)\n", buf, ret); } } diff --git a/tests/iio_readdev.c b/tests/iio_readdev.c index 7bc7aac6f..ac9640aa9 100644 --- a/tests/iio_readdev.c +++ b/tests/iio_readdev.c @@ -261,6 +261,7 @@ int main(int argc, char **argv) size_t sample_size; int timeout = -1; bool scan_for_context = false; + ssize_t ret; while ((c = getopt_long(argc, argv, "+hn:u:t:b:s:T:a", options, &option_index)) != -1) { @@ -316,8 +317,15 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - if (timeout >= 0) - iio_context_set_timeout(ctx, timeout); + if (timeout >= 0) { + ret = iio_context_set_timeout(ctx, timeout); + if (ret < 0) { + char err_str[1024]; + iio_strerror(-ret, err_str, sizeof(err_str)); + fprintf(stderr, "IIO contexts set timeout failed : %s (%zd)\n", + err_str, ret); + } + } dev = iio_context_find_device(ctx, argv[optind]); if (!dev) { @@ -346,11 +354,24 @@ int main(int argc, char **argv) * fail gracefully to remain compatible. */ if (iio_device_attr_write_longlong(trigger, - "sampling_frequency", DEFAULT_FREQ_HZ) < 0) - iio_device_attr_write_longlong(trigger, + "sampling_frequency", DEFAULT_FREQ_HZ) < 0) { + ret = iio_device_attr_write_longlong(trigger, "frequency", DEFAULT_FREQ_HZ); + if (ret < 0) { + char buf[256]; + iio_strerror(-ret, buf, sizeof(buf)); + fprintf(stderr, "sample rate not set : %s (%zd)\n", + buf, ret); + } + } - iio_device_set_trigger(dev, trigger); + ret = iio_device_set_trigger(dev, trigger); + if (ret < 0) { + char buf[256]; + iio_strerror(-ret, buf, sizeof(buf)); + fprintf(stderr, "set triffer failed : %s (%zd)\n", + buf, ret); + } } nb_channels = iio_device_get_channels_count(dev); @@ -427,7 +448,13 @@ int main(int argc, char **argv) quit_all(EXIT_SUCCESS); } } else { - iio_buffer_foreach_sample(buffer, print_sample, NULL); + ret = iio_buffer_foreach_sample(buffer, print_sample, NULL); + if (ret < 0) { + char buf[256]; + iio_strerror(-ret, buf, sizeof(buf)); + fprintf(stderr, "buffer processing failed : %s (%d)\n", + buf, ret); + } } } diff --git a/tests/iio_writedev.c b/tests/iio_writedev.c index b91bfa1c2..b2047dd0d 100644 --- a/tests/iio_writedev.c +++ b/tests/iio_writedev.c @@ -271,6 +271,7 @@ int main(int argc, char **argv) int timeout = -1; bool scan_for_context = false; bool cyclic_buffer = false; + ssize_t ret; while ((c = getopt_long(argc, argv, "+hn:u:t:b:s:T:ac", options, &option_index)) != -1) { @@ -329,8 +330,15 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - if (timeout >= 0) - iio_context_set_timeout(ctx, timeout); + if (timeout >= 0) { + ret = iio_context_set_timeout(ctx, timeout); + if (ret < 0) { + char err_str[1024]; + iio_strerror(-ret, err_str, sizeof(err_str)); + fprintf(stderr, "IIO contexts set timeout failed : %s (%zd)\n", + err_str, ret); + } + } dev = iio_context_find_device(ctx, argv[optind]); if (!dev) { @@ -359,11 +367,24 @@ int main(int argc, char **argv) * fail gracefully to remain compatible. */ if (iio_device_attr_write_longlong(trigger, - "sampling_frequency", DEFAULT_FREQ_HZ) < 0) - iio_device_attr_write_longlong(trigger, + "sampling_frequency", DEFAULT_FREQ_HZ) < 0) { + ret = iio_device_attr_write_longlong(trigger, "frequency", DEFAULT_FREQ_HZ); + if (ret < 0) { + char buf[256]; + iio_strerror(-ret, buf, sizeof(buf)); + fprintf(stderr, "sample rate not set : %s (%zd)\n", + buf, ret); + } + } - iio_device_set_trigger(dev, trigger); + ret = iio_device_set_trigger(dev, trigger); + if (ret < 0) { + char buf[256]; + iio_strerror(-ret, buf, sizeof(buf)); + fprintf(stderr, "set triffer failed : %s (%zd)\n", + buf, ret); + } } nb_channels = iio_device_get_channels_count(dev); @@ -426,7 +447,13 @@ int main(int argc, char **argv) quit_all(EXIT_SUCCESS); } } else { - iio_buffer_foreach_sample(buffer, read_sample, NULL); + ret = iio_buffer_foreach_sample(buffer, read_sample, NULL); + if (ret < 0) { + char buf[256]; + iio_strerror(-ret, buf, sizeof(buf)); + fprintf(stderr, "buffer processing failed : %s (%zd)\n", + buf, ret); + } } int ret = iio_buffer_push(buffer);