Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / vm / child-sort.c
diff --git a/src/tests/vm/child-sort.c b/src/tests/vm/child-sort.c
new file mode 100644 (file)
index 0000000..638a66d
--- /dev/null
@@ -0,0 +1,38 @@
+#include <debug.h>
+#include <syscall.h>
+#include "tests/lib.h"
+#include "tests/main.h"
+
+const char *test_name = "child-sort";
+
+unsigned char buf[128 * 1024];
+size_t histogram[256];
+
+int
+main (int argc UNUSED, char *argv[]) 
+{
+  int handle;
+  unsigned char *p;
+  size_t size;
+  size_t i;
+
+  quiet = true;
+
+  CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
+
+  size = read (handle, buf, sizeof buf);
+  for (i = 0; i < size; i++)
+    histogram[buf[i]]++;
+  p = buf;
+  for (i = 0; i < sizeof histogram / sizeof *histogram; i++) 
+    {
+      size_t j = histogram[i];
+      while (j-- > 0)
+        *p++ = i;
+    }
+  seek (handle, 0);
+  write (handle, buf, size);
+  close (handle);
+  
+  return 123;
+}