RiescueDダイレクトテスト実装メモ
実行コマンド:
riescued --testfile test1.s --cpuconfig cpu_configuration.yml --run_dir test1 --iss spike
まず、以下のエラーが生成された。
ValueError: key test_access is not a boolean in cfg={'address': '0x200_c000', 'size': '0x5ff_4000', 'test_access': 'available'}
いろいろCursorに解析してもらって修正した。
cpu_configuration.yml内のio1セクションで、test_accessが文字列"available"として設定されていた。
しかし、コードはブール値(trueまたはfalse)を期待しているようだったので、test_accessの値をブール値trueに変更した。
"io1": { "address": "0x200_c000", "size": "0x5ff_4000", "test_access": true }
次は以下のエラーだ。結構デフォルトのままの設定だとエラーが頻発する。
TypeError: string indices must be integers, not 'str'
これは、 cpu_configuration.ymlのioセクションが以下のような構造になっており、コードはioセクションが直接IOアイテムの辞書であることを期待していた。
cfg.get("io", {}).items()を呼び出すと、("address", "0")、("size", "0x8000_0000")、("items", {...})というタプルが返され、文字列値に対して辞書アクセスを試みてエラーが発生していた。
したがって、 itemsラッパーを削除し、ioセクションを直接IOアイテムの辞書として再構成した。
"io": { "address": "0", "size": "0x8000_0000", "items": { "io0": { ... }, "io1": { ... } } }
修正後は以下のようになった:
"io": { "io0": { "address": "0x0", "size": "0x1_0000" }, "io1": { "address": "0x200_c000", "size": "0x5ff_4000", "test_access": true }, "htif": { "address": "0x7000_0000", "size": "0x10" } }
つぎのエラーは、 .section .codeセクションの不足のようだった。
ValueError: Couldn't find a .section .code section in input file, test1.s. .section .code is requried for test code
これは test1.sファイルに.section .codeセクションが存在しなかった。RiescueDはテストコードを.section .codeセクション内に記述することを要求するようだ。
このへん、結構ドキュメント不足だ。
.section .codeセクションを追加した。
.section .code
さらに、 test_setupとtest_cleanup関数の未定義エラーが発生している。
undefined reference to `test_cleanup' undefined reference to `test_setup'
これは、スケジューラがtest_setupとtest_cleanup関数を呼び出すが、これらの関数が定義されていなかった。
生成されたtest1_scheduler.incを見ると、以下のようにこれらの関数へのポインタが定義されている。
scheduler__test_setup_ptr:
.dword test_setup
scheduler__test_cleanup_ptr:
.dword test_cleanup
また、os_test_sequenceにはtest_cleanupが登録されており、スケジューラが実行する関数として期待されている。
したがって、test1.sの.section .codeセクション内に、test_setupとtest_cleanup関数を定義した。
.section .code
# Test setup function - called before test execution
test_setup:
ret
# Test cleanup function - called after test execution
test_cleanup:
ret
結局、Riscue-Dについては、いったい何をユーザが記述すればテストとして実装できるのか?
必須のセクションと関数
.section .codeセクション: テストコードは必ずこのセクション内に記述するtest_setup関数: テスト実行前に呼ばれる初期化関数(scheduler__initから呼び出される)test_cleanup関数: テスト実行後に呼ばれるクリーンアップ関数(os_test_sequenceに登録され、scheduler__dispatchから呼び出される)
とりあえず、いかのような形で test1.s を完成させた。
;#test.name comprehensive_test ;#test.author engineer@company.com ;#test.arch rv64 ;#test.priv machine super ;#test.env bare_metal ;#test.cpus 1 ;#test.paging sv39 sv48 ;#test.category arch ;#test.class memory ;#test.features ext_v.enable ;#test.tags virtual_memory randomization ;#test.summary ;#test.summary Comprehensive test demonstrating multiple RiescueD features ;#test.summary including virtual memory, random data, and interrupt handling ;#test.summary .section .code # Test setup function - called before test execution test_setup: ret # Test cleanup function - called after test execution test_cleanup: ret
riescued --testfile test1.s --cpuconfig cpu_configuration.yml --run_dir test1 --iss spike
fpgen unavailable, skipping
/home/msyksphinz/work/riscv/riscued/.venv/bin/riescued --testfile test1.s --cpuconfig cpu_configuration.yml --run_dir test1 --iss spike
[2025-12-21T23:52:30]INFO riescue.lib.logger:161 Logger initialized, setting log level to INFO
[2025-12-21T23:52:30]INFO riescue:280 test_config: env: TEST_ENV_BARE_METAL
[2025-12-21T23:52:30]INFO riescue:281 test_config: secure_mode: NON_SECURE
[2025-12-21T23:52:30]INFO riescue:282 test_config: priv: SUPER
[2025-12-21T23:52:30]INFO riescue:283 test_config: paging: SV39
[2025-12-21T23:52:30]INFO riescue:284 test_config: paging_g: DISABLE
[2025-12-21T23:52:30]INFO riescue.dtest_framework.lib.pmp:276 Adding region 80000000 10000000000000 rwx
[2025-12-21T23:52:30]INFO riescue.dtest_framework.lib.pmp:276 Adding region 200c000 5ff4000 rwx
[2025-12-21T23:52:30]INFO riescue.dtest_framework.lib.pmp:276 Adding region 0 10000 rwx
[2025-12-21T23:52:30]INFO riescue.dtest_framework.lib.pmp:276 Adding region 70000000 10 rwx
[2025-12-21T23:52:31]ERROR riescue.dtest_framework.generator.generator:2066 Unknown section: text
[2025-12-21T23:52:31]WARNING riescue.dtest_framework.lib.addrgen.address_cluster:229 could not generate NEAR address in cluster: 31
[2025-12-21T23:52:31]INFO riescue.lib.toolchain.tool:97 Running
/home/msyksphinz/riscv64_251218/bin/riscv64-unknown-elf-gcc -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -march=rv64imafdcvh_svinval_zfh_zba_zbb_zbc_zbs_zifencei_zicsr_zvkned_zicbom_zicbop_zicboz_zawrs_zihintpause_zvbb1_zicond_zvkg_zvkn_zvbc_zfa_zk -I /home/msyksphinz/work/riscv/riscued/test1 -T /home/msyksphinz/work/riscv/riscued/test1/test1.ld -o /home/msyksphinz/work/riscv/riscued/test1/test1 /home/msyksphinz/work/riscv/riscued/test1/test1.S
[2025-12-21T23:52:31]INFO riescue.lib.toolchain.tool:93 Running
/home/msyksphinz/riscv64_251218/bin/riscv64-unknown-elf-objdump -D /home/msyksphinz/work/riscv/riscued/test1/test1 -M numeric > /home/msyksphinz/work/riscv/riscued/test1/test1.dis
うーん、なるほど。一応テストは生成させるようだ。test1/test1.dis は一応コンパイル後のディスアセンブルリストが含まれているようだが、これは実際のテストが含まれているようではなさそうだ。