-
Notifications
You must be signed in to change notification settings - Fork 42
/
gpiocdev_bmark_test.go
155 lines (145 loc) · 3.24 KB
/
gpiocdev_bmark_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]>
//
// SPDX-License-Identifier: MIT
package gpiocdev_test
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/warthog618/go-gpiocdev"
"github.com/warthog618/go-gpiosim"
)
func BenchmarkChipNewClose(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
for i := 0; i < b.N; i++ {
c, _ := gpiocdev.NewChip(s.DevPath())
c.Close()
}
}
func BenchmarkLineInfo(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
c, err := gpiocdev.NewChip(s.DevPath())
require.Nil(b, err)
require.NotNil(b, c)
defer c.Close()
for i := 0; i < b.N; i++ {
c.LineInfo(3)
}
}
func BenchmarkLineReconfigure(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
c, err := gpiocdev.NewChip(s.DevPath())
require.Nil(b, err)
require.NotNil(b, c)
defer c.Close()
l, err := c.RequestLine(3)
require.Nil(b, err)
require.NotNil(b, l)
defer l.Close()
for i := 0; i < b.N; i++ {
l.Reconfigure(gpiocdev.AsActiveLow)
}
}
func BenchmarkLineValue(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
c, err := gpiocdev.NewChip(s.DevPath())
require.Nil(b, err)
require.NotNil(b, c)
defer c.Close()
l, err := c.RequestLine(3)
require.Nil(b, err)
require.NotNil(b, l)
defer l.Close()
for i := 0; i < b.N; i++ {
l.Value()
}
}
func BenchmarkLinesValues(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
c, err := gpiocdev.NewChip(s.DevPath())
require.Nil(b, err)
require.NotNil(b, c)
defer c.Close()
l, err := c.RequestLines([]int{1, 2, 3})
require.Nil(b, err)
require.NotNil(b, l)
defer l.Close()
vv := make([]int, len(l.Offsets()))
for i := 0; i < b.N; i++ {
l.Values(vv)
}
}
func BenchmarkLineSetValue(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
c, err := gpiocdev.NewChip(s.DevPath())
require.Nil(b, err)
require.NotNil(b, c)
defer c.Close()
l, err := c.RequestLine(3, gpiocdev.AsOutput(0))
require.Nil(b, err)
require.NotNil(b, l)
defer l.Close()
for i := 0; i < b.N; i++ {
l.SetValue(1)
}
}
func BenchmarkLinesSetValues(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
c, err := gpiocdev.NewChip(s.DevPath())
require.Nil(b, err)
require.NotNil(b, c)
defer c.Close()
ll, err := c.RequestLines([]int{1, 2}, gpiocdev.AsOutput(0))
require.Nil(b, err)
require.NotNil(b, ll)
defer ll.Close()
vv := []int{0, 0}
for i := 0; i < b.N; i++ {
vv[0] = i & 1
ll.SetValues(vv)
}
}
func BenchmarkInterruptLatency(b *testing.B) {
s, err := gpiosim.NewSimpleton(6)
require.Nil(b, err)
defer s.Close()
c, err := gpiocdev.NewChip(s.DevPath())
require.Nil(b, err)
require.NotNil(b, c)
defer c.Close()
offset := 2
s.SetPull(offset, 1)
ich := make(chan int)
eh := func(evt gpiocdev.LineEvent) {
ich <- 1
}
r, err := c.RequestLine(offset,
gpiocdev.WithBothEdges,
gpiocdev.WithEventHandler(eh))
require.Nil(b, err)
require.NotNil(b, r)
// absorb any pending interrupt
select {
case <-ich:
case <-time.After(time.Millisecond):
}
for i := 0; i < b.N; i++ {
s.SetPull(offset, i&1)
<-ich
}
r.Close()
}