-
Notifications
You must be signed in to change notification settings - Fork 132
/
hid_test.go
41 lines (37 loc) · 946 Bytes
/
hid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// hid - Gopher Interface Devices (USB HID)
// Copyright (c) 2017 Péter Szilágyi. All rights reserved.
//
// This file is released under the 3-clause BSD license. Note however that Linux
// support depends on libusb, released under LGNU GPL 2.1 or later.
package hid
import (
"fmt"
"sync"
"testing"
)
// TestThreadedEnumerate Tests that HID enumeration can be called concurrently from multiple threads.
func TestThreadedEnumerate(t *testing.T) {
var (
threads = 8
errs []error = make([]error, threads)
pend sync.WaitGroup
)
for i := 0; i < threads; i++ {
pend.Add(1)
go func(index int) {
defer pend.Done()
for j := 0; j < 512; j++ {
if _, err := Enumerate(uint16(index), 0); err != nil {
errs[index] = fmt.Errorf("thread %d, iter %d: failed to enumerate-hid: %v", index, j, err)
break
}
}
}(i)
}
pend.Wait()
for _, err := range errs {
if err != nil {
t.Error(err)
}
}
}