Skip to main content

cu_profiler_core/backend/
program_test.rs

1//! `solana-program-test` backend — **interface stub**.
2//!
3//! This type defines the shape of a program-test backend but does not execute:
4//! [`ExecutionBackend::run`] returns [`crate::Error::BackendUnimplemented`],
5//! because keeping the Solana stack out of the core keeps it pure Rust and
6//! buildable on Windows. The **working** implementation lives in the detached
7//! `cu-profiler-program-test` integration crate; for real compute-unit metering
8//! use `cu-profiler-mollusk`. This stub remains only to document the trait shape.
9
10use std::path::PathBuf;
11
12use crate::Result;
13use crate::backend::{ExecutionBackend, SimulationOutput};
14use crate::error::Error;
15use crate::metadata::BackendKind;
16use crate::scenario::Scenario;
17
18/// Backend that runs scenarios in-process via `solana-program-test`.
19#[derive(Debug, Clone)]
20pub struct ProgramTestBackend {
21    /// Path to the compiled `.so` program under test.
22    pub program_so: PathBuf,
23    /// The program ID to deploy under.
24    pub program_id: String,
25}
26
27impl ProgramTestBackend {
28    /// Construct a backend targeting a compiled program.
29    #[must_use]
30    pub fn new(program_so: impl Into<PathBuf>, program_id: impl Into<String>) -> Self {
31        Self {
32            program_so: program_so.into(),
33            program_id: program_id.into(),
34        }
35    }
36}
37
38impl ExecutionBackend for ProgramTestBackend {
39    fn kind(&self) -> BackendKind {
40        BackendKind::ProgramTest
41    }
42
43    fn run(&self, _scenario: &Scenario) -> Result<SimulationOutput> {
44        Err(Error::BackendUnimplemented(
45            "program-test: this core type is an interface stub — use the \
46             `cu-profiler-program-test` integration crate for a working backend, \
47             or `cu-profiler-mollusk` for real compute-unit metering"
48                .to_string(),
49        ))
50    }
51}