diff --git a/tests/.gitignore b/tests/.gitignore
index 0d8fa6e5e417f76c6e61379a5c6d4883a6359bb8..3559f9e1a539a05c2554db73e34c8646b02ed8aa 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,54 +1,34 @@
 # Automatically generated by 'make ignore'
 /*.out
 /gen/
-alloc
 args
 arpainet
-asctime
 assert
-atof
-atoi
-brk
-chdir
-create
 ctype
-dup
-env
 error
-exec
-fchdir
-fcntl
-fsync
-ftruncate
-getc_unget
-gethostname
-getid
-gmtime
-link
+fcntl/create
+fcntl/fcntl
 locale
-localtime
 math
-mem
-mktime
-mkostemps
-pipe
-printf
-rename
-rmdir
-scanf
-setid
 setjmp
-sleep
-sprintf
 stdio/all
 stdio/freopen
 stdio/fwrite
+stdio/getc_unget
+stdio/printf
+stdio/rename
+stdio/scanf
+stdio/sprintf
 stdlib/a64l
-stdlib/bsearch
-stdlib/mktemp
+stdlib/atof
+stdlib/atoi
+stdlib/env
+stdlib/mkostemps
 stdlib/rand
 stdlib/strtol
 stdlib/strtoul
+stdlib/system
+string/mem
 string/strchr
 string/strcspn
 string/strncmp
@@ -58,15 +38,35 @@ string/strspn
 string/strstr
 string/strtok
 string/strtok_r
-strftime
 strings
-system
-time
+time/asctime
+time/gmtime
+time/localtime
+time/mktime
+time/strftime
+time/time
+unistd/brk
+unistd/dup
+unistd/exec
+unistd/fchdir
+unistd/fsync
+unistd/ftruncate
 unistd/getopt
-unlink
+unistd/pipe
+unistd/rmdir
+unistd/sleep
+unistd/write
 waitpid
 wchar/mbrtowc
 wchar/mbsrtowcs
 wchar/putwchar
 wchar/wcrtomb
-write
+stdlib/alloc
+stdlib/bsearch
+stdlib/mktemp
+unistd/chdir
+unistd/gethostname
+unistd/getid
+unistd/link
+unistd/setid
+unistd/unlink
diff --git a/tests/Makefile b/tests/Makefile
index e60abb595635caac880f525e523b4d5e159c6c29..8878777da19cf56253bb7852d84b49dc4694990e 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,78 +1,78 @@
 # Binaries that should generate the same output every time
 EXPECT_BINS=\
+	args \
 	arpainet \
 	assert \
-	atof \
-	atoi \
-	brk \
-	args \
-	create \
 	ctype \
-	dup \
-	env \
 	error \
-	exec \
-	fchdir \
-	fcntl \
-	fsync \
-	ftruncate \
-	getc_unget \
+	fcntl/create \
+	fcntl/fcntl \
 	locale \
-	localtime \
 	math \
-	mem \
-	mktime \
-	mkostemps \
-	pipe \
-	printf \
-	rename \
-	rmdir \
-	scanf \
 	setjmp \
-	sleep \
-	sprintf \
-	strftime \
-	strings \
-	stdio/fwrite \
 	stdio/all \
 	stdio/freopen \
-	stdlib/strtol \
-	stdlib/strtoul \
+	stdio/fwrite \
+	stdio/getc_unget \
+	stdio/printf \
+	stdio/rename \
+	stdio/scanf \
+	stdio/sprintf \
 	stdlib/a64l \
+	stdlib/atof \
+	stdlib/atoi \
+	stdlib/env \
+	stdlib/mkostemps \
 	stdlib/rand \
-	string/strncmp \
-	string/strcspn \
+	stdlib/strtol \
+	stdlib/strtoul \
+	stdlib/system \
+	string/mem \
 	string/strchr \
+	string/strcspn \
+	string/strncmp \
+	string/strpbrk \
 	string/strrchr \
 	string/strspn \
 	string/strstr \
-	string/strpbrk \
 	string/strtok \
 	string/strtok_r \
-	system \
+	strings \
+	time/asctime \
+	time/gmtime \
+	time/localtime \
+	time/mktime \
+	time/strftime \
+	time/time \
+	unistd/brk \
+	unistd/dup \
+	unistd/exec \
+	unistd/fchdir \
+	unistd/fsync \
+	unistd/ftruncate \
 	unistd/getopt \
+	unistd/pipe \
+	unistd/rmdir \
+	unistd/sleep \
+	unistd/write \
 	waitpid \
 	wchar/mbrtowc \
 	wchar/mbsrtowcs \
 	wchar/putwchar \
-	wchar/wcrtomb \
-	write \
-	time \
-	gmtime \
-	asctime
+	wchar/wcrtomb
 
 # Binaries that may generate varied output
 BINS=\
 	$(EXPECT_BINS) \
-	alloc \
-	chdir \
-	gethostname \
-	getid \
-	link \
-	setid \
+	stdlib/alloc \
 	stdlib/bsearch \
 	stdlib/mktemp \
-	unlink
+	unistd/chdir \
+	unistd/gethostname \
+	unistd/getid \
+	unistd/link \
+	unistd/setid \
+	unistd/unlink
 
 all: $(BINS)
 
diff --git a/tests/expected/exec.stdout b/tests/expected/exec.stdout
deleted file mode 100644
index 980a0d5f19a64b4b30a87d4206aade58726b60e3..0000000000000000000000000000000000000000
--- a/tests/expected/exec.stdout
+++ /dev/null
@@ -1 +0,0 @@
-Hello World!
diff --git a/tests/expected/create.stderr b/tests/expected/fcntl/create.stderr
similarity index 100%
rename from tests/expected/create.stderr
rename to tests/expected/fcntl/create.stderr
diff --git a/tests/expected/create.stdout b/tests/expected/fcntl/create.stdout
similarity index 100%
rename from tests/expected/create.stdout
rename to tests/expected/fcntl/create.stdout
diff --git a/tests/expected/fcntl.stderr b/tests/expected/fcntl/fcntl.stderr
similarity index 100%
rename from tests/expected/fcntl.stderr
rename to tests/expected/fcntl/fcntl.stderr
diff --git a/tests/expected/fcntl.stdout b/tests/expected/fcntl/fcntl.stdout
similarity index 100%
rename from tests/expected/fcntl.stdout
rename to tests/expected/fcntl/fcntl.stdout
diff --git a/tests/expected/getc_unget.stderr b/tests/expected/stdio/getc_unget.stderr
similarity index 100%
rename from tests/expected/getc_unget.stderr
rename to tests/expected/stdio/getc_unget.stderr
diff --git a/tests/expected/getc_unget.stdout b/tests/expected/stdio/getc_unget.stdout
similarity index 100%
rename from tests/expected/getc_unget.stdout
rename to tests/expected/stdio/getc_unget.stdout
diff --git a/tests/expected/printf.stderr b/tests/expected/stdio/printf.stderr
similarity index 100%
rename from tests/expected/printf.stderr
rename to tests/expected/stdio/printf.stderr
diff --git a/tests/expected/printf.stdout b/tests/expected/stdio/printf.stdout
similarity index 100%
rename from tests/expected/printf.stdout
rename to tests/expected/stdio/printf.stdout
diff --git a/tests/expected/rename.stderr b/tests/expected/stdio/rename.stderr
similarity index 100%
rename from tests/expected/rename.stderr
rename to tests/expected/stdio/rename.stderr
diff --git a/tests/expected/rename.stdout b/tests/expected/stdio/rename.stdout
similarity index 100%
rename from tests/expected/rename.stdout
rename to tests/expected/stdio/rename.stdout
diff --git a/tests/expected/scanf.stderr b/tests/expected/stdio/scanf.stderr
similarity index 100%
rename from tests/expected/scanf.stderr
rename to tests/expected/stdio/scanf.stderr
diff --git a/tests/expected/scanf.stdout b/tests/expected/stdio/scanf.stdout
similarity index 100%
rename from tests/expected/scanf.stdout
rename to tests/expected/stdio/scanf.stdout
diff --git a/tests/expected/sprintf.stderr b/tests/expected/stdio/sprintf.stderr
similarity index 100%
rename from tests/expected/sprintf.stderr
rename to tests/expected/stdio/sprintf.stderr
diff --git a/tests/expected/sprintf.stdout b/tests/expected/stdio/sprintf.stdout
similarity index 100%
rename from tests/expected/sprintf.stdout
rename to tests/expected/stdio/sprintf.stdout
diff --git a/tests/expected/atof.stderr b/tests/expected/stdlib/atof.stderr
similarity index 100%
rename from tests/expected/atof.stderr
rename to tests/expected/stdlib/atof.stderr
diff --git a/tests/expected/atof.stdout b/tests/expected/stdlib/atof.stdout
similarity index 100%
rename from tests/expected/atof.stdout
rename to tests/expected/stdlib/atof.stdout
diff --git a/tests/expected/atoi.stderr b/tests/expected/stdlib/atoi.stderr
similarity index 100%
rename from tests/expected/atoi.stderr
rename to tests/expected/stdlib/atoi.stderr
diff --git a/tests/expected/atoi.stdout b/tests/expected/stdlib/atoi.stdout
similarity index 100%
rename from tests/expected/atoi.stdout
rename to tests/expected/stdlib/atoi.stdout
diff --git a/tests/expected/env.stderr b/tests/expected/stdlib/env.stderr
similarity index 100%
rename from tests/expected/env.stderr
rename to tests/expected/stdlib/env.stderr
diff --git a/tests/expected/env.stdout b/tests/expected/stdlib/env.stdout
similarity index 100%
rename from tests/expected/env.stdout
rename to tests/expected/stdlib/env.stdout
diff --git a/tests/expected/mkostemps.stderr b/tests/expected/stdlib/mkostemps.stderr
similarity index 100%
rename from tests/expected/mkostemps.stderr
rename to tests/expected/stdlib/mkostemps.stderr
diff --git a/tests/expected/mkostemps.stdout b/tests/expected/stdlib/mkostemps.stdout
similarity index 100%
rename from tests/expected/mkostemps.stdout
rename to tests/expected/stdlib/mkostemps.stdout
diff --git a/tests/expected/system.stderr b/tests/expected/stdlib/system.stderr
similarity index 100%
rename from tests/expected/system.stderr
rename to tests/expected/stdlib/system.stderr
diff --git a/tests/expected/system.stdout b/tests/expected/stdlib/system.stdout
similarity index 100%
rename from tests/expected/system.stdout
rename to tests/expected/stdlib/system.stdout
diff --git a/tests/expected/mem.stderr b/tests/expected/string/mem.stderr
similarity index 100%
rename from tests/expected/mem.stderr
rename to tests/expected/string/mem.stderr
diff --git a/tests/expected/mem.stdout b/tests/expected/string/mem.stdout
similarity index 100%
rename from tests/expected/mem.stdout
rename to tests/expected/string/mem.stdout
diff --git a/tests/expected/asctime.stderr b/tests/expected/time/asctime.stderr
similarity index 100%
rename from tests/expected/asctime.stderr
rename to tests/expected/time/asctime.stderr
diff --git a/tests/expected/asctime.stdout b/tests/expected/time/asctime.stdout
similarity index 100%
rename from tests/expected/asctime.stdout
rename to tests/expected/time/asctime.stdout
diff --git a/tests/expected/gmtime.stderr b/tests/expected/time/gmtime.stderr
similarity index 100%
rename from tests/expected/gmtime.stderr
rename to tests/expected/time/gmtime.stderr
diff --git a/tests/expected/gmtime.stdout b/tests/expected/time/gmtime.stdout
similarity index 100%
rename from tests/expected/gmtime.stdout
rename to tests/expected/time/gmtime.stdout
diff --git a/tests/expected/localtime.stderr b/tests/expected/time/localtime.stderr
similarity index 100%
rename from tests/expected/localtime.stderr
rename to tests/expected/time/localtime.stderr
diff --git a/tests/expected/localtime.stdout b/tests/expected/time/localtime.stdout
similarity index 100%
rename from tests/expected/localtime.stdout
rename to tests/expected/time/localtime.stdout
diff --git a/tests/expected/mktime.stderr b/tests/expected/time/mktime.stderr
similarity index 100%
rename from tests/expected/mktime.stderr
rename to tests/expected/time/mktime.stderr
diff --git a/tests/expected/mktime.stdout b/tests/expected/time/mktime.stdout
similarity index 100%
rename from tests/expected/mktime.stdout
rename to tests/expected/time/mktime.stdout
diff --git a/tests/expected/strftime.stderr b/tests/expected/time/strftime.stderr
similarity index 100%
rename from tests/expected/strftime.stderr
rename to tests/expected/time/strftime.stderr
diff --git a/tests/expected/strftime.stdout b/tests/expected/time/strftime.stdout
similarity index 100%
rename from tests/expected/strftime.stdout
rename to tests/expected/time/strftime.stdout
diff --git a/tests/expected/time.stderr b/tests/expected/time/time.stderr
similarity index 100%
rename from tests/expected/time.stderr
rename to tests/expected/time/time.stderr
diff --git a/tests/expected/time.stdout b/tests/expected/time/time.stdout
similarity index 100%
rename from tests/expected/time.stdout
rename to tests/expected/time/time.stdout
diff --git a/tests/expected/brk.stderr b/tests/expected/unistd/brk.stderr
similarity index 100%
rename from tests/expected/brk.stderr
rename to tests/expected/unistd/brk.stderr
diff --git a/tests/expected/brk.stdout b/tests/expected/unistd/brk.stdout
similarity index 100%
rename from tests/expected/brk.stdout
rename to tests/expected/unistd/brk.stdout
diff --git a/tests/expected/dup.stderr b/tests/expected/unistd/dup.stderr
similarity index 100%
rename from tests/expected/dup.stderr
rename to tests/expected/unistd/dup.stderr
diff --git a/tests/expected/dup.stdout b/tests/expected/unistd/dup.stdout
similarity index 100%
rename from tests/expected/dup.stdout
rename to tests/expected/unistd/dup.stdout
diff --git a/tests/expected/unistd/exec.stderr b/tests/expected/unistd/exec.stderr
new file mode 100644
index 0000000000000000000000000000000000000000..1c76386e5d7dea9e50100ac8acc77cf62d9e3d26
--- /dev/null
+++ b/tests/expected/unistd/exec.stderr
@@ -0,0 +1 @@
+execv: No such file or directory
diff --git a/tests/expected/exec.stderr b/tests/expected/unistd/exec.stdout
similarity index 100%
rename from tests/expected/exec.stderr
rename to tests/expected/unistd/exec.stdout
diff --git a/tests/expected/fchdir.stderr b/tests/expected/unistd/fchdir.stderr
similarity index 100%
rename from tests/expected/fchdir.stderr
rename to tests/expected/unistd/fchdir.stderr
diff --git a/tests/expected/fchdir.stdout b/tests/expected/unistd/fchdir.stdout
similarity index 100%
rename from tests/expected/fchdir.stdout
rename to tests/expected/unistd/fchdir.stdout
diff --git a/tests/expected/fsync.stderr b/tests/expected/unistd/fsync.stderr
similarity index 100%
rename from tests/expected/fsync.stderr
rename to tests/expected/unistd/fsync.stderr
diff --git a/tests/expected/fsync.stdout b/tests/expected/unistd/fsync.stdout
similarity index 100%
rename from tests/expected/fsync.stdout
rename to tests/expected/unistd/fsync.stdout
diff --git a/tests/expected/ftruncate.stderr b/tests/expected/unistd/ftruncate.stderr
similarity index 100%
rename from tests/expected/ftruncate.stderr
rename to tests/expected/unistd/ftruncate.stderr
diff --git a/tests/expected/ftruncate.stdout b/tests/expected/unistd/ftruncate.stdout
similarity index 100%
rename from tests/expected/ftruncate.stdout
rename to tests/expected/unistd/ftruncate.stdout
diff --git a/tests/expected/pipe.stderr b/tests/expected/unistd/pipe.stderr
similarity index 100%
rename from tests/expected/pipe.stderr
rename to tests/expected/unistd/pipe.stderr
diff --git a/tests/expected/pipe.stdout b/tests/expected/unistd/pipe.stdout
similarity index 100%
rename from tests/expected/pipe.stdout
rename to tests/expected/unistd/pipe.stdout
diff --git a/tests/expected/rmdir.stderr b/tests/expected/unistd/rmdir.stderr
similarity index 100%
rename from tests/expected/rmdir.stderr
rename to tests/expected/unistd/rmdir.stderr
diff --git a/tests/expected/rmdir.stdout b/tests/expected/unistd/rmdir.stdout
similarity index 100%
rename from tests/expected/rmdir.stdout
rename to tests/expected/unistd/rmdir.stdout
diff --git a/tests/expected/sleep.stderr b/tests/expected/unistd/sleep.stderr
similarity index 100%
rename from tests/expected/sleep.stderr
rename to tests/expected/unistd/sleep.stderr
diff --git a/tests/expected/sleep.stdout b/tests/expected/unistd/sleep.stdout
similarity index 100%
rename from tests/expected/sleep.stdout
rename to tests/expected/unistd/sleep.stdout
diff --git a/tests/expected/write.stderr b/tests/expected/unistd/write.stderr
similarity index 100%
rename from tests/expected/write.stderr
rename to tests/expected/unistd/write.stderr
diff --git a/tests/expected/write.stdout b/tests/expected/unistd/write.stdout
similarity index 100%
rename from tests/expected/write.stdout
rename to tests/expected/unistd/write.stdout
diff --git a/tests/create.c b/tests/fcntl/create.c
similarity index 100%
rename from tests/create.c
rename to tests/fcntl/create.c
diff --git a/tests/fcntl.c b/tests/fcntl/fcntl.c
similarity index 100%
rename from tests/fcntl.c
rename to tests/fcntl/fcntl.c
diff --git a/tests/getc_unget.c b/tests/stdio/getc_unget.c
similarity index 100%
rename from tests/getc_unget.c
rename to tests/stdio/getc_unget.c
diff --git a/tests/printf.c b/tests/stdio/printf.c
similarity index 100%
rename from tests/printf.c
rename to tests/stdio/printf.c
diff --git a/tests/rename.c b/tests/stdio/rename.c
similarity index 100%
rename from tests/rename.c
rename to tests/stdio/rename.c
diff --git a/tests/scanf.c b/tests/stdio/scanf.c
similarity index 100%
rename from tests/scanf.c
rename to tests/stdio/scanf.c
diff --git a/tests/sprintf.c b/tests/stdio/sprintf.c
similarity index 100%
rename from tests/sprintf.c
rename to tests/stdio/sprintf.c
diff --git a/tests/alloc.c b/tests/stdlib/alloc.c
similarity index 100%
rename from tests/alloc.c
rename to tests/stdlib/alloc.c
diff --git a/tests/atof.c b/tests/stdlib/atof.c
similarity index 100%
rename from tests/atof.c
rename to tests/stdlib/atof.c
diff --git a/tests/atoi.c b/tests/stdlib/atoi.c
similarity index 100%
rename from tests/atoi.c
rename to tests/stdlib/atoi.c
diff --git a/tests/env.c b/tests/stdlib/env.c
similarity index 100%
rename from tests/env.c
rename to tests/stdlib/env.c
diff --git a/tests/mkostemps.c b/tests/stdlib/mkostemps.c
similarity index 100%
rename from tests/mkostemps.c
rename to tests/stdlib/mkostemps.c
diff --git a/tests/system.c b/tests/stdlib/system.c
similarity index 100%
rename from tests/system.c
rename to tests/stdlib/system.c
diff --git a/tests/mem.c b/tests/string/mem.c
similarity index 100%
rename from tests/mem.c
rename to tests/string/mem.c
diff --git a/tests/asctime.c b/tests/time/asctime.c
similarity index 100%
rename from tests/asctime.c
rename to tests/time/asctime.c
diff --git a/tests/gmtime.c b/tests/time/gmtime.c
similarity index 100%
rename from tests/gmtime.c
rename to tests/time/gmtime.c
diff --git a/tests/localtime.c b/tests/time/localtime.c
similarity index 100%
rename from tests/localtime.c
rename to tests/time/localtime.c
diff --git a/tests/mktime.c b/tests/time/mktime.c
similarity index 100%
rename from tests/mktime.c
rename to tests/time/mktime.c
diff --git a/tests/strftime.c b/tests/time/strftime.c
similarity index 100%
rename from tests/strftime.c
rename to tests/time/strftime.c
diff --git a/tests/time.c b/tests/time/time.c
similarity index 100%
rename from tests/time.c
rename to tests/time/time.c
diff --git a/tests/brk.c b/tests/unistd/brk.c
similarity index 100%
rename from tests/brk.c
rename to tests/unistd/brk.c
diff --git a/tests/chdir.c b/tests/unistd/chdir.c
similarity index 100%
rename from tests/chdir.c
rename to tests/unistd/chdir.c
diff --git a/tests/dup.c b/tests/unistd/dup.c
similarity index 100%
rename from tests/dup.c
rename to tests/unistd/dup.c
diff --git a/tests/exec.c b/tests/unistd/exec.c
similarity index 100%
rename from tests/exec.c
rename to tests/unistd/exec.c
diff --git a/tests/fchdir.c b/tests/unistd/fchdir.c
similarity index 100%
rename from tests/fchdir.c
rename to tests/unistd/fchdir.c
diff --git a/tests/fsync.c b/tests/unistd/fsync.c
similarity index 100%
rename from tests/fsync.c
rename to tests/unistd/fsync.c
diff --git a/tests/ftruncate.c b/tests/unistd/ftruncate.c
similarity index 100%
rename from tests/ftruncate.c
rename to tests/unistd/ftruncate.c
diff --git a/tests/gethostname.c b/tests/unistd/gethostname.c
similarity index 100%
rename from tests/gethostname.c
rename to tests/unistd/gethostname.c
diff --git a/tests/getid.c b/tests/unistd/getid.c
similarity index 100%
rename from tests/getid.c
rename to tests/unistd/getid.c
diff --git a/tests/link.c b/tests/unistd/link.c
similarity index 100%
rename from tests/link.c
rename to tests/unistd/link.c
diff --git a/tests/pipe.c b/tests/unistd/pipe.c
similarity index 100%
rename from tests/pipe.c
rename to tests/unistd/pipe.c
diff --git a/tests/rmdir.c b/tests/unistd/rmdir.c
similarity index 100%
rename from tests/rmdir.c
rename to tests/unistd/rmdir.c
diff --git a/tests/setid.c b/tests/unistd/setid.c
similarity index 100%
rename from tests/setid.c
rename to tests/unistd/setid.c
diff --git a/tests/sleep.c b/tests/unistd/sleep.c
similarity index 100%
rename from tests/sleep.c
rename to tests/unistd/sleep.c
diff --git a/tests/unlink.c b/tests/unistd/unlink.c
similarity index 100%
rename from tests/unlink.c
rename to tests/unistd/unlink.c
diff --git a/tests/write.c b/tests/unistd/write.c
similarity index 100%
rename from tests/write.c
rename to tests/unistd/write.c