Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement initial version of agent provider class #93

Merged
merged 1 commit into from
Feb 12, 2024
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
3 changes: 3 additions & 0 deletions python/binharness/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

__version__ = "0.1.0dev0"

from binharness.agentprovider import AgentProvider, DevEnvironmentAgentProvider
from binharness.common import BusyboxInjection
from binharness.localenvironment import LocalEnvironment
from binharness.serialize import TargetImportError, export_target, import_target
Expand All @@ -25,7 +26,9 @@
)

__all__ = [
"AgentProvider",
"BusyboxInjection",
"DevEnvironmentAgentProvider",
"Environment",
"ExecutableInjection",
"Executor",
Expand Down
49 changes: 49 additions & 0 deletions python/binharness/agentprovider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""binharness.agentprovider - AgentProvider class."""

from __future__ import annotations

import abc
from pathlib import Path


class AgentProvider(abc.ABC):
"""AgentProvider class."""

@abc.abstractmethod
def get_agent_bin(self: AgentProvider, target_triplet: str | None = None) -> Path:
"""Return a path to the agent binary for the given target triplet.

If target_triplet is None, return the default agent binary.
"""
raise NotImplementedError


class DevEnvironmentAgentProvider(AgentProvider):
"""DevEnvironmentAgentProvider class."""

path: Path
target: str

def __init__(
self: DevEnvironmentAgentProvider,
path: Path | None = None,
target: str = "debug",
) -> None:
"""Initialize a DevEnvironmentAgentProvider.

If path is not provided, the path will be set assuming the project is installed
in development mode.
"""
if path is None:
self.path = Path(__file__).parent.parent.parent
else:
self.path = path
self.target = target

def get_agent_bin(
self: DevEnvironmentAgentProvider, target_triplet: str | None = None
) -> Path:
"""Return a path to the agent binary for the given target triplet."""
if target_triplet is None:
return self.path / "target" / self.target / "bh_agent_server"
return self.path / "target" / target_triplet / self.target / "bh_agent_server"
13 changes: 13 additions & 0 deletions python/tests/test_agentprovider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

from pathlib import Path

from binharness import DevEnvironmentAgentProvider


def test_host_debug() -> None:
provider = DevEnvironmentAgentProvider()
assert (
provider.get_agent_bin()
== Path(__file__).parent.parent.parent / "target" / "debug" / "bh_agent_server"
)
Loading