-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.asm
More file actions
157 lines (147 loc) · 2.55 KB
/
tests.asm
File metadata and controls
157 lines (147 loc) · 2.55 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
test@title:
push rdi
mov rdi, test_title
call print
pop rdi
call print_int
ret
test@success:
push rdi
mov rdi, test_success
call println
pop rdi
ret
test@fail:
push rdi
mov rdi, test_fail
call println
pop rdi
ret
test@execute:
call test@alloc
call test@dealloc
call test@realloc
call test@alloc_max_size
call test@remove_page
ret
; () -> (rdi:addr)
test@alloc:
push rsi
push rdx
mov rdi, 0
call test@title
mov rdi, 20
call mem@alloc ; This should return an allocation of 32 bytes in size
push rdi
; Checking if the correct size was allocated
cmp dword [rdi], 32
jne .failed
; Checking if it was mapped correctly
mov rsi, 32
call mem@is_free_space_at
cmp rdi, 1
je .failed
mov rdi, [rsp]
add rdi, 32
call mem@is_free_space_at
cmp rdi, 1
jne .failed
call test@success
jmp .end
.failed:
call test@fail
.end:
pop rdi
pop rdx
pop rsi
ret
; (rdi:addr)
test@dealloc:
push rsi
push rdi
mov rdi, 1
call test@title
pop rdi
; The allocation of the previous test is used
call mem@dealloc
; Checking if the space is free at the location
mov rsi, 32
call mem@is_free_space_at
cmp rdi, 1
jne .failed
call test@success
jmp .end
.failed:
call test@fail
.end:
pop rsi
ret
test@realloc:
push rdi
push rsi
mov rdi, 2
call test@title
mov rdi, 20
call mem@alloc
mov rsi, 248
call mem@realloc
; Checking if the correct size was allocated
cmp dword [rdi], 256
jne .failed
; Checking if it was mapped correctly
push rdi
mov rsi, 256
call mem@is_free_space_at
cmp rdi, 1
je .failed
pop rdi
add rdi, 256
call mem@is_free_space_at
cmp rdi, 1
jne .failed
call test@success
jmp .end
.failed:
call test@fail
.end:
pop rsi
pop rdi
ret
test@alloc_max_size:
push rsi
mov rdi, 3
call test@title
mov rdi, 4060
call mem@alloc
push rdi
call mem@get_page_count
cmp rdi, 2
jne .failed
mov rdi, [rsp]
mov rsi, 4060
call mem@is_free_space_at
cmp rdi, 1
je .failed
call test@success
jmp .end
.failed:
call test@fail
.end:
pop rdi
pop rsi
ret
test@remove_page:
push rdi
mov rdi, 4
call test@title
pop rdi
call mem@dealloc
call mem@get_page_count
cmp rdi, 1
jne .failed
call test@success
jmp .end
.failed:
call test@fail
.end:
ret