Support for unit tests in plugins

This pushes the unit test kickoff down in the Zeek startup sequence, to give
plugins a chance to register. It also enforces deterministic mode for unit
testing, since without it some unit tests start to have nondeterministic results
at that stage.
This commit is contained in:
Christian Kreibich 2021-07-02 15:19:11 -07:00
parent f8b8401d84
commit f20f8ad4a8
2 changed files with 12 additions and 7 deletions

View file

@ -629,6 +629,7 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/patricia.h
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/setsignal.h
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/sqlite3.h
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/doctest.h
DESTINATION include/zeek/3rdparty
)

View file

@ -416,13 +416,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
}
if ( options.run_unit_tests )
{
doctest::Context context;
auto dargs = to_cargs(options.doctest_args);
context.applyCommandLine(dargs.size(), dargs.data());
ZEEK_LSAN_ENABLE();
exit(context.run());
}
options.deterministic_mode = true;
auto stem = Supervisor::CreateStem(options.supervisor_mode);
@ -601,6 +595,16 @@ SetupResult setup(int argc, char** argv, Options* zopts)
plugin_mgr->ActivateDynamicPlugins(! options.bare_mode);
// Delay the unit test until here so that plugins have been loaded.
if ( options.run_unit_tests )
{
doctest::Context context;
auto dargs = to_cargs(options.doctest_args);
context.applyCommandLine(dargs.size(), dargs.data());
ZEEK_LSAN_ENABLE();
exit(context.run());
}
// Print usage after plugins load so that any path extensions are properly shown.
if ( options.print_usage )
usage(argv[0], 0);