Debian Codegraph @

storage/probe_test.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // Copyright (c) 2011 CZ.NIC z.s.p.o. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // blame: jnml, labs.nic.cz
6
7 package storage // import "modernc.org/fileutil/storage"
8
9 import (
10 "os"
11 "testing"
12 )
13
14 func (p *Probe) assert(t *testing.T, msg int, opsRd, opsWr, bytesRd, bytesWr, sectorsRd, sectorsWr int64) {
15 if n := p.OpsRd; n != opsRd {
16 t.Fatal(msg, n, opsRd)
17 }
18
19 if n := p.OpsWr; n != opsWr {
20 t.Fatal(msg+1, n, opsWr)
21 }
22
23 if n := p.BytesRd; n != bytesRd {
24 t.Fatal(msg+2, n, bytesRd)
25 }
26
27 if n := p.BytesWr; n != bytesWr {
28 t.Fatal(msg+3, n, bytesWr)
29 }
30
31 if n := p.SectorsRd; n != sectorsRd {
32 t.Fatal(msg+4, n, sectorsRd)
33 }
34
35 if n := p.SectorsWr; n != sectorsWr {
36 t.Fatal(msg+5, n, sectorsWr)
37 }
38 }
39
40 func TestProbe(t *testing.T) {
41 return //TODO disabled due to atomic.AddInt64 failing on W32
42 const fn = "test.tmp"
43
44 store, err := NewFile(fn, os.O_CREATE|os.O_RDWR|os.O_CREATE, 0666)
45 if err != nil {
46 t.Fatal(10, err)
47 }
48
49 defer func() {
50 ec := store.Close()
51 er := os.Remove(fn)
52 if ec != nil {
53 t.Fatal(10000, ec)
54 }
55 if er != nil {
56 t.Fatal(10001, er)
57 }
58 }()
59
60 probe := NewProbe(store, nil)
61 if n, err := probe.WriteAt([]byte{1}, 0); n != 1 {
62 t.Fatal(20, err)
63 }
64
65 probe.assert(t, 30, 0, 1, 0, 1, 0, 1)
66 b := []byte{0}
67 if n, err := probe.ReadAt(b, 0); n != 1 {
68 t.Fatal(40, err)
69 }
70
71 if n := b[0]; n != 1 {
72 t.Fatal(50, n, 1)
73 }
74
75 probe.assert(t, 60, 1, 1, 1, 1, 1, 1)
76 if n, err := probe.WriteAt([]byte{2, 3}, 510); n != 2 {
77 t.Fatal(70, err)
78 }
79
80 probe.assert(t, 80, 1, 2, 1, 3, 1, 2)
81 if n, err := probe.WriteAt([]byte{2, 3}, 511); n != 2 {
82 t.Fatal(90, err)
83 }
84
85 probe.assert(t, 100, 1, 3, 1, 5, 1, 4)
86 }