Skip to content

Commit

Permalink
[ci] add lint CI
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Sep 3, 2024
1 parent 0d25d9e commit a9fbb68
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 24 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Code linting
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
- labeled
env:
USER: runner

# Cancel the current workflow when new commit pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
checkfmt:
name: "Check formats"
strategy:
fail-fast: false
runs-on: [self-hosted, linux, nixos]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: "Run testcases"
run: |
RET=0
warnOnFileChanged() {
if ! git diff -q --exit-code; then
RET=1
local msg="$1"; shift
echo "$msg"
echo "$msg" >> $GITHUB_STEP_SUMMARY
git reset --hard
fi
}
nix develop '.#t1.elaborator' -c mill -i configgen.reformat
nix develop '.#t1.elaborator' -c mill -i rocketv.reformat
nix develop '.#t1.elaborator' -c mill -i t1.reformat
nix develop '.#t1.elaborator' -c mill -i t1rocket.reformat
warnOnFileChanged "* Scala format fail, please run 'nix develop '.#t1.elaborator' -c mill -i _.reformat'"
nix fmt
warnOnFileChanged "* Nix format fail, please run 'nix fmt'"
pushd difftest
nix shell '.#cargo' '.#rustfmt' -c cargo fmt
warnOnFileChanged "* Cargo format fail, please run 'cd difftest; cargo -- format'"
popd
pushd t1rocketemu
nix shell '.#cargo' '.#rustfmt' -c cargo fmt
warnOnFileChanged "* Cargo format fail, please run 'cd t1rocketemu; cargo fmt'"
popd
if nix run '.#ripgrep' -- '\p{Script=Han}' t1 > zh-hans.txt; then
RET=1
msg="* Found ZH_CN comments"
echo "$msg"
echo "$msg" >> $GITHUB_STEP_SUMMARY
echo '```text' >> $GITHUB_STEP_SUMMARY
cat zh-hans.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
git reset --hard
fi
exit $RET
6 changes: 3 additions & 3 deletions difftest/dpi_t1rocket/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use dpi_common::dump::DumpControl;
use dpi_common::plusarg::PlusArgMatcher;
use dpi_common::DpiTarget;
use svdpi::SvScope;
use std::ffi::{c_char, c_longlong};
use svdpi::SvScope;
use tracing::debug;

use crate::drive::Driver;
Expand Down Expand Up @@ -58,7 +58,8 @@ unsafe fn load_from_payload(
})
.collect();
assert_eq!(
masks.len(), data.len(),
masks.len(),
data.len(),
"strobe bit width is not aligned with data byte width"
);

Expand Down Expand Up @@ -316,4 +317,3 @@ unsafe extern "C" fn get_resetvector(resetvector: *mut c_longlong) {
//--------------------------------
// import functions and wrappers
//--------------------------------

6 changes: 3 additions & 3 deletions difftest/dpi_t1rocket/src/drive.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::dpi::*;
use svdpi::SvScope;
use crate::OnlineArgs;
use crate::{get_t, EXIT_CODE, EXIT_POS};
use svdpi::SvScope;

use anyhow::Context;
use dpi_common::dump::{DumpControl, DumpEndError};
Expand Down Expand Up @@ -141,7 +141,7 @@ impl Driver {

shadow_mem,

quit: false
quit: false,
}
}

Expand Down Expand Up @@ -335,7 +335,7 @@ impl Driver {
WATCHDOG_TIMEOUT
} else {
match self.dump_control.trigger_watchdog(tick) {
Ok(()) => {},
Ok(()) => {}
Err(DumpEndError) => {
info!(
"[{tick}] run to dump end, exiting (last_commit_cycle={})",
Expand Down
3 changes: 2 additions & 1 deletion t1rocketemu/online_dpi/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ unsafe fn load_from_payload(
})
.collect();
assert_eq!(
masks.len(), data.len(),
masks.len(),
data.len(),
"strobe bit width is not aligned with data byte width"
);

Expand Down
2 changes: 1 addition & 1 deletion t1rocketemu/online_dpi/src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Driver {

shadow_mem,

quit: false
quit: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion t1rocketemu/online_dpi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ pub fn get_time() -> u64 {
#[cfg(all(not(feature = "sv2023"), feature = "svvpi"))]
pub fn get_time() -> u64 {
svvpi::get_time()
}
}
5 changes: 4 additions & 1 deletion t1rocketemu/online_dpi/src/svdpi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{ffi::{c_void, CString}, ptr::{self, NonNull}};
use std::{
ffi::{c_void, CString},
ptr::{self, NonNull},
};

#[rustfmt::skip]
pub mod sys;
Expand Down
20 changes: 10 additions & 10 deletions t1rocketemu/online_dpi/src/svvpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use std::ptr;

/// get current simulation time in _simulation time unit_
pub fn get_time() -> u64 {
let mut time = sys::s_vpi_time {
type_: sys::vpiSimTime as i32,
high: 0,
low: 0,
real: 0.0,
};
unsafe {
sys::vpi_get_time(ptr::null_mut(), &mut time);
}
((time.high as u64) << 32) + (time.low as u64)
let mut time = sys::s_vpi_time {
type_: sys::vpiSimTime as i32,
high: 0,
low: 0,
real: 0.0,
};
unsafe {
sys::vpi_get_time(ptr::null_mut(), &mut time);
}
((time.high as u64) << 32) + (time.low as u64)
}
7 changes: 5 additions & 2 deletions t1rocketemu/online_drive/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use cmake::Config;

fn main() {
#[cfg(feature = "trace")]
let dst =
Config::new("verilator_shim").define("VM_TRACE", "1").very_verbose(true).always_configure(true).build();
let dst = Config::new("verilator_shim")
.define("VM_TRACE", "1")
.very_verbose(true)
.always_configure(true)
.build();
#[cfg(not(feature = "trace"))]
let dst = Config::new("verilator_shim").very_verbose(true).always_configure(true).build();

Expand Down
10 changes: 8 additions & 2 deletions t1rocketemu/spike_rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use std::env;

fn main() {
println!("cargo::rustc-link-search=native={}", env::var("SPIKE_LIB_DIR").expect("SPIKE_LIB_DIR should be set"));
println!(
"cargo::rustc-link-search=native={}",
env::var("SPIKE_LIB_DIR").expect("SPIKE_LIB_DIR should be set")
);
println!("cargo::rustc-link-lib=static=riscv");
println!("cargo::rustc-link-lib=static=softfloat");
println!("cargo::rustc-link-lib=static=disasm");
println!("cargo::rustc-link-lib=static=fesvr");
println!("cargo::rustc-link-lib=static=fdt");

println!("cargo::rustc-link-search=native={}", env::var("SPIKE_INTERFACES_LIB_DIR").expect("SPIKE_INTERFACES_LIB_DIR should be set"));
println!(
"cargo::rustc-link-search=native={}",
env::var("SPIKE_INTERFACES_LIB_DIR").expect("SPIKE_INTERFACES_LIB_DIR should be set")
);
println!("cargo::rustc-link-lib=static=spike_interfaces");

println!("cargo::rerun-if-env-changed=SPIKE_LIB_DIR");
Expand Down

0 comments on commit a9fbb68

Please sign in to comment.