«前の日記(2008年07月20日) 最新 次の日記(2008年07月25日)» 編集

ema log


2008年07月23日 [長年日記]

_ [Programming]Verilog のシミュレータで自動テストを行うためのテストベンチ生成スクリプト

色々と不満も残ってますが、メモとして貼り付け。↓のような yaml 定義から

 #  ADDI, LDIH, LDIH, LDIH, NOP
 - name: LDIH_TEST_04
   delay: 100
   asserts:
     pcpuwm.pcpu.PC : 4
     # fetch
     # ADDI r0, 0x0001
     pcpuwm.pcpu.IR : 0x5001
     # decode
     # LDIH r2 <- 0x2000  -- 00110|010|0010 0000
     pcpuwm.pcpu.IF_ID_INST : 0x3220
     # execute
     # LDIH r1 <- 0x4000  -- 00110|001|0100 0000
     pcpuwm.pcpu.ID_EX_INST : 0x3140
     pcpuwm.pcpu.ID_EX_A : 0x4000
     pcpuwm.pcpu.ID_EX_B : 0
     pcpuwm.pcpu.ID_EX_ALU_CONTROL : 0 # ADD
     pcpuwm.pcpu.ID_EX_DST_PORT    : 1 # r1
     pcpuwm.pcpu.ID_EX_REG_WRITE   : 1 # enabled
     # memory
     # LDIH r0 <- 0x8000  -- 00110|000|1000 0000
     pcpuwm.pcpu.EX_MEM_INST: 0x3080
     pcpuwm.pcpu.EX_MEM_C: 0x8000
     pcpuwm.pcpu.EX_MEM_DST_PORT  : 0 # r0
     pcpuwm.pcpu.EX_MEM_REG_WRITE : 1 # enabled
     # write back
     # NOP
     pcpuwm.pcpu.MEM_WB_INST: 0

すごく、汚いですが、↓の様な動作を検証するテストベンチを吐き出して

// LDIH_TEST_04
   #99
   #1
       if (pcpuwm.pcpu.IF_ID_INST !== 16'h3220) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.IF_ID_INST@450, expected: 16'h3220, but actual: 0x%x", pcpuwm.pcpu.IF_ID_INST); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.IR !== 16'h5001) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.IR@450, expected: 16'h5001, but actual: 0x%x", pcpuwm.pcpu.IR); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.PC !== 8'h4) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.PC@450, expected: 8'h4, but actual: 0x%x", pcpuwm.pcpu.PC); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.MEM_WB_INST !== 16'h0) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.MEM_WB_INST@450, expected: 16'h0, but actual: 0x%x", pcpuwm.pcpu.MEM_WB_INST); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.ID_EX_REG_WRITE !== 1'h1) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.ID_EX_REG_WRITE@450, expected: 1'h1, but actual: 0x%x", pcpuwm.pcpu.ID_EX_REG_WRITE); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.ID_EX_INST !== 16'h3140) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.ID_EX_INST@450, expected: 16'h3140, but actual: 0x%x", pcpuwm.pcpu.ID_EX_INST); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.EX_MEM_C !== 16'h8000) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.EX_MEM_C@450, expected: 16'h8000, but actual: 0x%x", pcpuwm.pcpu.EX_MEM_C); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.ID_EX_DST_PORT !== 3'h1) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.ID_EX_DST_PORT@450, expected: 3'h1, but actual: 0x%x", pcpuwm.pcpu.ID_EX_DST_PORT); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.ID_EX_A !== 16'h4000) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.ID_EX_A@450, expected: 16'h4000, but actual: 0x%x", pcpuwm.pcpu.ID_EX_A); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.ID_EX_B !== 16'h0) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.ID_EX_B@450, expected: 16'h0, but actual: 0x%x", pcpuwm.pcpu.ID_EX_B); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.EX_MEM_REG_WRITE !== 1'h1) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.EX_MEM_REG_WRITE@450, expected: 1'h1, but actual: 0x%x", pcpuwm.pcpu.EX_MEM_REG_WRITE); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.EX_MEM_DST_PORT !== 3'h0) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.EX_MEM_DST_PORT@450, expected: 3'h0, but actual: 0x%x", pcpuwm.pcpu.EX_MEM_DST_PORT); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.EX_MEM_INST !== 16'h3080) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.EX_MEM_INST@450, expected: 16'h3080, but actual: 0x%x", pcpuwm.pcpu.EX_MEM_INST); test_error_count = test_error_count + 32'b1; end
       if (pcpuwm.pcpu.ID_EX_ALU_CONTROL !== 3'h0) begin $display("-------------------------------------------------------------------------------\n*** Error on LDIH_TEST_04::pcpuwm.pcpu.ID_EX_ALU_CONTROL@450, expected: 3'h0, but actual: 0x%x", pcpuwm.pcpu.ID_EX_ALU_CONTROL); test_error_count = test_error_count + 32'b1; end

シミュレーション後、

 test_result
-----------------------
 Asserts:      243
    Pass:      243
   Error:        0

All test green!!!!!!!

の様に、テスト結果のサマリを出力します。エラー時には

-------------------------------------------------------------------------------
*** Error on LOAD_STORE_TEST_07::pcpuwm.pcpu.MEM_WB_C1@1750, expected: 16'h0, but actual: 0x1001

のようにエラーを出力します。Makefile に仕込んでおくことで、退行バグを検出できます。

t_pcpuwm.v: recipe.yaml test_generator/test_generator.rb test_generator/template.v
  ruby test_generator/test_generator.rb recipe.yaml

として、Makefile に入れております。

_ [Programming] gcc のオプション順序

gcc -lopenjpeg -lm load_image.c

だとダメで

gcc load_image.c -lopenjpeg -lm

だとOK。なんで??とても嵌まった。

ダメな時は、↓のように、シンボルの解決ができないらしい。

load_image.c:(.text+0x66): undefined reference to `opj_set_default_decoder_parameters'
load_image.c:(.text+0x170): undefined reference to `opj_create_decompress'
load_image.c:(.text+0x18a): undefined reference to `opj_setup_decoder'
load_image.c:(.text+0x1a3): undefined reference to `opj_cio_open'
load_image.c:(.text+0x1bd): undefined reference to `opj_decode'
load_image.c:(.text+0x1d0): undefined reference to `opj_cio_close'

かといって、openjpeg を typo すると ld がエラーを吐く。

gcc -lopenjpg -lm load_image.c

どうなってるんだろう??

_ [最近]日本のインターネットが終了する日 [高木浩光@自宅の日記]

http://takagi-hiromitsu.jp/diary/20080710.html#p01

http://takagi-hiromitsu.jp/diary/20080722.html#p01

長いけど、ぜひいろんな人によんでみてもらいたいと思った記事。

長いけど、考えれば分かる内容なので技術に疎い人もぜひ。詳細な部分は飛ばしぎみでいいと思います。