usb 2.17.0 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -4
- package/README.md +25 -516
- package/dist/index.d.ts +67 -13
- package/dist/index.js +333 -64
- package/index.d.ts +89 -0
- package/index.js +583 -0
- package/package.json +53 -33
- package/CHANGELOG.md +0 -294
- package/binding.gyp +0 -128
- package/dist/index.js.map +0 -1
- package/dist/usb/bindings.d.ts +0 -266
- package/dist/usb/bindings.js +0 -10
- package/dist/usb/bindings.js.map +0 -1
- package/dist/usb/capability.d.ts +0 -13
- package/dist/usb/capability.js +0 -17
- package/dist/usb/capability.js.map +0 -1
- package/dist/usb/descriptors.d.ts +0 -128
- package/dist/usb/descriptors.js +0 -3
- package/dist/usb/descriptors.js.map +0 -1
- package/dist/usb/device.d.ts +0 -100
- package/dist/usb/device.js +0 -297
- package/dist/usb/device.js.map +0 -1
- package/dist/usb/endpoint.d.ts +0 -94
- package/dist/usb/endpoint.js +0 -219
- package/dist/usb/endpoint.js.map +0 -1
- package/dist/usb/index.d.ts +0 -31
- package/dist/usb/index.js +0 -116
- package/dist/usb/index.js.map +0 -1
- package/dist/usb/interface.d.ts +0 -80
- package/dist/usb/interface.js +0 -133
- package/dist/usb/interface.js.map +0 -1
- package/dist/webusb/index.d.ts +0 -64
- package/dist/webusb/index.js +0 -295
- package/dist/webusb/index.js.map +0 -1
- package/dist/webusb/webusb-device.d.ts +0 -54
- package/dist/webusb/webusb-device.js +0 -434
- package/dist/webusb/webusb-device.js.map +0 -1
- package/libusb/.clang-tidy +0 -34
- package/libusb/.codespellrc +0 -3
- package/libusb/.private/README.txt +0 -5
- package/libusb/.private/appveyor_build.sh +0 -26
- package/libusb/.private/bm.sh +0 -54
- package/libusb/.private/ci-build.sh +0 -92
- package/libusb/.private/ci-container-build.sh +0 -67
- package/libusb/.private/post-rewrite.sh +0 -32
- package/libusb/.private/pre-commit.sh +0 -52
- package/libusb/.private/wbs.txt +0 -43
- package/libusb/.travis.yml +0 -58
- package/libusb/AUTHORS +0 -231
- package/libusb/COPYING +0 -504
- package/libusb/ChangeLog +0 -365
- package/libusb/HACKING +0 -25
- package/libusb/INSTALL_WIN.txt +0 -52
- package/libusb/KEYS +0 -123
- package/libusb/Makefile.am +0 -50
- package/libusb/NEWS +0 -2
- package/libusb/PORTING +0 -94
- package/libusb/README +0 -29
- package/libusb/README.git +0 -41
- package/libusb/TODO +0 -2
- package/libusb/Xcode/common.xcconfig +0 -92
- package/libusb/Xcode/config.h +0 -31
- package/libusb/Xcode/debug.xcconfig +0 -32
- package/libusb/Xcode/libusb.xcconfig +0 -21
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
- package/libusb/Xcode/libusb_debug.xcconfig +0 -21
- package/libusb/Xcode/libusb_release.xcconfig +0 -21
- package/libusb/Xcode/release.xcconfig +0 -30
- package/libusb/android/README +0 -152
- package/libusb/android/config.h +0 -55
- package/libusb/android/examples/unrooted_android.c +0 -301
- package/libusb/android/examples/unrooted_android.h +0 -36
- package/libusb/android/jni/Android.mk +0 -23
- package/libusb/android/jni/Application.mk +0 -40
- package/libusb/android/jni/examples.mk +0 -168
- package/libusb/android/jni/libusb.mk +0 -60
- package/libusb/android/jni/tests.mk +0 -45
- package/libusb/appveyor.yml +0 -108
- package/libusb/autogen.sh +0 -10
- package/libusb/bootstrap.sh +0 -10
- package/libusb/configure.ac +0 -450
- package/libusb/doc/Makefile.in +0 -22
- package/libusb/doc/doxygen.cfg.in +0 -2571
- package/libusb/doc/libusb.png +0 -0
- package/libusb/examples/Makefile.am +0 -12
- package/libusb/examples/dpfp.c +0 -711
- package/libusb/examples/ezusb.c +0 -846
- package/libusb/examples/ezusb.h +0 -109
- package/libusb/examples/fxload.c +0 -310
- package/libusb/examples/hotplugtest.c +0 -147
- package/libusb/examples/listdevs.c +0 -73
- package/libusb/examples/sam3u_benchmark.c +0 -228
- package/libusb/examples/testlibusb.c +0 -312
- package/libusb/examples/xusb.c +0 -1254
- package/libusb/libusb/Makefile.am +0 -98
- package/libusb/libusb/Makefile.am.extra +0 -26
- package/libusb/libusb/core.c +0 -2925
- package/libusb/libusb/descriptor.c +0 -1558
- package/libusb/libusb/hotplug.c +0 -489
- package/libusb/libusb/io.c +0 -2865
- package/libusb/libusb/libusb-1.0.def +0 -199
- package/libusb/libusb/libusb-1.0.rc +0 -53
- package/libusb/libusb/libusb.h +0 -2421
- package/libusb/libusb/libusbi.h +0 -1535
- package/libusb/libusb/os/darwin_usb.c +0 -2977
- package/libusb/libusb/os/darwin_usb.h +0 -156
- package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
- package/libusb/libusb/os/events_posix.c +0 -340
- package/libusb/libusb/os/events_posix.h +0 -62
- package/libusb/libusb/os/events_windows.c +0 -214
- package/libusb/libusb/os/events_windows.h +0 -46
- package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
- package/libusb/libusb/os/haiku_usb.h +0 -113
- package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
- package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
- package/libusb/libusb/os/haiku_usb_raw.h +0 -188
- package/libusb/libusb/os/linux_netlink.c +0 -401
- package/libusb/libusb/os/linux_udev.c +0 -321
- package/libusb/libusb/os/linux_usbfs.c +0 -2829
- package/libusb/libusb/os/linux_usbfs.h +0 -221
- package/libusb/libusb/os/netbsd_usb.c +0 -617
- package/libusb/libusb/os/null_usb.c +0 -111
- package/libusb/libusb/os/openbsd_usb.c +0 -700
- package/libusb/libusb/os/sunos_usb.c +0 -1619
- package/libusb/libusb/os/sunos_usb.h +0 -79
- package/libusb/libusb/os/threads_posix.c +0 -126
- package/libusb/libusb/os/threads_posix.h +0 -98
- package/libusb/libusb/os/threads_windows.c +0 -40
- package/libusb/libusb/os/threads_windows.h +0 -113
- package/libusb/libusb/os/windows_common.c +0 -923
- package/libusb/libusb/os/windows_common.h +0 -424
- package/libusb/libusb/os/windows_usbdk.c +0 -724
- package/libusb/libusb/os/windows_usbdk.h +0 -106
- package/libusb/libusb/os/windows_winusb.c +0 -4766
- package/libusb/libusb/os/windows_winusb.h +0 -787
- package/libusb/libusb/strerror.c +0 -223
- package/libusb/libusb/sync.c +0 -342
- package/libusb/libusb/version.h +0 -18
- package/libusb/libusb/version_nano.h +0 -1
- package/libusb/libusb-1.0.pc.in +0 -11
- package/libusb/msvc/Base.props +0 -60
- package/libusb/msvc/Configuration.Application.props +0 -7
- package/libusb/msvc/Configuration.Base.props +0 -47
- package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
- package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
- package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
- package/libusb/msvc/build_all.ps1 +0 -17
- package/libusb/msvc/config.h +0 -58
- package/libusb/msvc/dpfp.vcxproj +0 -33
- package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
- package/libusb/msvc/fxload.vcxproj +0 -46
- package/libusb/msvc/getopt/getopt.c +0 -1060
- package/libusb/msvc/getopt/getopt.h +0 -180
- package/libusb/msvc/getopt/getopt1.c +0 -188
- package/libusb/msvc/getopt.vcxproj +0 -33
- package/libusb/msvc/hotplugtest.vcxproj +0 -32
- package/libusb/msvc/init_context.vcxproj +0 -35
- package/libusb/msvc/libusb.sln +0 -542
- package/libusb/msvc/libusb_dll.vcxproj +0 -61
- package/libusb/msvc/libusb_static.vcxproj +0 -49
- package/libusb/msvc/listdevs.vcxproj +0 -32
- package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
- package/libusb/msvc/set_option.vcxproj +0 -35
- package/libusb/msvc/stress.vcxproj +0 -35
- package/libusb/msvc/stress_mt.vcxproj +0 -33
- package/libusb/msvc/testlibusb.vcxproj +0 -32
- package/libusb/msvc/xusb.vcxproj +0 -38
- package/libusb/tests/Makefile.am +0 -40
- package/libusb/tests/init_context.c +0 -153
- package/libusb/tests/libusb_testlib.h +0 -76
- package/libusb/tests/macos.c +0 -130
- package/libusb/tests/set_option.c +0 -253
- package/libusb/tests/stress.c +0 -172
- package/libusb/tests/stress_mt.c +0 -267
- package/libusb/tests/testlib.c +0 -184
- package/libusb/tests/umockdev.c +0 -1175
- package/libusb/tests/webusb-test-shim/index.js +0 -12
- package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
- package/libusb/tests/webusb-test-shim/package.json +0 -10
- package/libusb.gypi +0 -154
- package/libusb_config/config.h +0 -1
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-arm64/node.napi.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +0 -439
- package/src/helpers.h +0 -64
- package/src/hotplug/hotplug.h +0 -22
- package/src/hotplug/libusb.cc +0 -90
- package/src/hotplug/windows.cc +0 -168
- package/src/node_usb.cc +0 -314
- package/src/node_usb.h +0 -131
- package/src/thread_name.cc +0 -79
- package/src/thread_name.h +0 -11
- package/src/transfer.cc +0 -143
- package/src/uv_async_queue.h +0 -41
- package/test/usb.coffee +0 -250
- package/test/webusb.coffee +0 -227
- package/test/worker.cjs +0 -13
package/libusb/tests/macos.c
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/* -*- Mode: C; indent-tabs-mode:nil -*- */
|
|
2
|
-
/*
|
|
3
|
-
* Unit tests for libusb_set_option
|
|
4
|
-
* Copyright © 2023 Nathan Hjelm <hjelmn@cs.unm.edu>
|
|
5
|
-
* Copyright © 2023 Google, LLC. All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
* This library is free software; you can redistribute it and/or
|
|
8
|
-
* modify it under the terms of the GNU Lesser General Public
|
|
9
|
-
* License as published by the Free Software Foundation; either
|
|
10
|
-
* version 2.1 of the License, or (at your option) any later version.
|
|
11
|
-
*
|
|
12
|
-
* This library is distributed in the hope that it will be useful,
|
|
13
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15
|
-
* Lesser General Public License for more details.
|
|
16
|
-
*
|
|
17
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
18
|
-
* License along with this library; if not, write to the Free Software
|
|
19
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
#include "config.h"
|
|
23
|
-
|
|
24
|
-
#include <stdbool.h>
|
|
25
|
-
#include <stdlib.h>
|
|
26
|
-
#include <stdio.h>
|
|
27
|
-
#include <inttypes.h>
|
|
28
|
-
#include "libusbi.h"
|
|
29
|
-
#include "libusb_testlib.h"
|
|
30
|
-
|
|
31
|
-
#define LIBUSB_TEST_CLEAN_EXIT(code) \
|
|
32
|
-
do { \
|
|
33
|
-
if (test_ctx != NULL) { \
|
|
34
|
-
libusb_exit(test_ctx); \
|
|
35
|
-
} \
|
|
36
|
-
unsetenv("LIBUSB_DEBUG"); \
|
|
37
|
-
return (code); \
|
|
38
|
-
} while (0)
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Fail the test if the expression does not evaluate to LIBUSB_SUCCESS.
|
|
42
|
-
*/
|
|
43
|
-
#define LIBUSB_TEST_RETURN_ON_ERROR(expr) \
|
|
44
|
-
do { \
|
|
45
|
-
int _result = (expr); \
|
|
46
|
-
if (LIBUSB_SUCCESS != _result) { \
|
|
47
|
-
libusb_testlib_logf("Not success (%s) at %s:%d", #expr, \
|
|
48
|
-
__FILE__, __LINE__); \
|
|
49
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_FAILURE); \
|
|
50
|
-
} \
|
|
51
|
-
} while (0)
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Use relational operator to compare two values and fail the test if the
|
|
55
|
-
* comparison is false. Intended to compare integer or pointer types.
|
|
56
|
-
*
|
|
57
|
-
* Example: LIBUSB_EXPECT(==, 0, 1) -> fail, LIBUSB_EXPECT(==, 0, 0) -> ok.
|
|
58
|
-
*/
|
|
59
|
-
#define LIBUSB_EXPECT(operator, lhs, rhs) \
|
|
60
|
-
do { \
|
|
61
|
-
int64_t _lhs = (lhs), _rhs = (rhs); \
|
|
62
|
-
if (!(_lhs operator _rhs)) { \
|
|
63
|
-
libusb_testlib_logf("Expected %s (%" PRId64 ") " #operator \
|
|
64
|
-
" %s (%" PRId64 ") at %s:%d", #lhs, \
|
|
65
|
-
(int64_t)(intptr_t)_lhs, #rhs, \
|
|
66
|
-
(int64_t)(intptr_t)_rhs, __FILE__, \
|
|
67
|
-
__LINE__); \
|
|
68
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_FAILURE); \
|
|
69
|
-
} \
|
|
70
|
-
} while (0)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
extern uint32_t libusb_testonly_fake_running_version;
|
|
74
|
-
extern uint32_t libusb_testonly_using_running_interface_version;
|
|
75
|
-
extern uint32_t libusb_testonly_using_running_device_version;
|
|
76
|
-
extern bool libusb_testonly_clear_running_version_cache;
|
|
77
|
-
|
|
78
|
-
static libusb_testlib_result test_macos_version_fallback(void) {
|
|
79
|
-
libusb_context *test_ctx = NULL;
|
|
80
|
-
libusb_testonly_fake_running_version = 100001;
|
|
81
|
-
libusb_testonly_clear_running_version_cache = true;
|
|
82
|
-
|
|
83
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
84
|
-
/*num_options=*/0));
|
|
85
|
-
LIBUSB_EXPECT(==, libusb_testonly_using_running_interface_version, 220);
|
|
86
|
-
LIBUSB_EXPECT(==, libusb_testonly_using_running_device_version, 197);
|
|
87
|
-
|
|
88
|
-
libusb_exit(test_ctx);
|
|
89
|
-
test_ctx = NULL;
|
|
90
|
-
|
|
91
|
-
libusb_testonly_fake_running_version = 100900;
|
|
92
|
-
|
|
93
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
94
|
-
/*num_options=*/0));
|
|
95
|
-
LIBUSB_EXPECT(==, libusb_testonly_using_running_interface_version, 650);
|
|
96
|
-
LIBUSB_EXPECT(==, libusb_testonly_using_running_device_version, 650);
|
|
97
|
-
|
|
98
|
-
libusb_exit(test_ctx);
|
|
99
|
-
test_ctx = NULL;
|
|
100
|
-
|
|
101
|
-
libusb_testonly_fake_running_version = 101200;
|
|
102
|
-
|
|
103
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
104
|
-
/*num_options=*/0));
|
|
105
|
-
LIBUSB_EXPECT(==, libusb_testonly_using_running_interface_version, 800);
|
|
106
|
-
LIBUSB_EXPECT(==, libusb_testonly_using_running_device_version, 650);
|
|
107
|
-
|
|
108
|
-
libusb_exit(test_ctx);
|
|
109
|
-
test_ctx = NULL;
|
|
110
|
-
|
|
111
|
-
// Test a version smaller than 10.0. Initialization should fail.
|
|
112
|
-
libusb_testonly_fake_running_version = 99999;
|
|
113
|
-
|
|
114
|
-
int error = libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
115
|
-
/*num_options=*/0);
|
|
116
|
-
LIBUSB_EXPECT(!=, error, LIBUSB_SUCCESS);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_SUCCESS);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static const libusb_testlib_test tests[] = {
|
|
123
|
-
{ "test_macos_version_fallback", &test_macos_version_fallback },
|
|
124
|
-
LIBUSB_NULL_TEST
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
int main(int argc, char *argv[])
|
|
128
|
-
{
|
|
129
|
-
return libusb_testlib_run_tests(argc, argv, tests);
|
|
130
|
-
}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/* -*- Mode: C; indent-tabs-mode:nil -*- */
|
|
2
|
-
/*
|
|
3
|
-
* Unit tests for libusb_set_option
|
|
4
|
-
* Copyright © 2023 Nathan Hjelm <hjelmn@cs.unm.edu>
|
|
5
|
-
* Copyright © 2023 Google, LLC. All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
* This library is free software; you can redistribute it and/or
|
|
8
|
-
* modify it under the terms of the GNU Lesser General Public
|
|
9
|
-
* License as published by the Free Software Foundation; either
|
|
10
|
-
* version 2.1 of the License, or (at your option) any later version.
|
|
11
|
-
*
|
|
12
|
-
* This library is distributed in the hope that it will be useful,
|
|
13
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15
|
-
* Lesser General Public License for more details.
|
|
16
|
-
*
|
|
17
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
18
|
-
* License along with this library; if not, write to the Free Software
|
|
19
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
#include "config.h"
|
|
23
|
-
|
|
24
|
-
#include <stdlib.h>
|
|
25
|
-
#include <stdio.h>
|
|
26
|
-
#include <inttypes.h>
|
|
27
|
-
#include "libusbi.h"
|
|
28
|
-
#include "libusb_testlib.h"
|
|
29
|
-
|
|
30
|
-
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
31
|
-
#include <winbase.h>
|
|
32
|
-
|
|
33
|
-
#if defined(ENABLE_LOGGING)
|
|
34
|
-
static int unsetenv(const char *env) {
|
|
35
|
-
return _putenv_s(env, "");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static int setenv(const char *env, const char *value, int overwrite) {
|
|
39
|
-
if (getenv(env) && !overwrite)
|
|
40
|
-
return 0;
|
|
41
|
-
return _putenv_s(env, value);
|
|
42
|
-
}
|
|
43
|
-
#endif
|
|
44
|
-
#endif
|
|
45
|
-
|
|
46
|
-
#define LIBUSB_TEST_CLEAN_EXIT(code) \
|
|
47
|
-
do { \
|
|
48
|
-
if (test_ctx != NULL) { \
|
|
49
|
-
libusb_exit(test_ctx); \
|
|
50
|
-
} \
|
|
51
|
-
unsetenv("LIBUSB_DEBUG"); \
|
|
52
|
-
return (code); \
|
|
53
|
-
} while (0)
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Fail the test if the expression does not evaluate to LIBUSB_SUCCESS.
|
|
57
|
-
*/
|
|
58
|
-
#define LIBUSB_TEST_RETURN_ON_ERROR(expr) \
|
|
59
|
-
do { \
|
|
60
|
-
int _result = (expr); \
|
|
61
|
-
if (LIBUSB_SUCCESS != _result) { \
|
|
62
|
-
libusb_testlib_logf("Not success (%s) at %s:%d", #expr, \
|
|
63
|
-
__FILE__, __LINE__); \
|
|
64
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_FAILURE); \
|
|
65
|
-
} \
|
|
66
|
-
} while (0)
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Use relational operator to compare two values and fail the test if the
|
|
70
|
-
* comparison is false. Intended to compare integer or pointer types.
|
|
71
|
-
*
|
|
72
|
-
* Example: LIBUSB_EXPECT(==, 0, 1) -> fail, LIBUSB_EXPECT(==, 0, 0) -> ok.
|
|
73
|
-
*/
|
|
74
|
-
#define LIBUSB_EXPECT(operator, lhs, rhs) \
|
|
75
|
-
do { \
|
|
76
|
-
int64_t _lhs = (int64_t)(intptr_t)(lhs), _rhs = (int64_t)(intptr_t)(rhs); \
|
|
77
|
-
if (!(_lhs operator _rhs)) { \
|
|
78
|
-
libusb_testlib_logf("Expected %s (%" PRId64 ") " #operator \
|
|
79
|
-
" %s (%" PRId64 ") at %s:%d", #lhs, \
|
|
80
|
-
(int64_t)(intptr_t)_lhs, #rhs, \
|
|
81
|
-
(int64_t)(intptr_t)_rhs, __FILE__, \
|
|
82
|
-
__LINE__); \
|
|
83
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_FAILURE); \
|
|
84
|
-
} \
|
|
85
|
-
} while (0)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
static libusb_testlib_result test_set_log_level_basic(void) {
|
|
89
|
-
#if defined(ENABLE_LOGGING) && !defined(ENABLE_DEBUG_LOGGING)
|
|
90
|
-
libusb_context *test_ctx = NULL;
|
|
91
|
-
|
|
92
|
-
/* unset LIBUSB_DEBUG if it is set */
|
|
93
|
-
unsetenv("LIBUSB_DEBUG");
|
|
94
|
-
|
|
95
|
-
/* test basic functionality */
|
|
96
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
97
|
-
/*num_options=*/0));
|
|
98
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(test_ctx,
|
|
99
|
-
LIBUSB_OPTION_LOG_LEVEL,
|
|
100
|
-
LIBUSB_LOG_LEVEL_ERROR));
|
|
101
|
-
LIBUSB_EXPECT(==, test_ctx->debug, LIBUSB_LOG_LEVEL_ERROR);
|
|
102
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(test_ctx,
|
|
103
|
-
LIBUSB_OPTION_LOG_LEVEL,
|
|
104
|
-
LIBUSB_LOG_LEVEL_NONE));
|
|
105
|
-
LIBUSB_EXPECT(==, test_ctx->debug, LIBUSB_LOG_LEVEL_NONE);
|
|
106
|
-
|
|
107
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_SUCCESS);
|
|
108
|
-
#else
|
|
109
|
-
return TEST_STATUS_SKIP;
|
|
110
|
-
#endif
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
static libusb_testlib_result test_set_log_level_default(void) {
|
|
114
|
-
#if defined(ENABLE_LOGGING) && !defined(ENABLE_DEBUG_LOGGING)
|
|
115
|
-
libusb_context *test_ctx = NULL;
|
|
116
|
-
|
|
117
|
-
/* set the default debug level */
|
|
118
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL,
|
|
119
|
-
LIBUSB_LOG_LEVEL_ERROR));
|
|
120
|
-
|
|
121
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
122
|
-
/*num_options=*/0));
|
|
123
|
-
/* check that debug level came from the default */
|
|
124
|
-
LIBUSB_EXPECT(==, test_ctx->debug, LIBUSB_LOG_LEVEL_ERROR);
|
|
125
|
-
|
|
126
|
-
/* try to override the old log level. since this was set from the default it
|
|
127
|
-
* should be possible to change it */
|
|
128
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(test_ctx,
|
|
129
|
-
LIBUSB_OPTION_LOG_LEVEL,
|
|
130
|
-
LIBUSB_LOG_LEVEL_NONE));
|
|
131
|
-
LIBUSB_EXPECT(==, test_ctx->debug, LIBUSB_LOG_LEVEL_NONE);
|
|
132
|
-
|
|
133
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_SUCCESS);
|
|
134
|
-
#else
|
|
135
|
-
return TEST_STATUS_SKIP;
|
|
136
|
-
#endif
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
static libusb_testlib_result test_set_log_level_env(void) {
|
|
140
|
-
#if defined(ENABLE_LOGGING)
|
|
141
|
-
libusb_context *test_ctx = NULL;
|
|
142
|
-
|
|
143
|
-
/* check that libusb_set_option does not change the log level when it was set
|
|
144
|
-
* from the environment. */
|
|
145
|
-
setenv("LIBUSB_DEBUG", "4", /*overwrite=*/0);
|
|
146
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
147
|
-
/*num_options=*/0));
|
|
148
|
-
#ifndef ENABLE_DEBUG_LOGGING
|
|
149
|
-
LIBUSB_EXPECT(==, test_ctx->debug, 4);
|
|
150
|
-
#endif
|
|
151
|
-
|
|
152
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(test_ctx,
|
|
153
|
-
LIBUSB_OPTION_LOG_LEVEL,
|
|
154
|
-
LIBUSB_LOG_LEVEL_ERROR));
|
|
155
|
-
/* environment variable should always override LIBUSB_OPTION_LOG_LEVEL if set */
|
|
156
|
-
#ifndef ENABLE_DEBUG_LOGGING
|
|
157
|
-
LIBUSB_EXPECT(==, test_ctx->debug, 4);
|
|
158
|
-
#endif
|
|
159
|
-
|
|
160
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_SUCCESS);
|
|
161
|
-
#else
|
|
162
|
-
return TEST_STATUS_SKIP;
|
|
163
|
-
#endif
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
static libusb_testlib_result test_no_discovery(void)
|
|
168
|
-
{
|
|
169
|
-
#if defined(__linux__)
|
|
170
|
-
libusb_context *test_ctx;
|
|
171
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
172
|
-
/*num_options=*/0));
|
|
173
|
-
libusb_device **device_list = NULL;
|
|
174
|
-
ssize_t num_devices = libusb_get_device_list(test_ctx, &device_list);
|
|
175
|
-
libusb_free_device_list(device_list, /*unref_devices=*/1);
|
|
176
|
-
libusb_exit(test_ctx);
|
|
177
|
-
test_ctx = NULL;
|
|
178
|
-
|
|
179
|
-
if (num_devices == 0) {
|
|
180
|
-
libusb_testlib_logf("Warning: no devices found, the test will only verify that setting LIBUSB_OPTION_NO_DEVICE_DISCOVERY succeeds.");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
LIBUSB_EXPECT(>=, num_devices, 0);
|
|
184
|
-
|
|
185
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY));
|
|
186
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
187
|
-
/*num_options=*/0));
|
|
188
|
-
device_list = NULL;
|
|
189
|
-
num_devices = libusb_get_device_list(test_ctx, &device_list);
|
|
190
|
-
libusb_free_device_list(device_list, /*unref_devices=*/1);
|
|
191
|
-
|
|
192
|
-
LIBUSB_EXPECT(==, num_devices, 0);
|
|
193
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_SUCCESS);
|
|
194
|
-
#else
|
|
195
|
-
return TEST_STATUS_SKIP;
|
|
196
|
-
#endif
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
#if defined(ENABLE_LOGGING) && !defined(ENABLE_DEBUG_LOGGING)
|
|
200
|
-
static void LIBUSB_CALL test_log_cb(libusb_context *ctx, enum libusb_log_level level,
|
|
201
|
-
const char *str) {
|
|
202
|
-
UNUSED(ctx);
|
|
203
|
-
UNUSED(level);
|
|
204
|
-
UNUSED(str);
|
|
205
|
-
}
|
|
206
|
-
#endif
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
static libusb_testlib_result test_set_log_cb(void)
|
|
210
|
-
{
|
|
211
|
-
#if defined(ENABLE_LOGGING) && !defined(ENABLE_DEBUG_LOGGING)
|
|
212
|
-
libusb_context *test_ctx = NULL;
|
|
213
|
-
|
|
214
|
-
/* set the log callback on the context */
|
|
215
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
216
|
-
/*num_options=*/0));
|
|
217
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(test_ctx, LIBUSB_OPTION_LOG_CB,
|
|
218
|
-
test_log_cb));
|
|
219
|
-
|
|
220
|
-
/* check that debug level came from the default */
|
|
221
|
-
LIBUSB_EXPECT(==, test_ctx->log_handler, test_log_cb);
|
|
222
|
-
|
|
223
|
-
libusb_exit(test_ctx);
|
|
224
|
-
test_ctx = NULL;
|
|
225
|
-
|
|
226
|
-
/* set the log callback for all future contexts */
|
|
227
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_set_option(/*ctx=*/NULL, LIBUSB_OPTION_LOG_CB,
|
|
228
|
-
test_log_cb));
|
|
229
|
-
LIBUSB_TEST_RETURN_ON_ERROR(libusb_init_context(&test_ctx, /*options=*/NULL,
|
|
230
|
-
/*num_options=*/0));
|
|
231
|
-
LIBUSB_EXPECT(==, test_ctx->log_handler, test_log_cb);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
LIBUSB_TEST_CLEAN_EXIT(TEST_STATUS_SUCCESS);
|
|
235
|
-
#else
|
|
236
|
-
return TEST_STATUS_SKIP;
|
|
237
|
-
#endif
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
static const libusb_testlib_test tests[] = {
|
|
241
|
-
{ "test_set_log_level_basic", &test_set_log_level_basic },
|
|
242
|
-
{ "test_set_log_level_env", &test_set_log_level_env },
|
|
243
|
-
{ "test_no_discovery", &test_no_discovery },
|
|
244
|
-
/* since default options can't be unset, run this one last */
|
|
245
|
-
{ "test_set_log_level_default", &test_set_log_level_default },
|
|
246
|
-
{ "test_set_log_cb", &test_set_log_cb },
|
|
247
|
-
LIBUSB_NULL_TEST
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
int main(int argc, char *argv[])
|
|
251
|
-
{
|
|
252
|
-
return libusb_testlib_run_tests(argc, argv, tests);
|
|
253
|
-
}
|
package/libusb/tests/stress.c
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* libusb stress test program to perform simple stress tests
|
|
3
|
-
* Copyright © 2012 Toby Gray <toby.gray@realvnc.com>
|
|
4
|
-
*
|
|
5
|
-
* This library is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU Lesser General Public
|
|
7
|
-
* License as published by the Free Software Foundation; either
|
|
8
|
-
* version 2.1 of the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This library is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this library; if not, write to the Free Software
|
|
17
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
#include <config.h>
|
|
21
|
-
|
|
22
|
-
#include <string.h>
|
|
23
|
-
|
|
24
|
-
#include "libusb.h"
|
|
25
|
-
#include "libusb_testlib.h"
|
|
26
|
-
|
|
27
|
-
/** Test that creates and destroys a single concurrent context
|
|
28
|
-
* 10000 times. */
|
|
29
|
-
static libusb_testlib_result test_init_and_exit(void)
|
|
30
|
-
{
|
|
31
|
-
for (int i = 0; i < 10000; ++i) {
|
|
32
|
-
libusb_context *ctx = NULL;
|
|
33
|
-
int r;
|
|
34
|
-
|
|
35
|
-
r = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0);
|
|
36
|
-
if (r != LIBUSB_SUCCESS) {
|
|
37
|
-
libusb_testlib_logf(
|
|
38
|
-
"Failed to init libusb on iteration %d: %d",
|
|
39
|
-
i, r);
|
|
40
|
-
return TEST_STATUS_FAILURE;
|
|
41
|
-
}
|
|
42
|
-
libusb_exit(ctx);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return TEST_STATUS_SUCCESS;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Tests that devices can be listed 1000 times. */
|
|
49
|
-
static libusb_testlib_result test_get_device_list(void)
|
|
50
|
-
{
|
|
51
|
-
libusb_context *ctx;
|
|
52
|
-
int r;
|
|
53
|
-
|
|
54
|
-
r = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0);
|
|
55
|
-
if (r != LIBUSB_SUCCESS) {
|
|
56
|
-
libusb_testlib_logf("Failed to init libusb: %d", r);
|
|
57
|
-
return TEST_STATUS_FAILURE;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for (int i = 0; i < 1000; ++i) {
|
|
61
|
-
libusb_device **device_list = NULL;
|
|
62
|
-
ssize_t list_size = libusb_get_device_list(ctx, &device_list);
|
|
63
|
-
if (list_size < 0 || !device_list) {
|
|
64
|
-
libusb_testlib_logf(
|
|
65
|
-
"Failed to get device list on iteration %d: %ld (%p)",
|
|
66
|
-
i, (long) -list_size, (void *) device_list);
|
|
67
|
-
libusb_exit(ctx);
|
|
68
|
-
return TEST_STATUS_FAILURE;
|
|
69
|
-
}
|
|
70
|
-
libusb_free_device_list(device_list, 1);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
libusb_exit(ctx);
|
|
74
|
-
return TEST_STATUS_SUCCESS;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Tests that 100 concurrent device lists can be open at a time. */
|
|
78
|
-
static libusb_testlib_result test_many_device_lists(void)
|
|
79
|
-
{
|
|
80
|
-
#define LIST_COUNT 100
|
|
81
|
-
libusb_testlib_result result = TEST_STATUS_SUCCESS;
|
|
82
|
-
libusb_context *ctx = NULL;
|
|
83
|
-
libusb_device **device_lists[LIST_COUNT];
|
|
84
|
-
int r;
|
|
85
|
-
|
|
86
|
-
r = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0);
|
|
87
|
-
if (r != LIBUSB_SUCCESS) {
|
|
88
|
-
libusb_testlib_logf("Failed to init libusb: %d", r);
|
|
89
|
-
return TEST_STATUS_FAILURE;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
memset(device_lists, 0, sizeof(device_lists));
|
|
93
|
-
|
|
94
|
-
/* Create the 100 device lists. */
|
|
95
|
-
for (int i = 0; i < LIST_COUNT; ++i) {
|
|
96
|
-
ssize_t list_size = libusb_get_device_list(ctx, &device_lists[i]);
|
|
97
|
-
if (list_size < 0 || !device_lists[i]) {
|
|
98
|
-
libusb_testlib_logf(
|
|
99
|
-
"Failed to get device list on iteration %d: %ld (%p)",
|
|
100
|
-
i, (long) -list_size, (void *) device_lists[i]);
|
|
101
|
-
result = TEST_STATUS_FAILURE;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/* Destroy the 100 device lists. */
|
|
107
|
-
for (int i = 0; i < LIST_COUNT; ++i) {
|
|
108
|
-
if (device_lists[i])
|
|
109
|
-
libusb_free_device_list(device_lists[i], 1);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
libusb_exit(ctx);
|
|
113
|
-
return result;
|
|
114
|
-
#undef LIST_COUNT
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Tests that the default context (used for various things including
|
|
118
|
-
* logging) works correctly when the first context created in a
|
|
119
|
-
* process is destroyed. */
|
|
120
|
-
static libusb_testlib_result test_default_context_change(void)
|
|
121
|
-
{
|
|
122
|
-
for (int i = 0; i < 100; ++i) {
|
|
123
|
-
libusb_context *ctx = NULL;
|
|
124
|
-
int r;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
/* Enable debug output on new context, to be sure to use the context */
|
|
128
|
-
struct libusb_init_option options[] = {
|
|
129
|
-
{
|
|
130
|
-
.option = LIBUSB_OPTION_LOG_LEVEL,
|
|
131
|
-
.value = {.ival = LIBUSB_LOG_LEVEL_DEBUG},
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
int num_options = 1;
|
|
135
|
-
|
|
136
|
-
/* First create a new context */
|
|
137
|
-
r = libusb_init_context(&ctx, options, num_options);
|
|
138
|
-
if (r != LIBUSB_SUCCESS) {
|
|
139
|
-
libusb_testlib_logf("Failed to init libusb: %d", r);
|
|
140
|
-
return TEST_STATUS_FAILURE;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/* Now create a reference to the default context */
|
|
144
|
-
r = libusb_init_context(/*ctx=*/NULL, options, num_options);
|
|
145
|
-
if (r != LIBUSB_SUCCESS) {
|
|
146
|
-
libusb_testlib_logf("Failed to init libusb: %d", r);
|
|
147
|
-
libusb_exit(ctx);
|
|
148
|
-
return TEST_STATUS_FAILURE;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/* Destroy the first context */
|
|
152
|
-
libusb_exit(ctx);
|
|
153
|
-
/* Destroy the default context */
|
|
154
|
-
libusb_exit(NULL);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return TEST_STATUS_SUCCESS;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/* Fill in the list of tests. */
|
|
161
|
-
static const libusb_testlib_test tests[] = {
|
|
162
|
-
{ "init_and_exit", &test_init_and_exit },
|
|
163
|
-
{ "get_device_list", &test_get_device_list },
|
|
164
|
-
{ "many_device_lists", &test_many_device_lists },
|
|
165
|
-
{ "default_context_change", &test_default_context_change },
|
|
166
|
-
LIBUSB_NULL_TEST
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
int main(int argc, char *argv[])
|
|
170
|
-
{
|
|
171
|
-
return libusb_testlib_run_tests(argc, argv, tests);
|
|
172
|
-
}
|