blob: 85438bda76af4f560fa98f99ad5dccdfc5881473 (
plain)
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
|
package openfiletable
import (
"sync"
"testing"
)
func TestTranslate(t *testing.T) {
const baseDev = 12345
m := NewInumMap(baseDev)
q := QIno{Dev: baseDev, Ino: 1}
out := m.Translate(q)
if out != 1 {
t.Errorf("expected 1, got %d", out)
}
q.Ino = inumTranslateBase
out = m.Translate(q)
if out < inumTranslateBase {
t.Errorf("got %d", out)
}
out2 := m.Translate(q)
if out2 != out {
t.Errorf("unstable mapping: %d %d", out2, out)
}
}
func TestTranslateStress(t *testing.T) {
const baseDev = 12345
m := NewInumMap(baseDev)
var wg sync.WaitGroup
wg.Add(4)
go func() {
q := QIno{Dev: baseDev}
for i := uint64(1); i <= 10000; i++ {
q.Ino = i
out := m.Translate(q)
if out != i {
t.Fail()
}
}
wg.Done()
}()
go func() {
q := QIno{Dev: baseDev}
for i := uint64(1); i <= 10000; i++ {
q.Ino = inumTranslateBase + i
out := m.Translate(q)
if out < inumTranslateBase {
t.Fail()
}
}
wg.Done()
}()
go func() {
q := QIno{Dev: 9999999}
for i := uint64(1); i <= 10000; i++ {
q.Ino = i
out := m.Translate(q)
if out < inumTranslateBase {
t.Fail()
}
}
wg.Done()
}()
go func() {
q := QIno{Dev: 4444444}
for i := uint64(1); i <= 10000; i++ {
q.Ino = i
out := m.Translate(q)
if out < inumTranslateBase {
t.Fail()
}
}
wg.Done()
}()
wg.Wait()
if m.Count() != 30000 {
t.Fail()
}
}
|