libusb 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -2
- data/Gemfile +2 -0
- data/History.md +12 -0
- data/README.md +25 -14
- data/Rakefile +64 -109
- data/appveyor.yml +23 -0
- data/ext/extconf.rb +10 -12
- data/ext/libusb_recipe.rb +29 -0
- data/lib/libusb/call.rb +14 -11
- data/lib/libusb/compat.rb +9 -9
- data/lib/libusb/context.rb +16 -1
- data/lib/libusb/dependencies.rb +7 -0
- data/lib/libusb/dev_handle.rb +13 -3
- data/lib/libusb/eventmachine.rb +4 -4
- data/lib/libusb/transfer.rb +71 -10
- data/lib/libusb/version_gem.rb +1 -1
- data/libusb.gemspec +7 -5
- data/ports/archives/libusb-1.0.21.tar.bz2 +0 -0
- data/test/test_libusb_bulk_stream_transfer.rb +1 -1
- data/test/test_libusb_descriptors.rb +4 -4
- data/test/test_libusb_event_machine.rb +7 -7
- data/test/test_libusb_hotplug.rb +15 -3
- data/test/test_libusb_iso_transfer.rb +1 -1
- data/test/test_libusb_mass_storage.rb +19 -19
- data/test/test_libusb_mass_storage2.rb +1 -1
- data/test/test_libusb_structs.rb +13 -0
- data/test/test_libusb_threads.rb +2 -2
- data/wireshark-usb-sniffer.png +0 -0
- metadata +32 -156
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ext/libusb-1.0.20/AUTHORS +0 -89
- data/ext/libusb-1.0.20/COPYING +0 -504
- data/ext/libusb-1.0.20/ChangeLog +0 -227
- data/ext/libusb-1.0.20/INSTALL +0 -234
- data/ext/libusb-1.0.20/Makefile.am +0 -28
- data/ext/libusb-1.0.20/Makefile.in +0 -897
- data/ext/libusb-1.0.20/NEWS +0 -2
- data/ext/libusb-1.0.20/PORTING +0 -94
- data/ext/libusb-1.0.20/README +0 -29
- data/ext/libusb-1.0.20/TODO +0 -2
- data/ext/libusb-1.0.20/Xcode/common.xcconfig +0 -49
- data/ext/libusb-1.0.20/Xcode/config.h +0 -28
- data/ext/libusb-1.0.20/Xcode/debug.xcconfig +0 -29
- data/ext/libusb-1.0.20/Xcode/libusb.xcconfig +0 -21
- data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +0 -865
- data/ext/libusb-1.0.20/Xcode/libusb_debug.xcconfig +0 -21
- data/ext/libusb-1.0.20/Xcode/libusb_release.xcconfig +0 -21
- data/ext/libusb-1.0.20/Xcode/release.xcconfig +0 -30
- data/ext/libusb-1.0.20/aclocal.m4 +0 -1193
- data/ext/libusb-1.0.20/android/README +0 -114
- data/ext/libusb-1.0.20/android/config.h +0 -81
- data/ext/libusb-1.0.20/android/jni/Android.mk +0 -23
- data/ext/libusb-1.0.20/android/jni/Application.mk +0 -24
- data/ext/libusb-1.0.20/android/jni/examples.mk +0 -134
- data/ext/libusb-1.0.20/android/jni/libusb.mk +0 -54
- data/ext/libusb-1.0.20/android/jni/tests.mk +0 -56
- data/ext/libusb-1.0.20/compile +0 -347
- data/ext/libusb-1.0.20/config.guess +0 -1421
- data/ext/libusb-1.0.20/config.h.in +0 -155
- data/ext/libusb-1.0.20/config.sub +0 -1807
- data/ext/libusb-1.0.20/configure +0 -15466
- data/ext/libusb-1.0.20/configure.ac +0 -326
- data/ext/libusb-1.0.20/depcomp +0 -791
- data/ext/libusb-1.0.20/doc/Makefile.am +0 -9
- data/ext/libusb-1.0.20/doc/Makefile.in +0 -456
- data/ext/libusb-1.0.20/doc/doxygen.cfg.in +0 -2334
- data/ext/libusb-1.0.20/examples/Makefile.am +0 -19
- data/ext/libusb-1.0.20/examples/Makefile.in +0 -713
- data/ext/libusb-1.0.20/examples/dpfp.c +0 -506
- data/ext/libusb-1.0.20/examples/dpfp_threaded.c +0 -549
- data/ext/libusb-1.0.20/examples/ezusb.c +0 -831
- data/ext/libusb-1.0.20/examples/ezusb.h +0 -120
- data/ext/libusb-1.0.20/examples/fxload.c +0 -308
- data/ext/libusb-1.0.20/examples/getopt/getopt.c +0 -1060
- data/ext/libusb-1.0.20/examples/getopt/getopt.h +0 -180
- data/ext/libusb-1.0.20/examples/getopt/getopt1.c +0 -188
- data/ext/libusb-1.0.20/examples/hotplugtest.c +0 -122
- data/ext/libusb-1.0.20/examples/listdevs.c +0 -71
- data/ext/libusb-1.0.20/examples/sam3u_benchmark.c +0 -193
- data/ext/libusb-1.0.20/examples/xusb.c +0 -1130
- data/ext/libusb-1.0.20/install-sh +0 -501
- data/ext/libusb-1.0.20/libusb-1.0.pc.in +0 -11
- data/ext/libusb-1.0.20/libusb/Makefile.am +0 -90
- data/ext/libusb-1.0.20/libusb/Makefile.in +0 -1053
- data/ext/libusb-1.0.20/libusb/core.c +0 -2452
- data/ext/libusb-1.0.20/libusb/descriptor.c +0 -1201
- data/ext/libusb-1.0.20/libusb/hotplug.c +0 -344
- data/ext/libusb-1.0.20/libusb/hotplug.h +0 -90
- data/ext/libusb-1.0.20/libusb/io.c +0 -2760
- data/ext/libusb-1.0.20/libusb/libusb-1.0.def +0 -168
- data/ext/libusb-1.0.20/libusb/libusb-1.0.rc +0 -61
- data/ext/libusb-1.0.20/libusb/libusb.h +0 -1999
- data/ext/libusb-1.0.20/libusb/libusbi.h +0 -1102
- data/ext/libusb-1.0.20/libusb/os/darwin_usb.c +0 -1969
- data/ext/libusb-1.0.20/libusb/os/darwin_usb.h +0 -158
- data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +0 -5
- data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +0 -810
- data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +0 -1193
- data/ext/libusb-1.0.20/libusb/os/haiku/compile +0 -347
- data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +0 -1421
- data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +0 -1807
- data/ext/libusb-1.0.20/libusb/os/haiku/configure +0 -17579
- data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +0 -8
- data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +0 -791
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +0 -378
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +0 -112
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +0 -550
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +0 -255
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +0 -180
- data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +0 -501
- data/ext/libusb-1.0.20/libusb/os/haiku/ltmain.sh +0 -9655
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/libtool.m4 +0 -7992
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltoptions.m4 +0 -384
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltsugar.m4 +0 -123
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltversion.m4 +0 -23
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/lt~obsolete.m4 +0 -98
- data/ext/libusb-1.0.20/libusb/os/haiku/missing +0 -215
- data/ext/libusb-1.0.20/libusb/os/linux_netlink.c +0 -369
- data/ext/libusb-1.0.20/libusb/os/linux_udev.c +0 -306
- data/ext/libusb-1.0.20/libusb/os/linux_usbfs.c +0 -2692
- data/ext/libusb-1.0.20/libusb/os/linux_usbfs.h +0 -192
- data/ext/libusb-1.0.20/libusb/os/netbsd_usb.c +0 -674
- data/ext/libusb-1.0.20/libusb/os/openbsd_usb.c +0 -768
- data/ext/libusb-1.0.20/libusb/os/poll_posix.c +0 -53
- data/ext/libusb-1.0.20/libusb/os/poll_posix.h +0 -11
- data/ext/libusb-1.0.20/libusb/os/poll_windows.c +0 -728
- data/ext/libusb-1.0.20/libusb/os/poll_windows.h +0 -131
- data/ext/libusb-1.0.20/libusb/os/threads_posix.c +0 -82
- data/ext/libusb-1.0.20/libusb/os/threads_posix.h +0 -50
- data/ext/libusb-1.0.20/libusb/os/threads_windows.c +0 -214
- data/ext/libusb-1.0.20/libusb/os/threads_windows.h +0 -87
- data/ext/libusb-1.0.20/libusb/os/wince_usb.c +0 -869
- data/ext/libusb-1.0.20/libusb/os/wince_usb.h +0 -131
- data/ext/libusb-1.0.20/libusb/os/windows_common.h +0 -108
- data/ext/libusb-1.0.20/libusb/os/windows_usb.c +0 -4643
- data/ext/libusb-1.0.20/libusb/os/windows_usb.h +0 -973
- data/ext/libusb-1.0.20/libusb/strerror.c +0 -202
- data/ext/libusb-1.0.20/libusb/sync.c +0 -308
- data/ext/libusb-1.0.20/libusb/version.h +0 -18
- data/ext/libusb-1.0.20/libusb/version_nano.h +0 -1
- data/ext/libusb-1.0.20/ltmain.sh +0 -9655
- data/ext/libusb-1.0.20/m4/libtool.m4 +0 -7992
- data/ext/libusb-1.0.20/m4/ltoptions.m4 +0 -384
- data/ext/libusb-1.0.20/m4/ltsugar.m4 +0 -123
- data/ext/libusb-1.0.20/m4/ltversion.m4 +0 -23
- data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +0 -98
- data/ext/libusb-1.0.20/missing +0 -215
- data/ext/libusb-1.0.20/tests/Makefile.am +0 -6
- data/ext/libusb-1.0.20/tests/Makefile.in +0 -596
- data/ext/libusb-1.0.20/tests/libusb_testlib.h +0 -107
- data/ext/libusb-1.0.20/tests/stress.c +0 -160
- data/ext/libusb-1.0.20/tests/testlib.c +0 -277
- metadata.gz.sig +0 -0
@@ -1,107 +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
|
-
#ifndef LIBUSB_TESTLIB_H
|
21
|
-
#define LIBUSB_TESTLIB_H
|
22
|
-
|
23
|
-
#include <stdio.h>
|
24
|
-
|
25
|
-
#if !defined(bool)
|
26
|
-
#define bool int
|
27
|
-
#endif
|
28
|
-
#if !defined(true)
|
29
|
-
#define true (1 == 1)
|
30
|
-
#endif
|
31
|
-
#if !defined(false)
|
32
|
-
#define false (!true)
|
33
|
-
#endif
|
34
|
-
|
35
|
-
/** Values returned from a test function to indicate test result */
|
36
|
-
typedef enum {
|
37
|
-
/** Indicates that the test ran successfully. */
|
38
|
-
TEST_STATUS_SUCCESS,
|
39
|
-
/** Indicates that the test failed one or more test. */
|
40
|
-
TEST_STATUS_FAILURE,
|
41
|
-
/** Indicates that an unexpected error occurred. */
|
42
|
-
TEST_STATUS_ERROR,
|
43
|
-
/** Indicates that the test can't be run. For example this may be
|
44
|
-
* due to no suitable device being connected to perform the tests.*/
|
45
|
-
TEST_STATUS_SKIP
|
46
|
-
} libusb_testlib_result;
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Context for test library functions
|
50
|
-
*/
|
51
|
-
typedef struct {
|
52
|
-
char ** test_names;
|
53
|
-
int test_count;
|
54
|
-
bool list_tests;
|
55
|
-
bool verbose;
|
56
|
-
int old_stdout;
|
57
|
-
int old_stderr;
|
58
|
-
FILE* output_file;
|
59
|
-
int null_fd;
|
60
|
-
} libusb_testlib_ctx;
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Logs some test information or state
|
64
|
-
*/
|
65
|
-
void libusb_testlib_logf(libusb_testlib_ctx * ctx,
|
66
|
-
const char* fmt, ...);
|
67
|
-
|
68
|
-
/**
|
69
|
-
* Function pointer for a libusb test function.
|
70
|
-
*
|
71
|
-
* Should return TEST_STATUS_SUCCESS on success or another TEST_STATUS value.
|
72
|
-
*/
|
73
|
-
typedef libusb_testlib_result
|
74
|
-
(*libusb_testlib_test_function)(libusb_testlib_ctx * ctx);
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Structure holding a test description.
|
78
|
-
*/
|
79
|
-
typedef struct {
|
80
|
-
/** Human readable name of the test. */
|
81
|
-
const char * name;
|
82
|
-
/** The test library will call this function to run the test. */
|
83
|
-
libusb_testlib_test_function function;
|
84
|
-
} libusb_testlib_test;
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Value to use at the end of a test array to indicate the last
|
88
|
-
* element.
|
89
|
-
*/
|
90
|
-
#define LIBUSB_NULL_TEST {NULL, NULL}
|
91
|
-
|
92
|
-
/**
|
93
|
-
* Runs the tests provided.
|
94
|
-
*
|
95
|
-
* Before running any tests argc and argv will be processed
|
96
|
-
* to determine the mode of operation.
|
97
|
-
*
|
98
|
-
* \param argc The argc from main
|
99
|
-
* \param argv The argv from main
|
100
|
-
* \param tests A NULL_TEST terminated array of tests
|
101
|
-
* \return 0 on success, non-zero on failure
|
102
|
-
*/
|
103
|
-
int libusb_testlib_run_tests(int argc,
|
104
|
-
char ** argv,
|
105
|
-
const libusb_testlib_test * tests);
|
106
|
-
|
107
|
-
#endif //LIBUSB_TESTLIB_H
|
@@ -1,160 +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 <stdio.h>
|
21
|
-
#include <string.h>
|
22
|
-
#include <memory.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(libusb_testlib_ctx * tctx)
|
30
|
-
{
|
31
|
-
libusb_context * ctx = NULL;
|
32
|
-
int i;
|
33
|
-
for (i = 0; i < 10000; ++i) {
|
34
|
-
int r = libusb_init(&ctx);
|
35
|
-
if (r != LIBUSB_SUCCESS) {
|
36
|
-
libusb_testlib_logf(tctx,
|
37
|
-
"Failed to init libusb on iteration %d: %d",
|
38
|
-
i, r);
|
39
|
-
return TEST_STATUS_FAILURE;
|
40
|
-
}
|
41
|
-
libusb_exit(ctx);
|
42
|
-
ctx = NULL;
|
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(libusb_testlib_ctx * tctx)
|
50
|
-
{
|
51
|
-
libusb_context * ctx = NULL;
|
52
|
-
int r, i;
|
53
|
-
r = libusb_init(&ctx);
|
54
|
-
if (r != LIBUSB_SUCCESS) {
|
55
|
-
libusb_testlib_logf(tctx, "Failed to init libusb: %d", r);
|
56
|
-
return TEST_STATUS_FAILURE;
|
57
|
-
}
|
58
|
-
for (i = 0; i < 1000; ++i) {
|
59
|
-
libusb_device ** device_list;
|
60
|
-
ssize_t list_size = libusb_get_device_list(ctx, &device_list);
|
61
|
-
if (list_size < 0 || device_list == NULL) {
|
62
|
-
libusb_testlib_logf(tctx,
|
63
|
-
"Failed to get device list on iteration %d: %d (%p)",
|
64
|
-
i, -list_size, device_list);
|
65
|
-
return TEST_STATUS_FAILURE;
|
66
|
-
}
|
67
|
-
libusb_free_device_list(device_list, 1);
|
68
|
-
}
|
69
|
-
libusb_exit(ctx);
|
70
|
-
return TEST_STATUS_SUCCESS;
|
71
|
-
}
|
72
|
-
|
73
|
-
/** Tests that 100 concurrent device lists can be open at a time. */
|
74
|
-
static libusb_testlib_result test_many_device_lists(libusb_testlib_ctx * tctx)
|
75
|
-
{
|
76
|
-
#define LIST_COUNT 100
|
77
|
-
libusb_context * ctx = NULL;
|
78
|
-
libusb_device ** device_lists[LIST_COUNT];
|
79
|
-
int r, i;
|
80
|
-
memset(device_lists, 0, sizeof(device_lists));
|
81
|
-
|
82
|
-
r = libusb_init(&ctx);
|
83
|
-
if (r != LIBUSB_SUCCESS) {
|
84
|
-
libusb_testlib_logf(tctx, "Failed to init libusb: %d", r);
|
85
|
-
return TEST_STATUS_FAILURE;
|
86
|
-
}
|
87
|
-
|
88
|
-
/* Create the 100 device lists. */
|
89
|
-
for (i = 0; i < LIST_COUNT; ++i) {
|
90
|
-
ssize_t list_size = libusb_get_device_list(ctx, &(device_lists[i]));
|
91
|
-
if (list_size < 0 || device_lists[i] == NULL) {
|
92
|
-
libusb_testlib_logf(tctx,
|
93
|
-
"Failed to get device list on iteration %d: %d (%p)",
|
94
|
-
i, -list_size, device_lists[i]);
|
95
|
-
return TEST_STATUS_FAILURE;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
/* Destroy the 100 device lists. */
|
100
|
-
for (i = 0; i < LIST_COUNT; ++i) {
|
101
|
-
if (device_lists[i]) {
|
102
|
-
libusb_free_device_list(device_lists[i], 1);
|
103
|
-
device_lists[i] = NULL;
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
libusb_exit(ctx);
|
108
|
-
return TEST_STATUS_SUCCESS;
|
109
|
-
#undef LIST_COUNT
|
110
|
-
}
|
111
|
-
|
112
|
-
/** Tests that the default context (used for various things including
|
113
|
-
* logging) works correctly when the first context created in a
|
114
|
-
* process is destroyed. */
|
115
|
-
static libusb_testlib_result test_default_context_change(libusb_testlib_ctx * tctx)
|
116
|
-
{
|
117
|
-
libusb_context * ctx = NULL;
|
118
|
-
int r, i;
|
119
|
-
|
120
|
-
for (i = 0; i < 100; ++i) {
|
121
|
-
/* First create a new context */
|
122
|
-
r = libusb_init(&ctx);
|
123
|
-
if (r != LIBUSB_SUCCESS) {
|
124
|
-
libusb_testlib_logf(tctx, "Failed to init libusb: %d", r);
|
125
|
-
return TEST_STATUS_FAILURE;
|
126
|
-
}
|
127
|
-
|
128
|
-
/* Enable debug output, to be sure to use the context */
|
129
|
-
libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_DEBUG);
|
130
|
-
libusb_set_debug(ctx, LIBUSB_LOG_LEVEL_DEBUG);
|
131
|
-
|
132
|
-
/* Now create a reference to the default context */
|
133
|
-
r = libusb_init(NULL);
|
134
|
-
if (r != LIBUSB_SUCCESS) {
|
135
|
-
libusb_testlib_logf(tctx, "Failed to init libusb: %d", r);
|
136
|
-
return TEST_STATUS_FAILURE;
|
137
|
-
}
|
138
|
-
|
139
|
-
/* Destroy the first context */
|
140
|
-
libusb_exit(ctx);
|
141
|
-
/* Destroy the default context */
|
142
|
-
libusb_exit(NULL);
|
143
|
-
}
|
144
|
-
|
145
|
-
return TEST_STATUS_SUCCESS;
|
146
|
-
}
|
147
|
-
|
148
|
-
/* Fill in the list of tests. */
|
149
|
-
static const libusb_testlib_test tests[] = {
|
150
|
-
{"init_and_exit", &test_init_and_exit},
|
151
|
-
{"get_device_list", &test_get_device_list},
|
152
|
-
{"many_device_lists", &test_many_device_lists},
|
153
|
-
{"default_context_change", &test_default_context_change},
|
154
|
-
LIBUSB_NULL_TEST
|
155
|
-
};
|
156
|
-
|
157
|
-
int main (int argc, char ** argv)
|
158
|
-
{
|
159
|
-
return libusb_testlib_run_tests(argc, argv, tests);
|
160
|
-
}
|
@@ -1,277 +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 "libusb_testlib.h"
|
21
|
-
|
22
|
-
#include <stdio.h>
|
23
|
-
#include <stdarg.h>
|
24
|
-
#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
|
-
|
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>
|
48
|
-
#define NULL_PATH "/dev/null"
|
49
|
-
#endif
|
50
|
-
#define INVALID_FD -1
|
51
|
-
#define IGNORE_RETVAL(expr) do { (void)(expr); } while(0)
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Converts a test result code into a human readable string.
|
55
|
-
*/
|
56
|
-
static const char* test_result_to_str(libusb_testlib_result result)
|
57
|
-
{
|
58
|
-
switch (result) {
|
59
|
-
case TEST_STATUS_SUCCESS:
|
60
|
-
return "Success";
|
61
|
-
case TEST_STATUS_FAILURE:
|
62
|
-
return "Failure";
|
63
|
-
case TEST_STATUS_ERROR:
|
64
|
-
return "Error";
|
65
|
-
case TEST_STATUS_SKIP:
|
66
|
-
return "Skip";
|
67
|
-
default:
|
68
|
-
return "Unknown";
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
static void print_usage(int argc, char ** argv)
|
73
|
-
{
|
74
|
-
printf("Usage: %s [-l] [-v] [<test_name> ...]\n",
|
75
|
-
argc > 0 ? argv[0] : "test_*");
|
76
|
-
printf(" -l List available tests\n");
|
77
|
-
printf(" -v Don't redirect STDERR/STDOUT during tests\n");
|
78
|
-
}
|
79
|
-
|
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, ...)
|
154
|
-
{
|
155
|
-
va_list va;
|
156
|
-
va_start(va, fmt);
|
157
|
-
vfprintf(ctx->output_file, fmt, va);
|
158
|
-
va_end(va);
|
159
|
-
fprintf(ctx->output_file, "\n");
|
160
|
-
fflush(ctx->output_file);
|
161
|
-
}
|
162
|
-
|
163
|
-
int libusb_testlib_run_tests(int argc,
|
164
|
-
char ** argv,
|
165
|
-
const libusb_testlib_test * tests)
|
166
|
-
{
|
167
|
-
int run_count = 0;
|
168
|
-
int idx = 0;
|
169
|
-
int pass_count = 0;
|
170
|
-
int fail_count = 0;
|
171
|
-
int error_count = 0;
|
172
|
-
int skip_count = 0;
|
173
|
-
int r, j;
|
174
|
-
size_t arglen;
|
175
|
-
libusb_testlib_result test_result;
|
176
|
-
libusb_testlib_ctx ctx;
|
177
|
-
|
178
|
-
/* 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;
|
187
|
-
|
188
|
-
/* Parse command line options */
|
189
|
-
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]) {
|
195
|
-
case 'l':
|
196
|
-
ctx.list_tests = true;
|
197
|
-
break;
|
198
|
-
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;
|
205
|
-
}
|
206
|
-
} else {
|
207
|
-
/* 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;
|
210
|
-
break;
|
211
|
-
}
|
212
|
-
}
|
213
|
-
}
|
214
|
-
|
215
|
-
/* 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);
|
219
|
-
return 1;
|
220
|
-
}
|
221
|
-
|
222
|
-
/* Setup test log output */
|
223
|
-
r = setup_test_output(&ctx);
|
224
|
-
if (r != 0)
|
225
|
-
return r;
|
226
|
-
|
227
|
-
/* 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);
|
234
|
-
return 0;
|
235
|
-
}
|
236
|
-
|
237
|
-
/* 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) {
|
242
|
-
/* Filtering tests to run, check if this is one of them */
|
243
|
-
int i;
|
244
|
-
for (i = 0; i < ctx.test_count; ++i) {
|
245
|
-
if (strcmp(ctx.test_names[i], test->name) == 0)
|
246
|
-
/* Matches a requested test name */
|
247
|
-
break;
|
248
|
-
}
|
249
|
-
if (i >= ctx.test_count) {
|
250
|
-
/* Failed to find a test match, so do the next loop iteration */
|
251
|
-
continue;
|
252
|
-
}
|
253
|
-
}
|
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);
|
260
|
-
switch (test_result) {
|
261
|
-
case TEST_STATUS_SUCCESS: pass_count++; break;
|
262
|
-
case TEST_STATUS_FAILURE: fail_count++; break;
|
263
|
-
case TEST_STATUS_ERROR: error_count++; break;
|
264
|
-
case TEST_STATUS_SKIP: skip_count++; break;
|
265
|
-
}
|
266
|
-
++run_count;
|
267
|
-
}
|
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
|
-
|
275
|
-
cleanup_test_output(&ctx);
|
276
|
-
return pass_count != run_count;
|
277
|
-
}
|