-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.c
403 lines (365 loc) · 9.07 KB
/
tests.c
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#include "tests.h"
#include "x86_desc.h"
#include "lib.h"
#include "system_call_handler.h"
#include "RTC.h"
#include "file_system.h"
#define PASS 1
#define FAIL 0
/* format these macros as you see fit */
#define TEST_HEADER \
printf("[TEST %s] Running %s at %s:%d\n", __FUNCTION__, __FUNCTION__, __FILE__, __LINE__)
#define TEST_OUTPUT(name, result) \
printf("[TEST %s] Result = %s\n", name, (result) ? "PASS" : "FAIL");
static inline void assertion_failure(){
/* Use exception #15 for assertions, otherwise
reserved by Intel */
asm volatile("int $15");
}
/* Checkpoint 1 tests */
/* IDT Test - Example
*
* Asserts that first 10 IDT entries are not NULL
* Inputs: None
* Outputs: PASS/FAIL
* Side Effects: None
* Coverage: Load IDT, IDT definition
* Files: x86_desc.h/S
*/
int idt_test(){
TEST_HEADER;
int i;
int result = PASS;
for (i = 0; i < 10; ++i){
if ((idt[i].offset_15_00 == NULL) &&
(idt[i].offset_31_16 == NULL)){
assertion_failure();
result = FAIL;
}
}
return result;
}
/* exception_test
* divide by zero to test the first entry of IDT
* Inputs: None
* Outputs: None
* Side Effects: send divide by zero exception and halt program
*/
void exception_test() {
int k;
int a = 0;
k = k/a;
}
/* page_test_0
* test the first in the page virtual memory by dereferencing it
* Inputs: None
* Outputs: None
* Side Effects: page fault reported, printed, halt program
*/
void page_test_0() {
int* temp;
temp = 0;
int a;
a = (int)*temp;
}
/* page_test_C0000
* test the address in the page virtual memory below video memory by dereferencing it
* Inputs: None
* Outputs: None
* Side Effects: page fault reported, printed, halt program
*/
void page_test_C0000() {
int* temp;
temp = (int *)0xC0000;
int a;
a = (int)*temp;
}
/* page_test_500000
* test the address in the page virtual memory in the kernel space by dereferencing it
* Inputs: None
* Outputs: None
* Side Effects: no exception happens
*/
void page_test_kernel() {
int* temp;
temp = (int *)0x500000;
int a;
a = (int)*temp;
}
/* page_test_900000
* test the address in the page virtual memory out of kernel space range by dereferencing it
* Inputs: None
* Outputs: None
* Side Effects: page fault reported, printed, halt program
*/
void page_test_outkernel() {
int* temp;
temp = (int *)0x900000;
int a;
a = (int)*temp;
}
/* Checkpoint 2 tests */
/* RTC_open_test
* Discription: test whether RTC_open works fine.
* Inputs: None
* Outputs: '1' are put on the screen periodically.
* Side Effects: '1' is put on the screen in a specific frequency if RTC_open works.
*/
void RTC_open_test(){
RTC_open(0);
while(1){
RTC_read(0,0,0);
putc('1');
}
}
/* RTC_write_test
* Discription: test whether RTC_write works fine.
* Inputs: freq: the freq that we want to set to the RTC.
* Outputs: '1' are put on the screen periodically.
* Side Effects: none.
*/
void RTC_write_test(int freq){
RTC_write(0,(int*)&freq,4);
while(1){
RTC_read(0,0,0);
putc('1');
}
}
/* RTC_write_test
* Discription: test whether RTC_close works fine.
* Inputs: none.
* Outputs: print "rtc close test success" if passes test.
* Side Effects: none.
*/
void RTC_close_test(){
if(!RTC_close(0))
printf("rtc close test success\n");
}
/* terminal_open_test
* Discription: test whether terminal_open works fine.
* Inputs: none.
* Outputs: print "terminal open test success" if passes test.
* Side Effects: none.
*/
void terminal_open_test(){
if(!terminal_open(0))
printf("terminal open test success\n");
}
/* terminal_close_test
* Discription: test whether terminal_close works fine.
* Inputs: none.
* Outputs: print "terminal close test success" if passes test.
* Side Effects: none.
*/
void terminal_close_test(){
if(!terminal_close(0))
printf("terminal close test success\n");
}
/* terminal_read_write_test
* Discription: test whether terminal_read and terminal_write work fine.
* Inputs: none.
* Outputs: print what we input on the keyboard to terminal twice.
* Side Effects: none.
*/
void terminal_read_write_test() {
uint8_t buf[130];
terminal_read(0, buf, 130);
terminal_write(0, buf, 130);
}
/* file_read_test_frame1
* Discription: test whether file_read works fine.
* Inputs: none.
* Outputs: print the file content to terminal if read succeessfully.
* Otherwise, print "open failed".
* Side Effects: none.
*/
void file_read_test_frame1() {
int8_t* filename;
int i = 0;
filename = "frame1.txt";
if(file_open((uint8_t*)filename)==-1){
printf("open failed\n");
return;}
uint8_t buf[200];
int len;
len = file_read(0,buf,200);
for(i = 0; i<len ; i ++)
putc(buf[i]);
}
/* file_read_test_frame0
* Discription: test whether file_read works fine.
* Inputs: none.
* Outputs: print the file content to terminal if read succeessfully.
* Otherwise, print "open failed".
* Side Effects: none.
*/
void file_read_test_frame0() {
int8_t* filename;
int i = 0;
filename = "frame0.txt";
if(file_open((uint8_t*)filename)==-1){
printf("open failed\n");
return;}
uint8_t buf[200];
int len;
len = file_read(0,buf,200);
for(i = 0; i<len ; i ++)
putc(buf[i]);
}
/* file_read_test_large
* Discription: test whether file_read works fine.
* Inputs: none.
* Outputs: print the file content to terminal if read succeessfully.
* Otherwise, print "open failed".
* Side Effects: none.
*/
void file_read_test_large() {
int8_t* filename;
int i = 0;
filename = "verylargetextwithverylongname.txt";
if(file_open((uint8_t*)filename)==-1){
printf("open failed\n");
return;}
uint8_t buf[4096];
int len;
len = file_read(0,buf,4096);
for(i = 0; i<len ; i ++)
putc(buf[i]);
}
/* file_read_test_execute
* Discription: test whether file_read works fine.
* Inputs: none.
* Outputs: print the file content to terminal if read succeessfully.
* Otherwise, print "open failed".
* Side Effects: none.
*/
void file_read_test_execute() {
int8_t* filename;
int i = 0;
filename = "cat";
if(file_open((uint8_t*)filename)==-1){
printf("open failed\n");
return;}
uint8_t buf[5445];
int len;
len = file_read(0,buf,5445);
for(i = 0; i<len ; i ++)
putc(buf[i]);
}
/* file_close_test
* Discription: test whether file_close works fine.
* Inputs: none.
* Outputs: print "file close test success" if works succeessfully.
* Side Effects: none.
*/
void file_close_test(){
if(!file_close(0))
printf("file close test success\n");
}
/* file_write_test
* Discription: test whether file_write works fine.
* Inputs: none.
* Outputs: print "file write test success" if works succeessfully.
* Side Effects: none.
*/
void file_write_test(){
if(file_write(0,(void*)0,0)==-1)
printf("file write test success\n");
}
/* dir_write_test
* Discription: test whether dir_write works fine.
* Inputs: none.
* Outputs: print "dir write test success" if works succeessfully.
* Side Effects: none.
*/
void dir_write_test(){
if(dir_write(0,(void*)0,0)==-1)
printf("dir write test success\n");
}
/* dir_read_test
* Discription: test whether dir_read works fine.
* Inputs: none.
* Outputs: print directory data to terminal if works succeessfully.
* Side Effects: none.
*/
void dir_read_test() {
uint8_t buf[32];
int len;
while ((len=dir_read(0, buf, 32)) != -1) {
terminal_write(0, buf, len);
putc('\n');
}
}
/* dir_open_test
* Discription: test whether dir_open works fine.
* Inputs: none.
* Outputs: print "dir open test success" to terminal if works succeessfully.
* Side Effects: none.
*/
void dir_open_test(){
int8_t* a;
a= ".";
if(dir_open((uint8_t*)a)!=-1)
printf("dir open test success\n");
}
/* dir_close_test
* Discription: test whether dir_close works fine.
* Inputs: none.
* Outputs: print "dir close test success" to terminal if works succeessfully.
* Side Effects: none.
*/
void dir_close_test(){
if(!dir_close(0))
printf("dir close test success\n");
}
/* Checkpoint 3 tests */
/* Checkpoint 4 tests */
/* Checkpoint 5 tests */
/* Test suite entry point */
void launch_tests(){
TEST_OUTPUT("idt_test", idt_test());
//RTC TEST
//RTC_open_test();
//RTC_write_test(256);
// RTC_close_test();
//terminal TEST
//terminal_open_test();
//terminal_close_test();
// printf("length: %d\n", terminal_write(0, "12345", 5));
//printf("length: %d\n", terminal_write(0, "12345", -1));
//printf("length: %d\n", terminal_write(0, "12345", 4));
// printf("length: %d\n", terminal_write(0, "12345", 6));
// terminal_read_write_test();
//file_system TEST
// dir_open_test();
// dir_close_test();
// dir_write_test();
// file_close_test();
// file_write_test();
//syscall TEST
/*
asm(
"PUSHL %EBX "
"MOVL $number,%EAX "
"MOVL 8(%ESP),%EBX "
"MOVL 12(%ESP),%ECX "
"MOVL 16(%ESP),%EDX "
"INT $0x80 "
"POPL %EBX "
"RET"
uint8_t buf[3];
if(-1==read(0,NULL,2))
printf("read invalid buf test: PASS\n");
if(-1==read(8,buf,2))
printf("read invalid fd(out of bound) test: PASS\n");
if(-1==read(5,buf,2))
printf("read invalid fd(not open) test: PASS\n");
if(4==read(0,buf,4))
printf("read overflow test: PASS\n");
if(2==read(0,buf,2))
printf("read overflow test1: PASS\n");*/
// file_read_test_frame0();
//file_read_test_frame1();
//file_read_test_large();
//file_read_test_execute();
}