00001
00002
00003
00004
00005 #include <syscall.h>
00006 #include "tests/lib.h"
00007 #include "tests/main.h"
00008
00009 static int
00010 wrap_open (const char *name)
00011 {
00012 static int fds[8], fd_cnt;
00013 int fd, i;
00014
00015 CHECK ((fd = open (name)) > 1, "open \"%s\"", name);
00016 for (i = 0; i < fd_cnt; i++)
00017 if (fds[i] == fd)
00018 fail ("fd returned is not unique");
00019 fds[fd_cnt++] = fd;
00020 return fd;
00021 }
00022
00023 void
00024 test_main (void)
00025 {
00026 int root_fd, a_fd0;
00027 char name[READDIR_MAX_LEN + 1];
00028
00029 root_fd = wrap_open ("/");
00030 CHECK (mkdir ("a"), "mkdir \"a\"");
00031
00032 a_fd0 = wrap_open ("/a");
00033 CHECK (!readdir (a_fd0, name), "verify \"/a\" is empty");
00034 CHECK (inumber (root_fd) != inumber (a_fd0),
00035 "\"/\" and \"/a\" must have different inumbers");
00036
00037 CHECK (chdir ("a"), "chdir \"a\"");
00038
00039 msg ("try to remove \"/a\"");
00040 if (remove ("/a"))
00041 {
00042 msg ("remove successful");
00043
00044 CHECK (open ("/a") == -1, "open \"/a\" (must fail)");
00045 CHECK (open (".") == -1, "open \".\" (must fail)");
00046 CHECK (open ("..") == -1, "open \"..\" (must fail)");
00047 CHECK (!create ("x", 512), "create \"x\" (must fail)");
00048 }
00049 else
00050 {
00051 int a_fd1, a_fd2, a_fd3;
00052
00053 msg ("remove failed");
00054
00055 CHECK (!remove ("../a"), "try to remove \"../a\" (must fail)");
00056 CHECK (!remove (".././a"), "try to remove \".././a\" (must fail)");
00057 CHECK (!remove ("/./a"), "try to remove \"/./a\" (must fail)");
00058
00059 a_fd1 = wrap_open ("/a");
00060 a_fd2 = wrap_open (".");
00061 CHECK (inumber (a_fd1) == inumber (a_fd2),
00062 "\"/a\" and \".\" must have same inumber");
00063 CHECK (inumber (root_fd) != inumber (a_fd1),
00064 "\"/\" and \"/a\" must have different inumbers");
00065
00066 CHECK (chdir ("/a"), "chdir \"/a\"");
00067 a_fd3 = wrap_open (".");
00068 CHECK (inumber (a_fd3) == inumber (a_fd1),
00069 "\".\" must have same inumber as before");
00070
00071 CHECK (chdir ("/"), "chdir \"/\"");
00072 CHECK (!remove ("a"), "try to remove \"a\" (must fail: still open)");
00073 }
00074 CHECK (!readdir (a_fd0, name), "verify \"/a\" is empty");
00075 }