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