diff options
| author | Xiang Dai <long0dai@foxmail.com> | 2020-06-10 17:10:55 +0800 |
|---|---|---|
| committer | Xiang Dai <long0dai@foxmail.com> | 2020-06-10 17:33:18 +0800 |
| commit | fe0d7dfbd973358c13b8bf5180e1d7f1f6a3d0d6 (patch) | |
| tree | 3b0503251378c652cbaacc6733b0c2ba216fd5f0 /edge/test | |
| parent | Merge pull request #1793 from daixiang0/doc (diff) | |
| download | kubeedge-fe0d7dfbd973358c13b8bf5180e1d7f1f6a3d0d6.tar.gz | |
Optimize integration test scripts
Signed-off-by: Xiang Dai <long0dai@foxmail.com>
Diffstat (limited to 'edge/test')
| -rwxr-xr-x | edge/test/integration/scripts/execute.sh | 95 | ||||
| -rwxr-xr-x | edge/test/integration/scripts/fast_test.sh | 18 | ||||
| -rw-r--r-- | edge/test/integration/utils/test_setup.go | 4 |
3 files changed, 66 insertions, 51 deletions
diff --git a/edge/test/integration/scripts/execute.sh b/edge/test/integration/scripts/execute.sh index 5bb0ff825..fa8a348c0 100755 --- a/edge/test/integration/scripts/execute.sh +++ b/edge/test/integration/scripts/execute.sh @@ -14,47 +14,64 @@ # See the License for the specific language governing permissions and # limitations under the License. -curpath=$PWD -echo $PWD +TEST_DIR=$(dirname $(dirname "${BASH_SOURCE[0]}")) -VAR_EDGED_DIR="/var/lib/kubeedge" -if [ ! -d ${VAR_EDGED_DIR} ]; then - sudo mkdir -p ${VAR_EDGED_DIR} && sudo chown $USER:$USER ${VAR_EDGED_DIR} -fi +function cleanup() { + sudo pkill -9 edgecore || true + while true; do + sleep 1 + ps faux | grep -q [e]dgecore || break + done -go get github.com/onsi/ginkgo/ginkgo -sudo cp $GOPATH/bin/ginkgo /usr/bin/ + sudo rm -rf $TEST_DIR/appdeployment/appdeployment.test $TEST_DIR/device/device.test +} -sudo pkill edgecore -#kill the edgecore process if it exists, wait 2s delay before start the edgecore process. -sleep 2s +function do_preparation() { + sudo mkdir -p /var/lib/kubeedge -PWD=${curpath}/edge/test/integration + which ginkgo &>/dev/null || { + go get github.com/onsi/ginkgo/ginkgo + sudo cp $GOPATH/bin/ginkgo /usr/bin/ + } -# create cert files -$PWD/scripts/generate_cert.sh -sudo rm -rf $PWD/appdeployment/appdeployment.test -sudo rm -rf $PWD/device/device.test -# Specify the module name to compile in below command -bash -x $PWD/scripts/compile.sh $1 -export MQTT_SERVER=127.0.0.1 -:> /tmp/testcase.log -bash -x ${PWD}/scripts/fast_test.sh $1 -#stop the edgecore after the test completion -sudo pkill edgecore -grep -e "Running Suite" -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | sed -r 's/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' -echo "Integration Test Final Summary Report" -echo "===============================================" -echo "Total Number of Test cases = `grep "Ran " /tmp/testcase.log | awk '{sum+=$2} END {print sum}'`" -passed=`grep -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | awk '{print $3}' | sed -r "s/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | awk '{sum+=$1} END {print sum}'` -echo "Number of Test cases PASSED = $passed" -fail=`grep -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | awk '{print $6}' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | awk '{sum+=$1} END {print sum}'` -echo "Number of Test cases FAILED = $fail" -echo "==================Result Summary=======================" -if [ "$fail" != "0" ];then - echo "Integration suite has failures, Please check !!" - exit 1 -else - echo "Integration suite successfully passed all the tests !!" - exit 0 -fi + # create cert files + $TEST_DIR/scripts/generate_cert.sh + + local module=$1 + # Specify the module name to compile in below command + bash -x $TEST_DIR/scripts/compile.sh $module +} + +function run_test() { + :> /tmp/testcase.log + + local module=$1 + MQTT_SERVER=127.0.0.1 bash -x ${TEST_DIR}/scripts/fast_test.sh $module + + grep -e "Running Suite" -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | sed -r 's/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' + echo "Integration Test Final Summary Report" + echo "===============================================" + echo "Total Number of Test cases = `grep "Ran " /tmp/testcase.log | awk '{sum+=$2} END {print sum}'`" + passed=`grep -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | awk '{print $3}' | sed -r "s/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | awk '{sum+=$1} END {print sum}'` + echo "Number of Test cases PASSED = $passed" + fail=`grep -e "SUCCESS\!" -e "FAIL\!" /tmp/testcase.log | awk '{print $6}' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | awk '{sum+=$1} END {print sum}'` + echo "Number of Test cases FAILED = $fail" + echo "==================Result Summary=======================" + if [ "$fail" != "0" ];then + echo "Integration suite has failures, Please check !!" + exit 1 + else + echo "Integration suite successfully passed all the tests !!" + exit 0 + fi +} + +set -eE +trap cleanup ERR +trap cleanup EXIT + +cleanup + +do_preparation $1 + +run_test $1 diff --git a/edge/test/integration/scripts/fast_test.sh b/edge/test/integration/scripts/fast_test.sh index 94cb828eb..eb23f7423 100755 --- a/edge/test/integration/scripts/fast_test.sh +++ b/edge/test/integration/scripts/fast_test.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash # Copyright 2019 The KubeEdge Authors. # @@ -14,16 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -cd `dirname $0` -workdir=`pwd` -cd $workdir debugflag="-test.v -ginkgo.v" compilemodule=$1 runtest=$2 -#setup env -cd ../ +KUBEEDGE_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/../../../..) +cd $(dirname $(dirname "${BASH_SOURCE[0]}")) + #Pre-configurations required for running the suite. #Any new config addition required corresponding code changes. cat >config.json<<END @@ -36,12 +34,12 @@ cat >config.json<<END } END -if [ $# -eq 0 ] - then +if [[ $# -eq 0 ]]; then #run testcase - ./appdeployment/appdeployment.test $debugflag 2>&1 | tee -a /tmp/testcase.log + export KUBEEDGE_ROOT=$KUBEEDGE_ROOT + ./appdeployment/appdeployment.test $debugflag 2>&1 | tee -a /tmp/testcase.log ./device/device.test $debugflag 2>&1 | tee -a /tmp/testcase.log else - ./$compilemodule/$compilemodule.test $debugflag $runtest 2>&1 | tee -a /tmp/testcase.log + ./$compilemodule/$compilemodule.test $debugflag $runtest 2>&1 | tee -a /tmp/testcase.log fi diff --git a/edge/test/integration/utils/test_setup.go b/edge/test/integration/utils/test_setup.go index b562063bc..9e1c6a475 100644 --- a/edge/test/integration/utils/test_setup.go +++ b/edge/test/integration/utils/test_setup.go @@ -16,9 +16,9 @@ import ( const ( EdgeCoreConfigFile = "/tmp/edgecore.yaml" CatEdgeCoreConfigFile = "cat /tmp/edgecore.yaml" - RunEdgecore = "sudo pkill -9 edgecore; cd ${GOPATH}/src/github.com/kubeedge/kubeedge/_output/local/bin/; sudo nohup ./edgecore --config=" + EdgeCoreConfigFile + " > edgecore.log 2>&1 &" + RunEdgecore = "sudo pkill -9 edgecore; cd ${KUBEEDGE_ROOT}/_output/local/bin/; sudo nohup ./edgecore --config=" + EdgeCoreConfigFile + " > edgecore.log 2>&1 &" CheckEdgecore = "sudo pgrep edgecore" - CatEdgecoreLog = "cd ${GOPATH}/src/github.com/kubeedge/kubeedge/_output/local/bin/; cat edgecore.log" + CatEdgecoreLog = "cat ${KUBEEDGE_ROOT}/_output/local/bin/edgecore.log" DBFile = "/tmp/edgecore/edgecore.db" ) |
