]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add unit-tests automation to Drone CI 134/head
authorAndrey Volk <andywolk@gmail.com>
Thu, 21 Nov 2019 18:43:28 +0000 (22:43 +0400)
committerAndrey Volk <andywolk@gmail.com>
Thu, 21 Nov 2019 20:15:40 +0000 (00:15 +0400)
.drone.yml [new file with mode: 0644]
tests/unit/collect-test-logs.sh [new file with mode: 0755]
tests/unit/run-tests.sh [new file with mode: 0755]

diff --git a/.drone.yml b/.drone.yml
new file mode 100644 (file)
index 0000000..5331fea
--- /dev/null
@@ -0,0 +1,47 @@
+---
+kind: pipeline
+name: unit-tests
+
+steps:
+    - name: run-tests
+      image: signalwire/freeswitch-public-base
+      pull: true
+      commands:
+      - ./bootstrap.sh -j
+      - echo "applications/mod_test" >> modules.conf
+      - ./configure
+      - echo "#!/bin/bash\nmake -j`nproc --all` |& tee ./unit-tests-build-result.txt\nexitstatus=\${PIPESTATUS[0]}\necho \$exitstatus > ./build-status.txt\nmake install\n" > build.sh
+      - chmod +x build.sh
+      - ./build.sh
+      - cd tests/unit
+      - ./run-tests.sh
+      - mkdir logs && (mv log_run-tests_*.html logs || true)
+      - echo 0 > run-tests-status.txt
+      - ./collect-test-logs.sh && exit 0 || echo 'Some tests failed'
+      - echo 1 > run-tests-status.txt
+      - cd logs && ls -la
+
+    - name: notify
+      image: signalwire/unit-tests-notify
+      pull: true
+      environment:
+        GITHUB_CI_APP_PEM:
+          from_secret: github_ci_app_pem
+        SSH_KEY:
+          from_secret: ssh_key
+        SLACK_WEBHOOK_URL:
+          from_secret: slack_webhook_url
+      commands:
+      - /root/notify.sh
+      
+trigger:
+  branch:
+  - master
+  event:
+  - pull_request
+  - push
+---
+kind: signature
+hmac: a34718dd1e2b9468a845962219ff05cac0c922ddf90d885af557a937a9e412e0
+
+...
diff --git a/tests/unit/collect-test-logs.sh b/tests/unit/collect-test-logs.sh
new file mode 100755 (executable)
index 0000000..a46102a
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+echo "Collecting test logs"
+LOG_DIR=./logs
+html="<html><h3>There are failed unit-tests:</h3><table>"
+html+="<tr align=\"left\"><th><br>Unit tests</th></tr>"
+logs=$(find $LOG_DIR -type f -iname "*.html" -print)
+logs_found=0
+for name in $logs
+do
+       logname=$(basename $name)
+       testname=$(echo $logname | awk -F 'log_run-tests_' '{print $2}' | awk -F '.html' '{print $1}')
+       html+="<tr align=\"left\"><td><a href="$logname">$testname</a></td></tr>"
+       logs_found=1
+done
+
+if [ $logs_found -ne 0 ]; then
+       html+="</table></html>"
+       echo $html > $LOG_DIR/artifacts.html
+       exit 1
+fi
+
+exit 0
diff --git a/tests/unit/run-tests.sh b/tests/unit/run-tests.sh
new file mode 100755 (executable)
index 0000000..55c41e2
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+TESTS=$(make -f -  2>/dev/null <<EOF
+include Makefile
+all:
+       @echo \$(TESTS)
+EOF
+)
+
+echo "-----------------------------------------------------------------";
+echo "Starting tests";
+echo "Tests found: ${TESTS}";
+echo "-----------------------------------------------------------------";
+for i in $TESTS
+do
+    echo "Testing $i" ;
+    logfilename="log_run-tests_$i.html";
+    ./$i | tee >(ansi2html > $logfilename) ;
+    exitstatus=${PIPESTATUS[0]} ;
+    if [ "0" -eq $exitstatus ] ; then
+       rm $logfilename ;
+    else
+       echo "*** ./$i exit status is $exitstatus" ;
+       echo "*** $logfilename was saved" ;
+    fi ;
+    echo "----------------" ;
+done