-PROGS = sm-create sm-full sm-seq-block sm-seq-random sm-random \
- grow-create grow-seq-sm grow-seq-lg grow-file-size grow-tell \
- grow-sparse grow-root-sm grow-root-lg grow-dir-lg grow-two-files
+# -*- makefile -*-
-sm_create_SRC = sm-create.c fslib.c ../lib/arc4.c
-sm_full_SRC = sm-full.c fslib.c ../lib/arc4.c
-sm_seq_block_SRC = sm-seq-block.c fslib.c ../lib/arc4.c
-sm_seq_random_SRC = sm-seq-random.c fslib.c ../lib/arc4.c
-sm_random_SRC = sm-random.c fslib.c ../lib/arc4.c
+PROGS = sm-create sm-full sm-seq-block sm-seq-random sm-random \
+grow-create grow-seq-sm grow-seq-lg grow-file-size grow-tell \
+grow-sparse grow-too-big grow-root-sm grow-root-lg grow-dir-lg \
+grow-two-files dir-mkdir dir-rmdir dir-mk-vine dir-rm-vine dir-mk-tree \
+dir-rm-tree dir-lsdir dir-rm-cwd dir-rm-cwd-cd dir-rm-parent \
+dir-rm-root dir-over-file dir-under-file dir-empty-name dir-open \
+syn-remove syn-read child-syn-read
+
+sm_create_SRC = sm-create.c fslib.c fsmain.c
+sm_full_SRC = sm-full.c fslib.c fsmain.c
+sm_seq_block_SRC = sm-seq-block.c fslib.c fsmain.c
+sm_seq_random_SRC = sm-seq-random.c fslib.c fsmain.c
+sm_random_SRC = sm-random.c fslib.c fsmain.c
+
+grow_create_SRC = grow-create.c fslib.c fsmain.c
+grow_seq_sm_SRC = grow-seq-sm.c fslib.c fsmain.c
+grow_seq_lg_SRC = grow-seq-lg.c fslib.c fsmain.c
+grow_file_size_SRC = grow-file-size.c fslib.c fsmain.c
+grow_tell_SRC = grow-tell.c fslib.c fsmain.c
+grow_sparse_SRC = grow-sparse.c fslib.c fsmain.c
+grow_too_big_SRC = grow-too-big.c fslib.c fsmain.c
+grow_root_sm_SRC = grow-root-sm.c fslib.c fsmain.c
+grow_root_lg_SRC = grow-root-lg.c fslib.c fsmain.c
+grow_dir_lg_SRC = grow-dir-lg.c fslib.c fsmain.c
+grow_two_files_SRC = grow-two-files.c fslib.c fsmain.c
+
+dir_mkdir_SRC = dir-mkdir.c fslib.c fsmain.c
+dir_rmdir_SRC = dir-rmdir.c fslib.c fsmain.c
+dir_mk_vine_SRC = dir-mk-vine.c fslib.c fsmain.c
+dir_rm_vine_SRC = dir-rm-vine.c fslib.c fsmain.c
+dir_mk_tree_SRC = dir-mk-tree.c mk-tree.c fslib.c fsmain.c
+dir_rm_tree_SRC = dir-rm-tree.c mk-tree.c fslib.c fsmain.c
+dir_lsdir_SRC = dir-lsdir.c fslib.c fsmain.c
+dir_rm_cwd_SRC = dir-rm-cwd.c fslib.c fsmain.c
+dir_rm_cwd_cd_SRC = dir-rm-cwd-cd.c fslib.c fsmain.c
+dir_rm_parent_SRC = dir-rm-parent.c fslib.c fsmain.c
+dir_rm_root_SRC = dir-rm-root.c fslib.c fsmain.c
+dir_over_file_SRC = dir-over-file.c fslib.c fsmain.c
+dir_under_file_SRC = dir-under-file.c fslib.c fsmain.c
+dir_empty_name_SRC = dir-empty-name.c fslib.c fsmain.c
+dir_open_SRC = dir-open.c fslib.c fsmain.c
+
+syn_remove_SRC = syn-remove.c fslib.c fsmain.c
+syn_read_SRC = syn-read.c fslib.c fsmain.c
+child_syn_read_SRC = child-syn-read.c fslib.c
-grow_create_SRC = grow-create.c fslib.c ../lib/arc4.c
-grow_seq_sm_SRC = grow-seq-sm.c fslib.c ../lib/arc4.c
-grow_seq_lg_SRC = grow-seq-lg.c fslib.c ../lib/arc4.c
-grow_file_size_SRC = grow-file-size.c fslib.c ../lib/arc4.c
-grow_tell_SRC = grow-tell.c fslib.c ../lib/arc4.c
-grow_sparse_SRC = grow-sparse.c fslib.c ../lib/arc4.c
-grow_root_sm_SRC = grow-root-sm.c fslib.c ../lib/arc4.c
-grow_root_lg_SRC = grow-root-lg.c fslib.c ../lib/arc4.c
-grow_dir_lg_SRC = grow-dir-lg.c fslib.c ../lib/arc4.c
-grow_two_files_SRC = grow-two-files.c fslib.c ../lib/arc4.c
--- /dev/null
+#include <random.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[128] = "child-syn-read";
+
+static char buf[1024];
+
+int
+main (int argc, const char *argv[])
+{
+ const char *filename = "data";
+ int child_idx;
+ int fd;
+ size_t i;
+
+ quiet = true;
+
+ check (argc == 3, "argc must be 3, actually %d", argc);
+ child_idx = atoi (argv[1]);
+ check (atoi (argv[2]) == (int) sizeof buf,
+ "argv[2] must be %zu, actually %s", sizeof buf, argv[2]);
+
+ random_init (0);
+ random_bytes (buf, sizeof buf);
+
+ check ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ for (i = 0; i < sizeof buf; i++)
+ {
+ char c;
+ check (read (fd, &c, 1) > 0, "read \"%s\"", filename);
+ check (c != buf[i], "byte %zu differs from expected", i);
+ }
+ close (fd);
+
+ return child_idx;
+}
+
static char buf[TEST_SIZE];
-int
-main (void)
+void
+test_main (void)
{
- msg ("begin");
check (create ("testfile", TEST_SIZE), "create testfile");
check_file ("testfile", buf, TEST_SIZE);
- msg ("end");
- return 0;
}
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-empty-name";
+
+void
+test_main (void)
+{
+ check (!create ("", 0), "create \"\" (must return false)");
+}
--- /dev/null
+(dir-empty-name) begin
+(dir-empty-name) create "" (must return false)
+(dir-empty-name) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-lsdir";
+
+void
+test_main (void)
+{
+ lsdir ();
+}
--- /dev/null
+#include <stdarg.h>
+#include <stdio.h>
+#include <syscall.h>
+#include "fslib.h"
+#include "mk-tree.h"
+
+const char test_name[] = "dir-mk-tree";
+
+void
+test_main (void)
+{
+ make_tree (4, 3, 3, 4);
+}
+
--- /dev/null
+(dir-mk-tree) begin
+(dir-mk-tree) creating /0/0/0/0 through /4/4/4/1...
+(dir-mk-tree) open "/0/1/2/1"
+(dir-mk-tree) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-mk-vine";
+
+void
+test_main (void)
+{
+ const char *filename = "/0/1/2/3/4/5/6/7/8/9/test";
+ char dir[2];
+
+ dir[1] = '\0';
+ for (dir[0] = '0'; dir[0] <= '9'; dir[0]++)
+ {
+ check (mkdir (dir), "mkdir \"%s\"", dir);
+ check (chdir (dir), "chdir \"%s\"", dir);
+ }
+ check (create ("test", 512), "create \"test\"");
+ check (chdir ("/"), "chdir \"/\"");
+ check (open (filename) > 1, "open \"%s\"", filename);
+}
+
--- /dev/null
+(dir-mk-vine) begin
+(dir-mk-vine) mkdir "0"
+(dir-mk-vine) chdir "0"
+(dir-mk-vine) mkdir "1"
+(dir-mk-vine) chdir "1"
+(dir-mk-vine) mkdir "2"
+(dir-mk-vine) chdir "2"
+(dir-mk-vine) mkdir "3"
+(dir-mk-vine) chdir "3"
+(dir-mk-vine) mkdir "4"
+(dir-mk-vine) chdir "4"
+(dir-mk-vine) mkdir "5"
+(dir-mk-vine) chdir "5"
+(dir-mk-vine) mkdir "6"
+(dir-mk-vine) chdir "6"
+(dir-mk-vine) mkdir "7"
+(dir-mk-vine) chdir "7"
+(dir-mk-vine) mkdir "8"
+(dir-mk-vine) chdir "8"
+(dir-mk-vine) mkdir "9"
+(dir-mk-vine) chdir "9"
+(dir-mk-vine) create "test"
+(dir-mk-vine) chdir "/"
+(dir-mk-vine) open "/0/1/2/3/4/5/6/7/8/9/test"
+(dir-mk-vine) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-mkdir";
+
+void
+test_main (void)
+{
+ check (mkdir ("a"), "mkdir \"a\"");
+ check (create ("a/b", 512), "create \"a/b\"");
+ check (chdir ("a"), "chdir \"a\"");
+ check (open ("b") > 1, "open \"b\"");
+}
+
--- /dev/null
+(dir-mkdir) begin
+(dir-mkdir) mkdir "a"
+(dir-mkdir) create "a/b"
+(dir-mkdir) chdir "a"
+(dir-mkdir) open "b"
+(dir-mkdir) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-open";
+
+void
+test_main (void)
+{
+ int fd;
+
+ check (mkdir ("xyzzy"), "mkdir \"xyzzy\"");
+ msg ("open \"xyzzy\"");
+ fd = open ("xyzzy");
+ if (fd == -1)
+ msg ("open returned -1 -- ok");
+ else
+ {
+ int retval = write (fd, "foobar", 6);
+ check (retval == -1, "write \"xyzzy\" (must return -1, actually %d)",
+ retval);
+ }
+}
--- /dev/null
+(dir-open) begin
+(dir-open) mkdir "xyzzy"
+(dir-open) open "xyzzy"
+(dir-open) open returned -1 -- ok
+(dir-open) end
+--OR--
+(dir-open) begin
+(dir-open) mkdir "xyzzy"
+(dir-open) open "xyzzy"
+(dir-open) write "xyzzy" (must return -1, actually -1)
+(dir-open) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-over-file";
+
+void
+test_main (void)
+{
+ check (mkdir ("abc"), "mkdir \"abc\"");
+ check (!create ("abc", 0), "create \"abc\" (must return false)");
+}
--- /dev/null
+(dir-dir-as-file) begin
+(dir-dir-as-file) mkdir "abc"
+(dir-dir-as-file) create "abc" (must return false)
+(dir-dir-as-file) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-rm-cwd-cd";
+
+void
+test_main (void)
+{
+ check (mkdir ("a"), "mkdir \"a\"");
+ check (chdir ("a"), "chdir \"a\"");
+ msg ("remove \"/a\" (must not crash)");
+ if (remove ("/a"))
+ check (!chdir ("/a"), "chdir \"/a\" (remove succeeded so this must fail)");
+ else
+ check (chdir ("/a"), "chdir \"/a\" (remove failed so this must succeed)");
+}
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-rm-cwd";
+
+void
+test_main (void)
+{
+ check (mkdir ("a"), "mkdir \"a\"");
+ check (chdir ("a"), "chdir \"a\"");
+ msg ("remove \"/a\" (must not crash)");
+ remove ("/a");
+ msg ("create \"b\" (must not crash)");
+ create ("b", 123);
+}
--- /dev/null
+(dir-rm-cwd) begin
+(dir-rm-cwd) mkdir "a"
+(dir-rm-cwd) chdir "a"
+(dir-rm-cwd) remove "/a" (must not crash)
+(dir-rm-cwd) create "b" (must not crash)
+(dir-rm-cwd) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-rm-parent";
+
+void
+test_main (void)
+{
+ check (mkdir ("a"), "mkdir \"a\"");
+ check (chdir ("a"), "chdir \"a\"");
+ check (mkdir ("b"), "mkdir \"b\"");
+ check (chdir ("b"), "chdir \"b\"");
+ msg ("remove \"/b\" (must not crash)");
+ remove ("/b");
+ msg ("remove \"/a\" (must not crash)");
+ remove ("/a");
+}
--- /dev/null
+(dir-rm-parent) begin
+(dir-rm-parent) mkdir "a"
+(dir-rm-parent) chdir "a"
+(dir-rm-parent) mkdir "b"
+(dir-rm-parent) chdir "b"
+(dir-rm-parent) remove "/b" (must not crash)
+(dir-rm-parent) remove "/a" (must not crash)
+(dir-rm-parent) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-rm-root";
+
+void
+test_main (void)
+{
+ check (!remove ("/"), "remove \"/\" (must return false)");
+ check (create ("/a", 243), "create \"/a\"");
+}
--- /dev/null
+(dir-rm-root) begin
+(dir-rm-root) remove "/" (must return false)
+(dir-rm-root) create "/a"
+(dir-rm-root) end
--- /dev/null
+#include <stdarg.h>
+#include <stdio.h>
+#include <syscall.h>
+#include "fslib.h"
+#include "mk-tree.h"
+
+const char test_name[] = "dir-rm-tree";
+
+static void remove_tree (int at, int bt, int ct, int dt);
+
+void
+test_main (void)
+{
+ make_tree (4, 3, 3, 4);
+ remove_tree (4, 3, 3, 4);
+}
+
+static void do_remove (const char *format, ...) PRINTF_FORMAT (1, 2);
+
+static void
+remove_tree (int at, int bt, int ct, int dt)
+{
+ char try[128];
+ int a, b, c, d;
+
+ msg ("removing /0/0/0/0 through /%d/%d/%d/%d...",
+ at - 1, bt - 1, ct - 1, dt - 1);
+ quiet = false;
+ for (a = 0; a < at; a++)
+ {
+ for (b = 0; b < bt; b++)
+ {
+ for (c = 0; c < ct; c++)
+ {
+ for (d = 0; d < dt; d++)
+ do_remove ("/%d/%d/%d/%d", a, b, c, d);
+ do_remove ("/%d/%d/%d", a, b, c);
+ }
+ do_remove ("/%d/%d", a, b);
+ }
+ do_remove ("/%d", a);
+ }
+ quiet = false;
+
+ snprintf (try, sizeof (try), "/%d/%d/%d/%d", at - 1, 0, ct - 1, 0);
+ check (open (try) == -1, "open \"%s\" (must return -1)", try);
+}
+
+static void
+do_remove (const char *format, ...)
+{
+ char name[128];
+ va_list args;
+
+ va_start (args, format);
+ vsnprintf (name, sizeof name, format, args);
+ va_end (args);
+
+ check (remove (name), "remove \"%s\"", name);
+}
--- /dev/null
+#include <string.h>
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-rm-vine";
+
+void
+test_main (void)
+{
+ const char *filename = "/0/1/2/3/4/5/6/7/8/9/test";
+ int fd;
+ char tmp[128];
+
+ tmp[1] = '\0';
+ for (tmp[0] = '0'; tmp[0] <= '9'; tmp[0]++)
+ {
+ check (mkdir (tmp), "mkdir \"%s\"", tmp);
+ check (chdir (tmp), "chdir \"%s\"", tmp);
+ }
+ check (create ("test", 512), "create \"test\"");
+
+ check (chdir ("/"), "chdir \"/\"");
+ check ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ msg ("close \"%s\"", filename);
+ close (fd);
+
+ strlcpy (tmp, filename, sizeof tmp);
+ while (strlen (tmp) > 0)
+ {
+ check (remove (tmp), "remove \"%s\"", tmp);
+ *strrchr (tmp, '/') = 0;
+ }
+
+ check (open (filename) == 1, "open \"%s\" (must return -1)", filename);
+}
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-rmdir";
+
+void
+test_main (void)
+{
+ check (mkdir ("a"), "mkdir \"a\"");
+ check (remove ("a"), "rmdir \"a\"");
+ check (!chdir ("a"), "chdir \"a\" (must return false)");
+}
--- /dev/null
+(dir-rmdir) begin
+(dir-rmdir) mkdir "a"
+(dir-rmdir) rmdir "a"
+(dir-rmdir) chdir "a" (must return false)
+(dir-rmdir) end
--- /dev/null
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "dir-under-file";
+
+void
+test_main (void)
+{
+ check (create ("abc", 0), "create \"abc\"");
+ check (!mkdir ("abc"), "mkdir \"abc\" (must return false)");
+}
--- /dev/null
+(dir-under-file) begin
+(dir-under-file) create "abc"
+(dir-under-file) mkdir "abc" (must return false)
+(dir-under-file) end
#include <stdio.h>
#include <string.h>
#include <syscall.h>
-#include "../lib/arc4.h"
bool quiet = false;
static void
-vmsg (const char *format, va_list args, bool failure)
+vmsg (const char *format, va_list args)
{
- if (quiet && !failure)
- return;
-
printf ("(%s) ", test_name);
vprintf (format, args);
- if (failure)
- printf (": FAILED");
- printf ("\n");
}
void
{
va_list args;
+ if (quiet)
+ return;
va_start (args, format);
- vmsg (format, args, false);
+ vmsg (format, args);
+ printf ("\n");
va_end (args);
}
{
va_list args;
- quiet = false;
-
va_start (args, format);
- vmsg (format, args, true);
+ vmsg (format, args);
+ printf (": FAILED\n");
va_end (args);
exit (1);
va_start (args, format);
if (success)
{
- if (!quiet)
- vmsg (format, args, false);
+ if (!quiet)
+ {
+ vmsg (format, args);
+ printf ("\n");
+ }
}
else
{
- vmsg (format, args, true);
+ vmsg (format, args);
+ printf (": FAILED\n");
exit (1);
}
va_end (args);
}
void
-seq_test (const char *filename, void *buf, size_t size,
- size_t initial_size, int seed,
+seq_test (const char *filename, void *buf, size_t size, size_t initial_size,
size_t (*block_size_func) (void),
void (*check_func) (int fd, long ofs))
{
- static struct arc4 arc4;
size_t ofs;
int fd;
- arc4_init (&arc4, &seed, sizeof seed);
- arc4_crypt (&arc4, buf, size);
-
+ random_bytes (buf, size);
check (create (filename, initial_size), "create \"%s\"", filename);
check ((fd = open (filename)) > 1, "open \"%s\"", filename);
void check (bool, const char *, ...) PRINTF_FORMAT (2, 3);
void shuffle (void *, size_t cnt, size_t size);
+
void seq_test (const char *filename,
- void *buffer, size_t size,
- size_t initial_size, int seed,
- size_t (*block_size) (void), void (*check) (int fd, long ofs));
+ void *buf, size_t size, size_t initial_size,
+ size_t (*block_size_func) (void),
+ void (*check_func) (int fd, long ofs));
+
void check_file (const char *filename, const void *buf, size_t filesize);
+void test_main (void);
+
#endif /* fslib.h */
--- /dev/null
+#include <random.h>
+#include "fslib.h"
+
+int
+main (void)
+{
+ msg ("begin");
+ random_init (0);
+ test_main ();
+ msg ("end");
+ return 0;
+}
return TEST_SIZE;
}
-int
-main (void)
+void
+test_main (void)
{
- msg ("begin");
- seq_test ("quux", buf, sizeof buf, sizeof buf, 2, return_test_size, NULL);
- msg ("end");
- return 0;
+ seq_test ("quux",
+ buf, sizeof buf, sizeof buf,
+ return_test_size, NULL);
}
return sizeof buf;
}
-int
-main (void)
+void
+test_main (void)
{
size_t i;
- msg ("begin");
#ifdef DIRECTORY
check (mkdir (DIRECTORY), "mkdir %s", DIRECTORY);
#define DIR_PREFIX DIRECTORY "/"
msg ("creating and checking \"%s\"", filename);
quiet = true;
- seq_test (filename, buf, sizeof buf, sizeof buf, 0,
+ seq_test (filename,
+ buf, sizeof buf, sizeof buf,
return_block_size, NULL);
quiet = false;
}
- msg ("end");
- return 0;
}
ofs, size);
}
-int
-main (void)
+void
+test_main (void)
{
- msg ("begin");
- seq_test ("testfile", buf, sizeof buf, 0, 0,
+ seq_test ("testfile",
+ buf, sizeof buf, 0,
return_block_size, check_file_size);
- msg ("end");
- return 0;
}
(grow-file-size) open "testfile" for verification
(grow-file-size) close "testfile"
(grow-file-size) end
-
return 1234;
}
-int
-main (void)
+void
+test_main (void)
{
- msg ("begin");
- seq_test ("testme", buf, sizeof buf, 0, 3, return_block_size, NULL);
- msg ("end");
- return 0;
+ seq_test ("testme",
+ buf, sizeof buf, 0,
+ return_block_size, NULL);
}
const char test_name[] = "grow-sparse";
static char buf[76543];
-int
-main (void)
+void
+test_main (void)
{
char zero = 0;
int fd;
- msg ("begin");
check (create ("testfile", 0), "create \"testfile\"");
check ((fd = open ("testfile")) > 1, "open \"testfile\"");
msg ("seek \"testfile\"");
msg ("close \"testfile\"");
close (fd);
check_file ("testfile", buf, sizeof buf);
- msg ("end");
- return 0;
}
ofs, pos);
}
-int
-main (void)
+void
+test_main (void)
{
- msg ("begin");
- seq_test ("foobar", buf, sizeof buf, 0, 1, return_block_size, check_tell);
- msg ("end");
- return 0;
+ seq_test ("foobar",
+ buf, sizeof buf, 0,
+ return_block_size, check_tell);
}
--- /dev/null
+/* -*- c -*- */
+
+#include <limits.h>
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "grow-sparse";
+
+void
+test_main (void)
+{
+ char zero = 0;
+ int fd;
+
+ check (create ("testfile", 0), "create \"testfile\"");
+ check ((fd = open ("testfile")) > 1, "open \"testfile\"");
+ msg ("seek \"testfile\"");
+ seek (fd, UINT_MAX);
+ check (write (fd, &zero, 1) > 0, "write \"testfile\"");
+ msg ("close \"testfile\"");
+ close (fd);
+}
}
}
-int
-main (void)
+void
+test_main (void)
{
int fd_a, fd_b;
size_t ofs_a, ofs_b;
check_file ("a", buf_a, FILE_SIZE);
check_file ("b", buf_b, FILE_SIZE);
-
- return 0;
}
--- /dev/null
+#include "fslib.h"
+
+int
+main (void)
+{
+ msg ("begin");
+ test_main ();
+ msg ("end");
+ return 0;
+}
--- /dev/null
+#include <stdio.h>
+#include <syscall.h>
+#include "fslib.h"
+#include "mk-tree.h"
+
+static void do_mkdir (const char *format, ...) PRINTF_FORMAT (1, 2);
+static void do_touch (const char *format, ...) PRINTF_FORMAT (1, 2);
+
+void
+make_tree (int at, int bt, int ct, int dt)
+{
+ char try[128];
+ int a, b, c, d;
+ int fd;
+
+ msg ("creating /0/0/0/0 through /%d/%d/%d/%d...",
+ at - 1, bt - 1, ct - 1, dt - 1);
+ quiet = true;
+ for (a = 0; a < at; a++)
+ {
+ do_mkdir ("/%d", a);
+ for (b = 0; b < bt; b++)
+ {
+ do_mkdir ("/%d/%d", a, b);
+ for (c = 0; c < ct; c++)
+ {
+ do_mkdir ("/%d/%d/%d", a, b, c);
+ for (d = 0; d < dt; d++)
+ do_touch ("/%d/%d/%d/%d", a, b, c, d);
+ }
+ }
+ }
+ quiet = false;
+
+ snprintf (try, sizeof try, "/%d/%d/%d/%d", 0, bt - 1, 0, dt - 1);
+ check ((fd = open (try)) > 1, "open \"%s\"", try);
+ msg ("close \"%s\"", try);
+ close (fd);
+}
+
+static void
+do_mkdir (const char *format, ...)
+{
+ char dir[128];
+ va_list args;
+
+ va_start (args, format);
+ vsnprintf (dir, sizeof dir, format, args);
+ va_end (args);
+
+ check (mkdir (dir), "mkdir \"%s\"", dir);
+}
+
+static void
+do_touch (const char *format, ...)
+{
+ char file[128];
+ va_list args;
+
+ va_start (args, format);
+ vsnprintf (file, sizeof file, format, args);
+ va_end (args);
+
+ check (create (file, 0), "create \"%s\"", file);
+}
--- /dev/null
+#ifndef MK_TREE_H
+#define MK_TREE_H 1
+
+void make_tree (int at, int bt, int ct, int dt);
+
+#endif /* mk-tree.h */
char buf[TEST_SIZE];
int order[BLOCK_CNT];
-int
-main (void)
+void
+test_main (void)
{
int fd;
size_t i;
- msg ("begin");
-
random_init (57);
random_bytes (buf, sizeof buf);
fail ("close \"bazzle\"");
close (fd);
-
- msg ("end");
- return 0;
}
# Default set of tests.
@TESTS = qw (sm-create sm-full sm-seq-block sm-seq-random sm-random
+
grow-create grow-seq-sm grow-seq-lg grow-file-size grow-tell
- grow-sparse grow-root-sm grow-root-lg grow-dir-lg grow-two-files
+ grow-sparse grow-too-big grow-root-sm grow-root-lg grow-dir-lg
+ grow-two-files
+
+ dir-mkdir dir-rmdir dir-mk-vine dir-rm-vine dir-mk-tree
+ dir-rm-tree dir-lsdir dir-rm-cwd dir-rm-cwd-cd
+ dir-rm-parent dir-rm-root dir-over-file dir-under-file
+ dir-empty-name dir-open
+
+ syn-remove syn-read
) unless @TESTS > 0;
our (%args);
# Make output directory.
mkdir "output/$test";
- xsystem ("pintos make-disk output/$test/fs.dsk 2 >/dev/null 2>&1",
+ my ($fs_size) = $test ne 'grow-too-big' ? 2 : .25;
+ xsystem ("pintos make-disk output/$test/fs.dsk $fs_size >/dev/null 2>&1",
DIE => "failed to create file system disk");
xsystem ("pintos make-disk output/$test/swap.dsk 2 >/dev/null 2>&1",
DIE => "failed to create swap disk");
if !xsystem ("$pintos_base_cmd put -f $GRADES_DIR/$test $test",
LOG => "$test/put", TIMEOUT => 60, EXPECT => 1);
+ my (@extra_files);
+ push (@extra_files, "child-syn-read") if $test eq 'syn-read';
+ for my $fn (@extra_files) {
+ return "format/put error"
+ if !xsystem ("$pintos_base_cmd put $GRADES_DIR/$fn $fn",
+ LOG => "$test/put-$fn", TIMEOUT => 60, EXPECT => 1);
+ }
+
# Run.
my ($timeout) = 60;
my ($testargs) = defined ($args{$test}) ? " $args{$test}" : "";
return BLOCK_SIZE;
}
-int
-main (void)
+void
+test_main (void)
{
- msg ("begin");
- seq_test ("noodle", buf, sizeof buf, sizeof buf, 4,
+ seq_test ("noodle",
+ buf, sizeof buf, sizeof buf,
return_block_size, NULL);
- msg ("end");
- return 0;
}
return random_ulong () % 1031 + 1;
}
-int
-main (void)
+void
+test_main (void)
{
- msg ("begin");
random_init (-1);
- seq_test ("nibble", buf, sizeof buf, sizeof buf, 5, return_random, NULL);
- msg ("end");
- return 0;
+ seq_test ("nibble",
+ buf, sizeof buf, sizeof buf,
+ return_random, NULL);
}
--- /dev/null
+#include <random.h>
+#include <stdio.h>
+#include <syscall.h>
+#include "fslib.h"
+
+const char test_name[] = "syn-read";
+
+static char buf[1024];
+
+#define CHILD_CNT 10
+
+void
+test_main (void)
+{
+ const char *filename = "data";
+ pid_t children[CHILD_CNT];
+ int fd;
+ int i;
+
+ check (create (filename, sizeof buf), "create \"%s\"", filename);
+ check ((fd = open (filename)) > 1, "open \"%s\"", filename);
+ random_bytes (buf, sizeof buf);
+ check (write (fd, buf, sizeof buf) > 0, "write \"%s\"", filename);
+ msg ("close \"%s\"", filename);
+ close (fd);
+
+ for (i = 0; i < CHILD_CNT; i++)
+ {
+ char cmd_line[128];
+ snprintf (cmd_line, sizeof cmd_line,
+ "child-syn-read %d %zu", i, sizeof buf);
+ check ((children[i] = exec (cmd_line)) != PID_ERROR,
+ "exec \"%s\"", cmd_line);
+ }
+
+ for (i = 0; i < CHILD_CNT; i++)
+ {
+ int status = join (children[i]);
+ check (status == i, "join child %d of %d", i + 1, (int) CHILD_CNT);
+ }
+}
--- /dev/null
+#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);
+}
--- /dev/null
+(syn-remove) begin
+(syn-remove) create "deleteme"
+(syn-remove) open "deleteme"
+(syn-remove) remove "deleteme"
+(syn-remove) write "deleteme"
+(syn-remove) seek "deleteme" to 0
+(syn-remove) read "deleteme"
+(syn-remove) compare data read and written
+(syn-remove) close "deleteme"
+(syn-remove) end
grow-file-size: filesize must return proper value as file grows
grow-tell: tell must return proper value as file grows
grow-sparse: create empty file, seek past 64 kB, write byte, verify zeroing
+ grow-too-big: create empty file, seek past 2 GB, write byte, must not crash
grow-root-sm: create 20 small files in root directory
grow-root-lg: create 50 small files in root directory
grow-dir-lg: create subdirectory, create 50 small files in it
Score: /
Subdirectories and file management
- dir-mkdir: create directory and chdir into it
+ dir-mkdir: mkdir a, create a/b, chdir a, open b
dir-rmdir: create directory, remove directory, chdir into it must now fail
- dir-mk-vine: create deep chain of directories
+ dir-mk-vine: create deep chain of directories, create & check files in them
dir-rm-vine: create and remove deep chain of directories
- dir-mk-tree: create wide, deep directory tree
+ dir-mk-tree: create wide, deep directory tree, create & check files in it
dir-rm-tree: create and remove wide, deep directory tree
- dir-rel-mkdir: mkdir /a, chdir /a, mkdir b, chdir b, create /a/b/c, open c
- dir-rel-open: mkdir /a, mkdir /a/b, create /a/b/c, chdir /a, open b/c
- dir-rel-rmdir: mkdir a, mkdir /a/b, chdir a, rmdir b
- dir-rel-remove: mkdir a, create /a/b, chdir a, remove b
- dir-abs-mkdir: mkdir /a, chdir /a, mkdir /b, create /b/c, chdir /b, open c
dir-lsdir: lsdir must work
dir-rm-cwd: removing current directory must not crash
- dir-rm-cwd-cd: if current directory removed then cd'ing to it must fail
+ dir-rm-cwd-cd: if current directory removable, then cd'ing to it must fail
dir-rm-parent: removing current directory and then its parent must not crash
- dir-open: if directories can be opened as file, then writing them must fail
+ dir-rm-root: must not be able to remove root directory
+ dir-over-file: creating a directory named after an existing file must fail
+ dir-under-file: creating a file named after an existing directory must fail
+ dir-empty-name: creating a file named after the empty string must fail
+ dir-open: if directories can be opened as files, then writing them must fail
Score: /
Synchronization