Skip to content

Commit

Permalink
[difftest] remove test_common
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Sep 8, 2024
1 parent f6e1886 commit e0446a2
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 290 deletions.
30 changes: 18 additions & 12 deletions difftest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion difftest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[workspace]
resolver = "2"
members = [
"test_common",
"spike_rs",
"offline_t1",
"offline_t1rocket",
"dpi_t1",
"dpi_t1rocket",
"dpi_common",
Expand Down
1 change: 0 additions & 1 deletion difftest/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ rustPlatform.buildRustPackage {
./dpi_common
./dpi_t1
./dpi_t1rocket
./test_common
./Cargo.lock
./Cargo.toml
];
Expand Down
1 change: 1 addition & 0 deletions difftest/dpi_t1/src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl Driver {
&SpikeArgs {
elf_file: args.elf_file.clone(),
log_file: args.log_file.clone(),
log_level: "info".to_string(),
vlen: args.vlen,
dlen: args.dlen,
set: args.set.clone(),
Expand Down
1 change: 0 additions & 1 deletion difftest/offline_t1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ num-bigint = { workspace = true }
libloading = "0.8.1"
xmas-elf = "0.9.1"

common = { path = "../test_common" }
spike_rs = { path = "../spike_rs" }
17 changes: 3 additions & 14 deletions difftest/offline_t1/src/difftest.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
use common::spike_runner::SpikeRunner;
use spike_rs::runner::*;
use std::path::Path;
use tracing::info;

use common::rtl_config::RTLConfig;
use common::CommonArgs;

use crate::dut::Dut;
use crate::json_events::*;

pub struct Difftest {
runner: SpikeRunner,
dut: Dut,

#[allow(dead_code)]
config: RTLConfig,
}

impl Difftest {
pub fn new(args: CommonArgs) -> Self {
let config = RTLConfig { vlen: args.vlen, dlen: args.dlen };
pub fn new(args: SpikeArgs) -> Self {
Self {
runner: SpikeRunner::new(&args, true),
dut: Dut::new(Path::new(
&args.log_file.expect("difftest must be run with a log file"),
)),
config,
}
}

Expand All @@ -39,9 +30,7 @@ impl Difftest {
Ok(())
}
JsonEvents::SimulationStop { reason, cycle } => {
info!("simulation stopped at cycle {}, reason {}", cycle, reason);
self.runner.cycle = *cycle;
Ok(())
anyhow::bail!("stop: simulation stopped at cycle {cycle}, reason {reason}")
}
JsonEvents::Issue { idx, cycle } => {
self.runner.cycle = *cycle;
Expand Down
11 changes: 1 addition & 10 deletions difftest/offline_t1/src/json_events.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
use common::spike_runner::SpikeRunner;
use num_bigint::BigUint;
use serde::{Deserialize, Deserializer};
use spike_rs::runner::SpikeRunner;
use spike_rs::spike_event::LSU_IDX_DEFAULT;
use tracing::{debug, info};

#[derive(Deserialize, Debug, PartialEq, Clone)]
pub enum Opcode {
PutFullData = 0,
PutPartialData = 1,
Get = 4,
// AccessAckData = 0,
// AccessAck = 0,
}

fn bigint_to_vec_u8<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where
D: Deserializer<'de>,
Expand Down
7 changes: 3 additions & 4 deletions difftest/offline_t1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ mod json_events;
use clap::Parser;
use tracing::info;

use common::spike_runner::SpikeRunner;
use common::CommonArgs;
use spike_rs::runner::*;

use crate::difftest::Difftest;

fn run_spike(args: &CommonArgs) -> anyhow::Result<()> {
fn run_spike(args: &SpikeArgs) -> anyhow::Result<()> {
let mut count: u64 = 0;

let spike = SpikeRunner::new(args, true);
Expand All @@ -32,7 +31,7 @@ fn run_spike(args: &CommonArgs) -> anyhow::Result<()> {

fn main() -> anyhow::Result<()> {
// parse args
let args = CommonArgs::parse();
let args = SpikeArgs::parse();

args.setup_logger()?;

Expand Down
1 change: 0 additions & 1 deletion difftest/offline_t1rocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ num-bigint = { workspace = true }
libloading = "0.8.1"
xmas-elf = "0.9.1"

common = { path = "../test_common" }
spike_rs = { path = "../spike_rs" }
12 changes: 2 additions & 10 deletions difftest/offline_t1rocket/src/difftest.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
use common::spike_runner::SpikeRunner;
use spike_rs::spike_runner::{SpikeArgs, SpikeRunner};
use std::path::Path;

use common::rtl_config::RTLConfig;
use common::CommonArgs;

use crate::dut::Dut;
use crate::json_events::*;

pub struct Difftest {
runner: SpikeRunner,
dut: Dut,

#[allow(dead_code)]
config: RTLConfig,
}

impl Difftest {
pub fn new(args: CommonArgs) -> Self {
let config = RTLConfig { vlen: args.vlen, dlen: args.dlen };
pub fn new(args: SpikeArgs) -> Self {
Self {
runner: SpikeRunner::new(&args, true),
dut: Dut::new(Path::new(
&args.log_file.expect("difftest must be run with a log file"),
)),
config,
}
}

Expand Down
1 change: 0 additions & 1 deletion difftest/offline_t1rocket/src/dut.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::Context;
use std::io::BufRead;
use std::path::Path;

Expand Down
2 changes: 1 addition & 1 deletion difftest/offline_t1rocket/src/json_events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use common::spike_runner::SpikeRunner;
use num_bigint::BigUint;
use serde::{Deserialize, Deserializer};
use spike_rs::runner::SpikeRunner;
use spike_rs::spike_event::LSU_IDX_DEFAULT;
use tracing::{debug, info};

Expand Down
7 changes: 3 additions & 4 deletions difftest/offline_t1rocket/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ mod json_events;
use clap::Parser;
use tracing::info;

use common::spike_runner::SpikeRunner;
use common::CommonArgs;
use spike_rs::runner::{SpikeArgs, SpikeRunner};

use crate::difftest::Difftest;

fn run_spike(args: &CommonArgs) -> anyhow::Result<()> {
fn run_spike(args: &SpikeArgs) -> anyhow::Result<()> {
let mut count: u64 = 0;

let spike = SpikeRunner::new(args, true);
Expand All @@ -32,7 +31,7 @@ fn run_spike(args: &CommonArgs) -> anyhow::Result<()> {

fn main() -> anyhow::Result<()> {
// parse args
let args = CommonArgs::parse();
let args = SpikeArgs::parse();

args.setup_logger()?;

Expand Down
3 changes: 3 additions & 0 deletions difftest/spike_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition = "2021"

[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

libc = "0.2.155"
xmas-elf = "0.9.1"
32 changes: 31 additions & 1 deletion difftest/spike_rs/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use clap::Parser;
use std::collections::VecDeque;
use std::path::{Path, PathBuf};
use tracing::debug;
use tracing::{debug, Level};
use tracing_subscriber::{EnvFilter, FmtSubscriber};

use crate::spike_event::SpikeEvent;
use crate::util::load_elf;
Expand Down Expand Up @@ -32,20 +34,31 @@ pub struct SpikeRunner {
pub do_log_vrf: bool,
}

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct SpikeArgs {
/// Path to the ELF file
#[arg(long)]
pub elf_file: PathBuf,

/// Path to the log file
#[arg(long)]
pub log_file: Option<PathBuf>,

/// Log level: trace, debug, info, warn, error
#[arg(long, default_value = "info")]
pub log_level: String,

/// vlen config
#[arg(long, default_value = env!("DESIGN_VLEN"))]
pub vlen: u32,

/// dlen config
#[arg(long, default_value = env!("DESIGN_DLEN"))]
pub dlen: u32,

/// ISA config
#[arg(long, default_value = env!("SPIKE_ISA_STRING"))]
pub set: String,
}

Expand All @@ -54,6 +67,23 @@ impl SpikeArgs {
let lvl = "M";
Spike::new(&self.set, lvl, (self.dlen / 32) as usize, MEM_SIZE)
}

pub fn setup_logger(&self) -> anyhow::Result<()> {
// setup log
let log_level: Level = self.log_level.parse()?;
let global_logger = FmtSubscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.with_max_level(log_level)
.without_time()
.with_target(false)
.with_ansi(true)
.compact()
.finish();
tracing::subscriber::set_global_default(global_logger)
.expect("internal error: fail to setup log subscriber");

Ok(())
}
}

pub const MEM_SIZE: usize = 1usize << 32;
Expand Down
11 changes: 0 additions & 11 deletions difftest/test_common/Cargo.toml

This file was deleted.

Loading

0 comments on commit e0446a2

Please sign in to comment.