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/stress_mt.c
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* libusb multi-thread test program
|
|
3
|
-
* Copyright 2022-2023 Tormod Volden
|
|
4
|
-
*
|
|
5
|
-
* This program 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 program 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 <libusb.h>
|
|
23
|
-
#include <stdio.h>
|
|
24
|
-
#include <stdbool.h>
|
|
25
|
-
|
|
26
|
-
#if defined(PLATFORM_POSIX)
|
|
27
|
-
|
|
28
|
-
#include <pthread.h>
|
|
29
|
-
typedef pthread_t thread_t;
|
|
30
|
-
typedef void * thread_return_t;
|
|
31
|
-
#define THREAD_RETURN_VALUE NULL
|
|
32
|
-
#define THREAD_CALL_TYPE
|
|
33
|
-
|
|
34
|
-
static inline int thread_create(thread_t *thread,
|
|
35
|
-
thread_return_t (*thread_entry)(void *arg), void *arg)
|
|
36
|
-
{
|
|
37
|
-
return pthread_create(thread, NULL, thread_entry, arg) == 0 ? 0 : -1;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static inline void thread_join(thread_t thread)
|
|
41
|
-
{
|
|
42
|
-
(void)pthread_join(thread, NULL);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
#include <stdatomic.h>
|
|
46
|
-
|
|
47
|
-
#elif defined(PLATFORM_WINDOWS)
|
|
48
|
-
|
|
49
|
-
typedef HANDLE thread_t;
|
|
50
|
-
#define THREAD_RETURN_VALUE 0
|
|
51
|
-
#define THREAD_CALL_TYPE __stdcall
|
|
52
|
-
|
|
53
|
-
#if defined(__CYGWIN__)
|
|
54
|
-
typedef DWORD thread_return_t;
|
|
55
|
-
#else
|
|
56
|
-
#include <process.h>
|
|
57
|
-
typedef unsigned thread_return_t;
|
|
58
|
-
#endif
|
|
59
|
-
|
|
60
|
-
static inline int thread_create(thread_t *thread,
|
|
61
|
-
thread_return_t (__stdcall *thread_entry)(void *arg), void *arg)
|
|
62
|
-
{
|
|
63
|
-
#if defined(__CYGWIN__)
|
|
64
|
-
*thread = CreateThread(NULL, 0, thread_entry, arg, 0, NULL);
|
|
65
|
-
#else
|
|
66
|
-
*thread = (HANDLE)_beginthreadex(NULL, 0, thread_entry, arg, 0, NULL);
|
|
67
|
-
#endif
|
|
68
|
-
return *thread != NULL ? 0 : -1;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
static inline void thread_join(thread_t thread)
|
|
72
|
-
{
|
|
73
|
-
(void)WaitForSingleObject(thread, INFINITE);
|
|
74
|
-
(void)CloseHandle(thread);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
typedef volatile LONG atomic_bool;
|
|
78
|
-
|
|
79
|
-
#define atomic_exchange InterlockedExchange
|
|
80
|
-
#endif /* PLATFORM_WINDOWS */
|
|
81
|
-
|
|
82
|
-
/* Test that creates and destroys contexts repeatedly */
|
|
83
|
-
|
|
84
|
-
#define NTHREADS 8
|
|
85
|
-
#define ITERS 64
|
|
86
|
-
#define MAX_DEVCOUNT 128
|
|
87
|
-
|
|
88
|
-
struct thread_info {
|
|
89
|
-
int number;
|
|
90
|
-
int enumerate;
|
|
91
|
-
ssize_t devcount;
|
|
92
|
-
int err;
|
|
93
|
-
int iteration;
|
|
94
|
-
} tinfo[NTHREADS];
|
|
95
|
-
|
|
96
|
-
atomic_bool no_access[MAX_DEVCOUNT];
|
|
97
|
-
|
|
98
|
-
/* Function called by backend during device initialization to convert
|
|
99
|
-
* multi-byte fields in the device descriptor to host-endian format.
|
|
100
|
-
* Copied from libusbi.h as we want test to be realistic and not depend on internals.
|
|
101
|
-
*/
|
|
102
|
-
static inline void usbi_localize_device_descriptor(struct libusb_device_descriptor *desc)
|
|
103
|
-
{
|
|
104
|
-
desc->bcdUSB = libusb_le16_to_cpu(desc->bcdUSB);
|
|
105
|
-
desc->idVendor = libusb_le16_to_cpu(desc->idVendor);
|
|
106
|
-
desc->idProduct = libusb_le16_to_cpu(desc->idProduct);
|
|
107
|
-
desc->bcdDevice = libusb_le16_to_cpu(desc->bcdDevice);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static thread_return_t THREAD_CALL_TYPE init_and_exit(void * arg)
|
|
111
|
-
{
|
|
112
|
-
struct thread_info *ti = (struct thread_info *) arg;
|
|
113
|
-
|
|
114
|
-
for (ti->iteration = 0; ti->iteration < ITERS && !ti->err; ti->iteration++) {
|
|
115
|
-
libusb_context *ctx = NULL;
|
|
116
|
-
|
|
117
|
-
ti->err = libusb_init_context(&ctx, /*options=*/NULL, /*num_options=*/0);
|
|
118
|
-
if (ti->err != 0) {
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
if (ti->enumerate) {
|
|
122
|
-
libusb_device **devs;
|
|
123
|
-
ti->devcount = libusb_get_device_list(ctx, &devs);
|
|
124
|
-
if (ti->devcount < 0) {
|
|
125
|
-
ti->err = (int)ti->devcount;
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
for (int i = 0; i < ti->devcount && ti->err == 0; i++) {
|
|
129
|
-
libusb_device *dev = devs[i];
|
|
130
|
-
struct libusb_device_descriptor desc;
|
|
131
|
-
ti->err = libusb_get_device_descriptor(dev, &desc);
|
|
132
|
-
if (ti->err != 0) {
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
if (no_access[i]) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
libusb_device_handle *dev_handle;
|
|
139
|
-
int open_err = libusb_open(dev, &dev_handle);
|
|
140
|
-
if (open_err == LIBUSB_ERROR_ACCESS
|
|
141
|
-
#if defined(PLATFORM_WINDOWS)
|
|
142
|
-
|| open_err == LIBUSB_ERROR_NOT_SUPPORTED
|
|
143
|
-
|| open_err == LIBUSB_ERROR_NOT_FOUND
|
|
144
|
-
#endif
|
|
145
|
-
) {
|
|
146
|
-
/* Use atomic swap to ensure we print warning only once across all threads.
|
|
147
|
-
This is a warning and not a hard error because it should be fine to run tests
|
|
148
|
-
even if we don't have access to some devices. */
|
|
149
|
-
if (!atomic_exchange(&no_access[i], true)) {
|
|
150
|
-
fprintf(stderr, "No access to device %04x:%04x, skipping transfer tests.\n", desc.idVendor, desc.idProduct);
|
|
151
|
-
}
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (open_err != 0) {
|
|
155
|
-
ti->err = open_err;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
/* Request raw descriptor via control transfer.
|
|
159
|
-
This tests opening, transferring and closing from multiple threads in parallel. */
|
|
160
|
-
struct libusb_device_descriptor raw_desc;
|
|
161
|
-
int raw_desc_len = libusb_get_descriptor(dev_handle, LIBUSB_DT_DEVICE, 0, (unsigned char *)&raw_desc, sizeof(raw_desc));
|
|
162
|
-
if (raw_desc_len < 0) {
|
|
163
|
-
ti->err = raw_desc_len;
|
|
164
|
-
goto close;
|
|
165
|
-
}
|
|
166
|
-
if (raw_desc_len != sizeof(raw_desc)) {
|
|
167
|
-
fprintf(stderr, "Thread %d: device %d: unexpected raw descriptor length %d\n",
|
|
168
|
-
ti->number, i, raw_desc_len);
|
|
169
|
-
ti->err = LIBUSB_ERROR_OTHER;
|
|
170
|
-
goto close;
|
|
171
|
-
}
|
|
172
|
-
usbi_localize_device_descriptor(&raw_desc);
|
|
173
|
-
#define ASSERT_EQ(field) if (raw_desc.field != desc.field) { \
|
|
174
|
-
fprintf(stderr, "Thread %d: device %d: mismatch in field " #field ": %d != %d\n", \
|
|
175
|
-
ti->number, i, raw_desc.field, desc.field); \
|
|
176
|
-
ti->err = LIBUSB_ERROR_OTHER; \
|
|
177
|
-
goto close; \
|
|
178
|
-
}
|
|
179
|
-
ASSERT_EQ(bLength);
|
|
180
|
-
ASSERT_EQ(bDescriptorType);
|
|
181
|
-
#if !defined(PLATFORM_WINDOWS)
|
|
182
|
-
/* these are hardcoded by the winusbx HID backend */
|
|
183
|
-
ASSERT_EQ(bcdUSB);
|
|
184
|
-
ASSERT_EQ(bDeviceClass);
|
|
185
|
-
ASSERT_EQ(bDeviceSubClass);
|
|
186
|
-
ASSERT_EQ(bDeviceProtocol);
|
|
187
|
-
ASSERT_EQ(bMaxPacketSize0);
|
|
188
|
-
ASSERT_EQ(bcdDevice);
|
|
189
|
-
#endif
|
|
190
|
-
ASSERT_EQ(idVendor);
|
|
191
|
-
ASSERT_EQ(idProduct);
|
|
192
|
-
ASSERT_EQ(iManufacturer);
|
|
193
|
-
ASSERT_EQ(iProduct);
|
|
194
|
-
ASSERT_EQ(iSerialNumber);
|
|
195
|
-
ASSERT_EQ(bNumConfigurations);
|
|
196
|
-
close:
|
|
197
|
-
libusb_close(dev_handle);
|
|
198
|
-
}
|
|
199
|
-
libusb_free_device_list(devs, 1);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
libusb_exit(ctx);
|
|
203
|
-
}
|
|
204
|
-
return (thread_return_t) THREAD_RETURN_VALUE;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
static int test_multi_init(int enumerate)
|
|
208
|
-
{
|
|
209
|
-
thread_t threadId[NTHREADS];
|
|
210
|
-
int errs = 0;
|
|
211
|
-
int t, i;
|
|
212
|
-
ssize_t last_devcount = 0;
|
|
213
|
-
int devcount_mismatch = 0;
|
|
214
|
-
int access_failures = 0;
|
|
215
|
-
|
|
216
|
-
printf("Starting %d threads\n", NTHREADS);
|
|
217
|
-
for (t = 0; t < NTHREADS; t++) {
|
|
218
|
-
tinfo[t].err = 0;
|
|
219
|
-
tinfo[t].number = t;
|
|
220
|
-
tinfo[t].enumerate = enumerate;
|
|
221
|
-
thread_create(&threadId[t], &init_and_exit, (void *) &tinfo[t]);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
for (t = 0; t < NTHREADS; t++) {
|
|
225
|
-
thread_join(threadId[t]);
|
|
226
|
-
if (tinfo[t].err) {
|
|
227
|
-
errs++;
|
|
228
|
-
fprintf(stderr,
|
|
229
|
-
"Thread %d failed (iteration %d): %s\n",
|
|
230
|
-
tinfo[t].number,
|
|
231
|
-
tinfo[t].iteration,
|
|
232
|
-
libusb_error_name(tinfo[t].err));
|
|
233
|
-
} else if (enumerate) {
|
|
234
|
-
if (t > 0 && tinfo[t].devcount != last_devcount) {
|
|
235
|
-
devcount_mismatch++;
|
|
236
|
-
printf("Device count mismatch: Thread %d discovered %ld devices instead of %ld\n",
|
|
237
|
-
tinfo[t].number,
|
|
238
|
-
(long int) tinfo[t].devcount,
|
|
239
|
-
(long int) last_devcount);
|
|
240
|
-
}
|
|
241
|
-
last_devcount = tinfo[t].devcount;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
for (i = 0; i < MAX_DEVCOUNT; i++)
|
|
246
|
-
if (no_access[i])
|
|
247
|
-
access_failures++;
|
|
248
|
-
|
|
249
|
-
if (enumerate && !devcount_mismatch)
|
|
250
|
-
printf("All threads discovered %ld devices (%i not opened)\n",
|
|
251
|
-
(long int) last_devcount, access_failures);
|
|
252
|
-
|
|
253
|
-
return errs + devcount_mismatch;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
int main(void)
|
|
257
|
-
{
|
|
258
|
-
int errs = 0;
|
|
259
|
-
|
|
260
|
-
printf("Running multithreaded init/exit test...\n");
|
|
261
|
-
errs += test_multi_init(0);
|
|
262
|
-
printf("Running multithreaded init/exit test with enumeration...\n");
|
|
263
|
-
errs += test_multi_init(1);
|
|
264
|
-
printf("All done, %d errors\n", errs);
|
|
265
|
-
|
|
266
|
-
return errs != 0;
|
|
267
|
-
}
|
package/libusb/tests/testlib.c
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* libusb test library helper functions
|
|
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 <errno.h>
|
|
23
|
-
#include <stdarg.h>
|
|
24
|
-
#include <stdbool.h>
|
|
25
|
-
#include <stdio.h>
|
|
26
|
-
#include <string.h>
|
|
27
|
-
|
|
28
|
-
#include "libusb_testlib.h"
|
|
29
|
-
|
|
30
|
-
#if defined(PLATFORM_POSIX)
|
|
31
|
-
#define NULL_PATH "/dev/null"
|
|
32
|
-
#elif defined(PLATFORM_WINDOWS)
|
|
33
|
-
#define NULL_PATH "nul"
|
|
34
|
-
#endif
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Converts a test result code into a human readable string.
|
|
38
|
-
*/
|
|
39
|
-
static const char *test_result_to_str(libusb_testlib_result result)
|
|
40
|
-
{
|
|
41
|
-
switch (result) {
|
|
42
|
-
case TEST_STATUS_SUCCESS:
|
|
43
|
-
return "Success";
|
|
44
|
-
case TEST_STATUS_FAILURE:
|
|
45
|
-
return "Failure";
|
|
46
|
-
case TEST_STATUS_ERROR:
|
|
47
|
-
return "Error";
|
|
48
|
-
case TEST_STATUS_SKIP:
|
|
49
|
-
return "Skip";
|
|
50
|
-
default:
|
|
51
|
-
return "Unknown";
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static void print_usage(const char *progname)
|
|
56
|
-
{
|
|
57
|
-
printf("Usage: %s [-l] [-v] [<test_name> ...]\n", progname);
|
|
58
|
-
printf(" -l List available tests\n");
|
|
59
|
-
printf(" -v Don't redirect STDERR before running tests\n");
|
|
60
|
-
printf(" -h Display this help and exit\n");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
void libusb_testlib_logf(const char *fmt, ...)
|
|
64
|
-
{
|
|
65
|
-
va_list va;
|
|
66
|
-
|
|
67
|
-
va_start(va, fmt);
|
|
68
|
-
vfprintf(stdout, fmt, va);
|
|
69
|
-
va_end(va);
|
|
70
|
-
fputc('\n', stdout);
|
|
71
|
-
fflush(stdout);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
int libusb_testlib_run_tests(int argc, char *argv[],
|
|
75
|
-
const libusb_testlib_test *tests)
|
|
76
|
-
{
|
|
77
|
-
int run_count = 0;
|
|
78
|
-
int idx = 0;
|
|
79
|
-
int pass_count = 0;
|
|
80
|
-
int fail_count = 0;
|
|
81
|
-
int error_count = 0;
|
|
82
|
-
int skip_count = 0;
|
|
83
|
-
|
|
84
|
-
/* Setup default mode of operation */
|
|
85
|
-
char **test_names = NULL;
|
|
86
|
-
int test_count = 0;
|
|
87
|
-
bool list_tests = false;
|
|
88
|
-
bool verbose = false;
|
|
89
|
-
|
|
90
|
-
/* Parse command line options */
|
|
91
|
-
if (argc >= 2) {
|
|
92
|
-
for (int j = 1; j < argc; j++) {
|
|
93
|
-
const char *argstr = argv[j];
|
|
94
|
-
size_t arglen = strlen(argstr);
|
|
95
|
-
|
|
96
|
-
if (argstr[0] == '-' || argstr[0] == '/') {
|
|
97
|
-
if (arglen == 2) {
|
|
98
|
-
switch (argstr[1]) {
|
|
99
|
-
case 'l':
|
|
100
|
-
list_tests = true;
|
|
101
|
-
continue;
|
|
102
|
-
case 'v':
|
|
103
|
-
verbose = true;
|
|
104
|
-
continue;
|
|
105
|
-
case 'h':
|
|
106
|
-
print_usage(argv[0]);
|
|
107
|
-
return 0;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
fprintf(stderr, "Unknown option: '%s'\n", argstr);
|
|
112
|
-
print_usage(argv[0]);
|
|
113
|
-
return 1;
|
|
114
|
-
} else {
|
|
115
|
-
/* End of command line options, remaining must be list of tests to run */
|
|
116
|
-
test_names = argv + j;
|
|
117
|
-
test_count = argc - j;
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/* Validate command line options */
|
|
124
|
-
if (test_names && list_tests) {
|
|
125
|
-
fprintf(stderr, "List of tests requested but test list provided\n");
|
|
126
|
-
print_usage(argv[0]);
|
|
127
|
-
return 1;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/* Setup test log output */
|
|
131
|
-
if (!verbose) {
|
|
132
|
-
if (!freopen(NULL_PATH, "w", stderr)) {
|
|
133
|
-
printf("Failed to open null handle: %d\n", errno);
|
|
134
|
-
return 1;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/* Act on any options not related to running tests */
|
|
139
|
-
if (list_tests) {
|
|
140
|
-
while (tests[idx].function)
|
|
141
|
-
libusb_testlib_logf("%s", tests[idx++].name);
|
|
142
|
-
return 0;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/* Run any requested tests */
|
|
146
|
-
while (tests[idx].function) {
|
|
147
|
-
const libusb_testlib_test *test = &tests[idx++];
|
|
148
|
-
libusb_testlib_result test_result;
|
|
149
|
-
|
|
150
|
-
if (test_count > 0) {
|
|
151
|
-
/* Filtering tests to run, check if this is one of them */
|
|
152
|
-
int i;
|
|
153
|
-
|
|
154
|
-
for (i = 0; i < test_count; i++) {
|
|
155
|
-
if (!strcmp(test_names[i], test->name))
|
|
156
|
-
/* Matches a requested test name */
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
if (i == test_count) {
|
|
160
|
-
/* Failed to find a test match, so do the next loop iteration */
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
libusb_testlib_logf("Starting test run: %s...", test->name);
|
|
165
|
-
test_result = test->function();
|
|
166
|
-
libusb_testlib_logf("%s (%d)", test_result_to_str(test_result), test_result);
|
|
167
|
-
switch (test_result) {
|
|
168
|
-
case TEST_STATUS_SUCCESS: pass_count++; break;
|
|
169
|
-
case TEST_STATUS_FAILURE: fail_count++; break;
|
|
170
|
-
case TEST_STATUS_ERROR: error_count++; break;
|
|
171
|
-
case TEST_STATUS_SKIP: skip_count++; break;
|
|
172
|
-
}
|
|
173
|
-
run_count++;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
libusb_testlib_logf("---");
|
|
177
|
-
libusb_testlib_logf("Ran %d tests", run_count);
|
|
178
|
-
libusb_testlib_logf("Passed %d tests", pass_count);
|
|
179
|
-
libusb_testlib_logf("Failed %d tests", fail_count);
|
|
180
|
-
libusb_testlib_logf("Error in %d tests", error_count);
|
|
181
|
-
libusb_testlib_logf("Skipped %d tests", skip_count);
|
|
182
|
-
|
|
183
|
-
return fail_count + error_count;
|
|
184
|
-
}
|