$(addprefix create-, normal empty null bad-ptr long exists bound) \
$(addprefix open-, normal missing boundary empty null bad-ptr twice) \
$(addprefix close-, normal twice stdin stdout bad-fd) \
- $(addprefix read-, normal bad-ptr boundary zero stdout bad-fd)
+ $(addprefix read-, normal bad-ptr boundary zero stdout bad-fd) \
+ $(addprefix write-, normal bad-ptr boundary zero stdin bad-fd)
define SINGLETON_PROG
PROGS += $(1)
qw (open-normal open-boundary open-twice
close-normal close-twice
read-normal read-bad-ptr read-boundary read-zero
- write-normal write-boundary write-zero));
+ write-normal write-bad-ptr write-boundary write-zero));
sub put_file {
my ($fn) = @_;
#include <stdio.h>
#include <string.h>
#include <syscall.h>
-
-char expected[] = {
- "Amazing Electronic Fact: If you scuffed your feet long enough without\n"
- "touching anything, you would build up so many electrons that your\n"
- "finger would explode! But this is nothing to worry about unless you\n"
- "have carpeting.\n"
-};
-
-
+#include "sample.inc"
static char *
mk_boundary_string (const char *src)
int byte_cnt;
char *actual_p;
- actual_p = mk_boundary_string (expected);
+ actual_p = mk_boundary_string (sample);
printf ("(read-boundary) begin\n");
if (handle < 2)
printf ("(read-boundary) fail: open() returned %d\n", handle);
- byte_cnt = read (handle, actual_p, sizeof expected - 1);
- if (byte_cnt != sizeof expected - 1)
+ byte_cnt = read (handle, actual_p, sizeof sample - 1);
+ if (byte_cnt != sizeof sample - 1)
printf ("(read-boundary) fail: read() returned %d instead of %d\n",
- byte_cnt, sizeof expected - 1);
- else if (strcmp (expected, actual_p))
+ byte_cnt, sizeof sample - 1);
+ else if (strcmp (sample, actual_p))
printf ("(read-boundary) fail: expected text differs from actual:\n%s",
actual_p);
#include <stdio.h>
#include <string.h>
#include <syscall.h>
+#include "sample.inc"
-char expected[] = {
- "Amazing Electronic Fact: If you scuffed your feet long enough without\n"
- "touching anything, you would build up so many electrons that your\n"
- "finger would explode! But this is nothing to worry about unless you\n"
- "have carpeting.\n"
-};
-
-char actual[sizeof expected];
+char actual[sizeof sample];
int
main (void)
if (byte_cnt != sizeof actual - 1)
printf ("(read-normal) fail: read() returned %d instead of %d\n",
byte_cnt, sizeof actual - 1);
- else if (strcmp (expected, actual))
+ else if (strcmp (sample, actual))
printf ("(read-normal) fail: expected text differs from actual:\n%s",
actual);
close-normal close-twice close-stdin close-stdout close-bad-fd
read-normal read-bad-ptr read-boundary read-zero read-stdout
read-bad-fd
+ write-normal write-bad-ptr write-boundary write-zero write-stdin
+ write-bad-fd
) unless @TESTS > 0;
our (%args);
my (@output) = snarf ("output/$test/run.out");
- if (-e "$GRADES_DIR/$test.exp") {
+ my ($grade_func) = "grade_$test";
+ $grade_func =~ s/-/_/g;
+ if (-e "$GRADES_DIR/$test.exp" && !defined (&$grade_func)) {
eval {
verify_common (@output);
compare_output ("$GRADES_DIR/$test.exp", @output);
}
} else {
- my ($grade_func);
- ($grade_func = $test) =~ s/-/_/g;
- eval "grade_$grade_func (\@output)";
+ eval "$grade_func (\@output)";
}
if ($@) {
die $@ if $@ =~ /at \S+ line \d+$/;
return "ok";
}
\f
-sub grade_alarm_multiple {
- verify_alarm (7, @_);
-}
-
-sub verify_alarm {
- my ($iterations, @output) = @_;
-
+sub grade_write_normal {
+ my (@output) = @_;
verify_common (@output);
-
- my (@products);
- for (my ($i) = 0; $i < $iterations; $i++) {
- for (my ($t) = 0; $t < 5; $t++) {
- push (@products, ($i + 1) * ($t + 1) * 10);
- }
- }
- @products = sort {$a <=> $b} @products;
-
- local ($_);
- foreach (@output) {
- die $_ if /Out of order/;
-
- my ($p) = /product=(\d+)$/;
- next if !defined $p;
-
- my ($q) = shift (@products);
- die "Too many wakeups.\n" if !defined $q;
- die "Out of order wakeups ($p vs. $q).\n" if $p != $q; # FIXME
- }
- die scalar (@products) . " fewer wakeups than expected.\n"
- if @products != 0;
+ compare_output ("$GRADES_DIR/write-normal.exp", @output);
+ my ($test_txt) = "output/$test/test.txt";
+ get_file ("test.txt", $test_txt) if ! -e $test_txt;
+ compare_output ("$GRADES_DIR/sample.txt", snarf ($test_txt));
}
-sub grade_alarm_zero {
- my (@output) = @_;
- verify_common (@output);
- die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output);
+sub get_file {
+ my ($guest_fn, $host_fn) = @_;
+ xsystem ("pintos "
+ . "--os-disk=pintos/src/userprog/build/os.dsk "
+ . "--fs-disk=output/$test/fs.dsk "
+ . "-v get $guest_fn $host_fn",
+ LOG => "$test/get-$guest_fn",
+ TIMEOUT => 10)
+ or die "get $guest_fn failed\n";
}
sub grade_alarm_negative {
--- /dev/null
+char sample[] = {
+ "Amazing Electronic Fact: If you scuffed your feet long enough without\n"
+ "touching anything, you would build up so many electrons that your\n"
+ "finger would explode! But this is nothing to worry about unless you\n"
+ "have carpeting.\n"
+};
--- /dev/null
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void)
+{
+ char buf = 123;
+ printf ("(write-bad-fd) begin\n");
+ write (0xc0101234, &buf, 1);
+ printf ("(write-bad-fd) end\n");
+ return 0;
+}
--- /dev/null
+(write-bad-fd) begin
+(write-bad-fd) end
+write-bad-fd: exit(0)
+--OR--
+(write-bad-fd) begin
+write-bad-fd: exit(-1)
--- /dev/null
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void)
+{
+ int handle;
+ printf ("(write-bad-ptr) begin\n");
+
+ handle = open ("sample.txt");
+ if (handle < 2)
+ printf ("(write-bad-ptr) fail: open() returned %d\n", handle);
+
+ write (handle, (char *) 0xc0101234, 123);
+
+ printf ("(write-bad-ptr) end\n");
+ return 0;
+}
--- /dev/null
+(write-bad-ptr) begin
+(write-bad-ptr) end
+write-bad-ptr: exit(0)
+--OR--
+(write-bad-ptr) begin
+write-bad-ptr: exit(-1)
--- /dev/null
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <syscall.h>
+#include "sample.inc"
+
+static char *
+mk_boundary_string (const char *src)
+{
+ static char dst[8192];
+ char *p = dst + (4096 - (uintptr_t) dst % 4096 - strlen (src) / 2);
+ strlcpy (p, src, 4096);
+ return p;
+}
+
+int
+main (void)
+{
+ int handle;
+ int byte_cnt;
+ char *sample_p;
+
+ sample_p = mk_boundary_string (sample);
+
+ printf ("(write-boundary) begin\n");
+
+ handle = open ("sample.txt");
+ if (handle < 2)
+ printf ("(write-boundary) fail: open() returned %d\n", handle);
+
+ byte_cnt = write (handle, sample_p, sizeof sample - 1);
+ if (byte_cnt != sizeof sample - 1)
+ printf ("(write-boundary) fail: write() returned %d instead of %d\n",
+ byte_cnt, sizeof sample - 1);
+
+ printf ("(write-boundary) end\n");
+ return 0;
+}
--- /dev/null
+(write-boundary) begin
+(write-boundary) end
+write-boundary: exit(0)
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <syscall.h>
+#include "sample.inc"
+
+int
+main (void)
+{
+ int handle, byte_cnt;
+ printf ("(write-normal) begin\n");
+
+ if (!create ("test.txt", sizeof sample - 1))
+ printf ("(write-normal) create() failed\n");
+
+ handle = open ("test.txt");
+ if (handle < 2)
+ printf ("(write-normal) fail: open() returned %d\n", handle);
+
+ byte_cnt = write (handle, sample, sizeof sample - 1);
+ if (byte_cnt != sizeof sample - 1)
+ printf ("(write-normal) fail: write() returned %d instead of %d\n",
+ byte_cnt, sizeof sample - 1);
+
+ printf ("(write-normal) end\n");
+ return 0;
+}
--- /dev/null
+(write-normal) begin
+(write-normal) end
+write-normal: exit(0)
--- /dev/null
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void)
+{
+ char buf = 123;
+ printf ("(write-stdin) begin\n");
+ write (0, &buf, 1);
+ printf ("(write-stdin) end\n");
+ return 0;
+}
--- /dev/null
+(write-stdin) begin
+(write-stdin) end
+write-stdin: exit(0)
+--OR--
+(write-stdin) begin
+write-stdin: exit(-1)
--- /dev/null
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void)
+{
+ int handle, byte_cnt;
+ char buf;
+ printf ("(write-zero) begin\n");
+
+ handle = open ("sample.txt");
+ if (handle < 2)
+ printf ("(write-zero) fail: open() returned %d\n", handle);
+
+ buf = 123;
+ byte_cnt = write (handle, &buf, 0);
+ if (byte_cnt != 0)
+ printf ("(write-zero) fail: write() returned %d instead of 0\n", byte_cnt);
+
+ printf ("(write-zero) end\n");
+ return 0;
+}
--- /dev/null
+(write-zero) begin
+(write-zero) end
+write-zero: exit(0)
VPATH = $(SRCDIR)
DEFINES = -DUSER
-CPPFLAGS = -nostdinc -I$(SRCDIR) -I- -I$(SRCDIR)/lib -I$(SRCDIR)/lib/user
+CPPFLAGS = -nostdinc -I$(SRCDIR) -I- -I$(SRCDIR)/lib -I$(SRCDIR)/lib/user -I.
# Linker flags.
LDFLAGS = -nostdlib -static -s