aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2016-05-09 18:10:23 +0200
committerklaar36 <klas.arvidsson@liu.se>2016-05-09 18:10:23 +0200
commitc4e42961e885612ca2b84dd0246d09b86aad2b97 (patch)
tree3fd5665708f3ddf6a534d1dde53a3773b58d4013 /src
parentc71baf223e8de56d8cef3814952d704987125ce2 (diff)
downloadpintos-rs-c4e42961e885612ca2b84dd0246d09b86aad2b97.tar.gz
pfs test
Diffstat (limited to 'src')
-rw-r--r--src/tests/Make.tests7
-rw-r--r--src/tests/klaar/Make.tests28
-rw-r--r--src/tests/klaar/pfs-reader.c44
-rw-r--r--src/tests/klaar/pfs-writer.c52
-rw-r--r--src/tests/klaar/pfs.c83
-rw-r--r--src/tests/klaar/pfs.ck7
-rw-r--r--src/tests/klaar/pfs.h2
7 files changed, 215 insertions, 8 deletions
diff --git a/src/tests/Make.tests b/src/tests/Make.tests
index a9a4459..5105d0d 100644
--- a/src/tests/Make.tests
+++ b/src/tests/Make.tests
@@ -85,7 +85,12 @@ endif
ifeq ($(filter vm, $(KERNEL_SUBDIRS)), vm)
TESTCMD += --swap-disk=4
endif
-TESTCMD += -- -F=10000 -q
+TESTCMD += -- -q
+# klaar@ida 2016-05: new kernel flag
+ifeq ($(filter -F=%, $(KERNELFLAGS)),)
+# BUG: Why is this not filtered out?
+TESTCMD += -F=10000
+endif
TESTCMD += $(KERNELFLAGS)
ifeq ($(filter userprog, $(KERNEL_SUBDIRS)), userprog)
TESTCMD += -f
diff --git a/src/tests/klaar/Make.tests b/src/tests/klaar/Make.tests
index 66b097a..bf2adc1 100644
--- a/src/tests/klaar/Make.tests
+++ b/src/tests/klaar/Make.tests
@@ -4,21 +4,35 @@ tests/%.output: FSDISK = 2
tests/%.output: PUTFILES = $(filter-out os.dsk, $^)
tests/klaar_TESTS = $(addprefix tests/klaar/,read-bad-buf low-mem \
-exec-corrupt)
+exec-corrupt pfs)
tests/klaar_PROGS = $(tests/klaar_TESTS) $(addprefix \
-tests/klaar/,child-simple)
+tests/klaar/,child-simple pfs-reader pfs-writer)
+# read-bad-buf
tests/klaar/read-bad-buf_SRC = tests/klaar/read-bad-buf.c tests/main.c
+tests/klaar/read-bad-buf_PUTFILES += tests/klaar/sample.txt
+
+# low-mem
tests/klaar/low-mem_SRC = tests/klaar/low-mem.c tests/main.c
+tests/klaar/child-simple_SRC = tests/klaar/child-simple.c
+tests/klaar/low-mem_PUTFILES += tests/klaar/child-simple
+
+# exec-corrupt
tests/klaar/exec-corrupt_SRC += tests/klaar/exec-corrupt.c tests/main.c
+tests/klaar/exec-corrupt_PUTFILES += tests/klaar/corrupt-elf
-tests/klaar/child-simple_SRC = tests/klaar/child-simple.c
+# pfs
+tests/klaar/pfs_SRC = tests/klaar/pfs.c
+tests/klaar/pfs-reader_SRC = tests/klaar/pfs-reader.c
+tests/klaar/pfs-writer_SRC = tests/klaar/pfs-writer.c
+tests/klaar/pfs_PUTFILES += tests/klaar/pfs-reader
+tests/klaar/pfs_PUTFILES += tests/klaar/pfs-writer
+tests/klaar/pfs_ARGS = 10 5
$(foreach prog,$(tests/klaar_PROGS),$(eval $(prog)_SRC += tests/lib.c))
-tests/klaar/read-bad-buf_PUTFILES += tests/klaar/sample.txt
-tests/klaar/low-mem_PUTFILES += tests/klaar/child-simple
-tests/klaar/exec-corrupt_PUTFILES += tests/klaar/corrupt-elf
-
tests/klaar/low-mem.output: KERNELFLAGS = -tcl=3
+
+tests/klaar/pfs.output: TIMEOUT = 180
+tests/klaar/pfs.output: KERNELFLAGS = -F=20000
diff --git a/src/tests/klaar/pfs-reader.c b/src/tests/klaar/pfs-reader.c
new file mode 100644
index 0000000..e6b4363
--- /dev/null
+++ b/src/tests/klaar/pfs-reader.c
@@ -0,0 +1,44 @@
+/* Part of pfs.c suite.
+
+ Reads from the file and checks consistency.
+ The buffer should all contain the same character!!
+ */
+
+#include <syscall.h>
+#include <stdio.h>
+
+#include "../lib.h"
+#include "pfs.h"
+
+static bool check_consistency(char* buf, int size)
+{
+ for (int i = 1; i < size; ++i)
+ {
+ if (buf[0] != buf[i])
+ {
+ /* Ooops, inconsistency */
+ return false;
+ }
+ }
+ return true;
+}
+
+char buffer[BIG];
+
+int main (int argc UNUSED, char *argv[])
+{
+ test_name = argv[0];
+ quiet = true;
+
+ for (int i = 0; i < TIMES; ++i)
+ {
+ int id = open ("file.1");
+ CHECK ( id > 1, "open \"file.1\"");
+ int bytes = read(id, buffer, BIG);
+ CHECK ( bytes == BIG, "read \"file.1\"");
+ close(id);
+
+ CHECK ( check_consistency(buffer, BIG), "inconsistency");
+ }
+ return 0;
+}
diff --git a/src/tests/klaar/pfs-writer.c b/src/tests/klaar/pfs-writer.c
new file mode 100644
index 0000000..34d9685
--- /dev/null
+++ b/src/tests/klaar/pfs-writer.c
@@ -0,0 +1,52 @@
+/* Part of pfs.c suite.
+
+ Write on the disk. Each time the buffer is filled with same
+ character. Different character every time!
+ */
+
+#include <syscall.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "../lib.h"
+#include "pfs.h"
+
+static void fill_buffer(char* buf, int size, char c)
+{
+ for (int i = 0; i < size; i++)
+ {
+ buf[i] = c;
+ }
+}
+
+char buffer[BIG];
+
+int main (int argc, char *argv[])
+{
+ test_name = argv[0];
+ quiet = true;
+
+ if (argc != 3 || strlen(argv[1]) != 1 || strlen(argv[2]) != 1)
+ return 1;
+
+ char start = argv[1][0];
+ char end = argv[2][0];
+
+ char c = start;
+ for (int i = 0; i < TIMES; ++i)
+ {
+ fill_buffer(buffer, BIG, c);
+
+ int id = open ("file.1");
+ CHECK ( id > 1, "open \"file.1\"");
+ int bytes = write(id, buffer, BIG);
+ CHECK ( bytes == BIG, "write \"file.1\"");
+ close(id);
+
+ c = c + 1;
+
+ if ( c > end )
+ c = start;
+ }
+ return 0;
+}
diff --git a/src/tests/klaar/pfs.c b/src/tests/klaar/pfs.c
new file mode 100644
index 0000000..fe1c3d7
--- /dev/null
+++ b/src/tests/klaar/pfs.c
@@ -0,0 +1,83 @@
+/* klaar@ida (convert to built-in pintos test)
+
+ Tests that read and write are properly synchronized. Also stresses
+ the filesystem somewhat.
+
+ pfs_reader and pfs_writer are needed child processes.
+*/
+
+#include <syscall.h>
+#include <random.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../lib.h"
+#include "pfs.h"
+
+static void swap(char* a, char* b)
+{
+ char c = *a;
+ *a = *b;
+ *b = c;
+}
+
+static void start_rw(int rn, int wn)
+{
+ int rpid = -1;
+ int wpid = -1;
+
+ if ( rn > 0 )
+ {
+ rpid = exec ("pfs-reader");
+ msg ("exec(\"pfs-reader\"): %d", rpid);
+ }
+
+ if ( wn > 0 )
+ {
+ int range = '~' - '!' + 1; // ascii 32 - 126
+ char start = '!' + random_ulong () % range;
+ char end = '!' + random_ulong () % range;
+
+ if ( end < start )
+ swap(&start, &end);
+
+ const int CMDSIZE = 64;
+ char cmd[CMDSIZE];
+ snprintf (cmd, CMDSIZE, "pfs-writer %c %c", start, end);
+
+ wpid = exec (cmd);
+ msg ("exec(\"%s\"): %d", cmd, wpid);
+ }
+
+ if ( rn > 0 || wn > 0 )
+ start_rw(rn-1, wn-1);
+
+ if ( rpid != -1 )
+ CHECK( wait( rpid ) != -1, "wait pfs-reader %d", rpid);
+
+ if ( wpid != -1 )
+ CHECK( wait( wpid ) != -1, "wait pfs-writer %d", wpid);
+}
+
+int main (int argc, char *argv[])
+{
+ if ( argc != 3 )
+ fail("usage: pfs START END");
+
+ quiet = true;
+ test_name = argv[0];
+ int num_reader = atoi(argv[1]);
+ int num_writer = atoi(argv[2]);
+
+ msg ("begin");
+
+ CHECK (create ("file.1", BIG), "create \"file.1\"");
+ CHECK (create ("messages", TIMES), "create \"messages\"");
+
+ random_init (0);
+
+ start_rw(num_reader, num_writer);
+
+ msg ("end");
+ return 0;
+}
diff --git a/src/tests/klaar/pfs.ck b/src/tests/klaar/pfs.ck
new file mode 100644
index 0000000..7e16ccf
--- /dev/null
+++ b/src/tests/klaar/pfs.ck
@@ -0,0 +1,7 @@
+# -*- perl -*-
+use strict;
+use warnings;
+use tests::tests;
+check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
+EOF
+pass;
diff --git a/src/tests/klaar/pfs.h b/src/tests/klaar/pfs.h
new file mode 100644
index 0000000..2ba7fce
--- /dev/null
+++ b/src/tests/klaar/pfs.h
@@ -0,0 +1,2 @@
+#define BIG 3000
+#define TIMES 500