• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#*******************************************************************************
3# Encoder binary comparison test model
4#             -- Compared with benchmark version using SHA-1 string
5#             -- Test bit stream under folder  openh264/res
6#             -- SHA-1 string of benchmark version for  all cases  of all bit streams
7#                 under folder  openh264/test/encoder_binary_comparion/SHA1Table
8#             -- For more detail,please refer to file AboutTest.
9#
10#brief:
11#             -- Usage:  run_OneBitStream.sh   $BitStreamName $TestType
12#             -- WorkingDir
13#                1) For local  test:  WorkingDir=openh264/test/encoder_binary_comparison
14#                2) For travis test:  WorkingDir=openh264
15#                   There will be an auto detection for working directory
16#             -- Before using this script, need to run below command:
17#                ./run_PrepareAllTestData.sh  32(or 64)
18#                cd  $WorkingDir
19#
20# date:    10/06/2014 Created
21#*******************************************************************************
22
23runInitial()
24{
25    TestYUVName=""
26    StreamName=""
27    BitStreamToYUVLog="Bit2YUV.log"
28    SHA1Table="${BitStreamName}_AllCases_SHA1_Table.csv"
29
30    #dir info
31    WorkingDir=`pwd`
32    EncoderTestDir=""
33    BitStreamTestDir=""
34    FinalResultDir=""
35    StreamFileFullPath=""
36    BitSreamDir=""
37
38    if [[  "${WorkingDir}" =~ "test/encoder_binary_comparison"  ]]
39    then
40        #for local test: working dir is  openh264/test/encoder_binary_comparison
41        EncoderTestDir=${WorkingDir}
42        BitStreamTestDir="${EncoderTestDir}/AllTestData/${BitStreamName}"
43        FinalResultDir="${EncoderTestDir}/FinalResult"
44        BitSreamDir="../../res"
45    else
46        #for travis test: working dir is  openh264/
47        EncoderTestDir=${WorkingDir}/test/encoder_binary_comparison
48        BitStreamTestDir="${EncoderTestDir}/AllTestData/${BitStreamName}"
49        FinalResultDir="${EncoderTestDir}/FinalResult"
50        BitSreamDir="${WorkingDir}/res"
51    fi
52
53    cd ${BitSreamDir}
54    StreamFileFullPath=`pwd`
55    StreamFileFullPath=${StreamFileFullPath}/${BitStreamName}
56    cd ${WorkingDir}
57
58}
59
60runBitStreamToYUV()
61{
62
63    ./run_BitStreamToYUV.sh  ${StreamFileFullPath}>${BitStreamToYUVLog}
64    if [  ! $? -eq 0 ]
65    then
66        echo "failed to translate bit stream to yuv !"
67        exit 1
68    fi
69
70    #parse basic info
71    TestYUVName=`runGetCurrentYUVName `
72    TestYUVName=`echo ${TestYUVName} | awk 'BEGIN {FS="/"}  {print $NF}   ' `
73    StreamName=`echo ${StreamFileFullPath} | awk 'BEGIN {FS="/"}  {print $NF}  ' `
74    echo ""
75    echo "TestYUVName is  ${TestYUVName}"
76    echo "StreamName  is  ${StreamName}"
77    echo "SHA1Table   is  ${SHA1Table}"
78    echo ""
79}
80
81
82runGetCurrentYUVName()
83 {
84
85    local YUVName=""
86    while read line
87    do
88        if [[ "$line" =~ "renamed as"  ]]
89        then
90            YUVName=`echo $line | awk 'BEGIN {FS=":"} {print $3}'`
91        fi
92    done <${BitStreamToYUVLog}
93    echo ${YUVName}
94 }
95
96runSHA1TableCheck()
97{
98    if [  ! -e  "${SHA1Table}"   ]
99    then
100        echo "SHA1 table does not exist:  ${SHA1Table} "
101        echo "SHA1 table should be named as \${StreamName}_AllCases_SHA1_Table.csv"
102        exit 0
103    fi
104    return 0
105 }
106
107runBitStreamCheck()
108{
109
110    local BitSreamName=`echo ${StreamFileFullPath} | awk 'BEGIN {FS="/"} {print $NF}'`
111    echo "bit stream is $BitSreamName"
112    if [ ! -e ${StreamFileFullPath}  ]
113    then
114        echo -e "\033[31m   bit stream does not exist:  $BitSreamName   \033[0m"
115        echo -e "\033[31m   please double check under  openh264/res folder \033[0m"
116        echo -e "\033[31m     -----detected by run_OneBitStream.sh  \033[0m"
117        exit 0
118    fi
119    return 0
120 }
121
122runTestSpaceCheck()
123 {
124
125    if [ ! -d ${BitStreamTestDir} ]
126    then
127        echo ""
128        echo  -e "\033[31m ----Test space for bitsream does not exist!--- ${BitStreamTestDir}  \033[0m"
129        echo  -e "\033[31m ---- before running this test locally, please follow step below:   \033[0m"
130        echo  -e "\033[31m       ---- 1)cd test/encoder_binary_comparison/  \033[0m"
131        echo  -e "\033[31m       ---- 2)run script file:  ./run_PrepareAllTestData.sh    \033[0m"
132        echo ""
133        exit 1
134    fi
135    return 0
136 }
137
138 #brief: delete temp files based on test type
139runPostAction()
140 {
141    echo ""
142    echo "deleting temp data,entire folder will be deleted........ "
143    if [ -d ${BitStreamTestDir} ]
144    then
145        ${EncoderTestDir}/Scripts/run_SafeDelete.sh ${BitStreamTestDir}
146    fi
147
148    if [ ${TestType} = "TravisTest" ]
149    then
150        if [ -d ${FinalResultDir} ]
151        then
152            ${EncoderTestDir}/Scripts/run_SafeDelete.sh ${FinalResultDir}
153        fi
154    fi
155 }
156
157 #usage: usage: runMain $BitStreamName $TestType
158runMain()
159{
160    if [ ! $# -eq 2 ]
161    then
162        echo "usage: runMain \$BitStreamName \$TestType"
163        echo "detected by run_OneBitStream.sh"
164        exit 1
165    fi
166    BitStreamName=$1
167    TestType=$2
168
169    runInitial
170    runBitStreamCheck
171    runTestSpaceCheck
172
173    #go to Bitstream test space
174    cd ${BitStreamTestDir}
175
176    runSHA1TableCheck
177
178    #bit stream to YUV
179    runBitStreamToYUV
180
181    #binary comparison
182    ./run_BinarySHA1Comparison.sh   ${TestYUVName}   ${SHA1Table}
183    if [  ! $? -eq 0 ]
184    then
185        echo ""
186        echo  -e "\033[31m  not all cases passed .....\033[0m"
187        echo  -e "\033[31m  this may caused by:      \033[0m"
188        echo  -e "\033[31m   --1) you changed encoder algorithm which changed the final bit stream  \033[0m"
189        echo  -e "\033[31m        if so, you need to update the SHA1 table in folder  ./test/encoder_binary_comparison/SHA1Table  \033[0m"
190        echo  -e "\033[31m   --2) the decoder  has been changed and since the test YUV is generated by h264dec,the input YUV changed,so bit stream will also change \033[0m"
191        echo  -e "\033[31m        if so, you need to update the SHA1 table in folder  ./test/encoder_binary_comparison/SHA1Table  \033[0m"
192        echo  -e "\033[31m        for how to update, please refer to doc:  ./test/encoder_binary_comparison/AboutTest  \033[0m"
193        echo  -e "\033[31m   --3) there may be something wrong in you code change (encoder or decoder) \033[0m"
194        echo  -e "\033[31m        if so, please fix bug in your code \033[0m"
195        cp  ./result/*    ${FinalResultDir}
196        cd  ${WorkingDir}
197        #delete the test data
198        runPostAction
199        exit 1
200    else
201        echo -e "\033[32m  all cases passed!! ----bit stream:  ${StreamName} \033[0m"
202        cp  ./result/*    ${FinalResultDir}
203        cd  ${WorkingDir}
204        #delete the test data
205        runPostAction
206        exit 0
207    fi
208 }
209BitSteamName=$1
210TestType=$2
211runMain    "${BitSteamName}" "${TestType}"
212
213