usb 2.1.2 → 2.3.0
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/CHANGELOG.md +24 -0
- package/README.md +20 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/usb/bindings.d.ts +4 -0
- package/dist/usb/device.js +5 -0
- package/dist/usb/device.js.map +1 -1
- package/dist/usb/index.js +7 -16
- package/dist/usb/index.js.map +1 -1
- package/dist/webusb/webusb-device.d.ts +2 -1
- package/dist/webusb/webusb-device.js +21 -14
- package/dist/webusb/webusb-device.js.map +1 -1
- package/libusb/.gitattributes +2 -6
- package/libusb/.private/appveyor_build.sh +22 -0
- package/libusb/.private/bm.sh +1 -1
- package/libusb/.private/ci-build.sh +67 -0
- package/libusb/.private/ci-container-build.sh +70 -0
- package/libusb/.private/post-rewrite.sh +5 -1
- package/libusb/.private/pre-commit.sh +5 -1
- package/libusb/.private/wbs.txt +4 -19
- package/libusb/.travis.yml +32 -23
- package/libusb/AUTHORS +86 -3
- package/libusb/ChangeLog +54 -3
- package/libusb/INSTALL_WIN.txt +22 -44
- package/libusb/Makefile.am +32 -10
- package/libusb/{README.md → README} +2 -2
- package/libusb/README.git +3 -3
- package/libusb/Xcode/common.xcconfig +23 -19
- package/libusb/Xcode/config.h +25 -13
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
- package/libusb/android/README +90 -54
- package/libusb/android/config.h +23 -43
- package/libusb/android/examples/unrooted_android.c +300 -0
- package/libusb/android/examples/unrooted_android.h +36 -0
- package/libusb/android/jni/Android.mk +1 -1
- package/libusb/android/jni/Application.mk +16 -0
- package/libusb/android/jni/examples.mk +63 -29
- package/libusb/android/jni/libusb.mk +14 -8
- package/libusb/android/jni/tests.mk +13 -24
- package/libusb/appveyor.yml +73 -30
- package/libusb/autogen.sh +5 -3
- package/libusb/bootstrap.sh +6 -2
- package/libusb/configure.ac +314 -227
- package/libusb/doc/Makefile.in +22 -0
- package/libusb/doc/doxygen.cfg.in +460 -223
- package/libusb/examples/Makefile.am +6 -13
- package/libusb/examples/dpfp.c +276 -73
- package/libusb/examples/ezusb.c +18 -8
- package/libusb/examples/ezusb.h +6 -17
- package/libusb/examples/fxload.c +4 -5
- package/libusb/examples/hotplugtest.c +1 -1
- package/libusb/examples/sam3u_benchmark.c +59 -24
- package/libusb/examples/testlibusb.c +138 -104
- package/libusb/examples/xusb.c +26 -22
- package/libusb/libusb/Makefile.am +57 -70
- package/libusb/libusb/Makefile.am.extra +26 -0
- package/libusb/libusb/core.c +432 -423
- package/libusb/libusb/descriptor.c +365 -419
- package/libusb/libusb/hotplug.c +200 -104
- package/libusb/libusb/io.c +522 -535
- package/libusb/libusb/libusb-1.0.def +7 -3
- package/libusb/libusb/libusb-1.0.rc +1 -9
- package/libusb/libusb/libusb.h +302 -226
- package/libusb/libusb/libusbi.h +607 -316
- package/libusb/libusb/os/darwin_usb.c +703 -329
- package/libusb/libusb/os/darwin_usb.h +39 -15
- package/libusb/libusb/os/events_posix.c +300 -0
- package/libusb/libusb/os/events_posix.h +59 -0
- package/libusb/libusb/os/events_windows.c +214 -0
- package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
- package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
- package/libusb/libusb/os/haiku_usb.h +12 -12
- package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
- package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
- package/libusb/libusb/os/linux_netlink.c +55 -63
- package/libusb/libusb/os/linux_udev.c +61 -69
- package/libusb/libusb/os/linux_usbfs.c +926 -1015
- package/libusb/libusb/os/linux_usbfs.h +74 -57
- package/libusb/libusb/os/netbsd_usb.c +103 -168
- package/libusb/libusb/os/null_usb.c +111 -0
- package/libusb/libusb/os/openbsd_usb.c +71 -120
- package/libusb/libusb/os/sunos_usb.c +289 -375
- package/libusb/libusb/os/sunos_usb.h +0 -1
- package/libusb/libusb/os/threads_posix.c +81 -32
- package/libusb/libusb/os/threads_posix.h +19 -23
- package/libusb/libusb/os/threads_windows.c +9 -95
- package/libusb/libusb/os/threads_windows.h +33 -31
- package/libusb/libusb/os/windows_common.c +915 -0
- package/libusb/libusb/os/windows_common.h +330 -42
- package/libusb/libusb/os/windows_usbdk.c +161 -267
- package/libusb/libusb/os/windows_usbdk.h +5 -2
- package/libusb/libusb/os/windows_winusb.c +1355 -1192
- package/libusb/libusb/os/windows_winusb.h +167 -167
- package/libusb/libusb/strerror.c +20 -30
- package/libusb/libusb/sync.c +20 -21
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/msvc/.gitattributes +3 -0
- package/libusb/msvc/config.h +27 -20
- package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
- package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
- package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2019.vcxproj +106 -0
- package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
- package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
- package/libusb/msvc/fxload_2013.vcxproj +6 -3
- package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2015.vcxproj +6 -3
- package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2017.vcxproj +6 -7
- package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
- package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
- package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
- package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
- package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
- package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
- package/libusb/msvc/getopt_2013.vcxproj +4 -5
- package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2015.vcxproj +4 -4
- package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2017.vcxproj +4 -10
- package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
- package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
- package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
- package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
- package/libusb/msvc/libusb_2013.sln +50 -20
- package/libusb/msvc/libusb_2015.sln +51 -21
- package/libusb/msvc/libusb_2017.sln +90 -36
- package/libusb/msvc/libusb_2019.sln +240 -0
- package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
- package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
- package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
- package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
- package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
- package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
- package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
- package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
- package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
- package/libusb/msvc/listdevs_2013.vcxproj +6 -3
- package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2015.vcxproj +6 -3
- package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2017.vcxproj +6 -7
- package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2019.vcxproj +105 -0
- package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
- package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
- package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
- package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
- package/libusb/msvc/stress_2013.vcxproj +4 -2
- package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2015.vcxproj +4 -2
- package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2017.vcxproj +4 -6
- package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
- package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
- package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
- package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
- package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
- package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2013.vcxproj +6 -3
- package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2015.vcxproj +6 -3
- package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2017.vcxproj +6 -7
- package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
- package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
- package/libusb/tests/Makefile.am +13 -1
- package/libusb/tests/libusb_testlib.h +12 -43
- package/libusb/tests/stress.c +59 -50
- package/libusb/tests/testlib.c +78 -171
- package/libusb/tests/umockdev.c +1175 -0
- package/libusb.gypi +10 -11
- package/package.json +2 -2
- 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-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +12 -7
- package/src/node_usb.cc +10 -0
- package/test/usb.coffee +6 -0
- package/tsc/index.ts +2 -0
- package/tsc/usb/bindings.ts +5 -0
- package/tsc/usb/device.ts +6 -0
- package/tsc/usb/index.ts +5 -8
- package/tsc/webusb/webusb-device.ts +12 -8
- package/libusb/.private/bd.cmd +0 -89
- package/libusb/.private/bwince.cmd +0 -57
- package/libusb/.private/wbs_wince.txt +0 -42
- package/libusb/Brewfile +0 -4
- package/libusb/appveyor_cygwin.bat +0 -11
- package/libusb/appveyor_minGW.bat +0 -19
- package/libusb/doc/Makefile.am +0 -9
- package/libusb/examples/dpfp_threaded.c +0 -557
- package/libusb/libusb/hotplug.h +0 -99
- package/libusb/libusb/os/poll_posix.c +0 -84
- package/libusb/libusb/os/poll_posix.h +0 -14
- package/libusb/libusb/os/poll_windows.c +0 -447
- package/libusb/libusb/os/poll_windows.h +0 -98
- package/libusb/libusb/os/wince_usb.c +0 -888
- package/libusb/libusb/os/wince_usb.h +0 -126
- package/libusb/libusb/os/windows_nt_common.c +0 -1010
- package/libusb/libusb/os/windows_nt_common.h +0 -110
- package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
- package/libusb/msvc/appveyor.bat +0 -27
- package/libusb/msvc/ddk_build.cmd +0 -219
- package/libusb/msvc/errno.h +0 -102
- package/libusb/msvc/fxload_sources +0 -23
- package/libusb/msvc/getopt_2005.vcproj +0 -288
- package/libusb/msvc/getopt_2010.vcxproj +0 -72
- package/libusb/msvc/getopt_sources +0 -24
- package/libusb/msvc/hotplugtest_sources +0 -20
- package/libusb/msvc/inttypes.h +0 -295
- package/libusb/msvc/libusb.dsw +0 -71
- package/libusb/msvc/libusb_2005.sln +0 -95
- package/libusb/msvc/libusb_2010.sln +0 -105
- package/libusb/msvc/libusb_2012.sln +0 -105
- package/libusb/msvc/libusb_dll.dsp +0 -194
- package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
- package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
- package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
- package/libusb/msvc/libusb_sources +0 -43
- package/libusb/msvc/libusb_static.dsp +0 -174
- package/libusb/msvc/libusb_static_2005.vcproj +0 -390
- package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
- package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
- package/libusb/msvc/libusb_wince.sln +0 -246
- package/libusb/msvc/listdevs.dsp +0 -103
- package/libusb/msvc/listdevs_2005.vcproj +0 -360
- package/libusb/msvc/listdevs_sources +0 -20
- package/libusb/msvc/listdevs_wince.vcproj +0 -1120
- package/libusb/msvc/missing.c +0 -80
- package/libusb/msvc/stdint.h +0 -256
- package/libusb/msvc/stress_2005.vcproj +0 -390
- package/libusb/msvc/stress_2012.vcxproj +0 -87
- package/libusb/msvc/stress_sources +0 -21
- package/libusb/msvc/stress_wince.vcproj +0 -1128
- package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
- package/libusb/msvc/testlibusb_sources +0 -20
- package/libusb/msvc/xusb.dsp +0 -102
- package/libusb/msvc/xusb_2005.vcproj +0 -344
- package/libusb/msvc/xusb_2012.vcxproj +0 -83
- package/libusb/msvc/xusb_sources +0 -20
- package/libusb/msvc/xusb_wince.vcproj +0 -1120
- package/libusb/travis-autogen.sh +0 -39
package/libusb/tests/testlib.c
CHANGED
|
@@ -17,43 +17,26 @@
|
|
|
17
17
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
#include
|
|
20
|
+
#include <config.h>
|
|
21
21
|
|
|
22
|
-
#include <
|
|
22
|
+
#include <errno.h>
|
|
23
23
|
#include <stdarg.h>
|
|
24
|
+
#include <stdbool.h>
|
|
25
|
+
#include <stdio.h>
|
|
24
26
|
#include <string.h>
|
|
25
|
-
#include <errno.h>
|
|
26
|
-
#if !defined(_WIN32_WCE)
|
|
27
|
-
#include <sys/types.h>
|
|
28
|
-
#include <sys/stat.h>
|
|
29
|
-
#include <fcntl.h>
|
|
30
|
-
#endif
|
|
31
27
|
|
|
32
|
-
#
|
|
33
|
-
|
|
34
|
-
#
|
|
35
|
-
#define STDOUT_FILENO 1
|
|
36
|
-
#elif defined(_WIN32)
|
|
37
|
-
#include <io.h>
|
|
38
|
-
#define dup _dup
|
|
39
|
-
#define dup2 _dup2
|
|
40
|
-
#define open _open
|
|
41
|
-
#define close _close
|
|
42
|
-
#define fdopen _fdopen
|
|
43
|
-
#define NULL_PATH "nul"
|
|
44
|
-
#define STDOUT_FILENO 1
|
|
45
|
-
#define STDERR_FILENO 2
|
|
46
|
-
#else
|
|
47
|
-
#include <unistd.h>
|
|
28
|
+
#include "libusb_testlib.h"
|
|
29
|
+
|
|
30
|
+
#if defined(PLATFORM_POSIX)
|
|
48
31
|
#define NULL_PATH "/dev/null"
|
|
32
|
+
#elif defined(PLATFORM_WINDOWS)
|
|
33
|
+
#define NULL_PATH "nul"
|
|
49
34
|
#endif
|
|
50
|
-
#define INVALID_FD -1
|
|
51
|
-
#define IGNORE_RETVAL(expr) do { (void)(expr); } while(0)
|
|
52
35
|
|
|
53
36
|
/**
|
|
54
37
|
* Converts a test result code into a human readable string.
|
|
55
38
|
*/
|
|
56
|
-
static const char*
|
|
39
|
+
static const char *test_result_to_str(libusb_testlib_result result)
|
|
57
40
|
{
|
|
58
41
|
switch (result) {
|
|
59
42
|
case TEST_STATUS_SUCCESS:
|
|
@@ -69,100 +52,27 @@ static const char* test_result_to_str(libusb_testlib_result result)
|
|
|
69
52
|
}
|
|
70
53
|
}
|
|
71
54
|
|
|
72
|
-
static void print_usage(
|
|
55
|
+
static void print_usage(const char *progname)
|
|
73
56
|
{
|
|
74
|
-
printf("Usage: %s [-l] [-v] [<test_name> ...]\n",
|
|
75
|
-
argc > 0 ? argv[0] : "test_*");
|
|
57
|
+
printf("Usage: %s [-l] [-v] [<test_name> ...]\n", progname);
|
|
76
58
|
printf(" -l List available tests\n");
|
|
77
|
-
printf(" -v Don't redirect STDERR
|
|
59
|
+
printf(" -v Don't redirect STDERR before running tests\n");
|
|
60
|
+
printf(" -h Display this help and exit\n");
|
|
78
61
|
}
|
|
79
62
|
|
|
80
|
-
|
|
81
|
-
{
|
|
82
|
-
#ifndef DISABLE_STDOUT_REDIRECTION
|
|
83
|
-
if (!ctx->verbose) {
|
|
84
|
-
if (ctx->old_stdout != INVALID_FD) {
|
|
85
|
-
IGNORE_RETVAL(dup2(ctx->old_stdout, STDOUT_FILENO));
|
|
86
|
-
ctx->old_stdout = INVALID_FD;
|
|
87
|
-
}
|
|
88
|
-
if (ctx->old_stderr != INVALID_FD) {
|
|
89
|
-
IGNORE_RETVAL(dup2(ctx->old_stderr, STDERR_FILENO));
|
|
90
|
-
ctx->old_stderr = INVALID_FD;
|
|
91
|
-
}
|
|
92
|
-
if (ctx->null_fd != INVALID_FD) {
|
|
93
|
-
close(ctx->null_fd);
|
|
94
|
-
ctx->null_fd = INVALID_FD;
|
|
95
|
-
}
|
|
96
|
-
if (ctx->output_file != stdout) {
|
|
97
|
-
fclose(ctx->output_file);
|
|
98
|
-
ctx->output_file = stdout;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
#endif
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Setup test output handles
|
|
106
|
-
* \return zero on success, non-zero on failure
|
|
107
|
-
*/
|
|
108
|
-
static int setup_test_output(libusb_testlib_ctx * ctx)
|
|
109
|
-
{
|
|
110
|
-
#ifndef DISABLE_STDOUT_REDIRECTION
|
|
111
|
-
/* Stop output to stdout and stderr from being displayed if using non-verbose output */
|
|
112
|
-
if (!ctx->verbose) {
|
|
113
|
-
/* Keep a copy of STDOUT and STDERR */
|
|
114
|
-
ctx->old_stdout = dup(STDOUT_FILENO);
|
|
115
|
-
if (ctx->old_stdout < 0) {
|
|
116
|
-
ctx->old_stdout = INVALID_FD;
|
|
117
|
-
printf("Failed to duplicate stdout handle: %d\n", errno);
|
|
118
|
-
return 1;
|
|
119
|
-
}
|
|
120
|
-
ctx->old_stderr = dup(STDERR_FILENO);
|
|
121
|
-
if (ctx->old_stderr < 0) {
|
|
122
|
-
ctx->old_stderr = INVALID_FD;
|
|
123
|
-
cleanup_test_output(ctx);
|
|
124
|
-
printf("Failed to duplicate stderr handle: %d\n", errno);
|
|
125
|
-
return 1;
|
|
126
|
-
}
|
|
127
|
-
/* Redirect STDOUT_FILENO and STDERR_FILENO to /dev/null or "nul"*/
|
|
128
|
-
ctx->null_fd = open(NULL_PATH, O_WRONLY);
|
|
129
|
-
if (ctx->null_fd < 0) {
|
|
130
|
-
ctx->null_fd = INVALID_FD;
|
|
131
|
-
cleanup_test_output(ctx);
|
|
132
|
-
printf("Failed to open null handle: %d\n", errno);
|
|
133
|
-
return 1;
|
|
134
|
-
}
|
|
135
|
-
if ((dup2(ctx->null_fd, STDOUT_FILENO) < 0) ||
|
|
136
|
-
(dup2(ctx->null_fd, STDERR_FILENO) < 0)) {
|
|
137
|
-
cleanup_test_output(ctx);
|
|
138
|
-
return 1;
|
|
139
|
-
}
|
|
140
|
-
ctx->output_file = fdopen(ctx->old_stdout, "w");
|
|
141
|
-
if (!ctx->output_file) {
|
|
142
|
-
ctx->output_file = stdout;
|
|
143
|
-
cleanup_test_output(ctx);
|
|
144
|
-
printf("Failed to open FILE for output handle: %d\n", errno);
|
|
145
|
-
return 1;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
#endif
|
|
149
|
-
return 0;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
void libusb_testlib_logf(libusb_testlib_ctx * ctx,
|
|
153
|
-
const char* fmt, ...)
|
|
63
|
+
void libusb_testlib_logf(const char *fmt, ...)
|
|
154
64
|
{
|
|
155
65
|
va_list va;
|
|
66
|
+
|
|
156
67
|
va_start(va, fmt);
|
|
157
|
-
vfprintf(
|
|
68
|
+
vfprintf(stdout, fmt, va);
|
|
158
69
|
va_end(va);
|
|
159
|
-
|
|
160
|
-
fflush(
|
|
70
|
+
fputc('\n', stdout);
|
|
71
|
+
fflush(stdout);
|
|
161
72
|
}
|
|
162
73
|
|
|
163
|
-
int libusb_testlib_run_tests(int argc,
|
|
164
|
-
|
|
165
|
-
const libusb_testlib_test * tests)
|
|
74
|
+
int libusb_testlib_run_tests(int argc, char *argv[],
|
|
75
|
+
const libusb_testlib_test *tests)
|
|
166
76
|
{
|
|
167
77
|
int run_count = 0;
|
|
168
78
|
int idx = 0;
|
|
@@ -170,108 +80,105 @@ int libusb_testlib_run_tests(int argc,
|
|
|
170
80
|
int fail_count = 0;
|
|
171
81
|
int error_count = 0;
|
|
172
82
|
int skip_count = 0;
|
|
173
|
-
int r, j;
|
|
174
|
-
size_t arglen;
|
|
175
|
-
libusb_testlib_result test_result;
|
|
176
|
-
libusb_testlib_ctx ctx;
|
|
177
83
|
|
|
178
84
|
/* Setup default mode of operation */
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
ctx.old_stdout = INVALID_FD;
|
|
184
|
-
ctx.old_stderr = INVALID_FD;
|
|
185
|
-
ctx.output_file = stdout;
|
|
186
|
-
ctx.null_fd = INVALID_FD;
|
|
85
|
+
char **test_names = NULL;
|
|
86
|
+
int test_count = 0;
|
|
87
|
+
bool list_tests = false;
|
|
88
|
+
bool verbose = false;
|
|
187
89
|
|
|
188
90
|
/* Parse command line options */
|
|
189
91
|
if (argc >= 2) {
|
|
190
|
-
for (j = 1; j < argc; j++) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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]) {
|
|
195
99
|
case 'l':
|
|
196
|
-
|
|
197
|
-
|
|
100
|
+
list_tests = true;
|
|
101
|
+
continue;
|
|
198
102
|
case 'v':
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return 1;
|
|
103
|
+
verbose = true;
|
|
104
|
+
continue;
|
|
105
|
+
case 'h':
|
|
106
|
+
print_usage(argv[0]);
|
|
107
|
+
return 0;
|
|
205
108
|
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fprintf(stderr, "Unknown option: '%s'\n", argstr);
|
|
112
|
+
print_usage(argv[0]);
|
|
113
|
+
return 1;
|
|
206
114
|
} else {
|
|
207
115
|
/* End of command line options, remaining must be list of tests to run */
|
|
208
|
-
|
|
209
|
-
|
|
116
|
+
test_names = argv + j;
|
|
117
|
+
test_count = argc - j;
|
|
210
118
|
break;
|
|
211
119
|
}
|
|
212
120
|
}
|
|
213
121
|
}
|
|
214
122
|
|
|
215
123
|
/* Validate command line options */
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
print_usage(
|
|
124
|
+
if (test_names && list_tests) {
|
|
125
|
+
fprintf(stderr, "List of tests requested but test list provided\n");
|
|
126
|
+
print_usage(argv[0]);
|
|
219
127
|
return 1;
|
|
220
128
|
}
|
|
221
129
|
|
|
222
130
|
/* Setup test log output */
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
+
}
|
|
226
137
|
|
|
227
138
|
/* Act on any options not related to running tests */
|
|
228
|
-
if (
|
|
229
|
-
while (tests[idx].function
|
|
230
|
-
libusb_testlib_logf(
|
|
231
|
-
++idx;
|
|
232
|
-
}
|
|
233
|
-
cleanup_test_output(&ctx);
|
|
139
|
+
if (list_tests) {
|
|
140
|
+
while (tests[idx].function)
|
|
141
|
+
libusb_testlib_logf("%s", tests[idx++].name);
|
|
234
142
|
return 0;
|
|
235
143
|
}
|
|
236
144
|
|
|
237
145
|
/* Run any requested tests */
|
|
238
|
-
while (tests[idx].function
|
|
239
|
-
const libusb_testlib_test *
|
|
240
|
-
|
|
241
|
-
|
|
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) {
|
|
242
151
|
/* Filtering tests to run, check if this is one of them */
|
|
243
152
|
int i;
|
|
244
|
-
|
|
245
|
-
|
|
153
|
+
|
|
154
|
+
for (i = 0; i < test_count; i++) {
|
|
155
|
+
if (!strcmp(test_names[i], test->name))
|
|
246
156
|
/* Matches a requested test name */
|
|
247
157
|
break;
|
|
248
158
|
}
|
|
249
|
-
if (i
|
|
159
|
+
if (i == test_count) {
|
|
250
160
|
/* Failed to find a test match, so do the next loop iteration */
|
|
251
161
|
continue;
|
|
252
162
|
}
|
|
253
163
|
}
|
|
254
|
-
libusb_testlib_logf(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
libusb_testlib_logf(&ctx,
|
|
258
|
-
"%s (%d)",
|
|
259
|
-
test_result_to_str(test_result), test_result);
|
|
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);
|
|
260
167
|
switch (test_result) {
|
|
261
168
|
case TEST_STATUS_SUCCESS: pass_count++; break;
|
|
262
169
|
case TEST_STATUS_FAILURE: fail_count++; break;
|
|
263
170
|
case TEST_STATUS_ERROR: error_count++; break;
|
|
264
171
|
case TEST_STATUS_SKIP: skip_count++; break;
|
|
265
172
|
}
|
|
266
|
-
|
|
173
|
+
run_count++;
|
|
267
174
|
}
|
|
268
|
-
libusb_testlib_logf(&ctx, "---");
|
|
269
|
-
libusb_testlib_logf(&ctx, "Ran %d tests", run_count);
|
|
270
|
-
libusb_testlib_logf(&ctx, "Passed %d tests", pass_count);
|
|
271
|
-
libusb_testlib_logf(&ctx, "Failed %d tests", fail_count);
|
|
272
|
-
libusb_testlib_logf(&ctx, "Error in %d tests", error_count);
|
|
273
|
-
libusb_testlib_logf(&ctx, "Skipped %d tests", skip_count);
|
|
274
175
|
|
|
275
|
-
|
|
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
|
+
|
|
276
183
|
return pass_count != run_count;
|
|
277
184
|
}
|