Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@ docs = [
"mkdocs-material>=9.5",
"pymdown-extensions>=10.9",
]

[tool.pytest.ini_options]
markers = [
"slow: marks tests as slow",
]
4 changes: 2 additions & 2 deletions src/hyperscan/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static int hs_match_handler(
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyObject *rv = PyObject_CallFunction(
cctx->callback, "IIIIO", id, from, to, flags, cctx->ctx);
cctx->callback, "IKKIO", id, from, to, flags, cctx->ctx);
int halt = 1;
if (rv == NULL) {
cctx->success = 0;
Expand Down Expand Up @@ -273,7 +273,7 @@ static int ch_match_handler(
}
PyObject *rv = PyObject_CallFunction(
cctx->callback,
"IIIIOO",
"IKKIOO",
id,
from,
to,
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest

def pytest_addoption(parser):
parser.addoption(
"--run-slow", action="store_true", default=False,
help="Run slow tests"
)

def pytest_collection_modifyitems(config, items):
if not config.getoption("--run-slow"):
skip_slow = pytest.mark.skip(reason="Pass --run-slow to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
28 changes: 28 additions & 0 deletions tests/test_hyperscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,31 @@ def on_test_match(pattern_id, from_offset, to_offset, flags, context):

test_db.scan(b"test", match_event_handler=on_test_match)
assert len(test_matches) > 0, "Basic pattern matching should work"


@pytest.mark.slow
def test_vectored_scan_large_offset(database_vector, mocker):
callback = mocker.Mock(return_value=None)
buffers = [
b"x"*(2**32-1),
b"fo"
]
database_vector.scan(buffers, match_event_handler=callback)
callback.assert_has_calls(
[
mocker.call(0,0,2**32+1,0,None),
],
)


@pytest.mark.slow
def test_stream_scan_large_offset(database_stream, mocker):
callback = mocker.Mock(return_value=None)
with database_stream.stream(match_event_handler=callback) as stream:
stream.scan(b"x"*(2**32-1))
stream.scan(b"fo")
callback.assert_has_calls(
[
mocker.call(0,0,2**32+1,0,None)
],
)
Loading