From a9fbb68837de74c2923bb7a08281b075f61ee933 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Tue, 3 Sep 2024 22:06:11 +0800 Subject: [PATCH] [ci] add lint CI Signed-off-by: Avimitin --- .github/workflows/lint.yml | 72 +++++++++++++++++++++++++++++ difftest/dpi_t1rocket/src/dpi.rs | 6 +-- difftest/dpi_t1rocket/src/drive.rs | 6 +-- t1rocketemu/online_dpi/src/dpi.rs | 3 +- t1rocketemu/online_dpi/src/drive.rs | 2 +- t1rocketemu/online_dpi/src/lib.rs | 2 +- t1rocketemu/online_dpi/src/svdpi.rs | 5 +- t1rocketemu/online_dpi/src/svvpi.rs | 20 ++++---- t1rocketemu/online_drive/build.rs | 7 ++- t1rocketemu/spike_rs/build.rs | 10 +++- 10 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..2db9422e3 --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 diff --git a/difftest/dpi_t1rocket/src/dpi.rs b/difftest/dpi_t1rocket/src/dpi.rs index 9f4db2699..8e9b85e69 100644 --- a/difftest/dpi_t1rocket/src/dpi.rs +++ b/difftest/dpi_t1rocket/src/dpi.rs @@ -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; @@ -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" ); @@ -316,4 +317,3 @@ unsafe extern "C" fn get_resetvector(resetvector: *mut c_longlong) { //-------------------------------- // import functions and wrappers //-------------------------------- - diff --git a/difftest/dpi_t1rocket/src/drive.rs b/difftest/dpi_t1rocket/src/drive.rs index 8f8cbca3b..af72cf530 100644 --- a/difftest/dpi_t1rocket/src/drive.rs +++ b/difftest/dpi_t1rocket/src/drive.rs @@ -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}; @@ -141,7 +141,7 @@ impl Driver { shadow_mem, - quit: false + quit: false, } } @@ -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={})", diff --git a/t1rocketemu/online_dpi/src/dpi.rs b/t1rocketemu/online_dpi/src/dpi.rs index f4b51f221..2d7f88a5f 100644 --- a/t1rocketemu/online_dpi/src/dpi.rs +++ b/t1rocketemu/online_dpi/src/dpi.rs @@ -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" ); diff --git a/t1rocketemu/online_dpi/src/drive.rs b/t1rocketemu/online_dpi/src/drive.rs index 5c47eed49..4288cdf70 100644 --- a/t1rocketemu/online_dpi/src/drive.rs +++ b/t1rocketemu/online_dpi/src/drive.rs @@ -189,7 +189,7 @@ impl Driver { shadow_mem, - quit: false + quit: false, } } diff --git a/t1rocketemu/online_dpi/src/lib.rs b/t1rocketemu/online_dpi/src/lib.rs index 35a72ec33..2f875209e 100644 --- a/t1rocketemu/online_dpi/src/lib.rs +++ b/t1rocketemu/online_dpi/src/lib.rs @@ -45,4 +45,4 @@ pub fn get_time() -> u64 { #[cfg(all(not(feature = "sv2023"), feature = "svvpi"))] pub fn get_time() -> u64 { svvpi::get_time() -} \ No newline at end of file +} diff --git a/t1rocketemu/online_dpi/src/svdpi.rs b/t1rocketemu/online_dpi/src/svdpi.rs index 227626d79..32d2af9b0 100644 --- a/t1rocketemu/online_dpi/src/svdpi.rs +++ b/t1rocketemu/online_dpi/src/svdpi.rs @@ -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; diff --git a/t1rocketemu/online_dpi/src/svvpi.rs b/t1rocketemu/online_dpi/src/svvpi.rs index 401f7f65a..f0cd8b8bd 100644 --- a/t1rocketemu/online_dpi/src/svvpi.rs +++ b/t1rocketemu/online_dpi/src/svvpi.rs @@ -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) } diff --git a/t1rocketemu/online_drive/build.rs b/t1rocketemu/online_drive/build.rs index fe883aaa8..d08bd0aa5 100644 --- a/t1rocketemu/online_drive/build.rs +++ b/t1rocketemu/online_drive/build.rs @@ -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(); diff --git a/t1rocketemu/spike_rs/build.rs b/t1rocketemu/spike_rs/build.rs index 9399fdaf0..a67a4ba1f 100644 --- a/t1rocketemu/spike_rs/build.rs +++ b/t1rocketemu/spike_rs/build.rs @@ -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");