File: run_BinarySHA1Comparison.sh

package info (click to toggle)
openh264 2.6.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,120 kB
  • sloc: cpp: 74,004; asm: 34,842; ansic: 23,866; sh: 2,540; python: 937; objc: 612; cs: 471; makefile: 354; java: 319; xml: 204; javascript: 17
file content (368 lines) | stat: -rwxr-xr-x 13,719 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/bin/bash
#***************************************************************************************************************
# Encoder binary comparison test model
#             -- Compared with Benchmark version using SHA-1 string
#             -- Test bit stream under folder  openh264/res
#             -- SHA-1 string of Benchmark version for  all cases  of all bit streams
#                   under folder  openh264/test/encoder_binary_comparion/SHA1Table
#             -- For more detail,please refer to file AboutTest?¡ê
#brief:
#             -- Test all cases in SHA1TableFile
#                  1) Generate SHA1 string for each case
#                  2) Compare with benchmark SHA1 string
#                  3) If the SHA1 string are the same with benchmark version, test case is marked as passed
#                  4) Otherwise, test case is marked as unpass! this may caused by:
#                      --the design of encoder has been changed and the bit stream also change
#                      --there may be some bugs in encoder and bit stream is not right
#             -- Usage:  ./run_BinarySHA1Comparison.sh  ${TestYUVName}   ${AllCaseSHA1TaleFile}
#
# date:    10/06/2014 Created
#***************************************************************************************************************
#global variable definition
#usage runGlobalVariableDef
runGlobalVariableDef()
{
    #test data space
    FinalResultPath=""
    IssueDataPath=""
    TempDataPath=""
    #for test sequence info
    PicW=""
    PicH=""
    #xxx.csv
    AllCasePassStatusFile=""
    #for encoder command
    declare -a aEncoderCommandSet
    declare -a aEncoderCommandName
    declare -a aEncoderCommandValue
    #encoder parameters  change based on the case info
    let "EncoderFlag = 0"
    CaseInfo=""
    BitStreamFile=""
    DiffFlag=""
    #pass number
    TotalCaseNum=""
    PassCaseNum=""
    UnpassCaseNum=""
}
#called by runGlobalVariableInitial
#usage runEncoderCommandInital
runEncoderCommandInital()
{
    aEncoderCommandSet=( -utype  -frms  -numl   -numtl \
                         -sw -sh    "-dw 0"  "-dh 0" "-dw 1" "-dh 1" "-dw 2" "-dh 2" "-dw 3" "-dh 3" \
                         "-frout 0" "-frout 1" "-frout 2" "-frout 3" \
                         "-lqp 0" "-lqp 1" "-lqp 2" "-lqp 3" \
                         -rc -fs -tarb "-ltarb 0"   "-ltarb 1" "-ltarb 2" "-ltarb 3" \
                         "-lmaxb 0"   "-lmaxb 1"  "-lmaxb 2"  "-lmaxb 3" \
                         "-slcmd 0" "-slcnum 0" "-slcmd 1" "-slcnum 1"\
                         "-slcmd 2" "-slcnum 2" "-slcmd 3" "-slcnum 3"\
                         -nalsize \
                         -iper     -thread  "-loadbalancing"  -ltr \
                         -db    -denois    -scene    -bgd    -aq )

    aEncoderCommandName=(usagetype    frms  numl   numtl \
                         sw sh    dw0 dh0 dw1 dh1 dw2 dh2 dw3 dh3 \
                         frout0 frout1 frout2 frout3 \
                         lqp0 lqp1 lqp2 lqp3 \
                         rc FrSkip tarb ltarb0  ltarb1 ltarb2 ltarb3 \
                         lmaxb0  lmaxb1 lmaxb2 lmaxb3 \
                         slcmd0 slcnum0 slcmd1 slcnum1 \
                         slcmd2 slcnum2 slcmd3 slcnum3 \
                         MaxNalSZ \
                         iper thread  loadbalancing ltr \
                         db    denois  scene  bgd  aq )

    NumParameter=${#aEncoderCommandSet[@]}
    for ((i=0;i<NumParameter; i++))
    do
        aEncoderCommandValue[$i]=0
    done

}
runGlobalVariableInitial()
{
    #TestSpaceDir=../AllTestData  CurrentDir=../AllTestData/TestSetXXX/***.264  eg ../AllTestData/TestSetCIF/BA1_MWD.264
    CurrentDir=`pwd`
    #test data space
    FinalResultPath="${CurrentDir}/result"
    IssueDataPath="${CurrentDir}/issue"
    TempDataPath="TempData"
    TestSequencePath="${CurrentDir}"

    #test info output file
    AllCasePassStatusFile="${FinalResultPath}/${TestYUVName}_AllCaseOutput.csv"
    UnpassCaseFile="${FinalResultPath}/${TestYUVName}_unpassCaseOutput.csv"
    UpdateSHA1TableFile="${FinalResultPath}/${TestYUVName}_UpdateSHA1Table.csv"

   HeadLine1="EncoderFlag, DecoderFlag, FPS, BitSreamSHA1, InputYUVSHA1, \
              -utype,    -frms,  -numl,  -numtl, -sw, -sh,\
              -dw 0, -dh 0, -dw 1, -dh 1, -dw 2, -dh 2, -dw 3, -dh 3,\
              -frout 0,    -frout 1, -frout 2, -frout 3,\
              -lqp 0, -lqp 1, -lqp 2, -lqp 3,\
              -rc,-fs, -tarb, -ltarb 0, -ltarb 1, -ltarb 2, -ltarb 3,\
              -lmaxb 0,   -lmaxb 1,  -lmaxb 2,  -lmaxb 3,\
              -slcmd 0, -slcnum 0, -slcmd 1, -slcnum 1,\
              -slcmd 2, -slcnum 2, -slcmd 3, -slcnum 3,\
              -nalsize,\
              -iper, -thread, -loadbalancing, -ltr, -db, -denois,\
              -scene,    -bgd ,  -aq, "

    HeadLine2="BitSreamSHA1, InputYUVSHA1,\
              -utype,    -frms,  -numl,  -numtl, -sw, -sh,\
              -dw 0, -dh 0, -dw 1, -dh 1,-dw 2, -dh 2, -dw 3, -dh 3,\
              -frout 0,    -frout 1, -frout 2, -frout 3,\
              -lqp 0, -lqp 1, -lqp 2, -lqp 3,\
              -rc, -fs, -tarb, -ltarb 0, -ltarb 1, -ltarb 2, -ltarb 3,\
              -lmaxb 0,   -lmaxb 1,  -lmaxb 2,  -lmaxb 3,\
              -slcmd 0, -slcnum 0, -slcmd 1, -slcnum 1,\
              -slcmd 2, -slcnum 2, -slcmd 3, -slcnum 3,\
              -nalsize,\
              -iper, -thread, -loadbalancing, -ltr, -db, -denois,\
              -scene    , bgd  , -aq "

    echo ${HeadLine1}>${AllCasePassStatusFile}
    echo ${HeadLine1}>${UnpassCaseFile}
    echo ${HeadLine2}>${UpdateSHA1TableFile}

    #intial Commandline parameters
    runEncoderCommandInital
    let "TotalCaseNum=0"
    let "PassCaseNum=0"
    let "UnpassCaseNum=0"
    EncoderCommand=""
    EncoderLogFile="${TempDataPath}/Encoder.log"
    TargetSHA1=""
    TargetYUVSHA1=""
    BenchmarkSHA1=""
    BenchmarkYUVSHA1=""

    RecParam=""
    for((i=0;i<4;i++))
    do
        RecParam="${RecParam} -drec ${i} ${TempDataPath}/${TestYUVName}_rec${i}.yuv"
    done
}
#***********************************************************
#called by    runAllCaseTest
# parse case info --encoder preprocess
#usage    runParseCaseInfo $CaseData
runParseCaseInfo()
{
    if [ $#  -lt 1  ]
    then
        echo "no parameter!"
        return 1
    fi

    local CaseData=$@
    BenchmarkSHA1=`echo $CaseData |awk 'BEGIN {FS="[,\r]"} {print $1} ' `
    BenchmarkYUVSHA1=`echo $CaseData |awk 'BEGIN {FS="[,\r]"} {print $2} ' `
    aEncoderCommandValue=(`echo $CaseData |awk 'BEGIN {FS="[,\r]"} {for(i=3;i<=NF;i++) printf(" %s",$i)} ' `)
    BitstreamTarget=${TempDataPath}/${TestYUVName}_codec_target.264
}

runEncodeOneCase()
{
    EncoderCommand=""
    BitStreamFile=${BitstreamTarget}

    for ((i=0; i<${NumParameter}; i++))
    do
        EncoderCommand="${EncoderCommand} ${aEncoderCommandSet[$i]}  ${aEncoderCommandValue[$i]} "
    done

    EncoderCommand="./h264enc welsenc.cfg -lconfig 0 layer0.cfg -lconfig 1 layer1.cfg -lconfig 2 layer2.cfg  -lconfig 3 layer3.cfg \
                    -bf ${BitStreamFile} -org ${TestSequencePath}/${TestYUVName} ${RecParam} ${EncoderCommand}"
    echo -e "\n---------------Encode One Case-------------------------------------------"
    echo -e "case encode command is : \n ${EncoderCommand} "

    echo -e  "\n\n"
    ${EncoderCommand}  2>${EncoderLogFile}
    if [ $? -eq 0  ]
    then
        let "EncoderFlag=0"
    else
        let "EncoderFlag=1"
    fi

    #delete the core down file as core down files for disk space limitation
    for file in  ./core*
    do
        if [ -e ${file} ]
        then
            ./run_SafeDelete.sh  ${file}
        fi
    done
    return 0
}

#called by    runAllCaseTest
#usage    runJSVMVerify
runBitStreamVerify()
{
    echo -e "\n******************************************"
    echo -e "Bit stream SHA1 value comparison.... "
    #*******************************************
    TargetSHA1="NULL"
    TargetYUVSHA1="NULL"

    if [ ${EncoderFlag} -eq 1 ]
    then
        let "UnpassCaseNum++"
        echo "1:unpassed! encoder initial failed or crash!"
        DiffFlag="1:unpassed! encoder initial failed or crash!"
        return 1
    fi

    if [ ! -s ${BitStreamFile} ]
    then
        let "UnpassCaseNum++"
        echo "2:unpassed! 0 bits--bit stream"
        DiffFlag="2:unpassed! 0 bits--bit stream"
        return 1
    fi

    #*******************************************
    #SHA1
    TargetSHA1=`openssl sha1  ${BitStreamFile} | awk '{print $2}'`
    TargetYUVSHA1=`openssl sha1  ${TestSequencePath}/${TestYUVName} | awk '{print $2}'`
    if [[  "${TargetSHA1}"  =~  "${BenchmarkSHA1}"  ]]
    then
        echo "bitstream pass! SHA1--${TargetSHA1} ----- ${BenchmarkSHA1} YUV--SHA1--info: ${TargetYUVSHA1} ---- ${BenchmarkYUVSHA1}"
        DiffFlag="0:passed!"
        let "PassCaseNum++"
        return 0
    else
        echo "!!! SHA1 string not match: ${TargetSHA1}  ----- ${BenchmarkSHA1} YUV--SHA1--info: ${TargetYUVSHA1} ---- ${BenchmarkYUVSHA1}"
        DiffFlag="3:unpassed!"
        let "UnpassCaseNum++"
        return 1
    fi
}

#called by  runAllCaseTest
#delete temp data    files and output single case test result to log file
#usage    runSingleCasePostAction $CaseData
runSingleCasePostAction()
{
    if [ $#  -lt 1  ]
    then
        echo "no parameter!"
        return 1
    fi
    local CaseData=$@
    #formating for update, keep the same with origin SHA1 table
    CaseInfo=`echo $CaseData | awk 'BEGIN {FS="[,\r]"} {for(i=3;i<=NF-1;i++) printf("%s,",$i)} '`
    LastEncCommandOption=`echo $CaseData | awk 'BEGIN {FS="[,\r]"} {print $NF} '`
    CaseInfo="${CaseInfo}${LastEncCommandOption}"

    PassStatusInfo="${DiffFlag}, ${TargetSHA1}, ${BenchmarkSHA1}, ${TargetYUVSHA1}, ${BenchmarkYUVSHA1}, ${CaseInfo}, ${EncoderCommand} "
    echo "${PassStatusInfo}">>${AllCasePassStatusFile}
    if [ "$DiffFlag" != "0:passed!"  ]
    then
        echo "${PassStatusInfo}">>${UnpassCaseFile}
    fi

    echo "${TargetSHA1}, ${TargetYUVSHA1},${CaseInfo}">>${UpdateSHA1TableFile}
    #./run_SafeDelete.sh ${BitstreamTarget} >>${AllCaseConsoleLogFile}
}

#usage runOutputPassNum
runOutputPassNum()
{
    # output file locate in ../result
    echo ""
    echo "***********************************************************"
    echo "${TestYUVName}"
    echo "total case  Num is: ${TotalCaseNum}"
    echo "pass  case  Num is: ${PassCaseNum}"
    echo "unpass case Num is: ${UnpassCaseNum}"
    echo "***********************************************************"
    echo ""
}

# run all test case based on XXXcase.csv file
#usage    runAllCaseTest
runAllCaseTest()
{
    local EncoderLogInfo=""
    while read CaseData
    do
        #get case parameter's value
        if [[ ! $CaseData =~ "SHA"  ]]
        then
            echo "" >>${AllCaseConsoleLogFile}
            echo "" >>${AllCaseConsoleLogFile}
            echo "" >>${AllCaseConsoleLogFile}
            echo "********************case index is ${TotalCaseNum}**************************************"  >>${AllCaseConsoleLogFile}
            runParseCaseInfo ${CaseData}  >>${AllCaseConsoleLogFile}
            echo ""                       >>${AllCaseConsoleLogFile}
            runEncodeOneCase              >>${AllCaseConsoleLogFile}
            cat    ${EncoderLogFile}      >>${AllCaseConsoleLogFile}
            runBitStreamVerify            >>${AllCaseConsoleLogFile}
            let "DisplayFlag=TotalCaseNum%100"
            if [  ${DisplayFlag} -eq 0  ]
            then
                if [  "$DiffFlag" = "0:passed!"   ]
                then
                  echo -e "\033[32m    OK!   ${TestYUVName} Case Index ${TotalCaseNum}:SHA-1(Current--Benchmark): ${TargetSHA1}-----${BenchmarkSHA1}    \033[0m"
                  echo -e "\033[32m          ----YUVSHA1: ${TargetYUVSHA1}, ${BenchmarkYUVSHA1} \033[0m"
                fi
            fi
            #******************************************
            if [ ! "$DiffFlag" = "0:passed!"  ]
            then
                echo -e "\033[31m    Failed! ${TestYUVName} Case Index ${TotalCaseNum}:SHA-1(Current--Benchmark): ${TargetSHA1}-----${BenchmarkSHA1}  \033[0m"
                echo -e "\033[31m            ----YUVSHA1:  ${TargetYUVSHA1}, ${BenchmarkYUVSHA1}  \033[0m"
                EncoderLogInfo=`cat  ${EncoderLogFile}`
                echo -e "\033[31m           ${EncoderLogInfo}   \033[0m"
            fi
            runSingleCasePostAction  ${CaseData}
            let "TotalCaseNum++"
        fi
    done <$AllCaseFile
}
#***********************************************************
# usage: runMain $TestYUV    $AllCaseFile
runMain()
{
    runGlobalVariableDef
    runGlobalVariableInitial
    TestFolder=`echo $CurrentDir | awk 'BEGIN {FS="/"} { i=NF; print $i}'`
    AllCaseConsoleLogFile="${FinalResultPath}/${TestYUVName}.TestLog"
    CaseSummaryFile="${FinalResultPath}/${TestYUVName}.Summary"
    FlagFile=""

    #run all cases
    runAllCaseTest

    # output file locate in ./result
    echo "${TestYUVName},            \
         ${PassCaseNum} pass!,    \
         ${UnpassCaseNum} unpass!,\
         detail file located in ../AllTestData/${TestFolder}/result">${CaseSummaryFile}
    runOutputPassNum

    #generate All case Flag
    if [  ! ${UnpassCaseNum} -eq 0  ]
    then
        echo ""
        exit 1
    else
        echo  ""
        exit 0
    fi
}
#************************************************************************
# main entry
#************************************************************************
if [ ! $# -eq 2  ]
then
    echo "usage: run_BinarySHA1Comparison.sh \$TestYUV  \$AllCaseFile"
    return 1
fi
TestYUVName=$1
AllCaseFile=$2
runMain