From fe5811304b00e1c9f466ab0090ccab4274c7f2c4 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 4 Mar 2014 14:01:43 +0800 Subject: [PATCH] add utest script to generate the utest Makefile --- trunk/auto/depends.sh | 0 trunk/auto/libs.sh | 4 ++ trunk/auto/options.sh | 2 +- trunk/auto/utest.sh | 116 ++++++++++++++++++++++++++++++++++ trunk/configure | 42 ++++++------ trunk/src/srs/srs.upp | 3 + trunk/src/utest/srs_utest.cpp | 24 +++++++ trunk/src/utest/srs_utest.hpp | 31 +++++++++ 8 files changed, 198 insertions(+), 24 deletions(-) mode change 100755 => 100644 trunk/auto/depends.sh create mode 100644 trunk/auto/utest.sh create mode 100644 trunk/src/utest/srs_utest.cpp create mode 100644 trunk/src/utest/srs_utest.hpp diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh old mode 100755 new mode 100644 diff --git a/trunk/auto/libs.sh b/trunk/auto/libs.sh index 880c41426..fcfeabc4b 100644 --- a/trunk/auto/libs.sh +++ b/trunk/auto/libs.sh @@ -55,4 +55,8 @@ for item in ${MODULE_OBJS[*]}; do done echo "" >> ${FILE} +# parent Makefile, to create module output dir before compile it. +echo " mkdir -p ${SRS_OBJS}/include" >> ${SRS_MAKEFILE} +echo " mkdir -p ${SRS_OBJS}/lib" >> ${SRS_MAKEFILE} + echo -n "generate lib ${LIB_NAME} ok"; echo '!'; diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 129973eab..506be6453 100644 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -26,7 +26,7 @@ SRS_SSL=YES SRS_FFMPEG=YES SRS_HTTP=YES SRS_RESEARCH=NO -SRS_UTEST=NO +SRS_UTEST=YES ##################################################################################### # parse options diff --git a/trunk/auto/utest.sh b/trunk/auto/utest.sh new file mode 100644 index 000000000..b7294b540 --- /dev/null +++ b/trunk/auto/utest.sh @@ -0,0 +1,116 @@ +# generate utest Makefile +# +# params: +# $SRS_OBJS the objs directory. ie. objs +# $SRS_MAKEFILE the makefile name. ie. Makefile +# + +FILE=${SRS_OBJS}/${SRS_MAKEFILE}.utest + +cat << END > ${FILE} +# A sample Makefile for building Google Test and using it in user +# tests. Please tweak it to suit your environment and project. You +# may want to move it to your project's root directory. +# +# SYNOPSIS: +# +# make [all] - makes everything. +# make TARGET - makes the given target. +# make clean - removes all files generated by make. + +# Please tweak the following variable definitions as needed by your +# project, except GTEST_HEADERS, which you can use in your own targets +# but shouldn't modify. + +# Points to the root of Google Test, relative to where this file is. +# Remember to tweak this if you move this file. +GTEST_DIR = gtest-1.6.0 + +# Where to find user code. +USER_DIR = . + +# Flags passed to the preprocessor. +CPPFLAGS += -I\$(GTEST_DIR)/include + +# Flags passed to the C++ compiler. +CXXFLAGS += -g -Wall -Wextra -O0 + +# All tests produced by this Makefile. Remember to add new tests you +# created to the list. +TESTS = smart_utest + +# All Google Test headers. Usually you shouldn't change this +# definition. +GTEST_HEADERS = \$(GTEST_DIR)/include/gtest/*.h \\ + \$(GTEST_DIR)/include/gtest/internal/*.h + +# House-keeping build targets. + +all : \$(TESTS) + +clean : + rm -f \$(TESTS) gtest.a gtest_main.a *.o + +# Builds gtest.a and gtest_main.a. + +# Usually you shouldn't tweak such internal variables, indicated by a +# trailing _. +GTEST_SRCS_ = \$(GTEST_DIR)/src/*.cc \$(GTEST_DIR)/src/*.h \$(GTEST_HEADERS) + +# For simplicity and to avoid depending on Google Test's +# implementation details, the dependencies specified below are +# conservative and not optimized. This is fine as Google Test +# compiles fast and for ordinary users its source rarely changes. +gtest-all.o : \$(GTEST_SRCS_) + \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\ + \$(GTEST_DIR)/src/gtest-all.cc + +gtest_main.o : \$(GTEST_SRCS_) + \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\ + \$(GTEST_DIR)/src/gtest_main.cc + +gtest.a : gtest-all.o + \$(AR) \$(ARFLAGS) \$@ \$^ + +gtest_main.a : gtest-all.o gtest_main.o + \$(AR) \$(ARFLAGS) \$@ \$^ + +# Builds a sample test. A test should link with either gtest.a or +# gtest_main.a, depending on whether it defines its own main() +# function. + +SMART_DIR=../objs +ST_DIR=\$(SMART_DIR)/st-1.9/obj +SSL_LINK = \$(SMART_DIR)/openssl-1.0.1c/libssl.a \$(SMART_DIR)/openssl-1.0.1c/libcrypto.a -ldl + +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 +smart_objs = \$(addprefix \$(SMART_DIR)/../, \$(smart_objs_o)) + +SMART_INC = -I\$(SMART_DIR)/inc -I\$(ST_DIR) +SSL_LINK = \$(SMART_DIR)/openssl-1.0.1c/libssl.a \$(SMART_DIR)/openssl-1.0.1c/libcrypto.a -ldl + +smart_refer_utest.o : \$(smart_objs) smart_refer_utest.cpp + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_refer_utest.cpp -o \$@ +smart_app_utest.o : \$(smart_objs) smart_app_utest.cpp + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_app_utest.cpp -o \$@ +smart_reload_utest.o : \$(smart_objs) smart_reload_utest.cpp + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_reload_utest.cpp -o \$@ +smart_process_pool_utest.o : \$(smart_objs) smart_process_pool_utest.cpp + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_process_pool_utest.cpp -o \$@ +smart_config_utest.o : \$(smart_objs) smart_config_utest.cpp + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_config_utest.cpp -o \$@ +smart_utest.o : \$(smart_objs) smart_utest.cpp + @echo "ensure the smart-server is updated: (cd .. && make all)" + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SMART_INC) -c smart_utest.cpp -o \$@ +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 +smart_utest : \$(utest_objs) gtest_main.a \$(smart_objs) + @echo \$(smart_objs) + @echo "====================" + @echo "the utest must run in centos6, for we depends on -lssl, that used in smart-server is openssl-1.0.1c" + \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) -lpthread \$^ \$(ST_DIR)/libst.a \$(SSL_LINK) -o \$@ +END + +# parent Makefile, to create module output dir before compile it. +echo " mkdir -p ${SRS_OBJS}/utest" >> ${SRS_MAKEFILE} + +echo -n "generate utest ok"; echo '!'; diff --git a/trunk/configure b/trunk/configure index 2906f94c6..c999f8379 100755 --- a/trunk/configure +++ b/trunk/configure @@ -49,9 +49,11 @@ echo "" >> $SRS_AUTO_HEADERS_H ##################################################################################### # srs-librtmp sample entry -SrsLibrtmpSampleEntry="nossl"; if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi +SrsLibrtmpSampleEntry="nossl" +if [ $SRS_SSL = YES ]; then SrsLibrtmpSampleEntry="ssl";fi # utest make entry, (cd utest; make) -SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\""; if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd utest; \$(MAKE))"; fi +SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\"" +if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(\$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE}.utest)"; fi ##################################################################################### # colorful summary @@ -102,7 +104,8 @@ help: @echo " utest build the utest for srs" clean: - (rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp srs_utest) + (rm -f Makefile; rm -f ${SRS_OBJS}/Makefile*) + (cd ${SRS_OBJS}; rm -rf srs bandwidth *.hpp srs_utest) (cd ${SRS_OBJS}; rm -rf src research include lib utest) (cd research/librtmp; make clean) @@ -153,8 +156,8 @@ CC ?= gcc GCC ?= gcc CXX ?= g++ AR ?= ar +LINK ?= g++ CXXFLAGS = ${CXXFLAGS} -LINK = g++ .PHONY: default srs bandwidth librtmp @@ -168,29 +171,20 @@ END # library(.a): add to ModuleLibFiles if binary need the specifeid library. for example, LibSTfile # # st(state-threads) the basic network library for SRS. -LibSTRoot="${SRS_OBJS}/st" -LibSTfile="${LibSTRoot}/libst.a" +LibSTRoot="${SRS_OBJS}/st"; LibSTfile="${LibSTRoot}/libst.a" # hp(http-parser) the http request/url parser, for SRS to support HTTP callback. -LibHttpParserRoot="" -LibHttpParserfile="" -if [ $SRS_HTTP = YES ]; then - LibHttpParserRoot="${SRS_OBJS}/hp" - LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a" -fi +LibHttpParserRoot=""; LibHttpParserfile="" +if [ $SRS_HTTP = YES ]; then LibHttpParserRoot="${SRS_OBJS}/hp"; LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a"; fi # openssl-1.0.1f, for the RTMP complex handshake. -LibSSLRoot="" -LibSSLfile="" -if [ $SRS_SSL = YES ]; then - LibSSLRoot="${SRS_OBJS}/openssl/include" - LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a" -fi +LibSSLRoot="";LibSSLfile="" +if [ $SRS_SSL = YES ]; then LibSSLRoot="${SRS_OBJS}/openssl/include"; LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a"; fi ##################################################################################### # Modules, compile each module, then link to binary # #Core, depends only on system apis. -MODULE_ID="CORE" -MODULE_DEPENDS=() +MODULE_ID="CORE" +MODULE_DEPENDS=() ModuleLibIncs=(${SRS_OBJS}) MODULE_FILES=("srs_core" "srs_core_autofree") MODULE_DIR="src/core" . auto/modules.sh @@ -240,6 +234,11 @@ MODULE_FILES=("srs_main_server" "srs_main_bandcheck") MODULE_DIR="src/main" . auto/modules.sh MAIN_OBJS="${MODULE_OBJS[@].o}" +##################################################################################### +# utest, the unit-test cases of srs, base on gtest1.6 +MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}" +BUILD_KEY="utest" APP_NAME="srs_utest" . auto/utest.sh + ##################################################################################### # Binaries, main entrances, link the module and its depends modules, # then link to a binary, for example, objs/srs @@ -272,9 +271,6 @@ echo 'configure ok! ' ##################################################################################### # create objs/logs for ffmpeg to write log. mkdir -p ${SRS_OBJS}/logs -# lib and include for library -mkdir -p ${SRS_OBJS}/lib -mkdir -p ${SRS_OBJS}/include ##################################################################################### # configure summary diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index 5cb9aece4..dc2151677 100644 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -73,6 +73,9 @@ file ..\app\srs_app_socket.cpp, ..\app\srs_app_source.hpp, ..\app\srs_app_source.cpp, + utest readonly separator, + ..\utest\srs_utest.hpp, + ..\utest\srs_utest.cpp, research readonly separator, ..\..\research\librtmp\srs_play.c, ..\..\research\librtmp\srs_publish.c, diff --git a/trunk/src/utest/srs_utest.cpp b/trunk/src/utest/srs_utest.cpp new file mode 100644 index 000000000..aed0ed882 --- /dev/null +++ b/trunk/src/utest/srs_utest.cpp @@ -0,0 +1,24 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include diff --git a/trunk/src/utest/srs_utest.hpp b/trunk/src/utest/srs_utest.hpp new file mode 100644 index 000000000..e6a491a85 --- /dev/null +++ b/trunk/src/utest/srs_utest.hpp @@ -0,0 +1,31 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef SRS_UTEST_PUBLIC_SHARED_HPP +#define SRS_UTEST_PUBLIC_SHARED_HPP + +/* +#include +*/ + +#endif