More filesys tests.
[pintos-anon] / grading / filesys / syn-remove.c
1 #include <random.h>
2 #include <string.h>
3 #include <syscall.h>
4 #include "fslib.h"
5
6 const char test_name[] = "syn-remove";
7
8 char buf1[1234];
9 char buf2[1234];
10
11 void
12 test_main (void) 
13 {
14   const char *filename = "deleteme";
15   int fd;
16   
17   check (create (filename, 0), "create \"%s\"", filename);
18   check ((fd = open (filename)) > 1, "open \"%s\"", filename);
19   check (remove (filename), "remove \"%s\"", filename);
20   random_bytes (buf1, sizeof buf1);
21   check (write (fd, buf1, sizeof buf1) > 0, "write \"%s\"", filename);
22   msg ("seek \"%s\" to 0", filename);
23   seek (fd, 0);
24   check (read (fd, buf2, sizeof buf2) > 0, "read \"%s\"", filename);
25   check (!memcmp (buf1, buf2, sizeof buf1), "compare data read and written");
26   msg ("close \"%s\"", filename);
27   close (fd);
28 }