zeek/testing/btest
Johanna Amann 83d5243cf6 Optimize Conn::set_conn to minimize operations
Now that Conn::set_conn is guaranteed to be called at the beginning and
at the end of the connection, we can skip re-setting the elements that
we know will not have changed. This prevents repeated lookups, e.g. to
check that addresses are in the local networks.

During `connection_state_remove`, only the duration, number of
packets, service, and history fields are updated.

local_orig and local_resp are updated when the connection is flipped. A
test was added for that purpose. It uses the already existing
http.zeek-image-post-1080-8000-x.pcap, which was slightly rewritten for
this, so that one side of the connection has IP addresses different from
127.0.0.1.

The existing history-flip test also was updated to have one side being
in a local-net, to check that the flipping of local_orig and local_resp
works correctly at the beginning of a connection.
2025-07-29 09:11:57 +01:00
..
af_packet
Baseline Optimize Conn::set_conn to minimize operations 2025-07-29 09:11:57 +01:00
Baseline.cpp minor BTest maintenance updates for -O gen-C++ 2025-05-31 12:52:44 -07:00
Baseline.zam Move Conn::set_conn() from connection_state_remove to new_connection 2025-07-29 09:11:57 +01:00
bifs conn_key/fivetuple: Handle one-way ICMP conns in DoConnKeyFromVal() 2025-07-24 09:48:33 +02:00
broker btest/broker/publish-errors: Avoid exit(0) 2025-06-24 19:06:52 +02:00
cluster cluster/WebSocket: Include X-Application-Name in cluster.log 2025-06-30 17:55:24 +02:00
core Optimize Conn::set_conn to minimize operations 2025-07-29 09:11:57 +01:00
coverage extend script coverage profiling to track whether conditionals evaluate to true/false 2025-06-26 16:10:50 +02:00
dns_mgr zeek.bif: Introduce blocking_lookup_hostname() 2025-03-05 19:22:57 +01:00
doc testing/btest/*zeek: Comment all @TEST lines 2025-04-17 16:30:23 +02:00
Files btest/cluster/telemetry: Add smoke testing for telemetry 2025-06-25 17:13:01 +02:00
javascript testing/btest/*js: Comment all @TEST lines 2025-04-17 16:30:23 +02:00
language crash fixes for constructs that expect add/delete expressions to return values 2025-07-11 12:56:08 -04:00
misc
opt ZAM optimizer fix for += / -= set operations 2025-07-09 13:40:33 -07:00
plugins Add storage metrics for operations, expirations, data transferred 2025-07-18 14:28:04 -07:00
scripts Merge remote-tracking branch 'origin/topic/johanna/gh-4656' 2025-07-28 14:16:24 -07:00
signatures testing/btest/*zeek: Comment all @TEST lines 2025-04-17 16:30:23 +02:00
spicy Spicy: Add functions to check if Zeek provides an analyzer of a given name. 2025-07-15 14:22:27 +02:00
supervisor testing/btest/*zeek: Comment all @TEST lines 2025-04-17 16:30:23 +02:00
telemetry
Traces Optimize Conn::set_conn to minimize operations 2025-07-29 09:11:57 +01:00
.gitignore
btest.cfg testing/btest: Remove btest-bg-run sleep 1 2025-03-20 10:11:12 +01: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.