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 /tests | |
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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stress.c | 27 | ||||
-rw-r--r-- | tests/stress_mt.c | 2 | ||||
-rw-r--r-- | tests/umockdev.c | 4 |
3 files changed, 18 insertions, 15 deletions
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); |