zeek/testing/btest
Arne Welzel 6d19c49efe intel/seen/file-names: Use file_over_new_connection()
The seen/file-names script relies on f$info$filename to be populated.
For HTTP and other network protocols, however, this field is only
populated during file_over_new_connection() that's running after
file_new().

Use the file_new() event only for files without connections and
file_over_new_connection() implies that f$conns is populated, anyway.

Special case SMB to avoid finding files twice, because there's a
custom implementation in seen/smb-filenames.zeek.

Fixes #2647
2023-01-10 10:10:28 +01:00
..
af_packet Include in Jan's AF_PACKET plugin as builtin plugin 2022-10-13 13:29:27 +02:00
Baseline intel/seen/file-names: Use file_over_new_connection() 2023-01-10 10:10:28 +01:00
Baseline.cpp maintenance updates for -O C++ 2022-12-04 17:59:14 -08:00
Baseline.dup
Baseline.inline
Baseline.opt test suite alternative baseline fixes for recent test renaming 2022-01-06 13:54:07 -07:00
Baseline.usage additional test suite updates for "-u" usage issues 2021-12-14 15:35:24 -08:00
Baseline.xform test suite updates for "xform" and "usage" alternatives, plus test name change 2021-12-14 12:50:17 -08:00
Baseline.zam maintenance updates for -O ZAM 2022-12-04 17:58:33 -08:00
bifs update test suite to avoid GH-2385 problems, including incorrect typing 2022-12-04 17:56:30 -08:00
broker Merge remote-tracking branch 'origin/topic/neverlord/web-socket-events-warning' 2022-11-18 09:41:18 -07:00
core zeek.bif: Add has_event_group() / has_module_events() 2022-12-09 16:59:07 +01:00
coverage mqtt: Move from policy/ into base/ 2022-11-30 10:14:20 +01:00
doc maintenance updates for -O C++ 2022-12-04 17:59:14 -08:00
language update test suite to avoid GH-2385 problems, including incorrect typing 2022-12-04 17:56:30 -08:00
opt annotated scripts to skip when testing compilation-to-C++ 2022-09-16 16:47:43 -07:00
plugins Spelling testing 2022-11-16 20:05:03 -05:00
scripts intel/seen/file-names: Use file_over_new_connection() 2023-01-10 10:10:28 +01:00
signatures Attr: Duplicated &is_used is allowed 2022-12-02 17:15:05 +01:00
spicy Deprecate bro_int_t and bro_uint_t 2022-07-12 12:01:23 -07:00
supervisor Spelling testing 2022-11-16 20:05:03 -05:00
telemetry telemetry: Remove singleton BIFs and the C++ pieces 2022-08-05 19:33:49 +02:00
Traces intel/seen/file-names: Use file_over_new_connection() 2023-01-10 10:10:28 +01:00
.gitignore
btest.cfg Add tests for bundled Spicy infrastructure. 2022-05-16 09:07:11 +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.