More filesys tests.
[pintos-anon] / grading / filesys / syn-remove.c
diff --git a/grading/filesys/syn-remove.c b/grading/filesys/syn-remove.c
new file mode 100644 (file)
index 0000000..e47456a
--- /dev/null
@@ -0,0 +1,28 @@
+#include <random.h>
+#include <string.h>
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "syn-remove";
+
+char buf1[1234];
+char buf2[1234];
+
+void
+test_main (void) 
+{
+  const char *filename = "deleteme";
+  int fd;
+  
+  check (create (filename, 0), "create \"%s\"", filename);
+  check ((fd = open (filename)) > 1, "open \"%s\"", filename);
+  check (remove (filename), "remove \"%s\"", filename);
+  random_bytes (buf1, sizeof buf1);
+  check (write (fd, buf1, sizeof buf1) > 0, "write \"%s\"", filename);
+  msg ("seek \"%s\" to 0", filename);
+  seek (fd, 0);
+  check (read (fd, buf2, sizeof buf2) > 0, "read \"%s\"", filename);
+  check (!memcmp (buf1, buf2, sizeof buf1), "compare data read and written");
+  msg ("close \"%s\"", filename);
+  close (fd);
+}