forked from google/periph
/
benchmark.go
68 lines (60 loc) · 1.55 KB
/
benchmark.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
// Copyright 2017 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package bcm283xsmoketest
import (
"errors"
"flag"
"fmt"
"periph.io/x/periph/conn/gpio"
"periph.io/x/periph/conn/gpio/gpioreg"
"periph.io/x/periph/host/bcm283x"
)
// Benchmark is imported by periph-smoketest.
type Benchmark struct {
short bool
p *bcm283x.Pin
pull gpio.Pull
}
// Name implements the SmokeTest interface.
func (s *Benchmark) Name() string {
return "bcm283x-benchmark"
}
// Description implements the SmokeTest interface.
func (s *Benchmark) Description() string {
return "Benchmarks bcm283x functionality"
}
// Run implements the SmokeTest interface.
func (s *Benchmark) Run(f *flag.FlagSet, args []string) error {
name := f.String("p", "", "Pin to use")
f.BoolVar(&s.short, "short", false, "Skip many partially redundant benchmarks")
if err := f.Parse(args); err != nil {
return err
}
if f.NArg() != 0 {
f.Usage()
return errors.New("unsupported flags")
}
if !bcm283x.Present() {
f.Usage()
return errors.New("this smoke test can only be run on a bcm283x based host")
}
if *name == "" {
f.Usage()
return errors.New("-p is required")
}
p := gpioreg.ByName(*name)
if p == nil {
return fmt.Errorf("invalid pin %q", *name)
}
if r, ok := p.(gpio.RealPin); ok {
p = r.Real()
}
ok := false
if s.p, ok = p.(*bcm283x.Pin); !ok {
return fmt.Errorf("pin is not bcm283x %q", *name)
}
s.pull = gpio.PullDown
s.runFastGPIOBenchmark()
return nil
}