Skip to content

Commit

Permalink
add trace options
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Koubaa committed May 14, 2024
1 parent f2058b4 commit 19ac1cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clr_loader/ffi/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
void mono_set_signal_chaining(bool chain_signals);
void mono_trace_set_level_string(const char* value);
void mono_trace_set_mask_string(const char* value);
"""
)
13 changes: 13 additions & 0 deletions clr_loader/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(
assembly_dir: Optional[str] = None,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False,
trace_mask: Optional[str] = None,
trace_level: Optional[str] = None
):
self._assemblies: Dict[Path, Any] = {}

Expand All @@ -39,6 +41,8 @@ def __init__(
assembly_dir=assembly_dir,
config_dir=config_dir,
set_signal_chaining=set_signal_chaining,
trace_mask=trace_mask,
trace_level=trace_level,
)

if domain is None:
Expand Down Expand Up @@ -130,11 +134,20 @@ def initialize(
assembly_dir: Optional[str] = None,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False,
trace_mask: Optional[str] = None,
trace_level: Optional[str] = None
) -> str:
global _MONO, _ROOT_DOMAIN
if _MONO is None:
_MONO = load_mono(libmono)

if trace_mask is not None:
_MONO.mono_trace_set_mask_string(trace_mask.encode("utf8"))

if trace_level is not None:
_MONO.mono_trace_set_level_string(trace_level.encode("utf8"))


if assembly_dir is not None and config_dir is not None:
_MONO.mono_set_dirs(assembly_dir.encode("utf8"), config_dir.encode("utf8"))

Expand Down
18 changes: 18 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ def test_mono_signal_chaining(example_netstandard: Path):
run_tests(asm)


def test_mono_trace_mask(example_netstandard: Path):
from clr_loader import get_mono

mono = get_mono(trace_mask="all")
asm = mono.get_assembly(example_netstandard / "example.dll")

run_tests(asm)


def test_mono_trace_level(example_netstandard: Path):
from clr_loader import get_mono

mono = get_mono(trace_level="message")
asm = mono.get_assembly(example_netstandard / "example.dll")

run_tests(asm)


def test_mono_set_dir(example_netstandard: Path):
from clr_loader import get_mono

Expand Down

0 comments on commit 19ac1cd

Please sign in to comment.