[117] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | #----------------------------------------------------------- |
---|
| 4 | # $Id: instruction_flow_diff.sh 122 2009-06-03 08:15:51Z rosiere $ |
---|
| 5 | #----------------------------------------------------------- |
---|
| 6 | |
---|
| 7 | #-----[ usage ]--------------------------------------------- |
---|
| 8 | function usage () |
---|
| 9 | { |
---|
| 10 | echo "Usage : ${0} file1 file2"; |
---|
| 11 | echo "Arguments : "; |
---|
| 12 | echo " * file1 : instruction flow file 1 (original)"; |
---|
| 13 | echo " * file2 : instruction flow file 2"; |
---|
| 14 | exit; |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | #-----[ test_usage ]---------------------------------------- |
---|
| 18 | function test_usage () |
---|
| 19 | { |
---|
| 20 | if test ${#} -ne 2; then |
---|
| 21 | usage ${*}; |
---|
| 22 | fi; |
---|
| 23 | |
---|
| 24 | if test ! -f ${1} -o ! -f ${2}; then |
---|
| 25 | usage ${*}; |
---|
| 26 | fi; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | #-----[ main ]---------------------------------------------- |
---|
| 30 | function main () |
---|
| 31 | { |
---|
| 32 | test_usage ${*}; |
---|
| 33 | |
---|
| 34 | # Read symbol file and take function address and function name |
---|
| 35 | local -a array1_address; |
---|
[122] | 36 | local -a array1_load_data; |
---|
[117] | 37 | local -i cpt1; |
---|
| 38 | local -i cpt2; |
---|
| 39 | local address1; |
---|
| 40 | local address2; |
---|
| 41 | |
---|
| 42 | # Read instruction flow file 1 |
---|
| 43 | cpt1=0; |
---|
| 44 | while read line; do |
---|
| 45 | if test $(echo "${line}" |grep -c "OK") -gt 0; then |
---|
| 46 | # extract address |
---|
| 47 | address1=$(echo ${line} | cut -d' ' -f2); |
---|
[122] | 48 | load_data1=$(echo ${line} | cut -d' ' -f7); |
---|
[117] | 49 | |
---|
| 50 | array1_address[${cpt1}]=${address1}; |
---|
[122] | 51 | array1_load_data[${cpt1}]=${load_data1}; |
---|
[117] | 52 | |
---|
| 53 | cpt1=$((${cpt1}+1)); |
---|
| 54 | fi; |
---|
| 55 | done < ${1}; |
---|
| 56 | |
---|
| 57 | # Read instruction flow file 2 and compare with flow 1 |
---|
| 58 | cpt1=0; |
---|
| 59 | cpt2=1; |
---|
| 60 | address1=${array1_address[${cpt1}]}; |
---|
[122] | 61 | load_data1=${array1_load_data[${cpt1}]}; |
---|
[117] | 62 | |
---|
| 63 | while read line; do |
---|
| 64 | if test $(echo "${line}" |grep -c "OK") -gt 0; then |
---|
| 65 | |
---|
| 66 | if test ${cpt1} -eq ${#array1_address[*]}; then |
---|
| 67 | echo "file \"${1}\" is empty, not file \"${2}\"."; |
---|
| 68 | exit; |
---|
| 69 | fi; |
---|
| 70 | |
---|
| 71 | # extract address |
---|
| 72 | address2=$(echo ${line} | cut -d' ' -f2); |
---|
[122] | 73 | load_data2=$(echo ${line} | cut -d' ' -f7); |
---|
[117] | 74 | |
---|
| 75 | # test address |
---|
| 76 | if test "${address1}" != "${address2}"; then |
---|
[122] | 77 | echo "diff line ${cpt2} on address:"; |
---|
[117] | 78 | echo "${line}"; |
---|
| 79 | exit; |
---|
| 80 | fi; |
---|
| 81 | |
---|
[122] | 82 | if test "${load_data1}" != "${load_data2}"; then |
---|
| 83 | echo "diff line ${cpt2} on load_data:"; |
---|
| 84 | echo "${line}"; |
---|
| 85 | exit; |
---|
| 86 | fi; |
---|
| 87 | |
---|
[117] | 88 | cpt1=$((${cpt1}+1)); |
---|
| 89 | address1=${array1_address[${cpt1}]}; |
---|
[122] | 90 | load_data1=${array1_load_data[${cpt1}]}; |
---|
[117] | 91 | |
---|
| 92 | fi; |
---|
| 93 | cpt2=$((${cpt2}+1)); |
---|
| 94 | done < ${2}; |
---|
| 95 | |
---|
| 96 | if test ${cpt1} -ne ${#array1_address[*]}; then |
---|
| 97 | echo "file \"${2}\" is empty, not file \"${1}\"."; |
---|
| 98 | exit; |
---|
| 99 | else |
---|
| 100 | echo "no diff."; |
---|
| 101 | fi; |
---|
| 102 | |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | #-----[ Corps ]--------------------------------------------- |
---|
| 106 | main ${*}; |
---|