Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / vm / child-sort.c
1 #include <debug.h>
2 #include <syscall.h>
3 #include "tests/lib.h"
4 #include "tests/main.h"
5
6 const char *test_name = "child-sort";
7
8 unsigned char buf[128 * 1024];
9 size_t histogram[256];
10
11 int
12 main (int argc UNUSED, char *argv[]) 
13 {
14   int handle;
15   unsigned char *p;
16   size_t size;
17   size_t i;
18
19   quiet = true;
20
21   CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
22
23   size = read (handle, buf, sizeof buf);
24   for (i = 0; i < size; i++)
25     histogram[buf[i]]++;
26   p = buf;
27   for (i = 0; i < sizeof histogram / sizeof *histogram; i++) 
28     {
29       size_t j = histogram[i];
30       while (j-- > 0)
31         *p++ = i;
32     }
33   seek (handle, 0);
34   write (handle, buf, size);
35   close (handle);
36   
37   return 123;
38 }