winlin

add utest build project, no testcase.

@@ -413,11 +413,17 @@ fi @@ -413,11 +413,17 @@ fi
413 # build utest code 413 # build utest code
414 ##################################################################################### 414 #####################################################################################
415 if [ $SRS_UTEST = YES ]; then 415 if [ $SRS_UTEST = YES ]; then
416 - mkdir -p ${SRS_OBJS}/utest  
417 -  
418 - (cd research/hls && make ${SRS_JOBS} && mv ts_info ../../${SRS_OBJS}/research)  
419 - ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/hls failed, ret=$ret"; exit $ret; fi  
420 -  
421 - (cd research/ffempty && make ${SRS_JOBS} && mv ffempty ../../${SRS_OBJS}/research)  
422 - ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/ffempty failed, ret=$ret"; exit $ret; fi 416 + if [[ -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]]; then
  417 + echo "gtest-1.6.0 is ok.";
  418 + else
  419 + echo "build gtest-1.6.0";
  420 + (
  421 + rm -rf ${SRS_OBJS}/gtest-1.6.0 && cd ${SRS_OBJS} &&
  422 + unzip -q ../3rdparty/gtest-1.6.0.zip &&
  423 + rm -f gtest && ln -sf gtest-1.6.0 gtest
  424 + )
  425 + fi
  426 + # check status
  427 + ret=$?; if [[ $ret -ne 0 ]]; then echo "build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi
  428 + if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "build gtest-1.6.0 failed."; exit -1; fi
423 fi 429 fi
@@ -4,10 +4,21 @@ @@ -4,10 +4,21 @@
4 # $SRS_OBJS the objs directory. ie. objs 4 # $SRS_OBJS the objs directory. ie. objs
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 8
8 -FILE=${SRS_OBJS}/${SRS_MAKEFILE}.utest 9 +UTEST_OBJS=${SRS_OBJS}/utest
  10 +FILE=${UTEST_OBJS}/${SRS_MAKEFILE}
  11 +
  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}
9 18
10 cat << END > ${FILE} 19 cat << END > ${FILE}
  20 +# generate *.a, *.o at current dir.
  21 +
11 # A sample Makefile for building Google Test and using it in user 22 # A sample Makefile for building Google Test and using it in user
12 # tests. Please tweak it to suit your environment and project. You 23 # tests. Please tweak it to suit your environment and project. You
13 # may want to move it to your project's root directory. 24 # may want to move it to your project's root directory.
@@ -24,7 +35,7 @@ cat << END > ${FILE} @@ -24,7 +35,7 @@ cat << END > ${FILE}
24 35
25 # Points to the root of Google Test, relative to where this file is. 36 # Points to the root of Google Test, relative to where this file is.
26 # Remember to tweak this if you move this file. 37 # Remember to tweak this if you move this file.
27 -GTEST_DIR = gtest-1.6.0 38 +GTEST_DIR = ${GTEST_DIR}
28 39
29 # Where to find user code. 40 # Where to find user code.
30 USER_DIR = . 41 USER_DIR = .
@@ -37,7 +48,7 @@ CXXFLAGS += -g -Wall -Wextra -O0 @@ -37,7 +48,7 @@ CXXFLAGS += -g -Wall -Wextra -O0
37 48
38 # All tests produced by this Makefile. Remember to add new tests you 49 # All tests produced by this Makefile. Remember to add new tests you
39 # created to the list. 50 # created to the list.
40 -TESTS = smart_utest 51 +TESTS = ${UTEST_APP}
41 52
42 # All Google Test headers. Usually you shouldn't change this 53 # All Google Test headers. Usually you shouldn't change this
43 # definition. 54 # definition.
@@ -79,35 +90,12 @@ gtest_main.a : gtest-all.o gtest_main.o @@ -79,35 +90,12 @@ gtest_main.a : gtest-all.o gtest_main.o
79 # gtest_main.a, depending on whether it defines its own main() 90 # gtest_main.a, depending on whether it defines its own main()
80 # function. 91 # function.
81 92
82 -SMART_DIR=../objs  
83 -ST_DIR=\$(SMART_DIR)/st-1.9/obj  
84 -SSL_LINK = \$(SMART_DIR)/openssl-1.0.1c/libssl.a \$(SMART_DIR)/openssl-1.0.1c/libcrypto.a -ldl  
85 -  
86 -smart_objs_o = objs/src/core/smt_public.o objs/src/core/smt_error_code.o objs/src/core/smt_log.o objs/src/core/smt_app.o objs/src/core/smt_utility.o objs/src/core/smt_process.o objs/src/core/smt_bytes_pool.o objs/src/core/smt_config.o objs/src/core/smt_buffer_manager.o objs/src/core/smt_connection.o objs/src/core/smt_descriptor.o objs/src/core/smt_tearup_ret.o objs/src/core/smt_context.o objs/src/core/smt_empty_app.o objs/src/core/smt_serialize.o objs/src/app/smt_app_process_handler.o objs/src/app/smt_app_smart_app.o objs/src/app/smt_app_connection.o objs/src/app/smt_app_socket_stream.o objs/src/app/smt_app_handshake.o objs/src/app/smt_app_context.o objs/src/app/smt_app_endpoint_switch.o objs/src/app/smt_app_edge.o objs/src/app/smt_app_edge_cache.o objs/src/app/smt_app_edge_stream.o objs/src/app/smt_app_utility.o objs/src/app/smt_app_edge_proxy.o objs/src/app/smt_app_api.o objs/src/app/smt_app_vhost_statistic.o objs/src/app/smt_app_bandwidth_check.o objs/src/protocol/rtmp/smt_rtmp_utility.o objs/src/protocol/rtmp/smt_rtmp_description_builder.o objs/src/protocol/rtmp/smt_rtmp_interfaces.o objs/src/protocol/rtmp/smt_rtmp_api.o objs/src/protocol/rtmp/smt_rtmp_chunk_packet.o objs/src/protocol/rtmp/smt_rtmp_handshake_packet.o objs/src/protocol/rtmp/smt_rtmp_message_packet.o objs/src/protocol/rtmp/smt_rtmp_farm.o objs/src/protocol/rtmp/smt_rtmp_crypto.o objs/src/protocol/rtmp/smt_rtmp_amf3.o objs/src/protocol/rtmp/smt_rtmp_bytes_pool.o objs/src/os/st/smt_st_process_model.o objs/src/os/st/smt_st_process_spawner.o objs/src/os/st/smt_st_process_channel.o objs/src/os/st/smt_st_utility.o objs/src/os/st/smt_st_pipe.o objs/src/os/st/smt_st_signal_channel.o objs/src/os/st/smt_st_server_listener.o objs/src/os/st/smt_st_connection.o objs/src/os/st/smt_st_connection_farm.o objs/src/os/st/smt_st_fd_auto_closer.o objs/src/log/smt_log_simple_log.o objs/src/log/smt_log_fast_log.o objs/src/amf0/smt_amf0_public.o objs/src/amf0/smt_amf0_packet.o objs/src/amf0/smt_amf0_codec.o objs/src/amf0/smt_amf0_utility.o objs/src/config/smt_config_app_args.o objs/src/config/smt_config_options_parser.o objs/src/config/smt_config_file_parser.o objs/src/stream/smt_stream_source.o objs/src/stream/smt_stream_vod_cache.o objs/src/stream/smt_stream_live_stream.o objs/src/stream/smt_stream_flv_muxer.o objs/src/stream/smt_stream_f4v_muxer.o objs/src/stream/smt_stream_vod_stream.o objs/src/stream/smt_stream_public_api.o objs/src/stream/smt_stream_internal_api.o objs/src/stream/smt_stream_utility.o objs/src/stream/smt_stream_buffer_manager.o objs/src/stream/smt_stream_factory.o objs/src/stream/smt_stream_file_stream.o objs/src/stream/smt_stream_strategy.o objs/src/stream/smt_stream_source_pool.o  
87 -smart_objs = \$(addprefix \$(SMART_DIR)/../, \$(smart_objs_o))  
88 -  
89 -SMART_INC = -I\$(SMART_DIR)/inc -I\$(ST_DIR)  
90 -SSL_LINK = \$(SMART_DIR)/openssl-1.0.1c/libssl.a \$(SMART_DIR)/openssl-1.0.1c/libcrypto.a -ldl  
91 -  
92 -smart_refer_utest.o : \$(smart_objs) smart_refer_utest.cpp  
93 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_refer_utest.cpp -o \$@  
94 -smart_app_utest.o : \$(smart_objs) smart_app_utest.cpp  
95 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_app_utest.cpp -o \$@  
96 -smart_reload_utest.o : \$(smart_objs) smart_reload_utest.cpp  
97 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_reload_utest.cpp -o \$@  
98 -smart_process_pool_utest.o : \$(smart_objs) smart_process_pool_utest.cpp  
99 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_process_pool_utest.cpp -o \$@  
100 -smart_config_utest.o : \$(smart_objs) smart_config_utest.cpp  
101 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_config_utest.cpp -o \$@  
102 -smart_utest.o : \$(smart_objs) smart_utest.cpp  
103 - @echo "ensure the smart-server is updated: (cd .. && make all)"  
104 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_utest.cpp -o \$@  
105 -utest_objs = smart_utest.o smart_config_utest.o smart_process_pool_utest.o smart_reload_utest.o smart_app_utest.o smart_refer_utest.o  
106 -smart_utest : \$(utest_objs) gtest_main.a \$(smart_objs)  
107 - @echo \$(smart_objs)  
108 - @echo "===================="  
109 - @echo "the utest must run in centos6, for we depends on -lssl, that used in smart-server is openssl-1.0.1c"  
110 - \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) -lpthread \$^ \$(ST_DIR)/libst.a \$(SSL_LINK) -o \$@ 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 +${UTEST_APP} : \$(SRS_UTEST_OBJS) gtest_main.a
  98 + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) -lpthread \$^ -o \$@
111 END 99 END
112 100
113 # parent Makefile, to create module output dir before compile it. 101 # parent Makefile, to create module output dir before compile it.
@@ -46,6 +46,7 @@ echo "" >> $SRS_AUTO_HEADERS_H @@ -46,6 +46,7 @@ echo "" >> $SRS_AUTO_HEADERS_H
46 ##################################################################################### 46 #####################################################################################
47 # generate Makefile. 47 # generate Makefile.
48 ##################################################################################### 48 #####################################################################################
  49 +SRS_MAKEFILE="Makefile"
49 50
50 ##################################################################################### 51 #####################################################################################
51 # srs-librtmp sample entry 52 # srs-librtmp sample entry
@@ -53,7 +54,7 @@ SrsLibrtmpSampleEntry="nossl" @@ -53,7 +54,7 @@ SrsLibrtmpSampleEntry="nossl"
53 if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi 54 if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi
54 # utest make entry, (cd utest; make) 55 # utest make entry, (cd utest; make)
55 SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\"" 56 SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\""
56 -if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(\$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE}.utest)"; fi 57 +if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd $${SRS_OBJS}/utest; \$(MAKE) ${SRS_MAKEFILE})"; fi
57 58
58 ##################################################################################### 59 #####################################################################################
59 # colorful summary 60 # colorful summary
@@ -67,7 +68,6 @@ SrsUtestSummaryColor="\$(YELLOW)(disabled) "; if [ $SRS_UTEST = YES ]; then SrsU @@ -67,7 +68,6 @@ SrsUtestSummaryColor="\$(YELLOW)(disabled) "; if [ $SRS_UTEST = YES ]; then SrsU
67 ##################################################################################### 68 #####################################################################################
68 # makefile 69 # makefile
69 echo "generate Makefile" 70 echo "generate Makefile"
70 -SRS_MAKEFILE="Makefile"  
71 cat << END > ${SRS_MAKEFILE} 71 cat << END > ${SRS_MAKEFILE}
72 .PHONY: default help clean server bandwidth librtmp librtmp-sample utest _prepare_dir 72 .PHONY: default help clean server bandwidth librtmp librtmp-sample utest _prepare_dir
73 73
@@ -104,7 +104,7 @@ help: @@ -104,7 +104,7 @@ help:
104 @echo " utest build the utest for srs" 104 @echo " utest build the utest for srs"
105 105
106 clean: 106 clean:
107 - (rm -f Makefile; rm -f ${SRS_OBJS}/Makefile*) 107 + (rm -f Makefile)
108 (cd ${SRS_OBJS}; rm -rf srs bandwidth *.hpp srs_utest) 108 (cd ${SRS_OBJS}; rm -rf srs bandwidth *.hpp srs_utest)
109 (cd ${SRS_OBJS}; rm -rf src research include lib utest) 109 (cd ${SRS_OBJS}; rm -rf src research include lib utest)
110 (cd research/librtmp; make clean) 110 (cd research/librtmp; make clean)
@@ -237,7 +237,7 @@ MAIN_OBJS="${MODULE_OBJS[@].o}" @@ -237,7 +237,7 @@ MAIN_OBJS="${MODULE_OBJS[@].o}"
237 ##################################################################################### 237 #####################################################################################
238 # utest, the unit-test cases of srs, base on gtest1.6 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[@]}" 239 MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}"
240 -BUILD_KEY="utest" APP_NAME="srs_utest" . auto/utest.sh 240 +APP_NAME="srs_utest" . auto/utest.sh
241 241
242 ##################################################################################### 242 #####################################################################################
243 # Binaries, main entrances, link the module and its depends modules, 243 # Binaries, main entrances, link the module and its depends modules,