FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

RISC-VのコンプライアンステストフレームワークRISCOFを試す (1. インストールとサンプル試行)

RISCOFというのは、RISC-V Compilance Flameworkの略で、RISC-Vアーキテクチャアセンブリテストを使用して、標準のRISC-Vリファレンスモデルに対するハードウェア・ソフトウェアのテストを行うためのPythonベースのフレームワークとなっている。

まずは、インストールを行ってみる。Pythonベースのフレームワークなので、pip3を使用してインストールする。

参考にしたのは以下のサイトである。

https://riscof.readthedocs.io/en/stable/index.html

$ cd work/riscv
$ pip3 install git+https://github.com/riscv/riscof.git

インストール後にコマンドを確認してみる。

$ riscof
Usage: riscof [OPTIONS] COMMAND [ARGS]...

Options:
  --version                       Show the version and exit.
  -v, --verbose [info|error|debug]
                                  Set verbose level
  --help                          Show this message and exit.

Commands:
  arch-test     Setup and maintenance for Architectural TestSuite.
  coverage      Run the tests on DUT and reference and compare signatures
  gendb         Generate Database for the Suite.
  run           Run the tests on DUT and reference and compare signatures
  setup         Initiate Setup for riscof.
  testlist      Generate the test list for the given DUT and suite.
  validateyaml  Validate the Input YAMLs using riscv-config.

大まかな手順であるが、

  1. riscof setupで必要なコンフィグレーションを生成する
  2. プラットフォームに応じてコンフィグレーションを変更する
  3. riscof validateyamlで変更したコンフィグレーションのチェックを行う
  4. riscv-arch-testをダウンロードしてテストリストを取得する
  5. riscof testlistを実行してプラットフォームに必要なテストリストファイルを生成する
  6. riscof runを実行してテストを実行する

1. risco setupによるコンフィグレーションファイルの生成

risof setupによりコンフィグレーションファイルおよびプラットフォームファイルを生成する。以下の例では、プラットフォーム(DUT)名をmsyksphinz_cpuとしている。

ちなみに、後でわかったのだが、この時にDUTファイル名はハイフンなどのPython上でクラス名にできない文字は入れてはいけない。

$ riscof setup --dutname=msyksphinz_cpu
    INFO | ****** RISCOF: RISC-V Architectural Test Framework 1.25.1 *******
    INFO | using riscv_isac version : 0.15.0
    INFO | using riscv_config version : 3.2.0
    INFO | Setting up sample plugin requirements [Old files will be overwritten]
    INFO | Creating sample Plugin directory for [DUT]: msyksphinz_cpu
    INFO | Creating sample Plugin directory for [REF]: sail_cSim
    INFO | Creating Sample Config File
    INFO | **NOTE**: Please update the paths of the reference and plugins in the config.ini file

これにより以下のコンフィグレーションファイルが生成されている。

$ tree .
.
├── config.ini
├── msyksphinz_cpu
│   ├── __pycache__
│   │   └── riscof_model.cpython-38.pyc
│   ├── env
│   │   ├── link.ld
│   │   └── model_test.h
│   ├── msyksphinz_cpu_isa.yaml
│   ├── msyksphinz_cpu_platform.yaml
│   └── riscof_msyksphinz_cpu.py
└── sail_cSim
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-38.pyc
    │   └── riscof_sail_cSim.cpython-38.pyc
    ├── env
    │   ├── link.ld
    │   └── model_test.h
    └── riscof_sail_cSim.py

6 directories, 13 files

ここでチェックしなければならないのは、msyksphinz_cpu/msykshpinz-cpu_isa.yamlmsyksphinz_cpu/msyksphinz_cpu_platform.yamlであろう。

  • msyksphinz_cpu/msyksphinz_cpu_isa.yaml
hart_ids: [0]
hart0:
  ISA: RV32IMCZicsr_Zifencei
  physical_addr_sz: 32
  User_Spec_Version: '2.3'
  supported_xlen: [32]
  misa:
   reset-val: 0x40001104
   rv32:
     accessible: true
     mxl:
       implemented: true
       type:
           warl:
              dependency_fields: []
              legal:
                - mxl[1:0] in [0x1]
              wr_illegal:
                - Unchanged
     extensions:
       implemented: true
       type:
           warl:
              dependency_fields: []
              legal:
                - extensions[25:0] bitmask [0x0001104, 0x0000000]
              wr_illegal:
                - Unchanged
  • msyksphinz_cpu/msyksphinz_cpu_platform.yaml
mtime:
  implemented: true
  address: 0xbff8
mtimecmp:
  implemented: true
  address: 0x4000
nmi:
  label: nmi_vector
reset:
  label: reset_vector

riscof validateyamlでコンフィグレーションのチェックを行う

riscof validateyamlコマンドで、現在のコンフィグレーションファイルの整合性を確認する。

$ riscof validateyaml --config=config.ini
    INFO | ****** RISCOF: RISC-V Architectural Test Framework 1.25.1 *******
    INFO | using riscv_isac version : 0.15.0
    INFO | using riscv_config version : 3.2.0
    INFO | Reading configuration from: /home/msyksphinz/work/riscv/riscof/config.ini
    INFO | Preparing Models
    INFO | Input-ISA file
    INFO | Loading input file: /home/msyksphinz/work/riscv/riscof/msyksphinz_cpu/msyksphinz_cpu_isa.yaml
    INFO | Load Schema /home/msyksphinz/.local/lib/python3.8/site-packages/riscv_config/schemas/schema_isa.yaml
    INFO | Processing Hart: hart0
    INFO | Initiating Validation
    INFO | No errors for Hart: 0 :)
    INFO | Initiating WARL legality checks.
    INFO | Initiating post processing and reset value checks.
    INFO | Performing Checks on PMP CSRs
    INFO | Dumping out Normalized Checked YAML: /home/msyksphinz/work/riscv/riscof/riscof_work/msyksphinz_cpu_isa_checked.yaml
    INFO | Input-Platform file
    INFO | Loading input file: /home/msyksphinz/work/riscv/riscof/msyksphinz_cpu/msyksphinz_cpu_platform.yaml
    INFO | Load Schema /home/msyksphinz/.local/lib/python3.8/site-packages/riscv_config/schemas/schema_platform.yaml
    INFO | Initiating Validation
    INFO | No Syntax errors in Input Platform Yaml. :)
    INFO | Dumping out Normalized Checked YAML: /home/msyksphinz/work/riscv/riscof/riscof_work/msyksphinz_cpu_platform_checked.yaml

riscv-arch-testをダウンロードしてテストリストを取得する

riscv-arch-testをダウンロードしてテストセットを用意する。

$ riscof --verbose info arch-test --clone
    INFO | ****** RISCOF: RISC-V Architectural Test Framework 1.25.1 *******
    INFO | using riscv_isac version : 0.15.0
    INFO | using riscv_config version : 3.2.0
    INFO | Clonning repository at /home/msyksphinz/work/riscv/riscof/riscv-arch-test
    INFO | Clonned version 3.4.1 of the repository with commit hash da638bafbc6d69f75ffc09769cfe7e3a45b41a3a

これで、同じディレクトリにriscv-arch-testがダウンロードされる。

riscof testlistでテストリストファイルを生成する

次に、このテストリストからコンフィグレーションに基づいてテストリストを作成する。

$ riscof testlist --config=config.ini --suite=riscv-arch-test/riscv-test-suite/ --env=riscv-arch-test/riscv-test-suite/env
    INFO | ****** RISCOF: RISC-V Architectural Test Framework 1.25.1 *******
    INFO | using riscv_isac version : 0.15.0
    INFO | using riscv_config version : 3.2.0
    INFO | Generating database for suite: /home/msyksphinz/work/riscv/riscof/riscv-arch-test/riscv-test-suite
    INFO | Database File Generated: /home/msyksphinz/work/riscv/riscof/riscof_work/database.yaml
    INFO | Env path set to/home/msyksphinz/work/riscv/riscof/riscv-arch-test/riscv-test-suite/env
    INFO | Reading configuration from: /home/msyksphinz/work/riscv/riscof/config.ini
    INFO | Preparing Models
    INFO | Input-ISA file
    INFO | Loading input file: /home/msyksphinz/work/riscv/riscof/msyksphinz_cpu/msyksphinz_cpu_isa.yaml
    INFO | Load Schema /home/msyksphinz/.local/lib/python3.8/site-packages/riscv_config/schemas/schema_isa.yaml
    INFO | Processing Hart: hart0
    INFO | Initiating Validation
    INFO | No errors for Hart: 0 :)
    INFO | Initiating WARL legality checks.
    INFO | Initiating post processing and reset value checks.
    INFO | Performing Checks on PMP CSRs
    INFO | Dumping out Normalized Checked YAML: /home/msyksphinz/work/riscv/riscof/riscof_work/msyksphinz_cpu_isa_checked.yaml
    INFO | Input-Platform file
    INFO | Loading input file: /home/msyksphinz/work/riscv/riscof/msyksphinz_cpu/msyksphinz_cpu_platform.yaml
    INFO | Load Schema /home/msyksphinz/.local/lib/python3.8/site-packages/riscv_config/schemas/schema_platform.yaml
    INFO | Initiating Validation
    INFO | No Syntax errors in Input Platform Yaml. :)
    INFO | Dumping out Normalized Checked YAML: /home/msyksphinz/work/riscv/riscof/riscof_work/msyksphinz_cpu_platform_checked.yaml
    INFO | Selecting Tests.

これで、riscof_work/test_list.yamlにテストリストが生成されている。

# testlist generated on 2022-09-25 06:29 GMT
/home/msyksphinz/work/riscv/riscof/riscv-arch-test/riscv-test-suite/rv32i_m/C/src/cadd-01.S:
  commit_id: 6ba8712973dade81eaf1182d1050e5799a7ef2a0
  work_dir: /home/msyksphinz/work/riscv/riscof/riscof_work/rv32i_m/C/src/cadd-01.S
  macros:
  - TEST_CASE_1=True
  - XLEN=32
  isa: RV32IC
  coverage_labels:
  - cadd
  test_path: /home/msyksphinz/work/riscv/riscof/riscv-arch-test/riscv-test-suite/rv32i_m/C/src/cadd-01.S
/home/msyksphinz/work/riscv/riscof/riscv-arch-test/riscv-test-suite/rv32i_m/C/src/caddi-01.S:
  commit_id: 6ba8712973dade81eaf1182d1050e5799a7ef2a0
  work_dir: /home/msyksphinz/work/riscv/riscof/riscof_work/rv32i_m/C/src/caddi-01.S
  macros:
  - TEST_CASE_1=True
  - XLEN=32
  isa: RV32IC
  coverage_labels:

riscof runを実行してテストを実行する

最後に、テストを実行する。

$ riscof run --config=config.ini --suite=riscv-arch-test/riscv-test-suite/ --env=riscv-arch-test/riscv-test-suite/env
INFO | ****** RISCOF: RISC-V Architectural Test Framework 1.25.1 *******
    INFO | using riscv_isac version : 0.15.0
    INFO | using riscv_config version : 3.2.0
    INFO | Reading configuration from: /home/msyksphinz/work/riscv/riscof/config.ini
    INFO | Preparing Models
    INFO | Input-ISA file
    INFO | Loading input file: /home/msyksphinz/work/riscv/riscof/msyksphinz_cpu/msyksphinz_cpu_isa.yaml
    INFO | Load Schema /home/msyksphinz/.local/lib/python3.8/site-packages/riscv_config/schemas/schema_isa.yaml
    INFO | Processing Hart: hart0
    INFO | Initiating Validation
    INFO | No errors for Hart: 0 :)
    INFO | Initiating WARL legality checks.
    INFO | Initiating post processing and reset value checks.
    INFO | Performing Checks on PMP CSRs
    INFO | Dumping out Normalized Checked YAML: /home/msyksphinz/work/riscv/riscof/riscof_work/msyksphinz_cpu_isa_checked.yaml
    INFO | Input-Platform file
    INFO | Loading input file: /home/msyksphinz/work/riscv/riscof/msyksphinz_cpu/msyksphinz_cpu_platform.yaml
    INFO | Load Schema /home/msyksphinz/.local/lib/python3.8/site-packages/riscv_config/schemas/schema_platform.yaml
    INFO | Initiating Validation
    INFO | No Syntax errors in Input Platform Yaml. :)
    INFO | Dumping out Normalized Checked YAML: /home/msyksphinz/work/riscv/riscof/riscof_work/msyksphinz_cpu_platform_checked.yaml
    INFO | Generating database for suite: /home/msyksphinz/work/riscv/riscof/riscv-arch-test/riscv-test-suite
    INFO | Database File Generated: /home/msyksphinz/work/riscv/riscof/riscof_work/database.yaml
    INFO | Env path set to/home/msyksphinz/work/riscv/riscof/riscv-arch-test/riscv-test-suite/env
    INFO | Running Build for DUT
    INFO | Running Build for Reference
   ERROR | riscv32-unknown-elf-objdump: executable not found. Please check environment setup.

おっと、ツールチェインをインストールしていないので最後に怒られてしまった。

ツールチェインをインストールして再実行すると、今度は以下のようなエラーが生成された。これは引き続き調査する。

ERROR | riscv_sim_RV32: executable not found. Please check environment setup.