-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevices_test.go
97 lines (76 loc) · 1.85 KB
/
devices_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
package devices
import (
"testing"
)
func TestGetBySignature(t *testing.T) {
mcu, err := GetBySignature(0x910b)
if err != nil {
t.Error(err)
}
if mcu == nil {
t.Errorf("MCU not found for 0x910b")
}
if m := mcu.Name(); m != "ATtiny24" {
t.Errorf("Bad MCU name: %s", m)
}
if m := mcu.EECR().Io8(); m != 0x1c {
t.Errorf("Bad EECR.Io8(): 0x%02x", m)
}
if m := mcu.EECR().Io16(); m != 0x1c {
t.Errorf("Bad EECR.Io16(): 0x%04x", m)
}
if m := mcu.EECR().Mem8(); m != 0x3c {
t.Errorf("Bad EECR.Mem8(): 0x%02x", m)
}
if m := mcu.EECR().Mem16(); m != 0x3c {
t.Errorf("Bad EECR.Mem16(): 0x%04x", m)
}
}
func TestGetBySignatureError(t *testing.T) {
mcu, err := GetBySignature(0xdead)
if err == nil {
t.Errorf("Error was expected")
}
if mcu != nil {
t.Errorf("Returned MCU for invalid signature: %s", mcu.Name())
}
if e := err.Error(); e != "devices: MCU lookup failed for signature: 0xdead" {
t.Errorf("Bad error message: %s", e)
}
}
func TestGetByName(t *testing.T) {
mcu, err := GetByName("attiny24a")
if err != nil {
t.Error(err)
}
if mcu == nil {
t.Errorf("MCU not found for 0x910b")
}
if m := mcu.Name(); m != "ATtiny24A" {
t.Errorf("Bad MCU name: %s", m)
}
if m := mcu.EECR().Io8(); m != 0x1c {
t.Errorf("Bad EECR.Io8(): 0x%02x", m)
}
if m := mcu.EECR().Io16(); m != 0x1c {
t.Errorf("Bad EECR.Io16(): 0x%04x", m)
}
if m := mcu.EECR().Mem8(); m != 0x3c {
t.Errorf("Bad EECR.Mem8(): 0x%02x", m)
}
if m := mcu.EECR().Mem16(); m != 0x3c {
t.Errorf("Bad EECR.Mem16(): 0x%04x", m)
}
}
func TestGetByNameError(t *testing.T) {
mcu, err := GetByName("attiny345")
if err == nil {
t.Errorf("Error was expected")
}
if mcu != nil {
t.Errorf("Returned MCU for invalid name: %s", mcu.Name())
}
if e := err.Error(); e != "devices: MCU lookup failed for name: attiny345" {
t.Errorf("Bad error message: %s", e)
}
}