forked from google/periph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagemap_test.go
85 lines (78 loc) · 1.83 KB
/
pagemap_test.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
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
82
83
84
85
// Copyright 2017 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package pmem
import (
"os"
"testing"
)
func TestReadPageMap_fail(t *testing.T) {
defer reset()
if u, err := ReadPageMap(8192); u != 0 || err == nil {
t.Fatal("can't open file")
}
}
func TestReadPageMap(t *testing.T) {
defer reset()
openFile = func(path string, flag int) (fileIO, error) {
if path != "/proc/self/pagemap" {
t.Fatal(path)
}
if flag != os.O_RDONLY|os.O_SYNC {
t.Fatal(flag)
}
return &simpleFile{data: []byte{1, 2, 3, 4, 5, 6, 7, 8}}, nil
}
u, err := readPageMapLinux(8192)
if err != nil {
t.Fatal(err)
}
if u != 0x807060504030201 {
t.Fatal(u)
}
}
func TestReadPageMap_short(t *testing.T) {
defer reset()
openFile = func(path string, flag int) (fileIO, error) {
if path != "/proc/self/pagemap" {
t.Fatal(path)
}
if flag != os.O_RDONLY|os.O_SYNC {
t.Fatal(flag)
}
return &simpleFile{data: []byte{1, 2}}, nil
}
if u, err := readPageMapLinux(8192); u != 0 || err == nil {
t.Fatal("didn't read 8 bytes")
}
}
func TestReadPageMap_read_fail(t *testing.T) {
defer reset()
openFile = func(path string, flag int) (fileIO, error) {
if path != "/proc/self/pagemap" {
t.Fatal(path)
}
if flag != os.O_RDONLY|os.O_SYNC {
t.Fatal(flag)
}
return &simpleFile{}, nil
}
if u, err := readPageMapLinux(8192); u != 0 || err == nil {
t.Fatal("Read() failed")
}
}
func TestReadPageMap_seek_fail(t *testing.T) {
defer reset()
openFile = func(path string, flag int) (fileIO, error) {
if path != "/proc/self/pagemap" {
t.Fatal(path)
}
if flag != os.O_RDONLY|os.O_SYNC {
t.Fatal(flag)
}
return &failFile{}, nil
}
if u, err := readPageMapLinux(8192); u != 0 || err == nil {
t.Fatal("Seek() failed")
}
}