zeek/testing/btest
Jon Siwek cd8f19328a Merge remote-tracking branch 'origin/topic/neverlord/gh-1408'
- Minor adjustments to header includes, whitespace, and a
  compiler warning fix during merge

* origin/topic/neverlord/gh-1408:
  Add new Timer class to the telemetry API
  Fix build with latest VectorVal API
  Update baselines
  Prefix telemetry BIFs with __
  Expose telemetry API to scripting land
  Add handle types for histogram metrics
  Move duplicated code to detail header
  Adhere to Zeek coding style
  Apply suggestions from code review
  Add telemetry Manager to Zeek setup / teardown
  Add missing whitespaces for Zeek coding style
  Add gauge metric types
  Add scaffold for new metrics API with counters
2021-04-05 14:21:44 -07:00
..
Baseline Merge remote-tracking branch 'origin/topic/neverlord/gh-1408' 2021-04-05 14:21:44 -07:00
Baseline.dup cleaner approach for localizing errors associated with duplicated ASTs: virtualize GetLocationInfo 2021-01-07 15:14:22 -08:00
Baseline.inline Update alternative plugins.hooks baselines 2020-12-13 13:24:47 -08:00
Baseline.opt don't know how I overlooked these minor test suite updates 2021-02-27 13:47:49 -08:00
Baseline.usage activate &is_used 2021-02-23 08:32:14 -08:00
Baseline.xform Add alternative 'xform' baseline for test: broker.store.create-failure 2021-03-08 12:59:30 -08:00
bifs Separate stdout from stderr in btest baselines 2021-03-30 16:23:23 -07:00
broker GH-1426: Improve handling of Broker data store creation failures 2021-03-06 02:32:29 -08:00
core Separate stdout from stderr in btest baselines 2021-03-30 16:23:23 -07:00
coverage Update Python invocations to explicit python3 2020-11-25 14:57:09 -08:00
doc Teach Zeekygen to produce source-code-range information 2021-02-26 14:55:59 -08:00
Files
language Separate stdout from stderr in btest baselines 2021-03-30 16:23:23 -07:00
opt inlining of Zeek script functions 2020-11-19 16:16:59 -08:00
plugins Increase timeout of plugins.reader btest 2021-04-03 09:40:45 -07:00
scripts Separate stdout from stderr in btest baselines 2021-03-30 16:23:23 -07:00
signatures GH-779: Add "udp-state" signature condition 2020-10-09 13:43:17 -07:00
supervisor General btest cleanup 2020-08-11 11:26:22 -07:00
telemetry Prefix telemetry BIFs with __ 2021-03-29 10:47:32 +02:00
Traces Fix crash in Analyzer::ForwardPacket due to recursive analyzer calls. 2021-03-25 08:45:38 -07:00
.gitignore
btest.cfg Expose telemetry API to scripting land 2021-03-29 10:47:32 +02:00
Makefile Rename aux/ to auxil/ 2020-06-04 15:18:44 -07:00
random.seed
README More bro-to-zeek renaming in the unit tests 2019-05-16 02:27:54 -05:00

This a test suite of small "unit tests" that verify individual pieces of Zeek
functionality.  They all utilize BTest, a simple framework/driver for
writing unit tests.  More information about BTest can be found at
https://github.com/zeek/btest

The test suite's BTest configuration is handled through the
``btest.cfg`` file.  Of particular interest is the "TestDirs" settings,
which specifies which directories BTest will recursively search for
test files.

Significant Subdirectories
==========================

* Baseline/
	Validated baselines for comparison against the output of each
	test on future runs. If the new output differs from the Baseline
	output, then the test fails.

* Traces/
	Packet captures utilized by the various BTest tests.

* scripts/
	This hierarchy of tests emulates the hierarchy of the Zeek scripts/
	directory.

* coverage/
	This collection of tests relates to checking whether we're covering
	everything we want to in terms of tests, documentation, and which
	scripts get loaded in different Zeek configurations.  These tests are
	more prone to fail as new Zeek scripts are developed and added to the
	distribution -- checking the individual test's comments is the best
	place to check for more details on what exactly the test is checking
	and hints on how to fix it when it fails.

Running Tests
=============

Either use the ``make all`` or ``make brief`` ``Makefile`` targets, or
run ``btest`` directly with desired options/arguments.  Examples:

* btest <no arguments>
	If you simply execute btest in this directory with no arguments,
	then all directories listed as "TestDirs" in btest.cfg will be
	searched recursively for test files.


* btest <btest options> test_directory
	You can specify a directory on the command line to run just the
	tests contained in that directory. This is useful if you wish to
	run all of a given type of test, without running all the tests
	there are. For example, "btest scripts" will run all of the Zeek
	script unit tests.


* btest <btest options> test_directory/test_file
	You can specify a single test file to run just that test. This
	is useful when testing a single failing test or when developing
	a new test.

Adding Tests
=============

See either the `BTest documentation
<https://github.com/zeek/btest>`_ or the existing unit
tests for examples of what they actually look like.  The essential
components of a new test include:

* A test file in one of the subdirectories listed in the ``TestDirs``
  of the ``btest.cfg`` file.

* If the unit test requires a known-good baseline output against which
  future tests will be compared (via ``btest-diff``), then that baseline
  output will need to live in the ``Baseline`` directory.  Manually
  adding that is possible, but it's easier to just use the ``-u`` or
  ``-U`` options of ``btest`` to do it for you (using ``btest -d`` on a
  test for which no baseline exists will show you the output so it can
  be verified first before adding/updating the baseline output).

If you create a new top-level testing directory for collecting related
tests, then you'll need to add it to the list of ``TestDirs`` in
``btest.cfg``. Do this only if your test really doesn't fit logically in
any of the extant directories.