Ignore:
Timestamp:
Jul 3, 2020, 7:19:17 PM (4 years ago)
Author:
coas-nagasima
Message:

ASP3, TINET, mbed を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/asp3_dcre/utils/gentest.rb

    r331 r429  
    55#      Toyohashi Open Platform for Embedded Real-Time Systems
    66#
    7 #  Copyright (C) 2007-2016 by Embedded and Real-Time Systems Laboratory
     7#  Copyright (C) 2007-2019 by Embedded and Real-Time Systems Laboratory
    88#              Graduate School of Information Science, Nagoya Univ., JAPAN
    99#
     
    4444#
    4545       
     46Encoding.default_external = 'utf-8'
     47require "pp"
     48require "fileutils"
     49
    4650#
    4751#  生成動作を決めるための設定
     
    6771  "ref_mtx" => { 2 => "T_RMTX" },
    6872  "ref_mbf" => { 2 => "T_RMBF" },
     73  "ref_spn" => { 2 => "T_RSPN" },
    6974  "get_mpf" => { 2 => "void *" },
    7075  "pget_mpf" => { 2 => "void *" },
     
    7782  "get_tid" => { 1 => "ID" },
    7883  "get_did" => { 1 => "ID" },
     84  "get_pid" => { 1 => "ID" },
    7985  "get_lod" => { 2 => "uint_t" },
    8086  "mget_lod" => { 3 => "uint_t" },
    8187  "get_nth" => { 3 => "ID" },
    8288  "mget_nth" => { 4 => "ID" },
     89  "ref_mem" => { 2 => "T_RMEM" },
    8390  "get_ipm" => { 1 => "PRI" },
    8491  "get_som" => { 1 => "ID" }
     
    8693
    8794$functionParameters = {
    88   "target_hrt_set_event" => "HRTCNT hrtcnt"
     95  "target_hrt_set_event" => "HRTCNT hrtcnt",
     96  "hook_hrt_set_event" => "HRTCNT hrtcnt"
    8997}
    9098 
     
    98106 
    99107$functionCheckParameter = {
    100   "target_hrt_set_event" => "hrtcnt"
     108  "target_hrt_set_event" => "hrtcnt",
     109  "hook_hrt_set_event" => "hrtcnt"
    101110}
    102111
     
    154163    lines.each do |line|
    155164      @code[@currentCount].push(line)
    156         end
     165    end
    157166  end
    158167
     
    174183    # 処理カウント変数の生成
    175184    if @countFlag
    176       print("\nstatic uint_t\t#{@count_var} = 0;\n")
     185      $outFile.print("\nstatic uint_t\t#{@count_var} = 0;\n")
    177186    end
    178187
     
    180189    case @puName
    181190    when /^TASK([0-9]*)$/
    182       print("\nvoid\n")
    183       print("task#{$1}(intptr_t exinf)\n")
     191      $outFile.print("\nvoid\n")
     192      $outFile.print("task#{$1}(intptr_t exinf)\n")
    184193    when /^CYC([0-9]*)$/
    185       print("\nvoid\n")
    186       print("cyclic#{$1}_handler(intptr_t exinf)\n")
     194      $outFile.print("\nvoid\n")
     195      $outFile.print("cyclic#{$1}_handler(intptr_t exinf)\n")
    187196    when /^ALM([0-9]*)$/
    188       print("\nvoid\n")
    189       print("alarm#{$1}_handler(intptr_t exinf)\n")
     197      $outFile.print("\nvoid\n")
     198      $outFile.print("alarm#{$1}_handler(intptr_t exinf)\n")
    190199    when /^OVR$/
    191       print("\nvoid\n")
    192       print("overrun_handler(ID tskid, intptr_t exinf)\n")
     200      $outFile.print("\nvoid\n")
     201      $outFile.print("overrun_handler(ID tskid, intptr_t exinf)\n")
    193202    when /^ISR([0-9]*)$/
    194       print("\nvoid\n")
    195       print("isr#{$1}(intptr_t exinf)\n")
     203      $outFile.print("\nvoid\n")
     204      $outFile.print("isr#{$1}(intptr_t exinf)\n")
    196205    when /^INTHDR([0-9]*)$/
    197       print("\nvoid\n")
    198       print("inthdr#{$1}_handler(void)\n")
     206      $outFile.print("\nvoid\n")
     207      $outFile.print("inthdr#{$1}_handler(void)\n")
    199208    when /^CPUEXC([0-9]*)$/
    200       print("\nvoid\n")
    201       print("cpuexc#{$1}_handler(void *p_excinf)\n")
     209      $outFile.print("\nvoid\n")
     210      $outFile.print("cpuexc#{$1}_handler(void *p_excinf)\n")
    202211    when /^EXTSVC([0-9]*)$/
    203       print("\nER_UINT\n")
    204       print("extsvc#{$1}_routine")
    205       print("(intptr_t par1, intptr_t par2, intptr_t par3,\n")
    206       print("\t\t\t\t\t\t\t\tintptr_t par4, intptr_t par5, ID cdmid)\n")
     212      $outFile.print("\nER_UINT\n")
     213      $outFile.print("extsvc#{$1}_routine")
     214      $outFile.print("(intptr_t par1, intptr_t par2, intptr_t par3,\n")
     215      $outFile.print("\t\t\t\t\t\t\t\tintptr_t par4, intptr_t par5, ID cdmid)\n")
    207216    else
    208217      if $functionValue[@puName]
    209         print("\n#{$functionValue[@puName]}\n")
     218        $outFile.print("\n#{$functionValue[@puName]}\n")
    210219      else
    211         print("\nvoid\n")
    212       end
    213       print(@puName)
     220        $outFile.print("\nvoid\n")
     221      end
     222      $outFile.print(@puName)
    214223      if $functionParameters[@puName]
    215         print("(#{$functionParameters[@puName]})\n")
     224        $outFile.print("(#{$functionParameters[@puName]})\n")
    216225      else
    217         print("(void)\n")
    218       end
    219     end
    220 
    221     print("{\n")
     226        $outFile.print("(void)\n")
     227      end
     228    end
     229
     230    $outFile.print("{\n")
    222231
    223232    @variableList.each do |varName, varType|
    224233      if /^(.+)\w*\*$/ =~ varType
    225234        varBaseType = $1
    226         print("\t#{varBaseType}")
    227         print(varBaseType.length < 4 ? "\t\t*" : "\t*")
     235        $outFile.print("\t#{varBaseType}")
     236        $outFile.print(varBaseType.length < 4 ? "\t\t*" : "\t*")
    228237      else
    229         print("\t#{varType}")
    230         print(varType.length < 4 ? "\t\t" : "\t")
    231       end
    232       print("#{varName};\n")
     238        $outFile.print("\t#{varType}")
     239        $outFile.print(varType.length < 4 ? "\t\t" : "\t")
     240      end
     241      $outFile.print("#{varName};\n")
    233242    end
    234243    if @silFlag
    235       print("\tSIL_PRE_LOC;\n")
    236     end
    237     print("\n")
     244      $outFile.print("\tSIL_PRE_LOC;\n")
     245    end
     246    $outFile.print("\n")
    238247
    239248    if @countFlag
    240       print("\tswitch (++#{@count_var}) {\n")
     249      $outFile.print("\tswitch (++#{@count_var}) {\n")
    241250      @code.keys.sort_by { |c| c.to_i }.each do |count|
    242         print("\tcase #{count}:\n")
     251        $outFile.print("\tcase #{count}:\n")
    243252        @code[count].each do |line|
    244           print("\t",line) if line != ""
    245           print("\n")
     253          $outFile.print("\t",line) if line != ""
     254          $outFile.print("\n")
    246255        end
    247         print("\t\tcheck_point(0);\n\n")
    248       end
    249       print("\tdefault:\n")
    250       print("\t\tcheck_point(0);\n")
    251       print("\t}\n")
     256        $outFile.print("\t\tcheck_assert(false);\n\n")
     257      end
     258      $outFile.print("\tdefault:\n")
     259      $outFile.print("\t\tcheck_assert(false);\n")
     260      $outFile.print("\t}\n")
    252261    else
    253262      @code[""].each do |line|
    254         print(line,"\n")
    255       end
    256     end
    257 
    258     print("\tcheck_point(0);\n")
     263        $outFile.print(line,"\n")
     264      end
     265    end
     266
     267    $outFile.print("\tcheck_assert(false);\n")
    259268    if /^EXTSVC([0-9]*)$/ =~ @puName
    260       print("\treturn(E_SYS);\n")
     269      $outFile.print("\treturn(E_SYS);\n")
    261270    elsif $functionReturn[@pu_nama]
    262       print("\treturn(#{$functionReturn[@puName]});\n")
    263     end
    264     print("}\n")
     271      $outFile.print("\treturn(#{$functionReturn[@puName]});\n")
     272    end
     273    $outFile.print("}\n")
    265274  end
    266275end
     
    303312def testStartCode(pu)
    304313  # テスト開始コードは一度のみ出力する
    305   if $startFlag == 0
     314  if !$startFlag
    306315    pu.append("\ttest_start(__FILE__);", "")
    307     $startFlag = 1
     316    $startFlag = true
    308317  end
    309318end
     
    312321#  ターゲット依存部関数の振る舞いの読み込み
    313322#
    314 def targetFunction(line, checkNum)
     323def targetFunction(line, checkNum, prcid)
    315324  if /^([a-zA-Z_]+)\s*(.*)$/ =~ line
    316325    functionName = $1
     
    333342  end
    334343
    335   pu.append("\tcheck_point(#{checkNum});");
     344  pu.append("\tcheck_point#{$cpSuffix[prcid]}(#{checkNum});");
    336345  if param && $functionCheckParameter[functionName]
    337346    pu.append(sprintf("\tcheck_assert(%s == %s);",
     
    347356
    348357#
     358#  チェックポイント番号の処理
     359#
     360def procCheckPoint(prcid, originalCheckNum, oline_list)
     361  checkNum = ($lastCheckPoint[prcid] += 1).to_s
     362  oline_list.each do |oline|
     363    oline.sub!(/#{originalCheckNum}/, "#{checkNum}:")
     364  end
     365  return(checkNum)
     366end
     367
     368#
    349369#  テストスクリプトの読み込み
    350370#
    351 def parseLine(line)
    352   if /^==\s*(([a-zA-Z_]+)[0-9]*)(.*)$/ =~ line
     371def parseLine(line, prcid, oline_list)
     372  if /^==\s*START(_[a-zA-Z0-9]+)?(.*)$/ =~ line
     373    $procFlag = true unless $procFlagEnd
     374    $cpSuffix[prcid] = $1
     375  elsif /^==\s*(([a-zA-Z_]+)[0-9]*)(.*)$/ =~ line
    353376    # 処理単位の開始
    354     $procFlag = 1
     377    $procFlag = true unless $procFlagEnd
    355378    puName = $1
    356379    line2 = $3
     
    359382      pu = $puList[puName] = PUCode.new(puName)
    360383    end
    361     $currentPu = pu
     384    $currentPu[prcid] = pu
    362385
    363386    case line2
     
    369392      pu.setCount("")
    370393    end
    371     testStartCode(pu) if /^START/ !~ puName
    372   elsif $procFlag != 0
    373     pu = $currentPu
     394    testStartCode(pu)
     395  elsif $procFlag
     396    pu = $currentPu[prcid]
    374397    if /^([0-9]+\:)\s*(.*)$/ =~ line
    375398      # チェックポイント番号の処理
    376       originalCheckNum = $1
    377399      line = $2
    378       checkNum = ($lastCheckPoint += 1).to_s
    379       $outputLine.sub!(/#{originalCheckNum}/, "#{checkNum}:")
     400      checkNum = procCheckPoint(prcid, $1, oline_list)
    380401
    381402      case line
    382403      when /^END$/
    383         pu.append("\tcheck_finish(#{checkNum});")
    384         $procFlag = 0
     404        pu.append("\tcheck_finish#{$cpSuffix[prcid]}(#{checkNum});")
     405        $procFlagEnd = true
    385406        return
    386407      when /^HOOK\((.*)\)$/
     
    388409        return
    389410      when /^\[(.*)\]$/
    390         targetFunction($1, checkNum)
     411        targetFunction($1, checkNum, prcid)
    391412        return
    392413      else
    393         pu.append("\tcheck_point(#{checkNum});")
     414        pu.append("\tcheck_point#{$cpSuffix[prcid]}(#{checkNum});")
    394415      end
    395416    end
     
    402423      pu.append("\t#{call_string};", "")
    403424      pu.useSil() if /^SIL_..._INT\(\)$/ =~ call_string
     425    when /^VAR\(\s*(.*)\s+(.*)\s*\)$/
     426      pu.addVariable($2, $1)
    404427    when /^RETURN((\(.*\))?)$/
    405428      pu.append("\treturn#{$1};", "")
     
    409432    when /^LABEL\((.*)\)$/
    410433      pu.append("#{$1}:", "")
     434    when /^BARRIER\((.*)\)$/
     435      pu.append("\ttest_barrier(#{$1});", "")
     436    when /^((SET|RESET|WAIT|WAIT_WO_RESET|WAIT_RESET)\(.*\))$/
     437      pu.append("\t#{$1};", "")
    411438    when /^([a-z_]+\(.*\))\s*(\-\>\s*([A-Za-z0-9_]*))?\s*$/
    412439      genServiceCall(pu, $1, $3)
     
    428455#
    429456inFileName = ARGV.shift
     457outFileName = inFileName + ".new"
    430458
    431459#
    432460#  スクリプトファイル読み込み処理
    433461#
    434 $lastCheckPoint = 0             # 最後のチェックポイント番号
    435 $procFlag = 0                           # スクリプト処理中フラグ
    436 $startFlag = 0                  # テスト開始コードの出力フラグ
    437 $currentPu = nil                        # 読み込み中の処理単位
    438 $puList = {}                            # 処理単位のリスト
     462$procFlag = false                                       # スクリプト処理中フラグ
     463$procFlagEnd = false                            # スクリプト処理終了フラグ
     464$startFlag = false                                      # テスト開始コードの出力フラグ
     465$currentPu = {}                                         # 読み込み中の処理単位
     466$puList = {}                                            # 処理単位のリスト
     467$outputLines = []                                       # 出力すべき行のリストのリスト
     468$cpSuffix = Hash.new("")                        # チェックポイント関数のサフィックス
     469$lastCheckPoint = Hash.new(0)           # 最後のチェックポイント番号
    439470
    440471begin
    441472  inFile = File.open(inFileName)
     473  $outFile = File.open(outFileName, "w")
    442474rescue Errno::ENOENT, Errno::EACCES => ex
    443475  abort(ex.message)
    444476end
    445477
     478statements = Hash.new("")
     479oline_lists = Hash.new([])
    446480while line = inFile.gets do
    447   $outputLine = line.dup
    448   line.chomp!
    449   line.sub!(/^\s*\*\s*/, "")
    450   line.sub!(/\s*\/\/.*$/, "")
    451   line.sub!(/\s*\.\.\..*$/, "")
    452 
    453   while line.sub!(/\\$/, "") do
    454     line1 = inFile.gets
    455     $outputLine += line1.dup
    456     line1.chomp!
    457     line1.sub!(/^\s*\*\s*/, "")
    458     line1.sub!(/\s*\/\/.*$/, "")
    459     line1.sub!(/\s*\.\.\..*$/, "")
    460     line += line1
    461   end
    462   parseLine(line) if line != ""
    463   print($outputLine)
    464   break if /DO NOT DELETE THIS LINE/ =~ $outputLine
     481  line.chomp!                                                                   # 末尾の改行の削除
     482  if /DO NOT DELETE THIS LINE/ =~ line
     483    $outputLines.push([ line ])
     484    break
     485  elsif line =~ /^(\s*\*)(.*)$/                                 # 行頭のスペースと "*" の削除
     486    outputLine = [ $1.dup ]
     487    $2.split(/|/, -1).each_with_index do |sline, index|
     488      outLine = sline.dup
     489      outputLine.push(outLine)
     490      sline.sub!(/^\s*/, "")                                    # 先頭のスペースの削除
     491      sline.sub!(/\/\/.*$/, "")                                 # // コメントの削除
     492      sline.sub!(/\.\.\..*$/, "")                               # ... コメントの削除
     493
     494      prcid = index + 1
     495      statements[prcid] += sline
     496      oline_lists[prcid].push(outLine)
     497      next if statements[prcid].sub!(/\\\s*$/, "")              # 継続行の場合
     498
     499      statements[prcid].sub!(/\s*$/, "")                # 末尾のスペースの削除
     500      if sline !~ /^\s*$/
     501        parseLine(statements[prcid], prcid, oline_lists[prcid])
     502      end
     503      statements[prcid] = ""
     504      oline_lists[prcid] = []
     505    end
     506    $outputLines.push(outputLine)
     507    $procFlag = false if $procFlagEnd
     508  else
     509    $outputLines.push([ line ])
     510  end
     511end
     512$outputLines.each do |outputLine|
     513  outputLine.each_with_index do |sline, index|
     514    $outFile.print("|") if index > 1
     515    $outFile.print(sline);
     516  end
     517  $outFile.print("\n");
    465518end
    466519
     
    471524  $puList[puName].generateCode()
    472525end
     526
     527#
     528#  ファイルの置き換え
     529#
     530FileUtils.move(inFileName, inFileName + ".bak")
     531FileUtils.move(outFileName, inFileName)
Note: See TracChangeset for help on using the changeset viewer.