Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Apr 2014 22:28:37 +0000
From:      "Peel, Casey" <casey.peel@isilon.com>
To:        Julio Merino <jmmv@freebsd.org>
Cc:        "freebsd-testing@freebsd.org" <freebsd-testing@freebsd.org>
Subject:   RE: Makefiles for skip-level directories?
Message-ID:  <16437CC5729B5345AF77F816513376E820BACB49@MX103CL02.corp.emc.com>
References:  <16437CC5729B5345AF77F816513376E8129868F1@MX103CL02.corp.emc.com> <CAFY7cWD2A_B949Fp7Pp5rKysNbQE_LqBJh%2BwYD1-v8uGcLEXBw@mail.gmail.com> <16437CC5729B5345AF77F816513376E820BAA20A@MX103CL02.corp.emc.com> <CAFY7cWD52sSES%2BLqFr6T6-=WREF7iF=HGTDuKov4NhJ9_dmxng@mail.gmail.com> 

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Ok, I figured it out and wrote up the following document (that is published on our internal wiki). You may take whatever you want of this for the FreeBSD wiki if you find it useful.

Something rcattelan pointed out while doing the code review for my gpart changes that I wanted to run past you:
<daelf> is the include bsd.own.mk to pick up MK_TESTS?
<cpeel> yes
<daelf> do you need to do that in the files that are not look at MK_TESTS?
<daelf> geom/tests/Makefile ?
<cpeel> I probably don't have to, but that's how the other Makefiles like that are done in FreeBSD, eg: src/bin/tests/Makefile
<daelf> bsd.own.mk is included by bsd.init.mk which is included by bsd.test.mk 
<daelf> so it seems redundant
<daelf> maybe we should ask the upstream if is correct ... might be better to leave it off vs perpetuating  something that might  not be right

-- Casey

--
Performance Test Ninja
casey.peel@isilon.com / 206.777.7945


-----Original Message-----
From: Peel, Casey 
Sent: Friday, April 04, 2014 10:15 AM
To: 'Julio Merino'
Cc: freebsd-testing@freebsd.org
Subject: RE: Makefiles for skip-level directories?

> Please let me know where the documentation above is lacking and/or how
> to make it more discoverable.

Well, lets start with the fact that the share/mk/bsd.README file isn't referenced anywhere on https://wiki.freebsd.org/TestSuite/DeveloperHowTo yet it contains information on the Makefile variables that don't seem to be documented anywhere else.

It would be good to keep in mind that most testers aren't build engineers and know just enough about Makefiles to get themselves in trouble (me included) so this is an area that needs to be over-documented. If we want to enable people to contribute test code, we need to lower th bar on how to wire them up to the build. In an ideal world, the entire source tree would contain tests/ directories ready and primed for testcases to be added and the Makefile within them simply updated.

In the meantime I'm going to acquire a Sonic Cherry Coke, put up my Do Not Disturb sign, and see if I can't figure out how the hell this stuff works and write up the definitive guide for n00bs like myself.

-- Casey

--
Performance Test Ninja
casey.peel@isilon.com / 206.777.7945

[-- Attachment #2 --]
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 <bsd.subdir.mk>

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 <bsd.lib.mk>

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 <bsd.subdir.mk>
 
 .include <bsd.lib.mk>

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 <bsd.own.mk>
 
 .PATH: ${.CURDIR}/../../misc
 
 GEOM_CLASS=	part
 
 DPADD=	${LIBUTIL}
 LDADD=	-lutil
 
 .if ${MK_TESTS} != "no"
 SUBDIR+=    tests
 .endif
  
 .include <bsd.subdir.mk>
 
 .include <bsd.lib.mk>

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 <bsd.own.mk>
 
 TESTSDIR=       ${TESTSBASE}/sbin/geom/class
 
 .PATH:          ${.CURDIR:H:H:H}/tests
 KYUAFILE=       yes
 
 .include <bsd.test.mk>

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.

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?16437CC5729B5345AF77F816513376E820BACB49>