Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

bash script to scan simulation log for errors

  1. This is a simple script, which I use to scan errors in log files and presents the results in a nice report. The script is brought here mainly as an example on how to write such scripts using bash. This site contains many scripts. Complex ones are written in perl. Scripts which execute a few shell commands and do some text manipulation, are better coded in bash.

  2. The report prints a prefix to each line of info:
    1. ru - for running.
    2. ok - for okay test end
    3. ko - for not okay test end
    4. er - an error was found.


    The report also prints the test seed and the simulation time, when the simulation log is last checked.
    A count of a total of all tests, okay ones and erred tests are displayed.

  3. More then one log file is checked for each simulation. Therefor an array is used to store the log file names to scan per each test.

  4. To scan files and find them, bash for i loops are used.

  5. To check strings, grep and sed are used. To find first occurrence of a string, the combination of grep and head -1 are used.
    The script uses cut command to extract from a variable string a field. The fields in the string are separated by a single space.

  6. Find first occurrence is done in two different ways in this bash script. First one uses grep command pipe to head -1. This is fine for cases not too complex. In other cases, I use some of the switches of the grep command. For instance to get the line number of the first error, I use:
    l_start=$(grep -n -m1 "\*\*\* Dut error" $x | sed 's/^\([0-9][0-9]*\):.*/\1/')

    The script also shows a few examples of: executing a shell command from script, piping its output to another command and storing the output textual result string in a script variable.

  7. It is recommended to pipe the output of the script to vim. One can save the report and use vim gf (go file) to easily navigate the assorted log files.


  8. The script is shown below:

    #!/bin/bash

    #how to operate
    #clear ; ./scan_short.unx | vi -


    #foreach x (`seq 1 1 20`)
      #clear
      #./scan_e.unx
      #echo $x
      #sleep 60
    #end


    #clear ; ./scan_short.unx | vi -

    cnt_ok="0"
    cnt_ko="0"
    cnt_to="0"
    cnt_en="1"

    #arr=('local_log.log' 'local_log.log')
    arr=('runsim.log' 'kuku_TB.elog')

    time_flg="1"


    for i in "${arr[@]}" ; do
      echo "============ "$i"============ (seed / sim time)"
      for x in `find . -name $i` ; do
        cnt_to=$[$cnt_to+1]
        if [ $time_flg -eq 1 ] ; then
          grep "seed [0-9][0-9]* " $x > /dev/null
          if [ $? -eq 0 ] ; then
            test_seed=$(grep "seed [0-9][0-9]* " $x | head -1 | sed 's/.*seed \([0-9][0-9]*\) .*/\1/')
            test_seed=$(echo $test_seed | sed 's/.*seed \(.*\) .*/\1/')
          else
            test_seed=$(grep "seed [0-9][0-9]*" $x | head -1 | sed 's/.*seed \([0-9][0-9]*\).*/\1/')
          fi
          #find the current simulation time
          grep "^\[[0-9*\]" $x | tail -1 > scan_short.tmp
          sed -i "s/\[\([0-9][0-9]*\)\].*/\1/" scan_short.tmp
          echo -ne $cnt_to") "$x" "$test_seed" / "
          #get size
          size=$(ls -l scan_short.tmp)
          value=$(cut -d' ' -f5 <<<"${size}")
          if [ $value -eq 0 ] ; then
            echo "0"
          else
            cat scan_short.tmp
          fi
        fi

        grep " 0 DUT errors, [0-9][0-9]* DUT warnings" $x > /dev/null
        if [ $? -eq 0 ] ; then
          cnt_ok=$[$cnt_ok+1]
          echo "ok "$x
        else
          #Don't pipe to dev/null. If there is an error, it is interesting to print it.
          grep -n "\* [DE][^On]" $x > /dev/null
          if [ $? -eq 0 ] ; then
            echo "ko "$x
            #It is possible to have a in progress test, so the test complete message
            #will not be present, but it might already include an error
            cnt_ko=$[$cnt_ko+1]
          fi
          grep " DUT errors, [0-9][0-9]* DUT warnings" $x > /dev/null
          if [ $? -eq 1 ] ; then
            echo "ru "$x
          fi
        fi
        echo
      done
      #
      if [ $cnt_en -eq 1 ] ; then
        echo $cnt_to
        echo "total="$cnt_to" ok="$cnt_ok" ko="$cnt_ko
        echo
        cnt_en="0";
      fi
      time_flg="0"
      cnt_ok="0"
      cnt_ko="0"
      cnt_to="0"
      #
    done

    echo ""
    echo "============ "detailed Dut error -only first one is printed- reports"============"
    for x in `find . -name "${arr[0]}"` ; do
      grep "\* [DE][^OnF]" $x > /dev/null
      if [ $? -eq 0 ] ; then
        echo "er "$x
        #grep only the first error
        #grep "^Bug:" $x | head -1
    #-------------------------------------------------------
      #*** Dut error at time 2487400
            #Checked at line 1318 in @kuku_env_RM
            #In kuku_item_s-@650636.check() (unit: sys.kuku.enV.interrupts.mdm_central.RM):
    #
    #Bug: kuku_ref_model: pending data event at end of test kuku item is: 0x0202
    #-------------------------------------------------------
        grep -n -m1 "\*\*\* Dut error" $x > /dev/null
        #3449134: *** Dut error at time 2487400
        if [ $? -eq 0 ] ; then
          offset="6"
          l_start=$(grep -n -m1 "\*\*\* Dut error" $x | sed 's/^\([0-9][0-9]*\):.*/\1/')
          #get the last interesting lines by using head and tail:
          l_start=$[$l_start+$offset]
          head -$l_start $x | tail -$offset
        fi
        echo ""
      fi
    done



Home

Download Area






Search This Site


Feedback This Site




new pages on this site