Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / userprog / boundary.c
1 #include <inttypes.h>
2 #include <round.h>
3 #include <string.h>
4 #include "tests/userprog/boundary.h"
5
6 static char dst[8192];
7
8 /* Returns the beginning of a page.  There are at least 2048
9    modifiable bytes on either side of the pointer returned. */
10 void *
11 get_boundary_area (void) 
12 {
13   char *p = (char *) ROUND_UP ((uintptr_t) dst, 4096);
14   if (p - dst < 2048)
15     p += 4096;
16   return p;
17 }
18
19 /* Returns a copy of SRC split across the boundary between two
20    pages. */
21 char *
22 copy_string_across_boundary (const char *src) 
23 {
24   char *p = get_boundary_area ();
25   p -= strlen (src) < 4096 ? strlen (src) / 2 : 4096;
26   strlcpy (p, src, 4096);
27   return p;
28 }
29