-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADTF_test.s
171 lines (124 loc) · 2.74 KB
/
ADTF_test.s
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
.include "ADTF_Macros.s"
.file "ADTF_test.s"
.text
.global _main
_main:
frame
call test_str_len
call test_str_equal
call test_mem_cpy
call test_str_cpy
call test_str_cat
movl $0, %eax
leave
ret
test_str_len:
frame
call_1 str_len, $str_1
call_3 assert_number_equal, %eax, $3, $str_ass_2
call_1 str_len, $str_4
call_3 assert_number_equal, %eax, $6, $str_ass_3
println $test_str_len_passed
leave
ret
test_str_equal:
frame
call_2 str_equals, $str_1, $str_2
call_2 assert_true, %eax, $str_eq_1
call_2 str_equals, $str_1, $str_3
call_2 assert_false, %eax, $str_eq_2
println $test_str_equal_passed
leave
ret
test_mem_cpy:
frame
pushl $0xDEADBEEF
subl $4, %esp
leal 4(%esp), %eax
leal (%esp), %ebx
call_3 mem_cpy, %eax, %ebx, $4
movl 4(%esp), %eax
movl (%esp), %ebx
call_3 assert_number_equal, %eax, %ebx, $str_ass_1
println $test_mem_cpy_passed
leave
ret
test_str_cpy:
frame
call_2 str_cpy, $str_1, $buffer
call_2 str_equals, $str_1, $buffer
call_2 assert_true, %eax, $str_eq_1
println $test_str_cpy_passed
leave
ret
test_str_cat:
frame
call_3 str_cat, $str_1, $str_3, $buffer
call_2 str_equals, $str_5, $buffer
call_2 assert_true, %eax, $str_eq_1
println $test_str_cat_passed
leave
ret
assert_false:
frame
#arg0 = boolean
#args1 = msg
pushl 8(%ebp)
negl (%esp)
call_2 assert_true, (%esp), 12(%ebp)
leave
ret
assert_true:
frame
#arg0 = boolean
#args1 = msg
cmpl $0, 8(%ebp)
je LT0_fail
jmp LT0_succes
LT0_fail:
call_2 print_assert_and_exit, 12(%ebp), $1
LT0_succes:
leave
ret
assert_number_equal:
frame
#arg0 = number 1
#arg1 = number 2
#arg2 = msg
movl 8(%ebp), %eax
cmpl %eax, 12(%ebp)
jne LT1_fail
jmp LT1_succes
LT1_fail:
call_2 print_assert_and_exit, 16(%ebp), $2
LT1_succes:
leave
ret
print_assert_and_exit:
frame
#arg0 = message
#arg1 = exit code
print $assert_err
print 8(%ebp)
call_1 exit, 12(%ebp)
leave
ret
.data
buffer: .skip 50
test_string: .string "Test"
test_str_len_passed: .string "test_str_len passed!"
test_str_equal_passed: .string "test_str_equal passed!"
test_mem_cpy_passed: .string "test_mem_cpy passed!"
test_str_cpy_passed: .string "test_str_cpy passed!"
test_str_cat_passed: .string "test_str_cat passed!"
assert_err: .string "Assertiong error on: "
str_eq_1: .string "Bla == Bla"
str_eq_2: .string "Bla != Blo"
str_ass_1: .string "0xDEADBEEF == 0xDEADBEEF"
str_ass_2: .string "len(Bla) == 3"
str_ass_3: .string "len(Blaaaa) == 6"
str_1: .string "Bla"
str_2: .string "Bla"
str_3: .string "Blo"
str_4: .string "Blaaaa"
str_5: .string "BlaBlo"