Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / userprog / read-boundary.c
1 #include <string.h>
2 #include <syscall.h>
3 #include "tests/userprog/boundary.h"
4 #include "tests/userprog/sample.inc"
5 #include "tests/lib.h"
6 #include "tests/main.h"
7
8 void
9 test_main (void) 
10 {
11   int handle;
12   int byte_cnt;
13   char *buffer;
14
15   CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
16
17   buffer = get_boundary_area () - sizeof sample / 2;
18   byte_cnt = read (handle, buffer, sizeof sample - 1);
19   if (byte_cnt != sizeof sample - 1)
20     fail ("read() returned %d instead of %zu", byte_cnt, sizeof sample - 1);
21   else if (strcmp (sample, buffer)) 
22     {
23       msg ("expected text:\n%s", sample);
24       msg ("text actually read:\n%s", buffer);
25       fail ("expected text differs from actual");
26     }
27 }