-
- MUST_SUCCEED (filesys_create ("foo", sizeof s));
- MUST_SUCCEED (filesys_open ("foo", &file));
- MUST_SUCCEED (file_write (&file, s, sizeof s) == sizeof s);
- MUST_SUCCEED (file_tell (&file) == sizeof s);
- MUST_SUCCEED (file_length (&file) == sizeof s);
- file_close (&file);
-
- MUST_SUCCEED (filesys_open ("foo", &file));
- MUST_SUCCEED (file_read (&file, s2, sizeof s2) == sizeof s2);
- MUST_SUCCEED (memcmp (s, s2, sizeof s) == 0);
- MUST_SUCCEED (file_tell (&file) == sizeof s2);
- MUST_SUCCEED (file_length (&file) == sizeof s2);
- file_close (&file);
-
- MUST_SUCCEED (filesys_remove ("foo"));
-
- printk ("filesys: self test ok\n");
+ int i;
+
+ filesys_remove ("foo");
+ for (i = 0; i < 2; i++)
+ {
+ /* Create file and check that it contains zeros
+ throughout the created length. */
+ MUST_SUCCEED (filesys_create ("foo", sizeof s));
+ MUST_SUCCEED ((file = filesys_open ("foo")) != NULL);
+ MUST_SUCCEED (file_read (file, s2, sizeof s2) == sizeof s2);
+ MUST_SUCCEED (memcmp (s2, zeros, sizeof s) == 0);
+ MUST_SUCCEED (file_tell (file) == sizeof s);
+ MUST_SUCCEED (file_length (file) == sizeof s);
+ file_close (file);
+
+ /* Reopen file and write to it. */
+ MUST_SUCCEED ((file = filesys_open ("foo")) != NULL);
+ MUST_SUCCEED (file_write (file, s, sizeof s) == sizeof s);
+ MUST_SUCCEED (file_tell (file) == sizeof s);
+ MUST_SUCCEED (file_length (file) == sizeof s);
+ file_close (file);
+
+ /* Reopen file and verify that it reads back correctly.
+ Delete file while open to check proper semantics. */
+ MUST_SUCCEED ((file = filesys_open ("foo")) != NULL);
+ MUST_SUCCEED (filesys_remove ("foo"));
+ MUST_SUCCEED (file_read (file, s2, sizeof s) == sizeof s);
+ MUST_SUCCEED (memcmp (s, s2, sizeof s) == 0);
+ MUST_SUCCEED (file_tell (file) == sizeof s);
+ MUST_SUCCEED (file_length (file) == sizeof s);
+ file_close (file);
+
+ /* Make sure file is deleted. */
+ MUST_SUCCEED ((file = filesys_open ("foo")) == NULL);
+ }
+
+ printf ("filesys: self test ok\n");