aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/klaar
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
committerklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
commite7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad (patch)
tree4de97af7207676b69cb6a9aba8cb443cc134855d /src/tests/klaar
parentb0418a24e709f0632d2ede5b0f327c422931939b (diff)
downloadpintos-rs-e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad.tar.gz
Initial Pintos
Diffstat (limited to 'src/tests/klaar')
-rw-r--r--src/tests/klaar/Make.tests24
-rw-r--r--src/tests/klaar/child-simple.c15
-rw-r--r--src/tests/klaar/corrupt-elfbin0 -> 14398 bytes
-rw-r--r--src/tests/klaar/exec-corrupt.c14
-rw-r--r--src/tests/klaar/exec-corrupt.ck31
-rw-r--r--src/tests/klaar/low-mem.c15
-rw-r--r--src/tests/klaar/low-mem.ck11
-rw-r--r--src/tests/klaar/read-bad-buf.c24
-rw-r--r--src/tests/klaar/read-bad-buf.ck15
-rw-r--r--src/tests/klaar/sample.txt4
10 files changed, 153 insertions, 0 deletions
diff --git a/src/tests/klaar/Make.tests b/src/tests/klaar/Make.tests
new file mode 100644
index 0000000..66b097a
--- /dev/null
+++ b/src/tests/klaar/Make.tests
@@ -0,0 +1,24 @@
+# -*- makefile -*-
+
+tests/%.output: FSDISK = 2
+tests/%.output: PUTFILES = $(filter-out os.dsk, $^)
+
+tests/klaar_TESTS = $(addprefix tests/klaar/,read-bad-buf low-mem \
+exec-corrupt)
+
+tests/klaar_PROGS = $(tests/klaar_TESTS) $(addprefix \
+tests/klaar/,child-simple)
+
+tests/klaar/read-bad-buf_SRC = tests/klaar/read-bad-buf.c tests/main.c
+tests/klaar/low-mem_SRC = tests/klaar/low-mem.c tests/main.c
+tests/klaar/exec-corrupt_SRC += tests/klaar/exec-corrupt.c tests/main.c
+
+tests/klaar/child-simple_SRC = tests/klaar/child-simple.c
+
+$(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
diff --git a/src/tests/klaar/child-simple.c b/src/tests/klaar/child-simple.c
new file mode 100644
index 0000000..0d2dacf
--- /dev/null
+++ b/src/tests/klaar/child-simple.c
@@ -0,0 +1,15 @@
+/* Child process run by exec-multiple, exec-one, wait-simple, and
+ wait-twice tests.
+ Just prints a single message and terminates. */
+
+#include <stdio.h>
+#include "tests/lib.h"
+
+const char *test_name = "child-simple";
+
+int
+main (void)
+{
+ msg ("run");
+ return 81;
+}
diff --git a/src/tests/klaar/corrupt-elf b/src/tests/klaar/corrupt-elf
new file mode 100644
index 0000000..456421b
--- /dev/null
+++ b/src/tests/klaar/corrupt-elf
Binary files differ
diff --git a/src/tests/klaar/exec-corrupt.c b/src/tests/klaar/exec-corrupt.c
new file mode 100644
index 0000000..9f83692
--- /dev/null
+++ b/src/tests/klaar/exec-corrupt.c
@@ -0,0 +1,14 @@
+/*
+ Try to load a corrupt executable.
+ (klaar@ida)
+*/
+
+#include <syscall.h>
+#include "tests/lib.h"
+#include "tests/main.h"
+
+void
+test_main (void)
+{
+ msg ("exec(\"corrupt-elf\"): %d", exec ("corrupt-elf"));
+}
diff --git a/src/tests/klaar/exec-corrupt.ck b/src/tests/klaar/exec-corrupt.ck
new file mode 100644
index 0000000..d66eeee
--- /dev/null
+++ b/src/tests/klaar/exec-corrupt.ck
@@ -0,0 +1,31 @@
+# -*- perl -*-
+use strict;
+use warnings;
+use tests::tests;
+check_expected ([<<'EOF', <<'EOF', <<'EOF', <<'EOF']);
+(exec-corrupt) begin
+load: corrupt-elf: error loading executable
+(exec-corrupt) exec("corrupt-elf"): -1
+(exec-corrupt) end
+exec-corrupt: exit(0)
+EOF
+(exec-corrupt) begin
+(exec-corrupt) exec("corrupt-elf"): -1
+(exec-corrupt) end
+exec-corrupt: exit(0)
+EOF
+(exec-corrupt) begin
+load: corrupt-elf: error loading executable
+corrupt-elf: exit(-1)
+(exec-corrupt) exec("corrupt-elf"): -1
+(exec-corrupt) end
+exec-corrupt: exit(0)
+EOF
+(exec-corrupt) begin
+load: corrupt-elf: error loading executable
+(exec-corrupt) exec("corrupt-elf"): -1
+corrupt-elf: exit(-1)
+(exec-corrupt) end
+exec-corrupt: exit(0)
+EOF
+pass;
diff --git a/src/tests/klaar/low-mem.c b/src/tests/klaar/low-mem.c
new file mode 100644
index 0000000..8f1da3e
--- /dev/null
+++ b/src/tests/klaar/low-mem.c
@@ -0,0 +1,15 @@
+/*
+ Simulate a failure in thread_create.
+ A real reason for failure could be low memory.
+ (klaar@ida)
+*/
+
+#include <syscall.h>
+#include "tests/lib.h"
+#include "tests/main.h"
+
+void
+test_main (void)
+{
+ msg ("exec(\"child-simple\"): %d", exec ("child-simple"));
+}
diff --git a/src/tests/klaar/low-mem.ck b/src/tests/klaar/low-mem.ck
new file mode 100644
index 0000000..f128c30
--- /dev/null
+++ b/src/tests/klaar/low-mem.ck
@@ -0,0 +1,11 @@
+# -*- perl -*-
+use strict;
+use warnings;
+use tests::tests;
+check_expected ([<<'EOF']);
+(low-mem) begin
+(low-mem) exec("child-simple"): -1
+(low-mem) end
+low-mem: exit(0)
+EOF
+pass;
diff --git a/src/tests/klaar/read-bad-buf.c b/src/tests/klaar/read-bad-buf.c
new file mode 100644
index 0000000..1e41562
--- /dev/null
+++ b/src/tests/klaar/read-bad-buf.c
@@ -0,0 +1,24 @@
+/* Passes an semingly valid pointer to the read system call.
+ The pointer will however span invalid pages.
+ The process must be terminated with -1 exit code.
+ (klaar@ida)
+*/
+
+#include <syscall.h>
+#include "tests/lib.h"
+#include "tests/main.h"
+
+char global; /* allocated with process image */
+
+void
+test_main (void)
+{
+ int handle;
+ char local; /* allocated on process stack */
+
+ CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
+
+ /* buffer will start and end at valid addresses ... */
+ read (handle, (char *)&global, &local - &global + 1);
+ fail ("should not have survived read()");
+}
diff --git a/src/tests/klaar/read-bad-buf.ck b/src/tests/klaar/read-bad-buf.ck
new file mode 100644
index 0000000..22adc50
--- /dev/null
+++ b/src/tests/klaar/read-bad-buf.ck
@@ -0,0 +1,15 @@
+# -*- perl -*-
+use strict;
+use warnings;
+use tests::tests;
+check_expected ([<<'EOF', <<'EOF']);
+(read-bad-buf) begin
+(read-bad-buf) open "sample.txt"
+(read-bad-buf) end
+read-bad-buf: exit(0)
+EOF
+(read-bad-buf) begin
+(read-bad-buf) open "sample.txt"
+read-bad-buf: exit(-1)
+EOF
+pass;
diff --git a/src/tests/klaar/sample.txt b/src/tests/klaar/sample.txt
new file mode 100644
index 0000000..5050fec
--- /dev/null
+++ b/src/tests/klaar/sample.txt
@@ -0,0 +1,4 @@
+"Amazing Electronic Fact: If you scuffed your feet long enough without
+ touching anything, you would build up so many electrons that your
+ finger would explode! But this is nothing to worry about unless you
+ have carpeting." --Dave Barry