-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblaster_test.go
29 lines (24 loc) · 1.46 KB
/
blaster_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
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
// testEeprom was read from the device after configuring it with Cypress’s Blaster tool.
var testEeprom = []byte{0xb4, 0x4, 0x72, 0x65, 0x90, 0xfe, 0x1e, 0x4, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa, 0x73, 0x74, 0x61, 0x70, 0x65, 0x6c, 0x62, 0x65, 0x72, 0x67, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8, 0x6b, 0x69, 0x6e, 0x58, 0x20, 0x68, 0x75, 0x62, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc, 0x30, 0x30, 0x30, 0x35, 0x30, 0x30, 0x33, 0x34, 0x30, 0x33, 0x31, 0x42, 0xff, 0xff, 0xff}
func TestParseEEPROM(t *testing.T) {
got, err := parse(testEeprom)
if err != nil {
t.Fatal(err)
}
want := &config{VID: 0x4b4, PID: 0x6572, Removable: 0x1e, Ports: 0x4, MaxPower: 0xfa, Vendor: "stapelberg", Product: "kinX hub", Serial: "00050034031B"}
if diff := cmp.Diff(got, want); diff != "" {
t.Fatalf("parse(%x): diff (-got +want):\n%s", testEeprom, diff)
}
b, err := got.Marshal()
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(b, testEeprom); diff != "" {
t.Fatalf("Marshal(): diff (-got +want):\n%s", diff)
}
}