zeek/testing/btest
Arne Welzel 4763282f36 Merge branch 'modbus-fixes' of https://github.com/zambo99/zeek
* 'modbus-fixes' of https://github.com/zambo99/zeek:
  Prevent non-Modbus on port 502 to be reported as Modbus
2024-10-21 15:54:11 +02:00
..
af_packet
Baseline Merge branch 'modbus-fixes' of https://github.com/zambo99/zeek 2024-10-21 15:54:11 +02:00
Baseline.cpp BTest baseline update for more complete function/lambda names 2024-09-27 14:16:10 -07:00
Baseline.dup
Baseline.inline
Baseline.opt
Baseline.usage
Baseline.xform
Baseline.zam Merge remote-tracking branch 'origin/topic/vern/remove-teredo-gtpv1-script-opt-insts' 2024-10-09 15:36:52 -07:00
bifs BTest updates for ZAM regularization changes 2024-08-16 11:18:58 +02:00
broker cluster: Deprecate the Cluster::Node$interface field 2023-11-07 16:06:16 +01:00
core Merge remote-tracking branch 'origin/topic/timw/remove-negative-timestamp-test' 2024-09-12 08:53:00 +02:00
coverage Spicy SSL analyzer - address feedback 2024-09-11 11:30:16 +02:00
doc Add btest for Zeekygen docs extraction on identifiers defined by the Zeek core. 2024-05-03 12:22:42 -07:00
Files/mmdb Add an IPv6 range to the test MMDB DBs 2024-01-25 23:43:34 -08:00
javascript testing/btest: Log::delay() from JavaScript 2023-11-29 12:52:19 +01:00
language Add enum value negative check 2024-09-17 12:04:19 -04:00
misc
opt BTest updates for ZAM regularization changes 2024-08-16 11:18:58 +02:00
plugins Spicy SSL analyzer - address feedback 2024-09-11 11:30:16 +02:00
scripts Prevent non-Modbus on port 502 to be reported as Modbus 2024-10-21 14:40:45 +02:00
signatures rule-parse: Remove id_to_str() lookup to squelch coverity warning 2024-08-09 09:49:43 +02:00
spicy Test .evt file &priority 2024-10-14 08:51:58 -04:00
supervisor Supervisor: Handle EAGAIN error on stem pipe 2023-10-25 12:53:37 +02:00
telemetry Change all instruments to only handle doubles 2024-05-31 13:36:37 -07:00
Traces Prevent non-Modbus on port 502 to be reported as Modbus 2024-10-21 14:40:45 +02:00
.gitignore
btest.cfg testing/btest: Default to HILTI_JIT_PARALLELISM=1 2024-07-10 11:04:47 +02:00
Makefile
random.seed
README

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.