mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 12:08:20 +00:00
cirrus: Add smoke testing for builtin plugins
This adds two example plugins within testing/builtin-plugins/Files: * protocol-plugin copied over from testing/btest/plugins/protocol-plugin * py-lib-plugin that embeds Python to have a dependency on an external shared library which was already available in CI and fun to use, too. Closes #2837
This commit is contained in:
parent
42c1fc3e7d
commit
1912ba7002
31 changed files with 435 additions and 0 deletions
34
testing/builtin-plugins/Files/py-lib-plugin/CMakeLists.txt
Normal file
34
testing/builtin-plugins/Files/py-lib-plugin/CMakeLists.txt
Normal file
|
@ -0,0 +1,34 @@
|
|||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
|
||||
find_package(PythonLibs REQUIRED)
|
||||
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1)
|
||||
|
||||
string(REGEX REPLACE "[.-]" " " version_numbers ${VERSION})
|
||||
separate_arguments(version_numbers)
|
||||
list(GET version_numbers 0 VERSION_MAJOR)
|
||||
list(GET version_numbers 1 VERSION_MINOR)
|
||||
list(GET version_numbers 2 VERSION_PATCH)
|
||||
|
||||
# Our plugin source and scripts are in a subdirectory
|
||||
set(BRO_PLUGIN_BASE "${CMAKE_CURRENT_SOURCE_DIR}/plugin")
|
||||
|
||||
include(ZeekPlugin)
|
||||
|
||||
include_directories(BEFORE ${PYTHON_INCLUDE_DIR})
|
||||
|
||||
zeek_plugin_begin(Zeek PyLib)
|
||||
|
||||
file(GLOB cc_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "plugin/src/*.cc")
|
||||
foreach(file ${cc_files})
|
||||
zeek_plugin_cc(${file})
|
||||
endforeach ()
|
||||
|
||||
file(GLOB bif_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "plugin/src/*.bif")
|
||||
foreach(file ${bif_files})
|
||||
zeek_plugin_bif(${file})
|
||||
endforeach ()
|
||||
|
||||
zeek_plugin_dist_files(README VERSION)
|
||||
zeek_plugin_link_library(${PYTHON_LIBRARY})
|
||||
zeek_plugin_end()
|
8
testing/builtin-plugins/Files/py-lib-plugin/README
Normal file
8
testing/builtin-plugins/Files/py-lib-plugin/README
Normal file
|
@ -0,0 +1,8 @@
|
|||
PyLib
|
||||
=====
|
||||
|
||||
Embedding Python with a plugin.
|
||||
|
||||
zeek -e 'Python::run_simple_string("import this")'
|
||||
|
||||
Mostly to test a link dependency of a builtin plugin.
|
1
testing/builtin-plugins/Files/py-lib-plugin/VERSION
Normal file
1
testing/builtin-plugins/Files/py-lib-plugin/VERSION
Normal file
|
@ -0,0 +1 @@
|
|||
0.0.1
|
|
@ -0,0 +1,34 @@
|
|||
#include "Plugin.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <Python.h>
|
||||
}
|
||||
|
||||
namespace zeek::plugin::Zeek_PyLib
|
||||
{
|
||||
Plugin plugin;
|
||||
}
|
||||
|
||||
using namespace zeek::plugin::Zeek_PyLib;
|
||||
|
||||
zeek::plugin::Configuration Plugin::Configure()
|
||||
{
|
||||
zeek::plugin::Configuration config;
|
||||
config.name = "Zeek::PyLib";
|
||||
config.description = "Plugin embedding Python, whoosh.";
|
||||
config.version.major = 0;
|
||||
config.version.minor = 0;
|
||||
config.version.patch = 1;
|
||||
return config;
|
||||
}
|
||||
|
||||
void Plugin::InitPostScript()
|
||||
{
|
||||
Py_Initialize();
|
||||
}
|
||||
|
||||
void Plugin::Done()
|
||||
{
|
||||
Py_FinalizeEx();
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <zeek/plugin/Plugin.h>
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
namespace Zeek_PyLib
|
||||
{
|
||||
|
||||
class Plugin : public zeek::plugin::Plugin
|
||||
{
|
||||
protected:
|
||||
zeek::plugin::Configuration Configure() override;
|
||||
void InitPostScript() override;
|
||||
void Done() override;
|
||||
};
|
||||
|
||||
extern Plugin plugin;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
module Python;
|
||||
|
||||
%%{
|
||||
extern "C" {
|
||||
#include <Python.h>
|
||||
}
|
||||
%%}
|
||||
|
||||
function version%(%): string
|
||||
%{
|
||||
return zeek::make_intrusive<zeek::StringVal>(Py_GetVersion());
|
||||
%}
|
||||
|
||||
function run_simple_string%(s: string%): bool
|
||||
%{
|
||||
PyRun_SimpleString(s->CheckString());
|
||||
return zeek::val_mgr->True();
|
||||
%}
|
Loading…
Add table
Add a link
Reference in a new issue