ASIC/FPGA Design and Verification Out Source Services
A simple script to calculate the percent of failing number of tests from the total and rounding up the results.
- In many occasions one needs to calculate the percentage of some results. In my case it was the percentage of failing tests from the total number of test.
- This page shows just part of the script. The constants and the mathematics to calculate the results and round up operation.
- ...
- cnt_del="5"
- cnt_prg="10"
- cnt_per="1000"
- cnt_ok="0"
- cnt_ko="0"
- ...
- #* 1000 to get higher precision
- per=$(($cnt_ko * $cnt_per)) #*1000
- per=$(($per / $cnt_tot)) #percent * 10
- per=$(($per + $cnt_del)) #round up by adding 5
- per=$(($per / $cnt_prg)) #result %
- echo "number of total tests "$cnt_tot" ok tests "${cnt_ok}" ko tests "${cnt_ko}" "$per" %" >> reg_res.txt
Note: if the file, which stres the results
(reg_res.txt), needs to have a uniqe name, one can
add the process ID to the file name.
- fp="reg_res_"$$".txt"
- echo "number of total tests "$cnt_tot" ok tests "${cnt_ok}" ko tests "${cnt_ko}" "$per" %" >> $fp
-
If the results need to be in hexadecimal, the
following command can be used:
printf '%02x\n' 12
The opposite is also true (from hexadecimal to
decimal): printf '%d\n' 0x23.
|