00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <string.h>
00011 #include <stdio.h>
00012 #include <syscall.h>
00013 #include "tests/lib.h"
00014 #include "tests/main.h"
00015
00016 void
00017 test_main (void)
00018 {
00019 int i;
00020
00021 msg ("creating many levels of files and directories...");
00022 quiet = true;
00023 CHECK (mkdir ("start"), "mkdir \"start\"");
00024 CHECK (chdir ("start"), "chdir \"start\"");
00025 for (i = 0; ; i++)
00026 {
00027 char name[3][READDIR_MAX_LEN + 1];
00028 char file_name[16], dir_name[16];
00029 char contents[128];
00030 int fd;
00031
00032
00033 snprintf (file_name, sizeof file_name, "file%d", i);
00034 if (!create (file_name, 0))
00035 break;
00036 CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
00037 snprintf (contents, sizeof contents, "contents %d\n", i);
00038 if (write (fd, contents, strlen (contents)) != (int) strlen (contents))
00039 {
00040 CHECK (remove (file_name), "remove \"%s\"", file_name);
00041 close (fd);
00042 break;
00043 }
00044 close (fd);
00045
00046
00047 snprintf (dir_name, sizeof dir_name, "dir%d", i);
00048 if (!mkdir (dir_name))
00049 {
00050 CHECK (remove (file_name), "remove \"%s\"", file_name);
00051 break;
00052 }
00053
00054
00055 CHECK ((fd = open (".")) > 1, "open \".\"");
00056 CHECK (readdir (fd, name[0]), "readdir \".\"");
00057 CHECK (readdir (fd, name[1]), "readdir \".\"");
00058 CHECK (!readdir (fd, name[2]), "readdir \".\" (should fail)");
00059 CHECK ((!strcmp (name[0], dir_name) && !strcmp (name[1], file_name))
00060 || (!strcmp (name[1], dir_name) && !strcmp (name[0], file_name)),
00061 "names should be \"%s\" and \"%s\", "
00062 "actually \"%s\" and \"%s\"",
00063 file_name, dir_name, name[0], name[1]);
00064 close (fd);
00065
00066
00067 CHECK (chdir (dir_name), "chdir \"%s\"", dir_name);
00068 }
00069 CHECK (i > 200, "created files and directories only to level %d", i);
00070 quiet = false;
00071
00072 msg ("removing all but top 10 levels of files and directories...");
00073 quiet = true;
00074 while (i-- > 10)
00075 {
00076 char file_name[16], dir_name[16];
00077
00078 snprintf (file_name, sizeof file_name, "file%d", i);
00079 snprintf (dir_name, sizeof dir_name, "dir%d", i);
00080 CHECK (chdir (".."), "chdir \"..\"");
00081 CHECK (remove (dir_name), "remove \"%s\"", dir_name);
00082 CHECK (remove (file_name), "remove \"%s\"", file_name);
00083 }
00084 quiet = false;
00085 }