355f4ebfb2b3f5dd62cb8b83575d8296059a852b
[pintos-anon] / src / tests / vm / child-qsort.c
1 /* Reads a 128 kB file onto the stack and "sorts" the bytes in
2    it, using quick sort, a multi-pass divide and conquer
3    algorithm.  The sorted data is written back to the same file
4    in-place. */
5
6 #include <debug.h>
7 #include <syscall.h>
8 #include "tests/lib.h"
9 #include "tests/main.h"
10 #include "tests/vm/qsort.h"
11
12 const char *test_name = "child-qsort";
13
14 int
15 main (int argc UNUSED, char *argv[]) 
16 {
17   int handle;
18   unsigned char buf[128 * 1024];
19   size_t size;
20
21   quiet = true;
22
23   CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
24
25   size = read (handle, buf, sizeof buf);
26   qsort_bytes (buf, sizeof buf);
27   seek (handle, 0);
28   write (handle, buf, size);
29   close (handle);
30   
31   return 72;
32 }