summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-02-22 11:45:38 +0100
committerTormod Volden <debian.tormod@gmail.com>2022-03-20 10:55:17 +0100
commit6b29aeb9ca22ed5ea9768020895698bd452c2a85 (patch)
treeac04911dd136015c226fb414ec6179d7af8c4edc /tests
parent66d3849974dbc93d8bad418dbf594b37c95416f9 (diff)
downloadlibusb-6b29aeb9ca22ed5ea9768020895698bd452c2a85.tar.gz
core: Install first context as implicit default (and warn about its use)
There was a behaviour change in libusb 1.0.25 which triggers issues when the API is misused. This caused for instance gutenprint to crash, see https://bugzilla.redhat.com/show_bug.cgi?id=2055504 This seems to affect several applications "out in the wild". For now, work around this by installing an implicit default. But, change the code to log an error in case this "feature" is being used. This will allow some grace time for developers to fix their applications, before we at a later point revert to the stricter behaviour. Fixes #1089
Diffstat (limited to 'tests')
-rw-r--r--tests/umockdev.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/umockdev.c b/tests/umockdev.c
index 1eda532..488edc2 100644
--- a/tests/umockdev.c
+++ b/tests/umockdev.c
@@ -559,6 +559,32 @@ test_open_close(UMockdevTestbedFixture * fixture, UNUSED_DATA)
}
static void
+test_implicit_default(UMockdevTestbedFixture * fixture, UNUSED_DATA)
+{
+ libusb_device **devs = NULL;
+
+ clear_libusb_log(fixture, LIBUSB_LOG_LEVEL_INFO);
+ g_assert_cmpint(libusb_get_device_list(NULL, &devs), ==, 1);
+ libusb_free_device_list(devs, TRUE);
+ assert_libusb_log_msg(fixture, LIBUSB_LOG_LEVEL_ERROR, "\\[usbi_get_context\\].*implicit default");
+
+ /* Only warns once */
+ g_assert_cmpint(libusb_get_device_list(NULL, &devs), ==, 1);
+ libusb_free_device_list(devs, TRUE);
+ clear_libusb_log(fixture, LIBUSB_LOG_LEVEL_INFO);
+
+ libusb_init(NULL);
+ g_assert_cmpint(libusb_get_device_list(NULL, &devs), ==, 1);
+ libusb_exit(NULL);
+
+ /* We free late, causing a warning from libusb_exit. However,
+ * we never see this warning (i.e. test success) because it is on a
+ * different context.
+ */
+ libusb_free_device_list(devs, TRUE);
+}
+
+static void
test_close_flying(UMockdevTestbedFixture * fixture, UNUSED_DATA)
{
UsbChat chat[] = {
@@ -1101,6 +1127,11 @@ main(int argc, char **argv)
test_open_close,
test_fixture_teardown);
+ g_test_add("/libusb/implicit-default", UMockdevTestbedFixture, NULL,
+ test_fixture_setup_with_canon,
+ test_implicit_default,
+ test_fixture_teardown);
+
g_test_add("/libusb/close-flying", UMockdevTestbedFixture, NULL,
test_fixture_setup_with_canon,
test_close_flying,