Skip to content

Commit

Permalink
Implement initial version of agent provider class (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin authored Feb 12, 2024
1 parent de2c281 commit 4f31a85
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
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"
)

0 comments on commit 4f31a85

Please sign in to comment.