diff options
author | Jakob Unterwurzacher | 2019-11-16 21:35:26 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2019-11-16 21:35:26 +0100 |
commit | e5d5ab397384001566d573a13a142ed1bc2bc2aa (patch) | |
tree | d9b268f51a5cb33d8876a35d12b6c5c8ac9e17a5 /internal/openfiletable/inummap_test.go | |
parent | 31ff557f85cca54b935231668d382cfc0e61751a (diff) |
openfiletable: add inummap
Generates unique inode numbers for files on different
devices.
https://github.com/rfjakob/gocryptfs/issues/435
Diffstat (limited to 'internal/openfiletable/inummap_test.go')
-rw-r--r-- | internal/openfiletable/inummap_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/internal/openfiletable/inummap_test.go b/internal/openfiletable/inummap_test.go new file mode 100644 index 0000000..85438bd --- /dev/null +++ b/internal/openfiletable/inummap_test.go @@ -0,0 +1,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() + } +} |