Add difftest support to npc #3

Merged
xin merged 10 commits from npc-debug-tools into master 2024-04-05 05:14:45 +00:00
7 changed files with 143 additions and 12 deletions
Showing only changes of commit e1438e25ed - Show all commits

View file

@ -0,0 +1,45 @@
name: Run CTests within npc
on: [push]
jobs:
npc-test:
runs-on: nix
steps:
- uses: https://github.com/cachix/cachix-action@v14
with:
name: ysyx
authToken: '${{ secrets.CACHIX_SIGNING_KEY }}'
- uses: actions/checkout@v4
with:
submodules: true
- name: Cache develop environment
id: cache-nix-develop
uses: actions/cache@v4
with:
path: /nix/store
key: nix-develop-${{ hashFiles('flake.*') }}
- name: Fetch nix store
if: steps.cache-nix-develop.outputs.cache-hit != 'true'
run: nix develop .#npc
- name: Use develop environment
uses: https://git.xinyang.life/xin/nix-develop@main
with:
arguments: .#npc
- name: Cache sbt dependencies
id: cache-sbt-dependency
uses: actions/cache@v4
with:
path: npc/core
key: core-${{ hashFiles('npc/core/build.sbt') }}
- name: Fetch sbt dependencies
if: steps.cache-sbt-dependency.outputs.cache-hit != 'true'
run: |
cd npc/core
sbt update
- name: Run difftests
run: |
mkdir -p npc/build
cd npc/build
cmake $cmakeFlags ../
make -j8
ctest -V

View file

@ -50,6 +50,7 @@
}; };
}; };
packages.nemu = pkgs.callPackage ./nemu { am-kernels = self.packages.${system}.am-kernels; }; packages.nemu = pkgs.callPackage ./nemu { am-kernels = self.packages.${system}.am-kernels; };
packages.nemu-lib = pkgs.callPackage ./nemu { am-kernels = self.packages.${system}.am-kernels; defconfig = "riscv32-lib_defconfig"; };
packages.abstract-machine = crossPkgs.callPackage ./abstract-machine { isa = "riscv"; platform = "nemu"; }; packages.abstract-machine = crossPkgs.callPackage ./abstract-machine { isa = "riscv"; platform = "nemu"; };
packages.am-kernels = crossPkgs.stdenv.mkDerivation rec { packages.am-kernels = crossPkgs.stdenv.mkDerivation rec {
@ -82,6 +83,7 @@
inputsFrom = [ inputsFrom = [
self.packages.${system}.nemu self.packages.${system}.nemu
]; ];
IMAGES_PATH = "${self.packages.${system}.am-kernels}/share/binary";
}; };
devShells.npc = with pkgs; mkShell { devShells.npc = with pkgs; mkShell {
@ -113,7 +115,12 @@
buildInputs = [ buildInputs = [
verilator verilator
nvboard nvboard
openssl
] ++ self.checks.${system}.pre-commit-check.enabledPackages; ] ++ self.checks.${system}.pre-commit-check.enabledPackages;
cmakeFlags = [
"-DDIFFTEST_LIB:string=${self.packages.${system}.nemu-lib}/lib/riscv32-nemu-interpreter-so"
];
}; };
} }
); );

View file

@ -0,0 +1,72 @@
#
# Automatically generated file; DO NOT EDIT.
# NEMU Configuration Menu
#
# CONFIG_ISA_x86 is not set
# CONFIG_ISA_mips32 is not set
CONFIG_ISA_riscv=y
# CONFIG_ISA_loongarch32r is not set
CONFIG_ISA="riscv32"
#
# ISA-dependent Options for riscv
#
# CONFIG_RV64 is not set
# CONFIG_RVE is not set
# end of ISA-dependent Options for riscv
CONFIG_ENGINE_INTERPRETER=y
CONFIG_ENGINE="interpreter"
CONFIG_MODE_SYSTEM=y
# CONFIG_TARGET_NATIVE_ELF is not set
CONFIG_TARGET_SHARE=y
# CONFIG_TARGET_AM is not set
#
# Build Options
#
CONFIG_CC_GCC=y
# CONFIG_CC_GPP is not set
# CONFIG_CC_CLANG is not set
CONFIG_CC="gcc"
# CONFIG_CC_O0 is not set
# CONFIG_CC_O1 is not set
CONFIG_CC_O2=y
# CONFIG_CC_O3 is not set
CONFIG_CC_OPT="-O2"
CONFIG_CC_LTO=y
CONFIG_CC_DEBUG=y
# CONFIG_CC_ASAN is not set
# end of Build Options
#
# Testing and Debugging
#
CONFIG_LOG_TRACE=y
# CONFIG_LOG_INFO is not set
# CONFIG_LOG_WARNING is not set
# CONFIG_LOG_ERROR is not set
CONFIG_LOG_LEVEL=4
# CONFIG_TRACE is not set
CONFIG_DIFFTEST_REF_PATH="none"
CONFIG_DIFFTEST_REF_NAME="none"
# end of Testing and Debugging
#
# Memory Configuration
#
CONFIG_MBASE=0x80000000
CONFIG_MSIZE=0x8000000
CONFIG_PC_RESET_OFFSET=0
# CONFIG_PMEM_MALLOC is not set
CONFIG_PMEM_GARRAY=y
CONFIG_MEM_RANDOM=y
# end of Memory Configuration
#
# Miscellaneous
#
CONFIG_TIMER_GETTIMEOFDAY=y
# CONFIG_TIMER_CLOCK_GETTIME is not set
CONFIG_RT_CHECK=y
# end of Miscellaneous

View file

@ -2,7 +2,8 @@
lib, lib,
stdenv, stdenv,
am-kernels, am-kernels,
dtc dtc,
defconfig ? "alldefconfig",
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@ -31,27 +32,27 @@ stdenv.mkDerivation rec {
configurePhase = '' configurePhase = ''
export NEMU_HOME=$(pwd) export NEMU_HOME=$(pwd)
make alldefconfig make ${defconfig}
''; '';
buildPhase = '' buildPhase = ''
make make
''; '';
doCheck = true; doCheck = (defconfig == "alldefconfig");
checkPhase = '' checkPhase = if doCheck then ''
export IMAGES_PATH=${am-kernels}/share/binary export IMAGES_PATH=${am-kernels}/share/binary
make test make test
''; '' else "";
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
mkdir -p $out/lib
make PREFIX=$out install make PREFIX=$out install
''; '';
shellHook = '' shellHook = ''
export NEMU_HOME=$(pwd) export NEMU_HOME=$(pwd)
export IMAGES_PATH=${am-kernels}/share/binary
''; '';
meta = with lib; { meta = with lib; {

View file

@ -76,8 +76,13 @@ $(BINARY):: $(OBJS) $(ARCHIVES)
@$(LD) -o $@ $(OBJS) $(LDFLAGS) $(ARCHIVES) $(LIBS) @$(LD) -o $@ $(OBJS) $(LDFLAGS) $(ARCHIVES) $(LIBS)
install: $(BINARY) install: $(BINARY)
ifeq ($(SHARE),1)
@mkdir -p $(PREFIX)/lib
@cp $(BINARY) $(PREFIX)/lib/
else
@mkdir -p $(PREFIX)/bin @mkdir -p $(PREFIX)/bin
@cp $(BINARY) $(PREFIX)/bin/ @cp $(BINARY) $(PREFIX)/bin/
endif
clean: clean:
-rm -rf $(BUILD_DIR) -rm -rf $(BUILD_DIR)

View file

@ -15,6 +15,7 @@ option(BUILD_SIM_TARGET "Whether to build verilator simulation binary" ON)
cmake_dependent_option(BUILD_SIM_NVBOARD_TARGET "Whether to build nvboard target" OFF "BUILD_SIM_TARGET" OFF) cmake_dependent_option(BUILD_SIM_NVBOARD_TARGET "Whether to build nvboard target" OFF "BUILD_SIM_TARGET" OFF)
option(ENABLE_YSYX_GIT_TRACKER "Ysyx tracker support" OFF) option(ENABLE_YSYX_GIT_TRACKER "Ysyx tracker support" OFF)
set(TOPMODULE "Flow" CACHE STRING "Topmodule name in chisel") set(TOPMODULE "Flow" CACHE STRING "Topmodule name in chisel")
set(DIFFTEST_LIB "" CACHE STRING "Dynamic library file used as difftest reference")
# -- Ysyx tracker, configure # -- Ysyx tracker, configure
if(ENABLE_YSYX_GIT_TRACKER) if(ENABLE_YSYX_GIT_TRACKER)
@ -61,12 +62,6 @@ include_directories(include)
add_subdirectory(csrc) add_subdirectory(csrc)
add_test(
NAME V${TOPMODULE}
COMMAND V${TOPMODULE}
--no-bin -m ${PROJECT_SOURCE_DIR}/resource/addi.txt
--diff-lib /home/xin/repo/ysyx-workbench/nemu/build/riscv32-nemu-interpreter-so)
# -- Add build tracking # -- Add build tracking
if(ENABLE_YSYX_GIT_TRACKER) if(ENABLE_YSYX_GIT_TRACKER)
add_custom_command( add_custom_command(

View file

@ -9,3 +9,9 @@ verilate(V${TOPMODULE} TRACE COVERAGE THREADS
VERILATOR_ARGS VERILATOR_ARGS
"--vpi" # Enable VPI "--vpi" # Enable VPI
) )
add_test(
NAME V${TOPMODULE}
COMMAND V${TOPMODULE}
--no-bin -m ${PROJECT_SOURCE_DIR}/resource/addi.txt
--diff-lib ${DIFFTEST_LIB})