-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-rtc.go
48 lines (41 loc) · 1.16 KB
/
test-rtc.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
package pcbatest
import (
"fmt"
"time"
"github.com/TheCacophonyProject/rtc-utils/rtc"
)
func TestRTC(attempts int, t *Tests) {
// RTC Battery. If the battery is low the test will also fail
// Battery test is repeated as if the battery plug is not connected it can be
// a floating voltage on the RTC battery pin
batteryPassed := true
for i := 0; i < 20; i++ {
if rtc.CheckBattery(attempts) != nil {
batteryPassed = false
break
}
time.Sleep(100 * time.Millisecond)
}
if batteryPassed {
t.addPass("RTC battery test passed")
} else {
t.addFail("RTC battery test failed. Check that battery is plugged in HAT and isn't flat")
}
now := time.Now().UTC() // Used for checking read test
if rtc.Write(attempts) == nil {
t.addPass("RTC time write passed")
} else {
t.addFail("RTC time write failed")
return // Don't test read if write failed
}
state, err := rtc.State(attempts)
if err != nil {
t.addFail("RTC state read failed")
return
}
if state.Time.Sub(now) > time.Second {
t.addFail(fmt.Sprintf("RTC write or read time failed. Time written %s, time read %s", now.UTC(), state.Time))
} else {
t.addPass("RTC read and write passed")
}
}