oa_gateway_bench/
main.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Latency and throughput utility. Calls public gateway APIs only.

mod cli;
mod clock;
mod owp_client;
mod payload;
mod report;
mod scenarios;

use std::process::ExitCode;

use cli::{parse_args, Command, USAGE};

#[tokio::main]
async fn main() -> ExitCode {
    match run().await {
        Ok(()) => ExitCode::SUCCESS,
        Err(err) => {
            if err == USAGE.trim_end() {
                print!("{USAGE}");
                ExitCode::SUCCESS
            } else {
                eprintln!("{err}");
                ExitCode::FAILURE
            }
        }
    }
}

async fn run() -> Result<(), String> {
    let command = parse_args(std::env::args().skip(1))?;
    match command {
        Command::Help => {
            print!("{USAGE}");
            Ok(())
        }
        Command::Engine(args) => scenarios::engine::run(args).await,
        Command::Loopback(args) => scenarios::loopback::run(args).await,
        Command::Owp(args) => scenarios::owp::run(args).await,
        Command::Uci(args) => scenarios::uci::run(args),
        Command::Ping(args) => scenarios::ping::run(args).await,
    }
}