c424c049b14bd2141cadd39e79b37abef26d159a
[pintos-anon] / src / tests / filesys / extended / dir-rm-vine.c
1 /* Creates a "vine" of directories /0/1/2/3/4/5/6/7/8/9
2    and changes directory into each of them,
3    then remove them. */
4
5 #include <string.h>
6 #include <syscall.h>
7 #include "tests/lib.h"
8 #include "tests/main.h"
9
10 void
11 test_main (void) 
12 {
13   const char *filename = "/0/1/2/3/4/5/6/7/8/9/test";
14   int fd;
15   char tmp[128];
16   
17   tmp[1] = '\0';
18   for (tmp[0] = '0'; tmp[0] <= '9'; tmp[0]++) 
19     {
20       CHECK (mkdir (tmp), "mkdir \"%s\"", tmp);
21       CHECK (chdir (tmp), "chdir \"%s\"", tmp);
22     }
23   CHECK (create ("test", 512), "create \"test\"");
24
25   CHECK (chdir ("/"), "chdir \"/\"");
26   CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
27   msg ("close \"%s\"", filename);
28   close (fd);
29
30   strlcpy (tmp, filename, sizeof tmp);
31   while (strlen (tmp) > 0)
32     {
33       CHECK (remove (tmp), "remove \"%s\"", tmp);
34       *strrchr (tmp, '/') = 0;
35     }
36
37   CHECK (open (filename) == -1, "open \"%s\" (must return -1)", filename);
38 }