Stack: C++14 on Linux and macOS, built with Autoconf, Automake, and Libtool, tested
with CppUnit (unit tests) and Autotest (integration and baseline tests), all driven by
make check. C++14 is the baseline — verify each target compiler actually builds it,
and bump to C++17 only if every target compiler supports it; check before assuming.
Compilers/platforms: GCC 9+ and Clang 12+ on Linux; Apple Clang on macOS (arm64 + x86_64). Unit-test framework: CppUnit (1.12 or later).
- The language standard is chosen once, in
configure.ac:CXX_FLAGS_CHECKprobes for--std=c++14and substitutes it asCXX_STD_FLAG, which configure adds toCXXFLAGS. Don't hardcode-std=in anyMakefile.am, and keep itc++14, notgnu++14, so code that only compiles with GNU extensions fails for everyone, not just on someone else's machine. AC_PREREQandAM_INIT_AUTOMAKE([<min version> ...])state the oldest Autoconf and Automake that must work. Don't use macros or Automake features newer than the oldest versions CI bootstraps with. Project-local macros live inconf/(AC_CONFIG_MACRO_DIR); add a new.m4there instead of inlining long shell logic inconfigure.ac.- Generated files are never committed:
configure,Makefile.in,Makefile,config.h,config.status,aclocal.m4,libtool, Autotesttestsuitescripts,package.m4,atconfig,atlocal, and anything built from a.intemplate. Commit the sources (configure.ac,Makefile.am,*.in,*.at,conf/*.m4) and regenerate withautoreconf -fiv. - Flags in
Makefile.amgo in the Automake variables —AM_CPPFLAGS,AM_CXXFLAGS,AM_LDFLAGS, or per-target<target>_CPPFLAGS/_CXXFLAGS/_LIBADD/_LDADD. Never assignCPPFLAGS,CXXFLAGS, orLDFLAGSin aMakefile.am; those belong to the user and to configure. - Dependencies are found in
configure.ac(PKG_CHECK_MODULES,AC_ARG_WITH, or a macro inconf/) and exported withAC_SUBSTasFOO_CFLAGS/FOO_LIBS. Optional features useAM_CONDITIONALand anif FOO ... endifblock inMakefile.am, never a hardcoded path or a check run atmaketime. - VPATH (out-of-source) builds must work: refer to sources as
$(srcdir)/...or$(top_srcdir)/...and to build products as$(builddir)/...or$(top_builddir)/....make distcheckbuilds from the tarball in a separate directory with a read-only source tree and runsmake check; it must pass before a release, and it is the test that catches a missing$(srcdir)or a file left out of the distribution. - Every file the build or tests need that isn't a compiled source — test data,
*.baselinefiles,*.atfiles,*.intemplates,.bescmdinputs — is listed inEXTRA_DIST(or adist_*_DATAvariable). Anything a build or test creates is inCLEANFILESorDISTCLEANFILES. - Code is built as Libtool libraries (
lib_LTLIBRARIES/noinst_LTLIBRARIES) that the executables, modules, and the tests link against — tests never recompile the library's sources. A new directory is added to its parent'sSUBDIRSand itsMakefile(plus anyatlocal/*.inoutputs) toAC_CONFIG_FILESinconfigure.ac. - Layout follows the existing tree: each component (
dispatch/,http/,dap/, and each handler undermodules/<name>/) holds its sources and headers together, with CppUnit tests in<component>/unit-tests/and Autotest suites in<component>/tests/. - Build modes are configure options, not hand-edited flags:
--enable-developer(-g3 -O0 -Wall, definesDEVELOPER, sets theBES_DEVELOPERconditional; without it the build is optimized with-DNDEBUG),--enable-asan(ASan + UBSan), and--enable-coverage(gcov). Code compiled only in developer mode is guarded by#ifndef NDEBUGor theDEVELOPERmacro, and must not change release behavior. - Warnings:
-Wallis on in developer builds; add-Wextrathere too. Move to-Werroronce the codebase is warning-clean, as an opt-in configure option (--enable-werror) that CI turns on. Don't silence a warning with a pragma without a comment saying why. - Automake doesn't emit
compile_commands.json. Generate it withbear -- make(orcompiledb make) in the build directory so clang-tidy and editors see the real flags; don't commit it.
- RAII everywhere. No naked
new/delete, and nomalloc/freeexcept to wrap a C API. Owning pointers arestd::unique_ptr(std::make_uniqueexists in C++14);std::shared_ptronly when ownership is genuinely shared. Raw pointers and references are non-owning, always. std::stringand standard containers overchar*and C arrays. Nostrcpy,sprintf, orgets; usesnprintfwith its return value checked, orstd::string.- Exceptions are allowed for errors at API boundaries: derive from
std::exception, throw by value, catch byconst&. Destructors arenoexcept. Never let an exception escape across a C ABI, a thread boundary, or a callback invoked from C code. Don't use exceptions for routine control flow (not-found, end-of-input). If this project builds with-fno-exceptions, replace this bullet with status codes / enums. <cstdint>fixed-width types for file formats, wire formats, and anything whose size is part of the contract;std::size_tfor sizes and indices. No mixed signed/unsigned comparisons without an explicit, commented cast.- Never read or write binary data by casting a struct or pointer. Serialize field by field with explicit endianness.
constby default;overrideon every virtual override; a virtual destructor on every polymorphic base;nullptr, neverNULLor0;enum classover plainenum;constexprover#definefor constants.- Headers are self-contained (each compiles on its own), use include guards
(
#pragma onceis fine), and never containusing namespace. Include what you use; forward-declare where that avoids an include. - C++17 library/language features are off-limits at the C++14 baseline: no
std::optional,std::variant,std::string_view,std::filesystem, structured bindings, orif constexpr. If one is truly needed, that's a decision to record as an ADR, not a quiet workaround.
- Standard C++ and POSIX only. Anything available on just one OS (
<endian.h>,<malloc.h>,strlcpy/strlcat,qsort_r,pthread_setname_np,memrchr, the GNU-vs-XSIstrerror_r) goes behind a small wrapper in one file, with#if defined(__linux__)/#if defined(__APPLE__)branches, each exercised by a test. When the question is "does this function/header exist" rather than "which OS", prefer an Autoconf check (AC_CHECK_FUNCS,AC_CHECK_HEADERS) and the resultingHAVE_FOOmacro fromconfig.h. - Plain
charsignedness differs across platforms (e.g. x86_64 vs aarch64 Linux). Usesigned char,unsigned char, oruint8_twherever it matters. - No GNU-only compiler extensions (statement expressions, VLAs, bare
__attribute__). - Never hardcode
.so,.dylib, orlibprefixes (macOS uses.dylib; BES modules are loaded by name frombes.conf). Link through Libtool.lafiles and let Libtool pick the platform's suffix and rpath. Uninstalled programs in the build tree are Libtool wrapper scripts that already find uninstalled libraries — don't setLD_LIBRARY_PATH, and never depend onDYLD_LIBRARY_PATH, which macOS SIP strips when a protected binary such as/bin/shis in the process chain. - OS-specific build logic belongs in
configure.ac(e.g.AS_CASE([$host], [*darwin*], ...)setting anAM_CONDITIONALlikeDARWIN), not in ad hocunamecalls in aMakefile.am. - macOS filesystems are usually case-insensitive and Linux's are case-sensitive:
#includepaths and file names must match case exactly. - Parallelism:
make -j<N>andmake check -j<N>(orTESTSUITEFLAGS=-j<N>for an Autotest suite). Get<N>withgetconf _NPROCESSORS_ONLN, which works on both OSes — notnproc(Linux-only) orsysctl -n hw.ncpu(macOS-only). A directory whose tests can't run in parallel says so with.NOTPARALLEL:and a comment explaining why.
make checkfrom the top of the build tree is the single command that runs everything;make distcheckruns the same suite from a VPATH build of the tarball. A test thatmake checkdoesn't run doesn't exist.- Unit tests use CppUnit and live in
<component>/unit-tests/. Each test is one program named inTESTS, withcheck_PROGRAMS = $(TESTS), linked against the component's Libtool library plus$(CPPUNIT_LIBS)($(CPPUNIT_CFLAGS)inAM_CPPFLAGS). The whole block sits insideif CPPUNIT ... else ... endifso a build without CppUnit still succeeds and prints a notice fromcheck-localinstead. Tests that only make sense in developer builds are added underif BES_DEVELOPER. - A CppUnit test is a
CppUnit::TestFixturewithCPPUNIT_TEST_SUITE/CPPUNIT_TEST/CPPUNIT_TEST_SUITE_END, and itsmainis the shared driver frommodules/common/run_tests_cppunit.h:int main(int argc, char *argv[]) { return bes_run_tests<FooTest>(argc, argv, "bes,foo") ? 0 : 1; }. That gives every test the same-d/-D/-b(debug, verbose debug, BESDEBUG contexts) and-hoptions, and lets you run a single test method by name. - Unit tests find their data through a configure-generated header (
test_config.hfromtest_config.h.in, listed inBUILT_SOURCES) that definesTEST_SRC_DIR,TEST_BUILD_DIR, and similar absolute paths. Tests never hardcode a path or assume the working directory. Read inputs from the source directory; write outputs only to the build directory. - Integration and baseline tests use Autotest and live in
<component>/tests/. The suite istestsuite.at, compiled byautom4te --language=autotestinto atestsuitescript, withpackage.m4generated fromconfigure.acand anatlocalproduced fromatlocal.inthroughAC_CONFIG_FILES.check-localruns$(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS);installcheck-localruns it again withAUTOTEST_PATH='$(bindir)'against the installed binaries;clean-localrunstestsuite --clean. Copy this wiring from an existingtests/Makefile.amrather than inventing a new one. - Use the shared macros in
modules/common/handler_tests_macros.m4(AT_BESCMD_RESPONSE_TEST,AT_BESCMD_BINARYDATA_RESPONSE_TEST,AT_BESCMD_ERROR_RESPONSE_TEST,AT_BESCMD_BESCONF_RESPONSE_TEST, ...) instead of writing rawAT_SETUP/AT_CHECK/AT_CLEANUPblocks. Each takes a.bescmdinput, runsbesstandalone, and compares against<input>.baseline. Mark known failures with the macro'sxfailargument (which usesAT_XFAIL_IF) and a comment or ticket — don't delete or comment out the test. - Baselines — where the output is a text artifact (DAP response, DMR/DDS/DAS,
generated metadata, CLI output) — are checked-in
*.baselinefiles next to their inputs. A mismatch fails the test and Autotest keeps the test's directory and diff intestsuite.dir/andtestsuite.log. Baselines change only through the one update mode:./testsuite --baselines=yes [test numbers or -k keyword], which writes<input>.baseline.tmpinstead of comparing; review it and move it over the old baseline. Never hand-edit a baseline. Update mode is off by default and never on in CI. Reviewgit diffon baseline files like source code; a baseline change in a PR needs a reason. - Output that legitimately varies between runs (dates, version strings, temp paths) is
scrubbed before comparison with the existing macros (
REMOVE_VERSIONS, the*_SCRUB_DATES_*variants) or a new one added to the shared.m4, not by loosening the comparison or regenerating the baseline each run. - Running pieces of the suite: in a
tests/directory,./testsuite -llists tests,./testsuite 12 15-20or./testsuite -k <keyword>runs a subset, and./testsuite -v -d -x <N>shows a failing test's commands and keeps its scratch directory. In aunit-tests/directory,make check TESTS=fooTruns one program and./fooT -d <method>runs one method with debugging on. - Commands inside
AT_CHECKand any helper scripts are portable shell:#!/bin/sh, POSIX only. No bashisms, and no GNU-only flags (sed -i,readlink -f,date -d,echo -e,grep -P); useprintf, and write to a temp file thenmvinstead ofsed -i. Autotest already gives each test its own scratch directory undertestsuite.dir/; a standalone helper script that needs scratch space usesmktemp -d "${TMPDIR:-/tmp}/name.XXXXXX", removed by atrap. - Paths and configuration reach tests through
atlocal,package.m4(AT_TOP_SRCDIR), the generatedbes.conffiles (built frombes.conf.inwith@abs_top_srcdir@/@abs_top_builddir@substituted), andtest_config.h— never hardcoded. Inside a test, use$abs_srcdir/$abs_builddir, not relative paths that guess the working directory. Keep long logic in an.m4macro or a script file rather than a quote-heavyAT_CHECKline; nested m4 and shell quoting is fragile and hard to review. - Tests are deterministic and independent: no reliance on test order, wall-clock time,
network, or a shared scratch location, so
make check -jand./testsuite -j<N>are safe. Fixed seeds only. Tests that genuinely need the network (e.g. remote-resource or AWS tests) are kept in a separate suite or behind a configure option or keyword so the defaultmake checkdoesn't need them. - New logic isn't done without a test. A bug fix isn't done without a regression test that fails before the fix and passes after.
- The suite also runs clean under ASan + UBSan on Linux and macOS: configure with
--enable-asan(add--enable-developerfor usable stack traces) and runmake check. LeakSanitizer isn't available on macOS, so leak checking is Linux-only; Valgrind with the checked-in suppression files (vg-*-supp.txt, seeREADME-VALGRIND.md) is the alternative.
clang-format(config committed to the repo) is the formatting source of truth — don't hand-format around it.clang-tidywith a committed.clang-tidyruns clean before a change is considered finished, or a new finding is suppressed with aNOLINTand a comment saying why.
- Every public function/class in an installed header (
include_HEADERS/pkginclude_HEADERS) gets a one-line Doxygen-style comment: what it does, ownership/lifetime of pointer or reference arguments and returns, units where relevant, whether it can throw, and thread-safety when it isn't obvious.