Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / vm / page-linear.c
1 #include <string.h>
2 #include "tests/arc4.h"
3 #include "tests/lib.h"
4 #include "tests/main.h"
5
6 #define SIZE (1024 * 1024)
7
8 static char buf[SIZE];
9
10 void
11 test_main (void)
12 {
13   struct arc4 arc4;
14   size_t i;
15
16   /* Initialize to 0x5a. */
17   msg ("initialize");
18   memset (buf, 0x5a, sizeof buf);
19
20   /* Check that it's all 0x5a. */
21   msg ("read pass");
22   for (i = 0; i < SIZE; i++)
23     if (buf[i] != 0x5a)
24       fail ("byte %zu != 0x5a", i);
25
26   /* Encrypt zeros. */
27   msg ("read/modify/write pass one");
28   arc4_init (&arc4, "foobar", 6);
29   arc4_crypt (&arc4, buf, SIZE);
30
31   /* Decrypt back to zeros. */
32   msg ("read/modify/write pass two");
33   arc4_init (&arc4, "foobar", 6);
34   arc4_crypt (&arc4, buf, SIZE);
35
36   /* Check that it's all 0x5a. */
37   msg ("read pass");
38   for (i = 0; i < SIZE; i++)
39     if (buf[i] != 0x5a)
40       fail ("byte %zu != 0x5a", i);
41 }