From fdcb857e3385e4ca53440aa58510dc4ad6d94f57 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 +-- 3 files changed, 78 insertions(+), 6 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..7e32e3c16 --- /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; nix run .#cargo -- format'" + popd + + pushd t1rocketemu + nix shell '.#cargo' '.#rustfmt' -c cargo fmt + warnOnFileChanged "* Cargo format fail, please run 'cd t1rocketemu; nix run .#cargo -- format'" + 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={})",