Skip to main content

kermit_bench/
benchmark.rs

1use {super::downloader::DownloadSpec, std::path::Path};
2
3/// A single benchmark sub-task: a specific data scale or configuration within a
4/// [`Task`].
5pub struct SubTask {
6    pub name: &'static str,
7    pub description: &'static str,
8    pub data_paths: &'static [&'static str],
9    pub query_paths: &'static [&'static str],
10}
11
12/// A group of related benchmark sub-tasks (e.g. "Uniform" or "Zipf"
13/// distribution).
14pub struct Task {
15    pub name: &'static str,
16    pub description: &'static str,
17    pub subtasks: &'static [SubTask],
18}
19
20/// Static metadata describing a benchmark: its name, download source, and task
21/// hierarchy.
22pub struct BenchmarkMetadata {
23    pub name: &'static str,
24    pub description: &'static str,
25    pub download_spec: DownloadSpec,
26    pub tasks: &'static [Task],
27}
28
29/// Trait that each benchmark must implement to define its metadata, loading
30/// logic, and validation.
31pub trait BenchmarkConfig {
32    /// Returns the static metadata for this benchmark.
33    fn metadata(&self) -> &BenchmarkMetadata;
34
35    /// Loads and transforms the raw downloaded dataset from `source` into the
36    /// benchmark directory at `path`.
37    fn load(&self, source: &Path, path: &Path) -> Result<(), Box<dyn std::error::Error>>;
38    /// Validates that all expected data and query files exist under `path`.
39    /// Uses the paths declared in [`SubTask`] definitions.
40    fn validate(&self, path: &Path) -> Result<(), Box<dyn std::error::Error>> {
41        let metadata = self.metadata();
42
43        for task in metadata.tasks {
44            for subtask in task.subtasks {
45                // Validate data paths
46                for data_path in subtask.data_paths {
47                    let full_data_path = path.join(metadata.download_spec.name).join(data_path);
48                    if !full_data_path.exists() {
49                        return Err(format!(
50                            "Data path does not exist: {} (expected at: {})",
51                            data_path,
52                            full_data_path.display()
53                        )
54                        .into());
55                    }
56                }
57
58                // Validate query paths
59                for query_path in subtask.query_paths {
60                    let full_query_path = path.join(metadata.download_spec.name).join(query_path);
61                    if !full_query_path.exists() {
62                        return Err(format!(
63                            "Query path does not exist: {} (expected at: {})",
64                            query_path,
65                            full_query_path.display()
66                        )
67                        .into());
68                    }
69                }
70            }
71        }
72
73        Ok(())
74    }
75}