freebsd-dev/share/mk
Enji Cooper 38f8fddf05 Add limited sandbox capability to "make check"
== Rationale ==

r295380 introduced "make check" and consolidated means for running
test code in an attempt to simplify running tests. One could either
install files/libraries/programs and run "make check", or run "make check"
with an explicit CHECKDIR, e.g., `make check CHECKDIR=$(make -V.OBJDIR)``.

One criticism that was received is that "make check" should be run with
the intent of making dev->test->commit easier, which means that the target
audience's workflow should be developers. One developer pattern available
in other opensource projects is to run test code from a developer sandbox,
instead of installing to a system.

== Method ==

This approach is slightly different from the standard approach, in the sense
that it builds and installs into a deterministic directory under .OBJDIR (as I call it,
the "sandbox"), then runs "make check" against that. In the event the test
run is successful, the deterministic directory is removed to save space.

== Approach ==

bsd.lib.mk, bsd.prog.mk:

To support this functionality, a new variable `HAS_TESTS` is being added.

HAS_TESTS enables appropriate behavior with bsd.lib.mk and bsd.prog.mk, as
follows:
- Add "make check" as an available target from the directory.
- Pass down appropriate variables via ${TESTS_ENV}, i.e.,
  ${TESTS_LD_LIBRARY_PATH} and ${TESTS_PATH}.

One should add "HAS_TESTS" to directories containing tests in them, e.g. from
bin/sh/Makefile,

  HAS_TESTS=
  SUBDIR.${MK_TESTS}+= tests

HAS_TESTS doesn't automatically add the tests subdirectory for flexibility
reasons.

bsd.opts.mk, src.opts.mk:
- The knob ${MK_MAKE_CHECK_USE_SANDBOX} has been added, both to explicitly
  direct (internally) when to set a deterministic ${DESTDIR} and to also allow
  users to disable this behavior globally, i.e., via src.conf.
- MK_TESTS has been promoted from src.opts.mk to bsd.opts.mk to leverage
  syntactic sugar for having MK_TESTS be a dependency for
  MK_MAKE_CHECK_USE_SANDBOX, but to also ensure that src.opts.mk isn't required
  to use suite.test.mk (which is a dependency of bsd.test.mk).

suite.test.mk:
- beforecheck behavior (when MK_MAKE_CHECK_USE_SANDBOX is enabled) is modified
  from a no-op to:
-- Build.
-- Run "make hierarchy" on the sandbox dir.
-- Install the tests/files to the sandbox dir.
- aftercheck behavior (when MK_MAKE_CHECK_USE_SANDBOX is enabled) is modified
  from a no-op to:
-- Remove the sandbox dir.

Again, because the dependency order set in bsd.test.mk is
beforecheck -> check -> aftercheck, "make check" will not be run unless
"beforecheck" completes successfully, and "aftercheck" will not be run unless
"beforecheck" and "check" complete successfully.

== Caveats ==

- This target must either be run with MK_INSTALL_AS_USER or as root. Otherwise
  it will fail when running "make install" as the default user/group for many
  makefiles when calling INSTALL is root/wheel.
- This target must be run from a suitable top-level directory. For example,
  running tests from `tests/sys/fs/tmpfs` won't work, but `tests/sys/fs` will,
  because `tests/sys/fs/tmpfs` relies on files installed by `tests/sys/fs`.
- Running MK_INSTALL_AS_USER may introduce determinism issues. However, using
  it could identify deficiences in tests in terms of needing to be run as
  root, which are not properly articulated in the test requirements.
- The doesn't negate the need for running "make installworld" and
  "make checkworld", etc. Again, this just is intended to simplify the
  dev->test->commit workflow.

== Cleanup done ==
- CHECKDIR is removed; one can use "MK_MAKE_CHECK_USE_SANDBOX=no" to enable
  "legacy" (r295380) behavior.

MFC after:	2 months
Relnotes:	yes (CHECKDIR removed; "make check" behavior changed)
Requested by:	jhb
Reviewed by:	arch (silence), testing (silence)
Differential Revision:	D11905
2017-08-14 19:03:05 +00:00
..
atf.test.mk Remove unused atf.test.mk variables 2015-12-06 07:30:18 +00:00
auto.obj.mk If MAKEOBJDIRPREFIX is a prefix match for .CURDIR, then __objdir is .CURDIR 2017-04-18 23:59:15 +00:00
bsd.arch.inc.mk
bsd.clang-analyze.mk Remove the old depend (mkdep) code and make FAST_DEPEND the one true way. 2016-03-30 23:50:23 +00:00
bsd.compiler.mk CCACHE_BUILD: Follow-up r321880: Fix some PATH issues with buildworld. 2017-08-01 18:26:20 +00:00
bsd.confs.mk DIRDEPS_BUILD: Fix '/' in group names creating a bad cookie. 2016-12-03 05:29:35 +00:00
bsd.cpu.mk We don't use ARM_ARCH_6 in the tree, and haven't for a long long 2017-08-13 04:10:47 +00:00
bsd.crunchgen.mk META_MODE: Fix build-tools still sometimes rebuilding during target build. 2017-04-06 18:21:59 +00:00
bsd.dep.mk Allow -DNO_SKIP_DEPEND to override the _SKIP_DEPEND logic. 2017-07-25 16:46:12 +00:00
bsd.doc.mk Revert crap accidentally committed 2017-01-28 16:31:23 +00:00
bsd.dtb.mk Add infrastructure to build dtb files from dts files. 2015-01-08 18:28:06 +00:00
bsd.endian.mk Add full softfloat and hardfloat support for MIPS. 2016-10-31 15:33:58 +00:00
bsd.files.mk Respect INSTALL_AS_USER for FILES. 2017-07-21 16:14:35 +00:00
bsd.incs.mk DIRDEPS_BUILD: Fix '/' in group names creating a bad cookie. 2016-12-03 05:29:35 +00:00
bsd.info.mk Revert r301079. 2016-06-03 19:25:36 +00:00
bsd.init.mk Fix 'make clean all' to work again. 2017-06-20 20:52:06 +00:00
bsd.kmod.mk WITH_META_MODE: Resolve SYSDIR to avoid changed build commands. 2016-05-31 23:08:43 +00:00
bsd.lib.mk Add limited sandbox capability to "make check" 2017-08-14 19:03:05 +00:00
bsd.libnames.mk Provide libdl. 2017-07-10 14:59:21 +00:00
bsd.linker.mk lld 5.0 supports filter libraries, so enable linker feature flag 2017-07-24 15:39:09 +00:00
bsd.links.mk Re-remove excess / for installing SYMLINKS 2017-08-12 18:11:41 +00:00
bsd.man.mk Revert r301079. 2016-06-03 19:25:36 +00:00
bsd.mkopt.mk Appy := to dependent opts once value determined. 2015-06-22 19:01:09 +00:00
bsd.nls.mk Revert r301079. 2016-06-03 19:25:36 +00:00
bsd.obj.mk cleandir: Fix ESTALE errors from parallel removals. 2017-07-25 00:12:48 +00:00
bsd.opts.mk Add limited sandbox capability to "make check" 2017-08-14 19:03:05 +00:00
bsd.own.mk Add SVNVERSION_CMD to bsd.own.mk, adding the capability to include 2017-08-11 19:21:40 +00:00
bsd.port.mk Avoid sub-shell for realpath(1) for bmake by using its built-in :tA. 2015-09-03 17:01:58 +00:00
bsd.port.options.mk
bsd.port.post.mk
bsd.port.pre.mk
bsd.port.subdir.mk Avoid sub-shell for realpath(1) for bmake by using its built-in :tA. 2015-09-03 17:01:58 +00:00
bsd.prog.mk Add limited sandbox capability to "make check" 2017-08-14 19:03:05 +00:00
bsd.progs.mk PROGS: Fix ESTALE errors on NFS while cleaning in directories with PROGS. 2017-07-24 17:54:03 +00:00
bsd.README Add limited sandbox capability to "make check" 2017-08-14 19:03:05 +00:00
bsd.snmpmod.mk Add a make target (smilint) for running smilint tool against BMIBS 2017-01-17 03:38:49 +00:00
bsd.stand.mk Support for v1.10 (latest) of RISC-V privilege specification. 2017-08-10 14:18:09 +00:00
bsd.subdir.mk Similar to r296013 for NO_ROOT, force SUBDIR_PARALLEL for buildworld WORLDTMP staging. 2017-06-21 18:56:53 +00:00
bsd.suffixes-posix.mk Extract suffix rules into bsd.suffixes[-posix].mk. 2016-10-12 00:42:46 +00:00
bsd.suffixes.mk Revert r307823 (Use upstream suffixes for LLVM IR) for now. It causes a 2016-10-27 18:46:52 +00:00
bsd.symver.mk
bsd.sys.mk Add warning flags for GCC 7.1.0 compiler. 2017-07-21 14:50:32 +00:00
bsd.test.mk Sort the tests alphabetically before adding them to the Kyuafiles 2017-07-17 18:20:54 +00:00
dirdeps.mk Fix typo in comment. 2017-03-07 01:42:30 +00:00
gendirdeps.mk Update meta* from bmake-20161212 2016-12-23 02:57:00 +00:00
host-target.mk Import latest host-target.mk 1.11 from contrib/bmake/mk 2016-01-25 18:43:21 +00:00
install-new.mk DIRDEPS_BUILD: Install new Makefile.depend files atomically. 2015-12-04 03:17:07 +00:00
local.autodep.mk Revert r288966 as it is redundant and not right. 2015-12-03 22:39:42 +00:00
local.dirdeps.mk DIRDEPS_BUILD: Exclude secure/lib* libraries for host builds. 2016-05-04 03:13:48 +00:00
local.gendirdeps.mk DIRDEPS_BUILD: Clang headers are now in lib/clang/headers 2016-09-02 19:28:24 +00:00
local.init.mk Define .MAKE.MODE to normal to avoid the need for :U later. 2016-01-19 22:41:44 +00:00
local.meta.sys.mk META_MODE: Move ignoring of /usr/local/etc/libmap.d to proper place. 2017-06-01 23:04:44 +00:00
local.sys.env.mk Move include of make.conf back to its old position. 2015-06-19 14:56:24 +00:00
local.sys.mk Follow-up r320061: Need to respect make.conf/env LIBDIR overrides. 2017-06-19 18:08:02 +00:00
Makefile Add basic bsd.linker.mk auto included from bsd.compiler.mk. 2017-06-22 21:03:20 +00:00
meta2deps.py Fix syntax error in parse_path after r316952. 2017-05-08 20:44:21 +00:00
meta2deps.sh Update meta* from bmake-20161212 2016-12-23 02:57:00 +00:00
meta.autodep.mk When MAKEOBJDIRPREFIX points to a case-insensitive file system, the 2016-09-24 15:11:27 +00:00
meta.stage.mk Update dirdeps/meta bits from latest bmake. 2017-03-06 23:13:25 +00:00
meta.subdir.mk Import latest meta.subdir.mk 1.11 from contrib/bmake/mk 2016-01-25 18:34:15 +00:00
meta.sys.mk Avoid clobbering existing value of META_COOKIE_TOUCH 2016-09-13 22:17:25 +00:00
netbsd-tests.test.mk Fix LDADD/DPADD that should be LIBADD. 2015-12-04 03:17:47 +00:00
plain.test.mk
src.init.mk The 'buildenv' target can safely be ran with '+'. 2015-11-06 21:49:17 +00:00
src.libnames.mk Provide libdl. 2017-07-10 14:59:21 +00:00
src.opts.mk Add limited sandbox capability to "make check" 2017-08-14 19:03:05 +00:00
src.sys.env.mk WITH_META_MODE: Don't let subdir traversals for 'make install' re-enable meta mode. 2016-08-25 23:55:56 +00:00
src.sys.mk Fix error when SRCCONF is empty. 2016-04-22 20:31:29 +00:00
stage-install.sh Add META_MODE support. 2015-06-13 19:20:56 +00:00
suite.test.mk Add limited sandbox capability to "make check" 2017-08-14 19:03:05 +00:00
sys.dependfile.mk Merge bmake-20160307 2016-03-11 01:35:39 +00:00
sys.mk arm*hf is no longer a thing, remove it from the conversion now that it's easy. 2017-08-12 17:07:32 +00:00
tap.test.mk - Use LOCALBASE instead of KYUA_PREFIX for the --prefix to kyua(1) 2015-12-20 06:26:15 +00:00
version_gen.awk