FreeBSD ATF Makefile for Dummies The primary ATF documentation is sadly lacking in details for how you wire up Makefiles for some directories. This attempts to shed some light on this. = Kernel tests don't follow the placement rules = If you are trying to add an ATF test to some code under src/sys/ you don't put them in src/sys. Instead, these belong in src/tests/sys/. In this location they follow similar rules as elsewhere -- if you're writing a test for src/sys/net the tests belong in src/tests/sys/net/ = Wiring up the tests/ subdirectory = When adding a new tests/ directory somewhere in the tree, its important to wire it up to its parent Makefile so it can be seen by the build. The [https://wiki.freebsd.org/TestSuite/DeveloperHowTo FreeBSD instructions] say simply to "Edit the parent Makefile to recurse into the new subdirectory" but it doesn't tell you how to do that. A nieve reading says it's as simple as editing the parent directory's Makefile and adding this: .if ${MK_TESTS} != "no" SUBDIR+= tests .endif .include And that works ... sometimes. Unfortunately that makes some huge assumptions about how the parent directory's Makefile is coded. For some Makefiles, like those in src/sbin/geom/class/part, this won't work. That Makefile looks like this: # $FreeBSD$ .PATH: ${.CURDIR}/../../misc GEOM_CLASS= part DPADD= ${LIBUTIL} LDADD= -lutil .include Adding the SUBDIR stuff to the end of this file won't work. bsd.lib.mk does some things that will skip subdirectory processing so you have to move it above that: # $FreeBSD$ .PATH: ${.CURDIR}/../../misc GEOM_CLASS= part DPADD= ${LIBUTIL} LDADD= -lutil .if ${MK_TESTS} != "no" SUBDIR+= tests .endif .include .include This won't work either though because MK_TESTS isn't defined yet. That doesn't get defined until bsd.own.mk gets pulled in through bsd.lib.mk. To resolve that, you need to include that at the top of the file: # $FreeBSD$ .include .PATH: ${.CURDIR}/../../misc GEOM_CLASS= part DPADD= ${LIBUTIL} LDADD= -lutil .if ${MK_TESTS} != "no" SUBDIR+= tests .endif .include .include Success! This is now pulling in the part/tests/ directory and the files are being laid out in the /usr/tests directory: [root /usr/tests]# find sbin/geom sbin/geom sbin/geom/class sbin/geom/class/part sbin/geom/class/part/t_gpart sbin/geom/class/part/Kyuafile Except kyua can't find them: [root /usr/tests]# kyua list | grep gpart [root /usr/tests]# = Wiring up all tests/ directory ancestors = kyua relies on each directory under /usr/tests with subdirectories to contain a Kyuafile. If you've added a deep subdirectory (like in the sbin/geom/class/part example above) these intermediary Kyuafiles won't exist. To fix that every ancestor directory of your tests directory also need a tests/ directory and a Makefile that looks similar to this: # $FreeBSD$ .include TESTSDIR= ${TESTSBASE}/sbin/geom/class .PATH: ${.CURDIR:H:H:H}/tests KYUAFILE= yes .include TESTSDIR should point to the directory that the Kyuafile will end up in /usr/tests (just like any other TESTSDIR). .PATH: needs to point to the src/tests directory where the Kyuafile will be pulled in from. The :H syntax in ${.CURDIR} specifies a relative path to ${.CURDIR}. ${.CURDIR} is the current working directory, ${.CURDIR:H} is the parent directory of the current working directory, ${.CURDIR:H:H} is the parent's parent directory, etc. So ${.CURDIR:H:H:H}/tests points to ../../../tests. In the case of sys/sbin/geom/class/, that resolves to sys/tests/. KYUAFILE=yes tells the Makefile to pull an existing Kyuafile, not to create one itself. It is critical to get .PATH set up correctly so the Kyuafile can be found by the build. Now for each of these new tests/ directories, you need to wire them up to the parent directory's Makefile per the instructions above. This means that to add tests within sbin/geom/class/part/tests you'll need to create the following additional directories: sbin/geom/tests sbin/geom/class/tests And populate them with customized Makefiles: sbin/geom/tests/Makefile sbin/geom/class/tests/Makefile The sbin/tests directory already exists, or we would have needed to add that too.