Add more tests.
[pintos-anon] / grading / userprog / read-boundary.c
1 #include <inttypes.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <syscall.h>
5
6 char expected[] = {
7   "Amazing Electronic Fact: If you scuffed your feet long enough without\n"
8   "touching anything, you would build up so many electrons that your\n"
9   "finger would explode!  But this is nothing to worry about unless you\n"
10   "have carpeting.\n" 
11 };
12
13
14
15 static char *
16 mk_boundary_string (const char *src) 
17 {
18   static char dst[8192];
19   char *p = dst + (4096 - (uintptr_t) dst % 4096 - strlen (src) / 2);
20   strlcpy (p, src, 4096);
21   return p;
22 }
23
24 int
25 main (void) 
26 {
27   int handle;
28   int byte_cnt;
29   char *actual_p;
30
31   actual_p = mk_boundary_string (expected);
32
33   printf ("(read-boundary) begin\n");
34
35   handle = open ("sample.txt");
36   if (handle < 2)
37     printf ("(read-boundary) fail: open() returned %d\n", handle);
38
39   byte_cnt = read (handle, actual_p, sizeof expected - 1);
40   if (byte_cnt != sizeof expected - 1)
41     printf ("(read-boundary) fail: read() returned %d instead of %d\n",
42             byte_cnt, sizeof expected - 1);
43   else if (strcmp (expected, actual_p))
44     printf ("(read-boundary) fail: expected text differs from actual:\n%s",
45             actual_p);
46   
47   printf ("(read-boundary) end\n");
48   return 0;
49 }