winlin

add gest framework for utest, build success.

@@ -422,6 +422,7 @@ See also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-serv @@ -422,6 +422,7 @@ See also: [Performance Test Guide](https://github.com/winlinvip/simple-rtmp-serv
422 * nginx v1.5.0: 139524 lines <br/> 422 * nginx v1.5.0: 139524 lines <br/>
423 423
424 ### History 424 ### History
  425 +* v1.0, 2014-03-04, add gest framework for utest, build success.
425 * v1.0, 2014-03-02, add wiki [srs-librtmp](https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLibrtmp), [srs for arm](https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLinuxArm), [product](https://github.com/winlinvip/simple-rtmp-server/wiki/Product) 426 * v1.0, 2014-03-02, add wiki [srs-librtmp](https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLibrtmp), [srs for arm](https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLinuxArm), [product](https://github.com/winlinvip/simple-rtmp-server/wiki/Product)
426 * v1.0, 2014-03-02, srs-librtmp, client publish/play library like librtmp. 427 * v1.0, 2014-03-02, srs-librtmp, client publish/play library like librtmp.
427 * v1.0, 2014-03-01, modularity, extract core/kernel/rtmp/app/main module. 428 * v1.0, 2014-03-01, modularity, extract core/kernel/rtmp/app/main module.
@@ -5,19 +5,22 @@ @@ -5,19 +5,22 @@
5 # $SRS_MAKEFILE the makefile name. ie. Makefile 5 # $SRS_MAKEFILE the makefile name. ie. Makefile
6 # 6 #
7 # $APP_NAME the app name to output. ie. srs_utest 7 # $APP_NAME the app name to output. ie. srs_utest
  8 +# $MODULE_DIR the src dir of utest code. ie. src/utest
8 9
9 -UTEST_OBJS=${SRS_OBJS}/utest  
10 -FILE=${UTEST_OBJS}/${SRS_MAKEFILE} 10 +FILE=${SRS_OBJS}/utest/${SRS_MAKEFILE}
  11 +# create dir for Makefile
  12 +mkdir -p ${SRS_OBJS}/utest
11 13
12 -# dirs relative to objs/utest  
13 -GTEST_DIR=../gtest  
14 -UTEST_SRC=../../src/utest  
15 -UTEST_APP=../${APP_NAME}  
16 -  
17 -mkdir -p ${UTEST_OBJS} 14 +# the prefix to generate the objs/utest/Makefile
  15 +# dirs relative to current dir(objs/utest), it's trunk/objs/utest
  16 +# trunk of srs, which contains the src dir, relative to objs/utest, it's trunk
  17 +SRS_TRUNK_PREFIX=../..
  18 +# gest dir, relative to objs/utest, it's trunk/objs/gtest
  19 +GTEST_DIR=${SRS_TRUNK_PREFIX}/${SRS_OBJS}/gtest
18 20
19 cat << END > ${FILE} 21 cat << END > ${FILE}
20 -# generate *.a, *.o at current dir. 22 +# user must run make the ${SRS_OBJS}/utest dir
  23 +# at the same dir of Makefile.
21 24
22 # A sample Makefile for building Google Test and using it in user 25 # A sample Makefile for building Google Test and using it in user
23 # tests. Please tweak it to suit your environment and project. You 26 # tests. Please tweak it to suit your environment and project. You
@@ -48,7 +51,7 @@ CXXFLAGS += -g -Wall -Wextra -O0 @@ -48,7 +51,7 @@ CXXFLAGS += -g -Wall -Wextra -O0
48 51
49 # All tests produced by this Makefile. Remember to add new tests you 52 # All tests produced by this Makefile. Remember to add new tests you
50 # created to the list. 53 # created to the list.
51 -TESTS = ${UTEST_APP} 54 +TESTS = ${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${APP_NAME}
52 55
53 # All Google Test headers. Usually you shouldn't change this 56 # All Google Test headers. Usually you shouldn't change this
54 # definition. 57 # definition.
@@ -90,14 +93,86 @@ gtest_main.a : gtest-all.o gtest_main.o @@ -90,14 +93,86 @@ gtest_main.a : gtest-all.o gtest_main.o
90 # gtest_main.a, depending on whether it defines its own main() 93 # gtest_main.a, depending on whether it defines its own main()
91 # function. 94 # function.
92 95
93 -srs_utest.o : ${UTEST_SRC}/srs_utest.cpp  
94 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) -I${UTEST_SRC} -c ${UTEST_SRC}/srs_utest.cpp -o \$@  
95 -SRS_UTEST_OBJS = srs_utest.o 96 +#####################################################################################
  97 +#####################################################################################
  98 +# SRS(Simple RTMP Server) utest section
  99 +#####################################################################################
  100 +#####################################################################################
  101 +
  102 +END
96 103
97 -${UTEST_APP} : \$(SRS_UTEST_OBJS) gtest_main.a  
98 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) -lpthread \$^ -o \$@ 104 +#####################################################################################
  105 +# Includes, the include dir.
  106 +echo "# Includes, the include dir." >> ${FILE}
  107 +#
  108 +# current module header files
  109 +echo -n "SRS_UTEST_INC = -I${SRS_TRUNK_PREFIX}/${MODULE_DIR} " >> ${FILE}
  110 +#
  111 +# depends module header files
  112 +for item in ${MODULE_DEPENDS[*]}; do
  113 + DEP_INCS_NAME="${item}_INCS"
  114 + echo -n "-I${SRS_TRUNK_PREFIX}/${!DEP_INCS_NAME} " >> ${FILE}
  115 +done
  116 +#
  117 +# depends library header files
  118 +for item in ${ModuleLibIncs[*]}; do
  119 + echo -n "-I${SRS_TRUNK_PREFIX}/${item} " >> ${FILE}
  120 +done
  121 +echo "" >> ${FILE}; echo "" >> ${FILE}
  122 +
  123 +#####################################################################################
  124 +# Depends, the depends objects
  125 +echo "# Depends, the depends objects" >> ${FILE}
  126 +#
  127 +# current module header files
  128 +echo -n "SRS_UTEST_DEPS = " >> ${FILE}
  129 +for item in ${MODULE_OBJS[*]}; do
  130 + FILE_NAME=${item%.*}
  131 + echo -n "${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${FILE_NAME}.o " >> ${FILE}
  132 +done
  133 +echo "" >> ${FILE}; echo "" >> ${FILE}
  134 +#
  135 +echo "# Depends, utest header files" >> ${FILE}
  136 +DEPS_NAME="UTEST_DEPS"
  137 +echo -n "${DEPS_NAME} = " >> ${FILE}
  138 +for item in ${MODULE_FILES[*]}; do
  139 + HEADER_FILE="${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.hpp"
  140 + echo -n " ${HEADER_FILE}" >> ${FILE}
  141 +done
  142 +echo "" >> ${FILE}; echo "" >> ${FILE}
  143 +
  144 +#####################################################################################
  145 +# Objects, build each object of utest
  146 +echo "# Objects, build each object of utest" >> ${FILE}
  147 +#
  148 +MODULE_OBJS=()
  149 +for item in ${MODULE_FILES[*]}; do
  150 + MODULE_OBJS="${MODULE_OBJS[@]} ${item}.o"
  151 + cat << END >> ${FILE}
  152 +${item}.o : \$(${DEPS_NAME}) ${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.cpp \$(SRS_UTEST_DEPS)
  153 + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SRS_UTEST_INC) -c ${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.cpp -o \$@
  154 +END
  155 +done
  156 +echo "" >> ${FILE}
  157 +
  158 +#####################################################################################
  159 +# App for utest
  160 +#
  161 +# link all depends libraries
  162 +echo "# link all depends libraries" >> ${FILE}
  163 +echo -n "DEPS_LIBRARIES_FILES = " >> ${FILE}
  164 +for item in ${ModuleLibFiles[*]}; do
  165 + echo -n "${SRS_TRUNK_PREFIX}/${item} " >> ${FILE}
  166 +done
  167 +echo "" >> ${FILE}; echo "" >> ${FILE}
  168 +#
  169 +echo "# generate the utest binary" >> ${FILE}
  170 +cat << END >> ${FILE}
  171 +${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${APP_NAME} : \$(SRS_UTEST_DEPS) ${MODULE_OBJS} gtest_main.a
  172 + \$(CXX) -o \$@ \$(CPPFLAGS) \$(CXXFLAGS) \$^ \$(DEPS_LIBRARIES_FILES) -lpthread -ldl
99 END 173 END
100 174
  175 +#####################################################################################
101 # parent Makefile, to create module output dir before compile it. 176 # parent Makefile, to create module output dir before compile it.
102 echo " mkdir -p ${SRS_OBJS}/utest" >> ${SRS_MAKEFILE} 177 echo " mkdir -p ${SRS_OBJS}/utest" >> ${SRS_MAKEFILE}
103 178
@@ -54,7 +54,7 @@ SrsLibrtmpSampleEntry="nossl" @@ -54,7 +54,7 @@ SrsLibrtmpSampleEntry="nossl"
54 if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi 54 if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi
55 # utest make entry, (cd utest; make) 55 # utest make entry, (cd utest; make)
56 SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\"" 56 SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\""
57 -if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd $${SRS_OBJS}/utest; \$(MAKE) ${SRS_MAKEFILE})"; fi 57 +if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS}/utest; \$(MAKE))"; fi
58 58
59 ##################################################################################### 59 #####################################################################################
60 # colorful summary 60 # colorful summary
@@ -187,7 +187,7 @@ MODULE_ID="CORE" @@ -187,7 +187,7 @@ MODULE_ID="CORE"
187 MODULE_DEPENDS=() 187 MODULE_DEPENDS=()
188 ModuleLibIncs=(${SRS_OBJS}) 188 ModuleLibIncs=(${SRS_OBJS})
189 MODULE_FILES=("srs_core" "srs_core_autofree") 189 MODULE_FILES=("srs_core" "srs_core_autofree")
190 -MODULE_DIR="src/core" . auto/modules.sh 190 +CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh
191 CORE_OBJS="${MODULE_OBJS[@]}" 191 CORE_OBJS="${MODULE_OBJS[@]}"
192 # 192 #
193 #Kernel, depends on core, provides error/log/config, nothing about stream information. 193 #Kernel, depends on core, provides error/log/config, nothing about stream information.
@@ -195,7 +195,7 @@ MODULE_ID="KERNEL" @@ -195,7 +195,7 @@ MODULE_ID="KERNEL"
195 MODULE_DEPENDS=("CORE") 195 MODULE_DEPENDS=("CORE")
196 ModuleLibIncs=(${SRS_OBJS}) 196 ModuleLibIncs=(${SRS_OBJS})
197 MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream" "srs_kernel_buffer") 197 MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream" "srs_kernel_buffer")
198 -MODULE_DIR="src/kernel" . auto/modules.sh 198 +KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh
199 KERNEL_OBJS="${MODULE_OBJS[@]}" 199 KERNEL_OBJS="${MODULE_OBJS[@]}"
200 # 200 #
201 #RTMP Protocol, depends on core/kernel, provides rtmp/htttp protocol features. 201 #RTMP Protocol, depends on core/kernel, provides rtmp/htttp protocol features.
@@ -204,7 +204,7 @@ MODULE_DEPENDS=("CORE" "KERNEL") @@ -204,7 +204,7 @@ MODULE_DEPENDS=("CORE" "KERNEL")
204 ModuleLibIncs=(${SRS_OBJS} ${LibSSLRoot}) 204 ModuleLibIncs=(${SRS_OBJS} ${LibSSLRoot})
205 MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_rtmp_stack" "srs_protocol_rtmp" 205 MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_rtmp_stack" "srs_protocol_rtmp"
206 "srs_protocol_handshake" "srs_protocol_utility") 206 "srs_protocol_handshake" "srs_protocol_utility")
207 -MODULE_DIR="src/rtmp" . auto/modules.sh 207 +RTMP_INCS="src/rtmp"; MODULE_DIR=${RTMP_INCS} . auto/modules.sh
208 RTMP_OBJS="${MODULE_OBJS[@]}" 208 RTMP_OBJS="${MODULE_OBJS[@]}"
209 # 209 #
210 #App Module 210 #App Module
@@ -215,7 +215,7 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_client" "srs_app_socket" @@ -215,7 +215,7 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_client" "srs_app_socket"
215 "srs_app_codec" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" 215 "srs_app_codec" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder"
216 "srs_app_http" "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" 216 "srs_app_http" "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log"
217 "srs_app_config" "srs_app_pithy_print" "srs_app_reload") 217 "srs_app_config" "srs_app_pithy_print" "srs_app_reload")
218 -MODULE_DIR="src/app" . auto/modules.sh 218 +APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
219 APP_OBJS="${MODULE_OBJS[@]}" 219 APP_OBJS="${MODULE_OBJS[@]}"
220 # 220 #
221 #LIBS Module, build libsrs.a for static link. 221 #LIBS Module, build libsrs.a for static link.
@@ -223,7 +223,7 @@ MODULE_ID="LIBS" @@ -223,7 +223,7 @@ MODULE_ID="LIBS"
223 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") 223 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
224 ModuleLibIncs=(${SRS_OBJS}) 224 ModuleLibIncs=(${SRS_OBJS})
225 MODULE_FILES=("srs_librtmp" "srs_lib_simple_socket") 225 MODULE_FILES=("srs_librtmp" "srs_lib_simple_socket")
226 -MODULE_DIR="src/libs" . auto/modules.sh 226 +LIBS_INCS="src/libs"; MODULE_DIR=${LIBS_INCS} . auto/modules.sh
227 LIBS_OBJS="${MODULE_OBJS[@]}" 227 LIBS_OBJS="${MODULE_OBJS[@]}"
228 # 228 #
229 #Main Module 229 #Main Module
@@ -231,13 +231,8 @@ MODULE_ID="MAIN" @@ -231,13 +231,8 @@ MODULE_ID="MAIN"
231 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") 231 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
232 ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS}) 232 ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS})
233 MODULE_FILES=("srs_main_server" "srs_main_bandcheck") 233 MODULE_FILES=("srs_main_server" "srs_main_bandcheck")
234 -MODULE_DIR="src/main" . auto/modules.sh  
235 -MAIN_OBJS="${MODULE_OBJS[@].o}"  
236 -  
237 -#####################################################################################  
238 -# utest, the unit-test cases of srs, base on gtest1.6  
239 -MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}"  
240 -APP_NAME="srs_utest" . auto/utest.sh 234 +MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh
  235 +MAIN_OBJS="${MODULE_OBJS[@]}"
241 236
242 ##################################################################################### 237 #####################################################################################
243 # Binaries, main entrances, link the module and its depends modules, 238 # Binaries, main entrances, link the module and its depends modules,
@@ -263,6 +258,14 @@ BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" . auto/ @@ -263,6 +258,14 @@ BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" . auto/
263 # srs librtmp 258 # srs librtmp
264 MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${LIBS_OBJS[@]}" 259 MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${LIBS_OBJS[@]}"
265 BUILD_KEY="librtmp" LIB_NAME="lib/srs_librtmp" . auto/libs.sh 260 BUILD_KEY="librtmp" LIB_NAME="lib/srs_librtmp" . auto/libs.sh
  261 +#
  262 +# utest, the unit-test cases of srs, base on gtest1.6
  263 +MODULE_FILES=("srs_utest")
  264 +ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot})
  265 +ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile})
  266 +MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
  267 +MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${APP_OBJS[@]}"
  268 +MODULE_DIR="src/utest" APP_NAME="srs_utest" . auto/utest.sh
266 269
267 echo 'configure ok! ' 270 echo 'configure ok! '
268 271
@@ -22,3 +22,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -22,3 +22,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */ 22 */
23 23
24 #include <srs_utest.hpp> 24 #include <srs_utest.hpp>
  25 +
  26 +#include <srs_kernel_log.hpp>
  27 +#include <srs_kernel_error.hpp>
  28 +#include <srs_app_server.hpp>
  29 +#include <srs_app_config.hpp>
  30 +#include <srs_app_log.hpp>
  31 +
  32 +// kernel module.
  33 +ISrsLog* _srs_log = new ISrsLog();
  34 +ISrsThreadContext* _srs_context = new ISrsThreadContext();
  35 +// app module.
  36 +SrsConfig* _srs_config = NULL;
  37 +SrsServer* _srs_server = NULL;
  38 +
  39 +// basic test and samples.
  40 +VOID TEST(SampleTest, FastSampleInt64Test){
  41 + EXPECT_EQ(1, (int)sizeof(int8_t));
  42 + EXPECT_EQ(2, (int)sizeof(int16_t));
  43 + EXPECT_EQ(4, (int)sizeof(int32_t));
  44 + EXPECT_EQ(8, (int)sizeof(int64_t));
  45 +}
@@ -27,5 +27,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -27,5 +27,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 /* 27 /*
28 #include <srs_utest.hpp> 28 #include <srs_utest.hpp>
29 */ 29 */
  30 +#include <srs_core.hpp>
  31 +
  32 +#include "gtest/gtest.h"
  33 +
  34 +// we add an empty macro for upp to show the smart tips.
  35 +#define VOID
30 36
31 #endif 37 #endif