winlin

add utest script to generate the utest Makefile

@@ -55,4 +55,8 @@ for item in ${MODULE_OBJS[*]}; do @@ -55,4 +55,8 @@ for item in ${MODULE_OBJS[*]}; do
55 done 55 done
56 echo "" >> ${FILE} 56 echo "" >> ${FILE}
57 57
  58 +# parent Makefile, to create module output dir before compile it.
  59 +echo " mkdir -p ${SRS_OBJS}/include" >> ${SRS_MAKEFILE}
  60 +echo " mkdir -p ${SRS_OBJS}/lib" >> ${SRS_MAKEFILE}
  61 +
58 echo -n "generate lib ${LIB_NAME} ok"; echo '!'; 62 echo -n "generate lib ${LIB_NAME} ok"; echo '!';
@@ -26,7 +26,7 @@ SRS_SSL=YES @@ -26,7 +26,7 @@ SRS_SSL=YES
26 SRS_FFMPEG=YES 26 SRS_FFMPEG=YES
27 SRS_HTTP=YES 27 SRS_HTTP=YES
28 SRS_RESEARCH=NO 28 SRS_RESEARCH=NO
29 -SRS_UTEST=NO 29 +SRS_UTEST=YES
30 30
31 ##################################################################################### 31 #####################################################################################
32 # parse options 32 # parse options
  1 +# generate utest Makefile
  2 +#
  3 +# params:
  4 +# $SRS_OBJS the objs directory. ie. objs
  5 +# $SRS_MAKEFILE the makefile name. ie. Makefile
  6 +#
  7 +
  8 +FILE=${SRS_OBJS}/${SRS_MAKEFILE}.utest
  9 +
  10 +cat << END > ${FILE}
  11 +# A sample Makefile for building Google Test and using it in user
  12 +# tests. Please tweak it to suit your environment and project. You
  13 +# may want to move it to your project's root directory.
  14 +#
  15 +# SYNOPSIS:
  16 +#
  17 +# make [all] - makes everything.
  18 +# make TARGET - makes the given target.
  19 +# make clean - removes all files generated by make.
  20 +
  21 +# Please tweak the following variable definitions as needed by your
  22 +# project, except GTEST_HEADERS, which you can use in your own targets
  23 +# but shouldn't modify.
  24 +
  25 +# Points to the root of Google Test, relative to where this file is.
  26 +# Remember to tweak this if you move this file.
  27 +GTEST_DIR = gtest-1.6.0
  28 +
  29 +# Where to find user code.
  30 +USER_DIR = .
  31 +
  32 +# Flags passed to the preprocessor.
  33 +CPPFLAGS += -I\$(GTEST_DIR)/include
  34 +
  35 +# Flags passed to the C++ compiler.
  36 +CXXFLAGS += -g -Wall -Wextra -O0
  37 +
  38 +# All tests produced by this Makefile. Remember to add new tests you
  39 +# created to the list.
  40 +TESTS = smart_utest
  41 +
  42 +# All Google Test headers. Usually you shouldn't change this
  43 +# definition.
  44 +GTEST_HEADERS = \$(GTEST_DIR)/include/gtest/*.h \\
  45 + \$(GTEST_DIR)/include/gtest/internal/*.h
  46 +
  47 +# House-keeping build targets.
  48 +
  49 +all : \$(TESTS)
  50 +
  51 +clean :
  52 + rm -f \$(TESTS) gtest.a gtest_main.a *.o
  53 +
  54 +# Builds gtest.a and gtest_main.a.
  55 +
  56 +# Usually you shouldn't tweak such internal variables, indicated by a
  57 +# trailing _.
  58 +GTEST_SRCS_ = \$(GTEST_DIR)/src/*.cc \$(GTEST_DIR)/src/*.h \$(GTEST_HEADERS)
  59 +
  60 +# For simplicity and to avoid depending on Google Test's
  61 +# implementation details, the dependencies specified below are
  62 +# conservative and not optimized. This is fine as Google Test
  63 +# compiles fast and for ordinary users its source rarely changes.
  64 +gtest-all.o : \$(GTEST_SRCS_)
  65 + \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
  66 + \$(GTEST_DIR)/src/gtest-all.cc
  67 +
  68 +gtest_main.o : \$(GTEST_SRCS_)
  69 + \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
  70 + \$(GTEST_DIR)/src/gtest_main.cc
  71 +
  72 +gtest.a : gtest-all.o
  73 + \$(AR) \$(ARFLAGS) \$@ \$^
  74 +
  75 +gtest_main.a : gtest-all.o gtest_main.o
  76 + \$(AR) \$(ARFLAGS) \$@ \$^
  77 +
  78 +# Builds a sample test. A test should link with either gtest.a or
  79 +# gtest_main.a, depending on whether it defines its own main()
  80 +# function.
  81 +
  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 \$@
  111 +END
  112 +
  113 +# parent Makefile, to create module output dir before compile it.
  114 +echo " mkdir -p ${SRS_OBJS}/utest" >> ${SRS_MAKEFILE}
  115 +
  116 +echo -n "generate utest ok"; echo '!';
@@ -49,9 +49,11 @@ echo "" >> $SRS_AUTO_HEADERS_H @@ -49,9 +49,11 @@ echo "" >> $SRS_AUTO_HEADERS_H
49 49
50 ##################################################################################### 50 #####################################################################################
51 # srs-librtmp sample entry 51 # srs-librtmp sample entry
52 -SrsLibrtmpSampleEntry="nossl"; if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi 52 +SrsLibrtmpSampleEntry="nossl"
  53 +if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi
53 # utest make entry, (cd utest; make) 54 # utest make entry, (cd utest; make)
54 -SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\""; if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd utest; \$(MAKE))"; fi 55 +SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\""
  56 +if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(\$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE}.utest)"; fi
55 57
56 ##################################################################################### 58 #####################################################################################
57 # colorful summary 59 # colorful summary
@@ -102,7 +104,8 @@ help: @@ -102,7 +104,8 @@ help:
102 @echo " utest build the utest for srs" 104 @echo " utest build the utest for srs"
103 105
104 clean: 106 clean:
105 - (rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp srs_utest) 107 + (rm -f Makefile; rm -f ${SRS_OBJS}/Makefile*)
  108 + (cd ${SRS_OBJS}; rm -rf srs bandwidth *.hpp srs_utest)
106 (cd ${SRS_OBJS}; rm -rf src research include lib utest) 109 (cd ${SRS_OBJS}; rm -rf src research include lib utest)
107 (cd research/librtmp; make clean) 110 (cd research/librtmp; make clean)
108 111
@@ -153,8 +156,8 @@ CC ?= gcc @@ -153,8 +156,8 @@ CC ?= gcc
153 GCC ?= gcc 156 GCC ?= gcc
154 CXX ?= g++ 157 CXX ?= g++
155 AR ?= ar 158 AR ?= ar
  159 +LINK ?= g++
156 CXXFLAGS = ${CXXFLAGS} 160 CXXFLAGS = ${CXXFLAGS}
157 -LINK = g++  
158 161
159 .PHONY: default srs bandwidth librtmp 162 .PHONY: default srs bandwidth librtmp
160 163
@@ -168,29 +171,20 @@ END @@ -168,29 +171,20 @@ END
168 # library(.a): add to ModuleLibFiles if binary need the specifeid library. for example, LibSTfile 171 # library(.a): add to ModuleLibFiles if binary need the specifeid library. for example, LibSTfile
169 # 172 #
170 # st(state-threads) the basic network library for SRS. 173 # st(state-threads) the basic network library for SRS.
171 -LibSTRoot="${SRS_OBJS}/st"  
172 -LibSTfile="${LibSTRoot}/libst.a" 174 +LibSTRoot="${SRS_OBJS}/st"; LibSTfile="${LibSTRoot}/libst.a"
173 # hp(http-parser) the http request/url parser, for SRS to support HTTP callback. 175 # hp(http-parser) the http request/url parser, for SRS to support HTTP callback.
174 -LibHttpParserRoot=""  
175 -LibHttpParserfile=""  
176 -if [ $SRS_HTTP = YES ]; then  
177 - LibHttpParserRoot="${SRS_OBJS}/hp"  
178 - LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a"  
179 -fi 176 +LibHttpParserRoot=""; LibHttpParserfile=""
  177 +if [ $SRS_HTTP = YES ]; then LibHttpParserRoot="${SRS_OBJS}/hp"; LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a"; fi
180 # openssl-1.0.1f, for the RTMP complex handshake. 178 # openssl-1.0.1f, for the RTMP complex handshake.
181 -LibSSLRoot=""  
182 -LibSSLfile=""  
183 -if [ $SRS_SSL = YES ]; then  
184 - LibSSLRoot="${SRS_OBJS}/openssl/include"  
185 - LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a"  
186 -fi 179 +LibSSLRoot="";LibSSLfile=""
  180 +if [ $SRS_SSL = YES ]; then LibSSLRoot="${SRS_OBJS}/openssl/include"; LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a"; fi
187 181
188 ##################################################################################### 182 #####################################################################################
189 # Modules, compile each module, then link to binary 183 # Modules, compile each module, then link to binary
190 # 184 #
191 #Core, depends only on system apis. 185 #Core, depends only on system apis.
192 -MODULE_ID="CORE"  
193 -MODULE_DEPENDS=() 186 +MODULE_ID="CORE"
  187 +MODULE_DEPENDS=()
194 ModuleLibIncs=(${SRS_OBJS}) 188 ModuleLibIncs=(${SRS_OBJS})
195 MODULE_FILES=("srs_core" "srs_core_autofree") 189 MODULE_FILES=("srs_core" "srs_core_autofree")
196 MODULE_DIR="src/core" . auto/modules.sh 190 MODULE_DIR="src/core" . auto/modules.sh
@@ -241,6 +235,11 @@ MODULE_DIR="src/main" . auto/modules.sh @@ -241,6 +235,11 @@ MODULE_DIR="src/main" . auto/modules.sh
241 MAIN_OBJS="${MODULE_OBJS[@].o}" 235 MAIN_OBJS="${MODULE_OBJS[@].o}"
242 236
243 ##################################################################################### 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 +BUILD_KEY="utest" APP_NAME="srs_utest" . auto/utest.sh
  241 +
  242 +#####################################################################################
244 # Binaries, main entrances, link the module and its depends modules, 243 # Binaries, main entrances, link the module and its depends modules,
245 # then link to a binary, for example, objs/srs 244 # then link to a binary, for example, objs/srs
246 # 245 #
@@ -272,9 +271,6 @@ echo 'configure ok! ' @@ -272,9 +271,6 @@ echo 'configure ok! '
272 ##################################################################################### 271 #####################################################################################
273 # create objs/logs for ffmpeg to write log. 272 # create objs/logs for ffmpeg to write log.
274 mkdir -p ${SRS_OBJS}/logs 273 mkdir -p ${SRS_OBJS}/logs
275 -# lib and include for library  
276 -mkdir -p ${SRS_OBJS}/lib  
277 -mkdir -p ${SRS_OBJS}/include  
278 274
279 ##################################################################################### 275 #####################################################################################
280 # configure summary 276 # configure summary
@@ -73,6 +73,9 @@ file @@ -73,6 +73,9 @@ file
73 ..\app\srs_app_socket.cpp, 73 ..\app\srs_app_socket.cpp,
74 ..\app\srs_app_source.hpp, 74 ..\app\srs_app_source.hpp,
75 ..\app\srs_app_source.cpp, 75 ..\app\srs_app_source.cpp,
  76 + utest readonly separator,
  77 + ..\utest\srs_utest.hpp,
  78 + ..\utest\srs_utest.cpp,
76 research readonly separator, 79 research readonly separator,
77 ..\..\research\librtmp\srs_play.c, 80 ..\..\research\librtmp\srs_play.c,
78 ..\..\research\librtmp\srs_publish.c, 81 ..\..\research\librtmp\srs_publish.c,
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_utest.hpp>
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_UTEST_PUBLIC_SHARED_HPP
  25 +#define SRS_UTEST_PUBLIC_SHARED_HPP
  26 +
  27 +/*
  28 +#include <srs_utest.hpp>
  29 +*/
  30 +
  31 +#endif