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