diff options
author | Nathan Hjelm <hjelmn@me.com> | 2021-12-31 10:21:38 -0700 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2023-01-20 11:04:14 +0100 |
commit | 3c33e499a051562a4bafaeb38a79089351c94381 (patch) | |
tree | b1108eef39580285610b501bef433fe42dfee46c | |
parent | 6622f386f52807dac76c8a260c98aa02c311bc93 (diff) | |
download | libusb-3c33e499a051562a4bafaeb38a79089351c94381.tar.gz |
Update tests and example to use the new libusb_init_context() function
This commit updates all test and example code to use the newer
libusb_init_context() function instead of libusb_init().
Signed-off-by: Nathan Hjelm <hjelmn@google.com>
[Tormod: Update umockdev.c as well]
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
-rw-r--r-- | examples/dpfp.c | 2 | ||||
-rw-r--r-- | examples/fxload.c | 4 | ||||
-rw-r--r-- | examples/hotplugtest.c | 2 | ||||
-rw-r--r-- | examples/listdevs.c | 2 | ||||
-rw-r--r-- | examples/sam3u_benchmark.c | 2 | ||||
-rw-r--r-- | examples/testlibusb.c | 2 | ||||
-rw-r--r-- | examples/xusb.c | 2 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 | ||||
-rw-r--r-- | tests/stress.c | 27 | ||||
-rw-r--r-- | tests/stress_mt.c | 2 | ||||
-rw-r--r-- | tests/umockdev.c | 4 |
11 files changed, 27 insertions, 24 deletions
diff --git a/examples/dpfp.c b/examples/dpfp.c index ac43dac..2949383 100644 --- a/examples/dpfp.c +++ b/examples/dpfp.c @@ -601,7 +601,7 @@ int main(void) { int r; - r = libusb_init(NULL); + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (r < 0) { fprintf(stderr, "failed to initialise libusb %d - %s\n", r, libusb_strerror(r)); exit(1); diff --git a/examples/fxload.c b/examples/fxload.c index 541c3d3..2526083 100644 --- a/examples/fxload.c +++ b/examples/fxload.c @@ -172,9 +172,9 @@ int main(int argc, char*argv[]) } /* open the device using libusb */ - status = libusb_init(NULL); + status = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (status < 0) { - logerror("libusb_init() failed: %s\n", libusb_error_name(status)); + logerror("libusb_init_context() failed: %s\n", libusb_error_name(status)); return -1; } libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, verbose); diff --git a/examples/hotplugtest.c b/examples/hotplugtest.c index 94f7e56..98b01ee 100644 --- a/examples/hotplugtest.c +++ b/examples/hotplugtest.c @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) product_id = (argc > 2) ? (int)strtol (argv[2], NULL, 0) : 0x5005; class_id = (argc > 3) ? (int)strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY; - rc = libusb_init (NULL); + rc = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (rc < 0) { printf("failed to initialise libusb: %s\n", libusb_error_name(rc)); diff --git a/examples/listdevs.c b/examples/listdevs.c index b5b027c..b5a9494 100644 --- a/examples/listdevs.c +++ b/examples/listdevs.c @@ -55,7 +55,7 @@ int main(void) int r; ssize_t cnt; - r = libusb_init(NULL); + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (r < 0) return r; diff --git a/examples/sam3u_benchmark.c b/examples/sam3u_benchmark.c index 8979775..ef7a669 100644 --- a/examples/sam3u_benchmark.c +++ b/examples/sam3u_benchmark.c @@ -191,7 +191,7 @@ int main(void) (void)signal(SIGINT, sig_hdlr); #endif - rc = libusb_init(NULL); + rc = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (rc < 0) { fprintf(stderr, "Error initializing libusb: %s\n", libusb_error_name(rc)); exit(1); diff --git a/examples/testlibusb.c b/examples/testlibusb.c index ba00f90..394cec5 100644 --- a/examples/testlibusb.c +++ b/examples/testlibusb.c @@ -287,7 +287,7 @@ int main(int argc, char *argv[]) } } - r = libusb_init(NULL); + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (r < 0) return r; diff --git a/examples/xusb.c b/examples/xusb.c index 0fb5261..39a96fb 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -1153,7 +1153,7 @@ int main(int argc, char** argv) version = libusb_get_version(); printf("Using libusb v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano); - r = libusb_init(NULL); + r = libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); if (r < 0) return r; diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 13076b2..9e7b749 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11768 +#define LIBUSB_NANO 11769 diff --git a/tests/stress.c b/tests/stress.c index 0dc9173..09e670a 100644 --- a/tests/stress.c +++ b/tests/stress.c @@ -32,7 +32,7 @@ static libusb_testlib_result test_init_and_exit(void) libusb_context *ctx = NULL; int r; - r = libusb_init(&ctx); + r = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0); if (r != LIBUSB_SUCCESS) { libusb_testlib_logf( "Failed to init libusb on iteration %d: %d", @@ -51,7 +51,7 @@ static libusb_testlib_result test_get_device_list(void) libusb_context *ctx; int r; - r = libusb_init(&ctx); + r = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0); if (r != LIBUSB_SUCCESS) { libusb_testlib_logf("Failed to init libusb: %d", r); return TEST_STATUS_FAILURE; @@ -83,7 +83,7 @@ static libusb_testlib_result test_many_device_lists(void) libusb_device **device_lists[LIST_COUNT]; int r; - r = libusb_init(&ctx); + r = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0); if (r != LIBUSB_SUCCESS) { libusb_testlib_logf("Failed to init libusb: %d", r); return TEST_STATUS_FAILURE; @@ -123,22 +123,25 @@ static libusb_testlib_result test_default_context_change(void) libusb_context *ctx = NULL; int r; + + /* Enable debug output on new context, to be sure to use the context */ + struct libusb_init_option options[] = { + { + .option = LIBUSB_OPTION_LOG_LEVEL, + .value = {.ival = LIBUSB_LOG_LEVEL_DEBUG}, + }, + }; + int num_options = 1; + /* First create a new context */ - r = libusb_init(&ctx); + r = libusb_init_context(&ctx, options, num_options); if (r != LIBUSB_SUCCESS) { libusb_testlib_logf("Failed to init libusb: %d", r); return TEST_STATUS_FAILURE; } - /* Enable debug output on new context, to be sure to use the context */ - libusb_set_option(ctx, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG); - - /* Enable debug output on the default context. This should work even before - * the context has been created. */ - libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG); - /* Now create a reference to the default context */ - r = libusb_init(NULL); + r = libusb_init_context(/*ctx=*/NULL, options, num_options); if (r != LIBUSB_SUCCESS) { libusb_testlib_logf("Failed to init libusb: %d", r); libusb_exit(ctx); diff --git a/tests/stress_mt.c b/tests/stress_mt.c index 0299bfc..c59a5c7 100644 --- a/tests/stress_mt.c +++ b/tests/stress_mt.c @@ -16,7 +16,7 @@ static void *test_init_and_exit(void * arg) libusb_context *ctx = NULL; int r; - r = libusb_init(&ctx); + r = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0); if (r != LIBUSB_SUCCESS) { printf("Failed to init libusb on iteration %d: %d", i, r); return NULL; diff --git a/tests/umockdev.c b/tests/umockdev.c index 488edc2..9362b06 100644 --- a/tests/umockdev.c +++ b/tests/umockdev.c @@ -430,7 +430,7 @@ test_fixture_setup_libusb(UMockdevTestbedFixture * fixture, int devcount) { libusb_device **devs = NULL; - libusb_init (&fixture->ctx); + libusb_init_context(/*ctx=*/&fixture->ctx, /*options=*/NULL, /*num_options=*/0); /* Supress global log messages completely * (though, in some tests it might be interesting to check there are no real ones). @@ -573,7 +573,7 @@ test_implicit_default(UMockdevTestbedFixture * fixture, UNUSED_DATA) libusb_free_device_list(devs, TRUE); clear_libusb_log(fixture, LIBUSB_LOG_LEVEL_INFO); - libusb_init(NULL); + libusb_init_context(/*ctx=*/NULL, /*options=*/NULL, /*num_options=*/0); g_assert_cmpint(libusb_get_device_list(NULL, &devs), ==, 1); libusb_exit(NULL); |