code_executor/
lib.rs

1mod cgroup;
2mod compiler;
3mod error;
4mod language;
5mod metrics;
6mod runner;
7mod util;
8
9pub use cgroup::*;
10pub use compiler::*;
11pub use error::*;
12pub use language::*;
13pub use metrics::*;
14pub use runner::*;
15
16#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
17pub struct CommandArgs<'a> {
18    pub binary: &'a str,
19    pub args: &'a [&'a str],
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct Language<'a> {
24    pub compiler: Compiler<'a>,
25    pub runner_args: CommandArgs<'a>,
26}
27
28#[cfg(test)]
29mod test {
30    use std::{fs, path::Path};
31
32    use crate::Language;
33
34    pub fn read_test_cases(problem_path: &Path) -> Vec<(Vec<u8>, Vec<u8>)> {
35        let test_cases: Vec<_> = fs::read_dir(problem_path)
36            .unwrap()
37            .filter_map(|entry| {
38                let entry = entry.unwrap();
39                let path = entry.path();
40                if !path.is_dir() {
41                    return None;
42                }
43
44                let input_path = path.join("in.txt");
45                let input = fs::read(input_path).unwrap();
46
47                let output_path = path.join("out.txt");
48                let output = fs::read(output_path).unwrap();
49
50                Some((input, output))
51            })
52            .collect();
53
54        test_cases
55    }
56
57    pub fn read_code(language: Language, problem_path: &Path) -> Vec<u8> {
58        fs::read(problem_path.join(language.compiler.main_file)).unwrap()
59    }
60}