13 char *echoargv
[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
16 // simple file system tests
23 printf(stdout
, "open test\n");
26 printf(stdout
, "open echo failed!\n");
30 fd
= open("doesnotexist", 0);
32 printf(stdout
, "open doesnotexist succeeded!\n");
35 printf(stdout
, "open test ok\n");
44 printf(stdout
, "small file test\n");
45 fd
= open("small", O_CREATE
|O_RDWR
);
47 printf(stdout
, "creat small succeeded; ok\n");
49 printf(stdout
, "error: creat small failed!\n");
52 for(i
= 0; i
< 100; i
++){
53 if(write(fd
, "aaaaaaaaaa", 10) != 10){
54 printf(stdout
, "error: write aa %d new file failed\n", i
);
57 if(write(fd
, "bbbbbbbbbb", 10) != 10){
58 printf(stdout
, "error: write bb %d new file failed\n", i
);
62 printf(stdout
, "writes ok\n");
64 fd
= open("small", O_RDONLY
);
66 printf(stdout
, "open small succeeded ok\n");
68 printf(stdout
, "error: open small failed!\n");
71 i
= read(fd
, buf
, 2000);
73 printf(stdout
, "read succeeded ok\n");
75 printf(stdout
, "read failed\n");
80 if(unlink("small") < 0){
81 printf(stdout
, "unlink small failed\n");
84 printf(stdout
, "small file test ok\n");
92 printf(stdout
, "big files test\n");
94 fd
= open("big", O_CREATE
|O_RDWR
);
96 printf(stdout
, "error: creat big failed!\n");
100 for(i
= 0; i
< MAXFILE
; i
++){
102 if(write(fd
, buf
, 512) != 512){
103 printf(stdout
, "error: write big file failed\n", i
);
110 fd
= open("big", O_RDONLY
);
112 printf(stdout
, "error: open big failed!\n");
118 i
= read(fd
, buf
, 512);
120 if(n
== MAXFILE
- 1){
121 printf(stdout
, "read only %d blocks from big", n
);
126 printf(stdout
, "read failed %d\n", i
);
129 if(((int*)buf
)[0] != n
){
130 printf(stdout
, "read content of block %d is %d\n",
137 if(unlink("big") < 0){
138 printf(stdout
, "unlink big failed\n");
141 printf(stdout
, "big files ok\n");
149 printf(stdout
, "many creates, followed by unlink test\n");
153 for(i
= 0; i
< 52; i
++){
155 fd
= open(name
, O_CREATE
|O_RDWR
);
160 for(i
= 0; i
< 52; i
++){
164 printf(stdout
, "many creates, followed by unlink; ok\n");
169 printf(stdout
, "mkdir test\n");
171 if(mkdir("dir0") < 0){
172 printf(stdout
, "mkdir failed\n");
176 if(chdir("dir0") < 0){
177 printf(stdout
, "chdir dir0 failed\n");
182 printf(stdout
, "chdir .. failed\n");
186 if(unlink("dir0") < 0){
187 printf(stdout
, "unlink dir0 failed\n");
190 printf(stdout
, "mkdir test\n");
196 printf(stdout
, "exec test\n");
197 if(exec("echo", echoargv
) < 0){
198 printf(stdout
, "exec echo failed\n");
203 // simple fork and pipe read/write
209 int seq
, i
, n
, cc
, total
;
212 printf(1, "pipe() failed\n");
219 for(n
= 0; n
< 5; n
++){
220 for(i
= 0; i
< 1033; i
++)
222 if(write(fds
[1], buf
, 1033) != 1033){
223 printf(1, "pipe1 oops 1\n");
232 while((n
= read(fds
[0], buf
, cc
)) > 0){
233 for(i
= 0; i
< n
; i
++){
234 if((buf
[i
] & 0xff) != (seq
++ & 0xff)){
235 printf(1, "pipe1 oops 2\n");
244 if(total
!= 5 * 1033){
245 printf(1, "pipe1 oops 3 total %d\n", total
);
251 printf(1, "fork() failed\n");
254 printf(1, "pipe1 ok\n");
257 // meant to be run w/ at most two CPUs
261 int pid1
, pid2
, pid3
;
264 printf(1, "preempt: ");
279 if(write(pfds
[1], "x", 1) != 1)
280 printf(1, "preempt write error");
287 if(read(pfds
[0], buf
, sizeof(buf
)) != 1){
288 printf(1, "preempt read error");
292 printf(1, "kill... ");
296 printf(1, "wait... ");
300 printf(1, "preempt ok\n");
303 // try to find any races between exit and wait
309 for(i
= 0; i
< 100; i
++){
312 printf(1, "fork failed\n");
317 printf(1, "wait wrong pid\n");
324 printf(1, "exitwait ok\n");
333 printf(1, "mem test\n");
335 if((pid
= fork()) == 0){
337 while((m2
= malloc(10001)) != 0){
346 m1
= malloc(1024*20);
348 printf(1, "couldn't allocate mem?!!\n");
353 printf(1, "mem ok\n");
360 // More file system tests
362 // two processes write to the same file descriptor
363 // is the offset shared? does inode locking work?
367 int fd
, pid
, i
, n
, nc
, np
;
370 printf(1, "sharedfd test\n");
373 fd
= open("sharedfd", O_CREATE
|O_RDWR
);
375 printf(1, "fstests: cannot open sharedfd for writing");
379 memset(buf
, pid
==0?'c':'p', sizeof(buf
));
380 for(i
= 0; i
< 1000; i
++){
381 if(write(fd
, buf
, sizeof(buf
)) != sizeof(buf
)){
382 printf(1, "fstests: write sharedfd failed\n");
391 fd
= open("sharedfd", 0);
393 printf(1, "fstests: cannot open sharedfd for reading\n");
397 while((n
= read(fd
, buf
, sizeof(buf
))) > 0){
398 for(i
= 0; i
< sizeof(buf
); i
++){
407 if(nc
== 10000 && np
== 10000){
408 printf(1, "sharedfd ok\n");
410 printf(1, "sharedfd oops %d %d\n", nc
, np
);
415 // two processes write two different files at the same
416 // time, to test block allocation.
420 int fd
, pid
, i
, j
, n
, total
;
423 printf(1, "twofiles test\n");
430 printf(1, "fork failed\n");
434 fname
= pid
? "f1" : "f2";
435 fd
= open(fname
, O_CREATE
| O_RDWR
);
437 printf(1, "create failed\n");
441 memset(buf
, pid
?'p':'c', 512);
442 for(i
= 0; i
< 12; i
++){
443 if((n
= write(fd
, buf
, 500)) != 500){
444 printf(1, "write failed %d\n", n
);
454 for(i
= 0; i
< 2; i
++){
455 fd
= open(i
?"f1":"f2", 0);
457 while((n
= read(fd
, buf
, sizeof(buf
))) > 0){
458 for(j
= 0; j
< n
; j
++){
459 if(buf
[j
] != (i
?'p':'c')){
460 printf(1, "wrong char\n");
468 printf(1, "wrong length %d\n", total
);
476 printf(1, "twofiles ok\n");
479 // two processes create and delete different files in same directory
487 printf(1, "createdelete test\n");
490 printf(1, "fork failed\n");
494 name
[0] = pid
? 'p' : 'c';
496 for(i
= 0; i
< N
; i
++){
498 fd
= open(name
, O_CREATE
| O_RDWR
);
500 printf(1, "create failed\n");
504 if(i
> 0 && (i
% 2 ) == 0){
505 name
[1] = '0' + (i
/ 2);
506 if(unlink(name
) < 0){
507 printf(1, "unlink failed\n");
518 for(i
= 0; i
< N
; i
++){
522 if((i
== 0 || i
>= N
/2) && fd
< 0){
523 printf(1, "oops createdelete %s didn't exist\n", name
);
525 } else if((i
>= 1 && i
< N
/2) && fd
>= 0){
526 printf(1, "oops createdelete %s did exist\n", name
);
535 if((i
== 0 || i
>= N
/2) && fd
< 0){
536 printf(1, "oops createdelete %s didn't exist\n", name
);
538 } else if((i
>= 1 && i
< N
/2) && fd
>= 0){
539 printf(1, "oops createdelete %s did exist\n", name
);
546 for(i
= 0; i
< N
; i
++){
554 printf(1, "createdelete ok\n");
557 // can I unlink a file and still read it?
563 printf(1, "unlinkread test\n");
564 fd
= open("unlinkread", O_CREATE
| O_RDWR
);
566 printf(1, "create unlinkread failed\n");
569 write(fd
, "hello", 5);
572 fd
= open("unlinkread", O_RDWR
);
574 printf(1, "open unlinkread failed\n");
577 if(unlink("unlinkread") != 0){
578 printf(1, "unlink unlinkread failed\n");
582 fd1
= open("unlinkread", O_CREATE
| O_RDWR
);
583 write(fd1
, "yyy", 3);
586 if(read(fd
, buf
, sizeof(buf
)) != 5){
587 printf(1, "unlinkread read failed");
591 printf(1, "unlinkread wrong data\n");
594 if(write(fd
, buf
, 10) != 10){
595 printf(1, "unlinkread write failed\n");
599 unlink("unlinkread");
600 printf(1, "unlinkread ok\n");
608 printf(1, "linktest\n");
613 fd
= open("lf1", O_CREATE
|O_RDWR
);
615 printf(1, "create lf1 failed\n");
618 if(write(fd
, "hello", 5) != 5){
619 printf(1, "write lf1 failed\n");
624 if(link("lf1", "lf2") < 0){
625 printf(1, "link lf1 lf2 failed\n");
630 if(open("lf1", 0) >= 0){
631 printf(1, "unlinked lf1 but it is still there!\n");
637 printf(1, "open lf2 failed\n");
640 if(read(fd
, buf
, sizeof(buf
)) != 5){
641 printf(1, "read lf2 failed\n");
646 if(link("lf2", "lf2") >= 0){
647 printf(1, "link lf2 lf2 succeeded! oops\n");
652 if(link("lf2", "lf1") >= 0){
653 printf(1, "link non-existant succeeded! oops\n");
657 if(link(".", "lf1") >= 0){
658 printf(1, "link . lf1 succeeded! oops\n");
662 printf(1, "linktest ok\n");
665 // test concurrent create/link/unlink of the same file
677 printf(1, "concreate test\n");
680 for(i
= 0; i
< 40; i
++){
684 if(pid
&& (i
% 3) == 1){
686 } else if(pid
== 0 && (i
% 5) == 1){
689 fd
= open(file
, O_CREATE
| O_RDWR
);
691 printf(1, "concreate create %s failed\n", file
);
702 memset(fa
, 0, sizeof(fa
));
705 while(read(fd
, &de
, sizeof(de
)) > 0){
708 if(de
.name
[0] == 'C' && de
.name
[2] == '\0'){
709 i
= de
.name
[1] - '0';
710 if(i
< 0 || i
>= sizeof(fa
)){
711 printf(1, "concreate weird file %s\n", de
.name
);
715 printf(1, "concreate duplicate file %s\n", de
.name
);
725 printf(1, "concreate not enough files in directory listing\n");
729 for(i
= 0; i
< 40; i
++){
733 printf(1, "fork failed\n");
736 if(((i
% 3) == 0 && pid
== 0) ||
737 ((i
% 3) == 1 && pid
!= 0)){
738 close(open(file
, 0));
739 close(open(file
, 0));
740 close(open(file
, 0));
741 close(open(file
, 0));
754 printf(1, "concreate ok\n");
757 // another concurrent link/unlink/create test,
758 // to look for deadlocks.
764 printf(1, "linkunlink test\n");
769 printf(1, "fork failed\n");
773 unsigned int x
= (pid
? 1 : 97);
774 for(i
= 0; i
< 100; i
++){
775 x
= x
* 1103515245 + 12345;
777 close(open("x", O_RDWR
| O_CREATE
));
778 } else if((x
% 3) == 1){
790 printf(1, "linkunlink ok\n");
793 // directory that uses indirect blocks
800 printf(1, "bigdir test\n");
803 fd
= open("bd", O_CREATE
);
805 printf(1, "bigdir create failed\n");
810 for(i
= 0; i
< 500; i
++){
812 name
[1] = '0' + (i
/ 64);
813 name
[2] = '0' + (i
% 64);
815 if(link("bd", name
) != 0){
816 printf(1, "bigdir link failed\n");
822 for(i
= 0; i
< 500; i
++){
824 name
[1] = '0' + (i
/ 64);
825 name
[2] = '0' + (i
% 64);
827 if(unlink(name
) != 0){
828 printf(1, "bigdir unlink failed");
833 printf(1, "bigdir ok\n");
841 printf(1, "subdir test\n");
844 if(mkdir("dd") != 0){
845 printf(1, "subdir mkdir dd failed\n");
849 fd
= open("dd/ff", O_CREATE
| O_RDWR
);
851 printf(1, "create dd/ff failed\n");
857 if(unlink("dd") >= 0){
858 printf(1, "unlink dd (non-empty dir) succeeded!\n");
862 if(mkdir("/dd/dd") != 0){
863 printf(1, "subdir mkdir dd/dd failed\n");
867 fd
= open("dd/dd/ff", O_CREATE
| O_RDWR
);
869 printf(1, "create dd/dd/ff failed\n");
875 fd
= open("dd/dd/../ff", 0);
877 printf(1, "open dd/dd/../ff failed\n");
880 cc
= read(fd
, buf
, sizeof(buf
));
881 if(cc
!= 2 || buf
[0] != 'f'){
882 printf(1, "dd/dd/../ff wrong content\n");
887 if(link("dd/dd/ff", "dd/dd/ffff") != 0){
888 printf(1, "link dd/dd/ff dd/dd/ffff failed\n");
892 if(unlink("dd/dd/ff") != 0){
893 printf(1, "unlink dd/dd/ff failed\n");
896 if(open("dd/dd/ff", O_RDONLY
) >= 0){
897 printf(1, "open (unlinked) dd/dd/ff succeeded\n");
901 if(chdir("dd") != 0){
902 printf(1, "chdir dd failed\n");
905 if(chdir("dd/../../dd") != 0){
906 printf(1, "chdir dd/../../dd failed\n");
909 if(chdir("dd/../../../dd") != 0){
910 printf(1, "chdir dd/../../dd failed\n");
913 if(chdir("./..") != 0){
914 printf(1, "chdir ./.. failed\n");
918 fd
= open("dd/dd/ffff", 0);
920 printf(1, "open dd/dd/ffff failed\n");
923 if(read(fd
, buf
, sizeof(buf
)) != 2){
924 printf(1, "read dd/dd/ffff wrong len\n");
929 if(open("dd/dd/ff", O_RDONLY
) >= 0){
930 printf(1, "open (unlinked) dd/dd/ff succeeded!\n");
934 if(open("dd/ff/ff", O_CREATE
|O_RDWR
) >= 0){
935 printf(1, "create dd/ff/ff succeeded!\n");
938 if(open("dd/xx/ff", O_CREATE
|O_RDWR
) >= 0){
939 printf(1, "create dd/xx/ff succeeded!\n");
942 if(open("dd", O_CREATE
) >= 0){
943 printf(1, "create dd succeeded!\n");
946 if(open("dd", O_RDWR
) >= 0){
947 printf(1, "open dd rdwr succeeded!\n");
950 if(open("dd", O_WRONLY
) >= 0){
951 printf(1, "open dd wronly succeeded!\n");
954 if(link("dd/ff/ff", "dd/dd/xx") == 0){
955 printf(1, "link dd/ff/ff dd/dd/xx succeeded!\n");
958 if(link("dd/xx/ff", "dd/dd/xx") == 0){
959 printf(1, "link dd/xx/ff dd/dd/xx succeeded!\n");
962 if(link("dd/ff", "dd/dd/ffff") == 0){
963 printf(1, "link dd/ff dd/dd/ffff succeeded!\n");
966 if(mkdir("dd/ff/ff") == 0){
967 printf(1, "mkdir dd/ff/ff succeeded!\n");
970 if(mkdir("dd/xx/ff") == 0){
971 printf(1, "mkdir dd/xx/ff succeeded!\n");
974 if(mkdir("dd/dd/ffff") == 0){
975 printf(1, "mkdir dd/dd/ffff succeeded!\n");
978 if(unlink("dd/xx/ff") == 0){
979 printf(1, "unlink dd/xx/ff succeeded!\n");
982 if(unlink("dd/ff/ff") == 0){
983 printf(1, "unlink dd/ff/ff succeeded!\n");
986 if(chdir("dd/ff") == 0){
987 printf(1, "chdir dd/ff succeeded!\n");
990 if(chdir("dd/xx") == 0){
991 printf(1, "chdir dd/xx succeeded!\n");
995 if(unlink("dd/dd/ffff") != 0){
996 printf(1, "unlink dd/dd/ff failed\n");
999 if(unlink("dd/ff") != 0){
1000 printf(1, "unlink dd/ff failed\n");
1003 if(unlink("dd") == 0){
1004 printf(1, "unlink non-empty dd succeeded!\n");
1007 if(unlink("dd/dd") < 0){
1008 printf(1, "unlink dd/dd failed\n");
1011 if(unlink("dd") < 0){
1012 printf(1, "unlink dd failed\n");
1016 printf(1, "subdir ok\n");
1019 // test writes that are larger than the log.
1025 printf(1, "bigwrite test\n");
1028 for(sz
= 499; sz
< 12*512; sz
+= 471){
1029 fd
= open("bigwrite", O_CREATE
| O_RDWR
);
1031 printf(1, "cannot create bigwrite\n");
1035 for(i
= 0; i
< 2; i
++){
1036 int cc
= write(fd
, buf
, sz
);
1038 printf(1, "write(%d) ret %d\n", sz
, cc
);
1046 printf(1, "bigwrite ok\n");
1052 int fd
, i
, total
, cc
;
1054 printf(1, "bigfile test\n");
1057 fd
= open("bigfile", O_CREATE
| O_RDWR
);
1059 printf(1, "cannot create bigfile");
1062 for(i
= 0; i
< 20; i
++){
1063 memset(buf
, i
, 600);
1064 if(write(fd
, buf
, 600) != 600){
1065 printf(1, "write bigfile failed\n");
1071 fd
= open("bigfile", 0);
1073 printf(1, "cannot open bigfile\n");
1078 cc
= read(fd
, buf
, 300);
1080 printf(1, "read bigfile failed\n");
1086 printf(1, "short read bigfile\n");
1089 if(buf
[0] != i
/2 || buf
[299] != i
/2){
1090 printf(1, "read bigfile wrong data\n");
1096 if(total
!= 20*600){
1097 printf(1, "read bigfile wrong total\n");
1102 printf(1, "bigfile test ok\n");
1111 printf(1, "fourteen test\n");
1113 if(mkdir("12345678901234") != 0){
1114 printf(1, "mkdir 12345678901234 failed\n");
1117 if(mkdir("12345678901234/123456789012345") != 0){
1118 printf(1, "mkdir 12345678901234/123456789012345 failed\n");
1121 fd
= open("123456789012345/123456789012345/123456789012345", O_CREATE
);
1123 printf(1, "create 123456789012345/123456789012345/123456789012345 failed\n");
1127 fd
= open("12345678901234/12345678901234/12345678901234", 0);
1129 printf(1, "open 12345678901234/12345678901234/12345678901234 failed\n");
1134 if(mkdir("12345678901234/12345678901234") == 0){
1135 printf(1, "mkdir 12345678901234/12345678901234 succeeded!\n");
1138 if(mkdir("123456789012345/12345678901234") == 0){
1139 printf(1, "mkdir 12345678901234/123456789012345 succeeded!\n");
1143 printf(1, "fourteen ok\n");
1149 printf(1, "rmdot test\n");
1150 if(mkdir("dots") != 0){
1151 printf(1, "mkdir dots failed\n");
1154 if(chdir("dots") != 0){
1155 printf(1, "chdir dots failed\n");
1158 if(unlink(".") == 0){
1159 printf(1, "rm . worked!\n");
1162 if(unlink("..") == 0){
1163 printf(1, "rm .. worked!\n");
1166 if(chdir("/") != 0){
1167 printf(1, "chdir / failed\n");
1170 if(unlink("dots/.") == 0){
1171 printf(1, "unlink dots/. worked!\n");
1174 if(unlink("dots/..") == 0){
1175 printf(1, "unlink dots/.. worked!\n");
1178 if(unlink("dots") != 0){
1179 printf(1, "unlink dots failed!\n");
1182 printf(1, "rmdot ok\n");
1190 printf(1, "dir vs file\n");
1192 fd
= open("dirfile", O_CREATE
);
1194 printf(1, "create dirfile failed\n");
1198 if(chdir("dirfile") == 0){
1199 printf(1, "chdir dirfile succeeded!\n");
1202 fd
= open("dirfile/xx", 0);
1204 printf(1, "create dirfile/xx succeeded!\n");
1207 fd
= open("dirfile/xx", O_CREATE
);
1209 printf(1, "create dirfile/xx succeeded!\n");
1212 if(mkdir("dirfile/xx") == 0){
1213 printf(1, "mkdir dirfile/xx succeeded!\n");
1216 if(unlink("dirfile/xx") == 0){
1217 printf(1, "unlink dirfile/xx succeeded!\n");
1220 if(link("README", "dirfile/xx") == 0){
1221 printf(1, "link to dirfile/xx succeeded!\n");
1224 if(unlink("dirfile") != 0){
1225 printf(1, "unlink dirfile failed!\n");
1229 fd
= open(".", O_RDWR
);
1231 printf(1, "open . for writing succeeded!\n");
1235 if(write(fd
, "x", 1) > 0){
1236 printf(1, "write . succeeded!\n");
1241 printf(1, "dir vs file OK\n");
1244 // test that iput() is called at the end of _namei()
1250 printf(1, "empty file name\n");
1253 for(i
= 0; i
< 50 + 1; i
++){
1254 if(mkdir("irefd") != 0){
1255 printf(1, "mkdir irefd failed\n");
1258 if(chdir("irefd") != 0){
1259 printf(1, "chdir irefd failed\n");
1265 fd
= open("", O_CREATE
);
1268 fd
= open("xx", O_CREATE
);
1275 printf(1, "empty file name OK\n");
1278 // test that fork fails gracefully
1279 // the forktest binary also does this, but it runs out of proc entries first.
1280 // inside the bigger usertests binary, we run out of memory first.
1286 printf(1, "fork test\n");
1288 for(n
=0; n
<1000; n
++){
1297 printf(1, "fork claimed to work 1000 times!\n");
1303 printf(1, "wait stopped early\n");
1309 printf(1, "wait got too many\n");
1313 printf(1, "fork test OK\n");
1319 int fds
[2], pid
, pids
[10], ppid
;
1320 char *a
, *b
, *c
, *lastaddr
, *oldbrk
, *p
, scratch
;
1323 printf(stdout
, "sbrk test\n");
1326 // can one sbrk() less than a page?
1329 for(i
= 0; i
< 5000; i
++){
1332 printf(stdout
, "sbrk test failed %d %x %x\n", i
, a
, b
);
1340 printf(stdout
, "sbrk test fork failed\n");
1346 printf(stdout
, "sbrk test failed post-fork\n");
1353 // can one grow address space to something big?
1354 #define BIG (100*1024*1024)
1356 amt
= (BIG
) - (uint
)a
;
1359 printf(stdout
, "sbrk test failed to grow big address space; enough phys mem?\n");
1362 lastaddr
= (char*) (BIG
-1);
1365 // can one de-allocate?
1368 if(c
== (char*)0xffffffff){
1369 printf(stdout
, "sbrk could not deallocate\n");
1374 printf(stdout
, "sbrk deallocation produced wrong address, a %x c %x\n", a
, c
);
1378 // can one re-allocate that page?
1381 if(c
!= a
|| sbrk(0) != a
+ 4096){
1382 printf(stdout
, "sbrk re-allocation failed, a %x c %x\n", a
, c
);
1385 if(*lastaddr
== 99){
1387 printf(stdout
, "sbrk de-allocation didn't really deallocate\n");
1392 c
= sbrk(-(sbrk(0) - oldbrk
));
1394 printf(stdout
, "sbrk downsize failed, a %x c %x\n", a
, c
);
1398 // can we read the kernel's memory?
1399 for(a
= (char*)(KERNBASE
); a
< (char*) (KERNBASE
+2000000); a
+= 50000){
1403 printf(stdout
, "fork failed\n");
1407 printf(stdout
, "oops could read %x = %x\n", a
, *a
);
1414 // if we run the system out of memory, does it clean up the last
1415 // failed allocation?
1417 printf(1, "pipe() failed\n");
1420 for(i
= 0; i
< sizeof(pids
)/sizeof(pids
[0]); i
++){
1421 if((pids
[i
] = fork()) == 0){
1422 // allocate a lot of memory
1423 sbrk(BIG
- (uint
)sbrk(0));
1424 write(fds
[1], "x", 1);
1425 // sit around until killed
1426 for(;;) sleep(1000);
1429 read(fds
[0], &scratch
, 1);
1431 // if those failed allocations freed up the pages they did allocate,
1432 // we'll be able to allocate here
1434 for(i
= 0; i
< sizeof(pids
)/sizeof(pids
[0]); i
++){
1440 if(c
== (char*)0xffffffff){
1441 printf(stdout
, "failed sbrk leaked memory\n");
1445 if(sbrk(0) > oldbrk
)
1446 sbrk(-(sbrk(0) - oldbrk
));
1448 printf(stdout
, "sbrk test OK\n");
1455 asm("mov %%esp, %%ebx\n\t"
1458 "mov %%ebx, %%esp" :
1460 "a" (SYS_sleep
), "n" (T_SYSCALL
), "c" (p
) :
1470 printf(stdout
, "validate test\n");
1473 for(p
= 0; p
<= (uint
)hi
; p
+= 4096){
1474 if((pid
= fork()) == 0){
1475 // try to crash the kernel by passing in a badly placed integer
1476 validateint((int*)p
);
1484 // try to crash the kernel by passing in a bad string pointer
1485 if(link("nosuchfile", (char*)p
) != -1){
1486 printf(stdout
, "link should not succeed\n");
1491 printf(stdout
, "validate ok\n");
1494 // does unintialized data start out zero?
1501 printf(stdout
, "bss test\n");
1502 for(i
= 0; i
< sizeof(uninit
); i
++){
1503 if(uninit
[i
] != '\0'){
1504 printf(stdout
, "bss test failed\n");
1508 printf(stdout
, "bss test ok\n");
1511 // does exec return an error if the arguments
1512 // are larger than a page? or does it write
1513 // below the stack and wreck the instructions/data?
1519 unlink("bigarg-ok");
1522 static char *args
[MAXARG
];
1524 for(i
= 0; i
< MAXARG
-1; i
++)
1525 args
[i
] = "bigargs test: failed\n ";
1527 printf(stdout
, "bigarg test\n");
1529 printf(stdout
, "bigarg test ok\n");
1530 fd
= open("bigarg-ok", O_CREATE
);
1534 printf(stdout
, "bigargtest: fork failed\n");
1538 fd
= open("bigarg-ok", 0);
1540 printf(stdout
, "bigarg test failed!\n");
1544 unlink("bigarg-ok");
1547 // what happens when the file system runs out of blocks?
1548 // answer: balloc panics, so this test is not useful.
1555 printf(1, "fsfull test\n");
1557 for(nfiles
= 0; ; nfiles
++){
1560 name
[1] = '0' + nfiles
/ 1000;
1561 name
[2] = '0' + (nfiles
% 1000) / 100;
1562 name
[3] = '0' + (nfiles
% 100) / 10;
1563 name
[4] = '0' + (nfiles
% 10);
1565 printf(1, "writing %s\n", name
);
1566 int fd
= open(name
, O_CREATE
|O_RDWR
);
1568 printf(1, "open %s failed\n", name
);
1573 int cc
= write(fd
, buf
, 512);
1579 printf(1, "wrote %d bytes\n", total
);
1588 name
[1] = '0' + nfiles
/ 1000;
1589 name
[2] = '0' + (nfiles
% 1000) / 100;
1590 name
[3] = '0' + (nfiles
% 100) / 10;
1591 name
[4] = '0' + (nfiles
% 10);
1597 printf(1, "fsfull test finished\n");
1600 unsigned long randstate
= 1;
1604 randstate
= randstate
* 1664525 + 1013904223;
1609 main(int argc
, char *argv
[])
1611 printf(1, "usertests starting\n");
1613 if(open("usertests.ran", 0) >= 0){
1614 printf(1, "already ran user tests -- rebuild fs.img\n");
1617 close(open("usertests.ran", O_CREATE
));