#!/bin/bash # Run all the different permutations of all the tests and other things # This helps ensure that nothing gets broken. _tests() { local vet="" # TODO: make it off local gover=$( ${gocmd} version | cut -f 3 -d ' ' ) [[ $( ${gocmd} version ) == *"gccgo"* ]] && zcover=0 [[ $( ${gocmd} version ) == *"gollvm"* ]] && zcover=0 case $gover in go1.[7-9]*|go1.1[0-9]*|go2.*|devel*) true ;; *) return 1 esac # note that codecgen requires fastpath, so you cannot do "codecgen codec.notfastpath" # we test the following permutations wnich all execute different code paths as below. echo "TestCodecSuite: (fastpath/unsafe), (!fastpath/unsafe), (fastpath/!unsafe), (!fastpath/!unsafe), (codecgen/unsafe)" local echo=1 local nc=2 # count local cpus="1,$(nproc)" # if using the race detector, then set nc to if [[ " ${zargs[@]} " =~ "-race" ]]; then cpus="$(nproc)" fi local a=( "" "codec.notfastpath" "codec.safe" "codec.notfastpath codec.safe" "codecgen" ) local b=() local c=() for i in "${a[@]}" do local i2=${i:-default} [[ "$zwait" == "1" ]] && echo ">>>> TAGS: 'alltests $i'; RUN: 'TestCodecSuite'" [[ "$zcover" == "1" ]] && c=( -coverprofile "${i2// /-}.cov.out" ) true && ${gocmd} vet -printfuncs "errorf" "$@" && if [[ "$echo" == 1 ]]; then set -o xtrace; fi && ${gocmd} test ${zargs[*]} ${ztestargs[*]} -vet "$vet" -tags "alltests $i" -count $nc -cpu $cpus -run "TestCodecSuite" "${c[@]}" "$@" & if [[ "$echo" == 1 ]]; then set +o xtrace; fi b+=("${i2// /-}.cov.out") [[ "$zwait" == "1" ]] && wait # if [[ "$?" != 0 ]]; then return 1; fi done if [[ "$zextra" == "1" ]]; then [[ "$zwait" == "1" ]] && echo ">>>> TAGS: 'codec.notfastpath x'; RUN: 'Test.*X$'" [[ "$zcover" == "1" ]] && c=( -coverprofile "x.cov.out" ) ${gocmd} test ${zargs[*]} ${ztestargs[*]} -vet "$vet" -tags "codec.notfastpath x" -count $nc -run 'Test.*X$' "${c[@]}" & b+=("x.cov.out") [[ "$zwait" == "1" ]] && wait fi wait # go tool cover is not supported for gccgo, gollvm, other non-standard go compilers [[ "$zcover" == "1" ]] && command -v gocovmerge && gocovmerge "${b[@]}" > __merge.cov.out && ${gocmd} tool cover -html=__merge.cov.out } # is a generation needed? _ng() { local a="$1" if [[ ! -e "$a" ]]; then echo 1; return; fi for i in `ls -1 *.go.tmpl gen.go values_test.go` do if [[ "$a" -ot "$i" ]]; then echo 1; return; fi done } _prependbt() { cat > ${2} <> ${2} rm -f ${1} } # _build generates fast-path.go and gen-helper.go. _build() { if ! [[ "${zforce}" || $(_ng "fast-path.generated.go") || $(_ng "gen-helper.generated.go") || $(_ng "gen.generated.go") ]]; then return 0; fi if [ "${zbak}" ]; then _zts=`date '+%m%d%Y_%H%M%S'` _gg=".generated.go" [ -e "gen-helper${_gg}" ] && mv gen-helper${_gg} gen-helper${_gg}__${_zts}.bak [ -e "fast-path${_gg}" ] && mv fast-path${_gg} fast-path${_gg}__${_zts}.bak [ -e "gen${_gg}" ] && mv gen${_gg} gen${_gg}__${_zts}.bak fi rm -f gen-helper.generated.go fast-path.generated.go gen.generated.go \ *safe.generated.go *_generated_test.go *.generated_ffjson_expose.go cat > gen.generated.go <> gen.generated.go < gen-dec-map.go.tmpl cat >> gen.generated.go <> gen.generated.go < gen-dec-array.go.tmpl cat >> gen.generated.go <> gen.generated.go < gen-enc-chan.go.tmpl cat >> gen.generated.go < gen-from-tmpl.codec.generated.go < gen-from-tmpl.sort-slice-stubs.generated.go <> gen-from-tmpl.sort-slice-stubs.generated.go < bench/shared_test.go # explicitly return 0 if this passes, else return 1 local btags="codec.notfastpath codec.safe codecgen.exec" rm -f sort-slice.generated.go fast-path.generated.go gen-helper.generated.go mammoth_generated_test.go mammoth2_generated_test.go cat > gen-from-tmpl.sort-slice.generated.go < gen-from-tmpl.generated.go < $f <>$f if [[ "$i" != "master" ]]; then i="release-branch.go$i"; fi (false || (echo "===== BUILDING GO SDK for branch: $i ... =====" && cd $GOROOT && git checkout -f $i && git reset --hard && git clean -f . && cd src && ./make.bash >>$f 2>&1 && sleep 1 ) ) && echo "===== GO SDK BUILD DONE =====" && _prebuild && echo "===== PREBUILD DONE with exit: $? =====" && _tests "$@" if [[ "$?" != 0 ]]; then return 1; fi done zforce=${makeforce} echo "++++++++ RELEASE TEST SUITES ALL PASSED ++++++++" } _usage() { # hidden args: # -pf [p=prebuild (f=force)] cat < [t=tests (e=extra, s=short, o=cover, w=wait), m=make, n=inlining diagnostics, l=mid-stack inlining, d=race detector] -v -> v=verbose EOF if [[ "$(type -t _usage_run)" = "function" ]]; then _usage_run ; fi } _main() { if [[ -z "$1" ]]; then _usage; return 1; fi local x # determines the main action to run in this build local zforce # force local zcover # generate cover profile and show in browser when done local zwait # run tests in sequence, not parallel ie wait for one to finish before starting another local zextra # means run extra (python based tests, etc) during testing local ztestargs=() local zargs=() local zverbose=() local zbenchflags="" local gocmd=${MYGOCMD:-go} OPTIND=1 while getopts ":cetmnrgpfvldsowkxyzb:" flag do case "x$flag" in 'xo') zcover=1 ;; 'xe') zextra=1 ;; 'xw') zwait=1 ;; 'xf') zforce=1 ;; 'xs') ztestargs+=("-short") ;; 'xv') zverbose+=(1) ;; 'xl') zargs+=("-gcflags"); zargs+=("-l=4") ;; 'xn') zargs+=("-gcflags"); zargs+=("-m=2") ;; 'xd') zargs+=("-race") ;; 'xb') x='b'; zbenchflags=${OPTARG} ;; x\?) _usage; return 1 ;; *) x=$flag ;; esac done shift $((OPTIND-1)) # echo ">>>> _main: extra args: $@" case "x$x" in 'xt') _tests "$@" ;; 'xm') _make "$@" ;; 'xr') _release "$@" ;; 'xg') _go ;; 'xp') _prebuild "$@" ;; 'xc') _clean "$@" ;; 'xx') _analyze_checks "$@" ;; 'xy') _analyze_debug_types "$@" ;; 'xz') _analyze_do_inlining_and_more "$@" ;; 'xk') _go_compiler_validation_suite ;; 'xb') _bench "$@" ;; esac # unset zforce zargs zbenchflags } [ "." = `dirname $0` ] && _main "$@"