Пример #1
0
func TestReset(t *testing.T) {
	if testing.Short() {
		t.SkipNow()
	}
	d, err := eeprom.First()
	if err != nil {
		t.Fatal(err)
	}
	defer d.Close()

	d.Reset()
}
Пример #2
0
func BenchmarkErase(b *testing.B) {
	d, err := eeprom.First()
	if err != nil {
		b.Fatal(err)
	}
	defer d.Close()

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if err := d.Erase(); err != nil {
			b.Fatal(err)
		}
	}
}
Пример #3
0
func benchmarkDataCommand(b *testing.B, cmd dataCommand, n int) {
	d, err := eeprom.First()
	if err != nil {
		b.Fatal(err)
	}
	defer d.Close()

	data := make([]byte, n)
	if err := d.Erase(); err != nil {
		b.Fatal(err)
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if err := cmd(d, 0, data); err != nil {
			b.Fatal(err)
		}
	}
}
Пример #4
0
func TestVerify(t *testing.T) {
	if testing.Short() {
		t.SkipNow()
	}
	d, err := eeprom.First()
	if err != nil {
		t.Fatal(err)
	}
	defer d.Close()

	tests := []struct {
		name string
		cmd  dataCommand
	}{
		{"WriteBytes", (*eeprom.Device).WriteBytes},
		{"WritePages", (*eeprom.Device).WritePages},
	}
	for _, test := range tests {
		t.Log("verifying", test.name)
		if err := d.Erase(); err != nil {
			t.Fatal(err)
		}
		wbuf := make([]byte, eeprom.MaxBytes)
		for i := range wbuf {
			wbuf[i] = byte(i)
		}
		if err := test.cmd(d, 0, wbuf); err != nil {
			t.Fatal(err)
		}
		rbuf := make([]byte, eeprom.MaxBytes)
		if err := d.Read(0, rbuf); err != nil {
			t.Fatal(err)
		}
		for i, b := range wbuf {
			if rbuf[i] != b {
				t.Fatalf("rbuf[%d]: expected %#x; got %#x", i, b, rbuf[i])
			}
		}
	}
}