<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/9380">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">CI: Initial commit for moving CI into source repo<br><br>Create tests/CI directory and add files used by Jenkins to<br>build and test Asterisk.<br><br>With this commit, Jenkins will run the Asterisk Unit Tests using<br>the Jenkinsfile at tests/CI/unittests.jenkinsfile. Bash scripts<br>to do the actual building and testing are also in the same directory.<br>Output is placed in tests/CI/output so that directory has been<br>added to .gitignore.<br><br>Change-Id: I9448065465e6de2b878634510ace8fd1ef378608<br>---<br>M .gitignore<br>A tests/CI/buildAsterisk.sh<br>A tests/CI/ci.functions<br>A tests/CI/installAsterisk.sh<br>A tests/CI/runTestsuite.sh<br>A tests/CI/runUnittests.sh<br>A tests/CI/setupEnvironment.sh<br>A tests/CI/unittests.jenkinsfile<br>8 files changed, 428 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/80/9380/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/.gitignore b/.gitignore</span><br><span>index 3e09738..0f31820 100644</span><br><span>--- a/.gitignore</span><br><span>+++ b/.gitignore</span><br><span>@@ -36,3 +36,5 @@</span><br><span> doxygen.log</span><br><span> out/</span><br><span> *.orig</span><br><span style="color: hsl(120, 100%, 40%);">+tests/CI/output</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/tests/CI/buildAsterisk.sh b/tests/CI/buildAsterisk.sh</span><br><span>new file mode 100755</span><br><span>index 0000000..fce81fc</span><br><span>--- /dev/null</span><br><span>+++ b/tests/CI/buildAsterisk.sh</span><br><span>@@ -0,0 +1,103 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/bin/bash</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+CIDIR=$(dirname $(readlink -fn $0))</span><br><span style="color: hsl(120, 100%, 40%);">+source $CIDIR/ci.functions</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+gen_cats() {</span><br><span style="color: hsl(120, 100%, 40%);">+ set +x</span><br><span style="color: hsl(120, 100%, 40%);">+ action=$1</span><br><span style="color: hsl(120, 100%, 40%);">+ shift</span><br><span style="color: hsl(120, 100%, 40%);">+ cats=$@</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for x in $cats ; do</span><br><span style="color: hsl(120, 100%, 40%);">+ echo " --${action}-category ${x}"</span><br><span style="color: hsl(120, 100%, 40%);">+ done</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+gen_mods() {</span><br><span style="color: hsl(120, 100%, 40%);">+ set +x</span><br><span style="color: hsl(120, 100%, 40%);">+ action=$1</span><br><span style="color: hsl(120, 100%, 40%);">+ shift</span><br><span style="color: hsl(120, 100%, 40%);">+ mods=$@</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for x in $mods ; do</span><br><span style="color: hsl(120, 100%, 40%);">+ echo " --${action} ${x}"</span><br><span style="color: hsl(120, 100%, 40%);">+ done</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+sudo mkdir -p /srv/cache/externals /srv/cache/sounds || :</span><br><span style="color: hsl(120, 100%, 40%);">+sudo chown -R jenkins:users /srv/cache</span><br><span style="color: hsl(120, 100%, 40%);">+[ ! -d tests/CI/output ] && mkdir tests/CI/output</span><br><span style="color: hsl(120, 100%, 40%);">+sudo chown -R jenkins:users tests/CI/output</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+MAKE=`which make`</span><br><span style="color: hsl(120, 100%, 40%);">+printenv | sort</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+common_config_args="--sysconfdir=/etc --with-pjproject-bundled"</span><br><span style="color: hsl(120, 100%, 40%);">+common_config_args+=" --with-sounds-cache=/srv/cache/sounds --with-externals-cache=/srv/cache/externals"</span><br><span style="color: hsl(120, 100%, 40%);">+common_config_args+=" --enable-dev-mode"</span><br><span style="color: hsl(120, 100%, 40%);">+export WGET_EXTRA_ARGS="--quiet"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner ./configure ${common_config_args} CCACHE_DISABLE=1 >tests/CI/output/configure.txt</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner ${MAKE} menuselect.makeopts</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner menuselect/menuselect `gen_mods enable DONT_OPTIMIZE BETTER_BACKTRACES MALLOC_DEBUG DO_CRASH TEST_FRAMEWORK` menuselect.makeopts</span><br><span style="color: hsl(120, 100%, 40%);">+runner menuselect/menuselect `gen_mods disable COMPILE_DOUBLE BUILD_NATIVE` menuselect.makeopts</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+cat_enables="MENUSELECT_BRIDGES MENUSELECT_CEL MENUSELECT_CDR"</span><br><span style="color: hsl(120, 100%, 40%);">+cat_enables+=" MENUSELECT_CHANNELS MENUSELECT_CODECS MENUSELECT_FORMATS MENUSELECT_FUNCS"</span><br><span style="color: hsl(120, 100%, 40%);">+cat_enables+=" MENUSELECT_PBX MENUSELECT_RES MENUSELECT_UTILS MENUSELECT_TESTS"</span><br><span style="color: hsl(120, 100%, 40%);">+runner menuselect/menuselect `gen_cats enable $cat_enables` menuselect.makeopts</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+mod_disables="res_digium_phone chan_vpb"</span><br><span style="color: hsl(120, 100%, 40%);">+[ "$BRANCH_NAME" == "master" ] && mod_disables+=" codec_opus codec_silk codec_g729a codec_siren7 codec_siren14"</span><br><span style="color: hsl(120, 100%, 40%);">+runner menuselect/menuselect `gen_mods disable $mod_disables` menuselect.makeopts</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+mod_enables="app_voicemail app_directory FILE_STORAGE"</span><br><span style="color: hsl(120, 100%, 40%);">+mod_enables+=" res_mwi_external res_ari_mailboxes res_mwi_external_ami res_stasis_mailbox"</span><br><span style="color: hsl(120, 100%, 40%);">+mod_enables+=" CORE-SOUNDS-EN-GSM MOH-OPSOUND-GSM EXTRA-SOUNDS-EN-GSM"</span><br><span style="color: hsl(120, 100%, 40%);">+runner menuselect/menuselect `gen_mods enable $mod_enables` menuselect.makeopts</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner ${MAKE} -j8 || runner ${MAKE} -j1 NOISY_BUILD=yes</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ALEMBIC=$(which alembic 2>/dev/null || : )</span><br><span style="color: hsl(120, 100%, 40%);">+if [ x"$ALEMBIC" = x ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "Alembic not installed"</span><br><span style="color: hsl(120, 100%, 40%);">+ exit 1</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+cd contrib/ast-db-manage</span><br><span style="color: hsl(120, 100%, 40%);">+find -name *.pyc -delete</span><br><span style="color: hsl(120, 100%, 40%);">+out=$(alembic -c config.ini.sample branches)</span><br><span style="color: hsl(120, 100%, 40%);">+if [ "x$out" != "x" ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo "Alembic branches were found for config"</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo $out</span><br><span style="color: hsl(120, 100%, 40%);">+ exit 1</span><br><span style="color: hsl(120, 100%, 40%);">+else</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo "Alembic for 'config' OK"</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+out=$(alembic -c cdr.ini.sample branches)</span><br><span style="color: hsl(120, 100%, 40%);">+if [ "x$out" != "x" ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo "Alembic branches were found for cdr"</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo $out</span><br><span style="color: hsl(120, 100%, 40%);">+ exit 1</span><br><span style="color: hsl(120, 100%, 40%);">+else</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo "Alembic for 'cdr' OK"</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+out=$(alembic -c voicemail.ini.sample branches)</span><br><span style="color: hsl(120, 100%, 40%);">+if [ "x$out" != "x" ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo "Alembic branches were found for voicemail"</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo $out</span><br><span style="color: hsl(120, 100%, 40%);">+ exit 1</span><br><span style="color: hsl(120, 100%, 40%);">+else</span><br><span style="color: hsl(120, 100%, 40%);">+ >&2 echo "Alembic for 'voicemail' OK"</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if [ -f "doc/core-en_US.xml" ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ ${MAKE} validate-docs || ${MAKE} NOISY_BUILD=yes validate-docs</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/tests/CI/ci.functions b/tests/CI/ci.functions</span><br><span>new file mode 100644</span><br><span>index 0000000..f3de16e</span><br><span>--- /dev/null</span><br><span>+++ b/tests/CI/ci.functions</span><br><span>@@ -0,0 +1,26 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This file contains useful Bash functions</span><br><span style="color: hsl(120, 100%, 40%);">+# and can be "source"d from the scripts.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+for a in "$@" ; do</span><br><span style="color: hsl(120, 100%, 40%);">+ OPTION_COUNT+=1</span><br><span style="color: hsl(120, 100%, 40%);">+ case "$a" in</span><br><span style="color: hsl(120, 100%, 40%);">+ --*=*)</span><br><span style="color: hsl(120, 100%, 40%);">+ [[ $a =~ --([^=]+)=(.*) ]]</span><br><span style="color: hsl(120, 100%, 40%);">+ l=${BASH_REMATCH[1]//-/_}</span><br><span style="color: hsl(120, 100%, 40%);">+ r=${BASH_REMATCH[2]}</span><br><span style="color: hsl(120, 100%, 40%);">+ eval ${l^^}=\"$r\"</span><br><span style="color: hsl(120, 100%, 40%);">+ ;;</span><br><span style="color: hsl(120, 100%, 40%);">+ --*)</span><br><span style="color: hsl(120, 100%, 40%);">+ [[ $a =~ --(.+) ]]</span><br><span style="color: hsl(120, 100%, 40%);">+ l=${BASH_REMATCH[1]//-/_}</span><br><span style="color: hsl(120, 100%, 40%);">+ eval ${l^^}=1</span><br><span style="color: hsl(120, 100%, 40%);">+ ;;</span><br><span style="color: hsl(120, 100%, 40%);">+ esac</span><br><span style="color: hsl(120, 100%, 40%);">+done</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner() {</span><br><span style="color: hsl(120, 100%, 40%);">+ ( set -x ; "$@" )</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>diff --git a/tests/CI/installAsterisk.sh b/tests/CI/installAsterisk.sh</span><br><span>new file mode 100755</span><br><span>index 0000000..b75730f</span><br><span>--- /dev/null</span><br><span>+++ b/tests/CI/installAsterisk.sh</span><br><span>@@ -0,0 +1,23 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/bin/bash</span><br><span style="color: hsl(120, 100%, 40%);">+MAKE=`which make`</span><br><span style="color: hsl(120, 100%, 40%);">+if [ x"${@}" != x ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ mkdir -p "${@}"</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+destdir=${@:+DESTDIR=${@}}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+${MAKE} ${destdir} install || ${MAKE} ${destdir} NOISY_BUILD=yes install || exit 1</span><br><span style="color: hsl(120, 100%, 40%);">+${MAKE} ${destdir} samples</span><br><span style="color: hsl(120, 100%, 40%);">+if [ -n "${@}" ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ sed -i -r -e "s@\[directories\]\(!\)@[directories]@g" $@/etc/asterisk/asterisk.conf</span><br><span style="color: hsl(120, 100%, 40%);">+ sed -i -r -e "s@ /(var|etc|usr)/@ ${@}/\1/@g" $@/etc/asterisk/asterisk.conf</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+set +e</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:users ${@}/var/lib/asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:users ${@}/var/spool/asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:users ${@}/var/log/asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:users ${@}/var/run/asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:users ${@}/etc/asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+[ ! -d ${@}/tmp/asterisk-jenkins ] && mkdir ${@}/tmp/asterisk-jenkins</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:users ${@}/tmp/asterisk-jenkins</span><br><span style="color: hsl(120, 100%, 40%);">+ldconfig</span><br><span>\ No newline at end of file</span><br><span>diff --git a/tests/CI/runTestsuite.sh b/tests/CI/runTestsuite.sh</span><br><span>new file mode 100755</span><br><span>index 0000000..c96b9a4</span><br><span>--- /dev/null</span><br><span>+++ b/tests/CI/runTestsuite.sh</span><br><span>@@ -0,0 +1,22 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env bash</span><br><span style="color: hsl(120, 100%, 40%);">+CIDIR=$(dirname $(readlink -fn $0))</span><br><span style="color: hsl(120, 100%, 40%);">+source $CIDIR/ci.functions</span><br><span style="color: hsl(120, 100%, 40%);">+ASTETCDIR=$DESTDIR/etc/asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+pushd $TESTSUITE_DIR</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner sudo PYTHONPATH=./lib/python/ ./runtests.py --cleanup ${TEST_COMMAND} || :</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if [ -f asterisk-test-suite-report.xml ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ sudo chown jenkins:users asterisk-test-suite-report.xml</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner ${CIDIR}/fixTestResults.py asterisk-test-suite-report.xml asterisk-test-suite-report.xml</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if [ -f core* ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "*** Found a core file after running unit tests ***"</span><br><span style="color: hsl(120, 100%, 40%);">+ sudo /var/lib/asterisk/scripts/ast_coredumper --no-default-search core*</span><br><span style="color: hsl(120, 100%, 40%);">+ exit 1</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+popd</span><br><span>\ No newline at end of file</span><br><span>diff --git a/tests/CI/runUnittests.sh b/tests/CI/runUnittests.sh</span><br><span>new file mode 100755</span><br><span>index 0000000..a463e15</span><br><span>--- /dev/null</span><br><span>+++ b/tests/CI/runUnittests.sh</span><br><span>@@ -0,0 +1,69 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env bash</span><br><span style="color: hsl(120, 100%, 40%);">+CIDIR=$(dirname $(readlink -fn $0))</span><br><span style="color: hsl(120, 100%, 40%);">+source $CIDIR/ci.functions</span><br><span style="color: hsl(120, 100%, 40%);">+ASTETCDIR=$DESTDIR/etc/asterisk</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+echo "full => notice,warning,error,debug,verbose" > "$ASTETCDIR/logger.conf"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+echo "[default]" > "$ASTETCDIR/extensions.conf"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+cat <<-EOF > "$ASTETCDIR/manager.conf"</span><br><span style="color: hsl(120, 100%, 40%);">+ [general]</span><br><span style="color: hsl(120, 100%, 40%);">+ enabled=yes</span><br><span style="color: hsl(120, 100%, 40%);">+ bindaddr=127.0.0.1</span><br><span style="color: hsl(120, 100%, 40%);">+ port=5038</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ [test]</span><br><span style="color: hsl(120, 100%, 40%);">+ secret=test</span><br><span style="color: hsl(120, 100%, 40%);">+ read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan</span><br><span style="color: hsl(120, 100%, 40%);">+ write = system,call,agent,user,config,command,reporting,originate</span><br><span style="color: hsl(120, 100%, 40%);">+EOF</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+cat <<-EOF > "$ASTETCDIR/http.conf"</span><br><span style="color: hsl(120, 100%, 40%);">+ [general]</span><br><span style="color: hsl(120, 100%, 40%);">+ enabled=yes</span><br><span style="color: hsl(120, 100%, 40%);">+ bindaddr=127.0.0.1</span><br><span style="color: hsl(120, 100%, 40%);">+ port=8088</span><br><span style="color: hsl(120, 100%, 40%);">+EOF</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+cat <<-EOF > "$ASTETCDIR/modules.conf"</span><br><span style="color: hsl(120, 100%, 40%);">+ [modules]</span><br><span style="color: hsl(120, 100%, 40%);">+ autoload=yes</span><br><span style="color: hsl(120, 100%, 40%);">+ noload=res_mwi_external.so</span><br><span style="color: hsl(120, 100%, 40%);">+ noload=res_mwi_external_ami.so</span><br><span style="color: hsl(120, 100%, 40%);">+ noload=res_ari_mailboxes.so</span><br><span style="color: hsl(120, 100%, 40%);">+ noload=res_stasis_mailbox.so</span><br><span style="color: hsl(120, 100%, 40%);">+EOF</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+cat <<-EOF >> "$ASTETCDIR/sorcery.conf"</span><br><span style="color: hsl(120, 100%, 40%);">+ [res_pjsip_pubsub]</span><br><span style="color: hsl(120, 100%, 40%);">+ resource_list=memory</span><br><span style="color: hsl(120, 100%, 40%);">+EOF</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ASTERISK="$DESTDIR/usr/sbin/asterisk"</span><br><span style="color: hsl(120, 100%, 40%);">+CONFFILE=$ASTETCDIR/asterisk.conf</span><br><span style="color: hsl(120, 100%, 40%);">+OUTPUTDIR=${OUTPUT_DIR:-tests/CI/output/}</span><br><span style="color: hsl(120, 100%, 40%);">+OUTPUTFILE=${OUTPUT_XML:-${OUTPUTDIR}/unittests-results.xml}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[ ! -d ${OUTPUTDIR} ] && mkdir -p $OUTPUTDIR</span><br><span style="color: hsl(120, 100%, 40%);">+sudo chown -R jenkins:users $OUTPUTDIR</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+rm -rf $ASTETCDIR/extensions.{ael,lua} || :</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner sudo $ASTERISK -U jenkins -G users -gn -C $CONFFILE</span><br><span style="color: hsl(120, 100%, 40%);">+sleep 3</span><br><span style="color: hsl(120, 100%, 40%);">+runner $ASTERISK -rx "core waitfullybooted" -C $CONFFILE</span><br><span style="color: hsl(120, 100%, 40%);">+sleep 1</span><br><span style="color: hsl(120, 100%, 40%);">+runner $ASTERISK -rx "${TEST_COMMAND:-test execute all}" -C $CONFFILE</span><br><span style="color: hsl(120, 100%, 40%);">+runner $ASTERISK -rx "test show results failed" -C $CONFFILE</span><br><span style="color: hsl(120, 100%, 40%);">+runner $ASTERISK -rx "test generate results xml $OUTPUTFILE" -C $CONFFILE</span><br><span style="color: hsl(120, 100%, 40%);">+runner $ASTERISK -rx "core stop now" -C $CONFFILE</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+runner rsync -vaH $DESTDIR/var/log/asterisk/. $OUTPUTDIR</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+sudo chown -R jenkins:users $OUTPUTDIR</span><br><span style="color: hsl(120, 100%, 40%);">+if [ -f core* ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "*** Found a core file after running unit tests ***"</span><br><span style="color: hsl(120, 100%, 40%);">+ $DESTDIR/var/lib/asterisk/scripts/ast_coredumper --no-default-search core*</span><br><span style="color: hsl(120, 100%, 40%);">+ exit 1</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span>diff --git a/tests/CI/setupEnvironment.sh b/tests/CI/setupEnvironment.sh</span><br><span>new file mode 100755</span><br><span>index 0000000..eef47a6</span><br><span>--- /dev/null</span><br><span>+++ b/tests/CI/setupEnvironment.sh</span><br><span>@@ -0,0 +1,13 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/env bash</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+chmod 0750 /etc/sudoers.d</span><br><span style="color: hsl(120, 100%, 40%);">+chmod 0440 /etc/sudoers.d/jenkins</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+chown root:root -R /root</span><br><span style="color: hsl(120, 100%, 40%);">+chmod -R go-rwx /root/.ssh</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:jenkins /home/jenkins</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:jenkins /srv/cache</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:jenkins /srv/jenkins</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:jenkins /srv/git</span><br><span style="color: hsl(120, 100%, 40%);">+chmod -R go-rwx /home/jenkins/.ssh</span><br><span style="color: hsl(120, 100%, 40%);">+chmod -R go-rwx /home/jenkins/.ssh/authorized_keys</span><br><span>diff --git a/tests/CI/unittests.jenkinsfile b/tests/CI/unittests.jenkinsfile</span><br><span>new file mode 100644</span><br><span>index 0000000..0925910</span><br><span>--- /dev/null</span><br><span>+++ b/tests/CI/unittests.jenkinsfile</span><br><span>@@ -0,0 +1,170 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This pipeline is the "template" for the Asterisk Unit Tests multi-branch</span><br><span style="color: hsl(120, 100%, 40%);">+ * parent job. Jenkins will automatically scan the branches in the "asterisk"</span><br><span style="color: hsl(120, 100%, 40%);">+ * or "Security-asterisk" projects in Gerrit and automatically create a branch-</span><br><span style="color: hsl(120, 100%, 40%);">+ * specific job for each branch it finds this file in.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file starts as a declarative pipeline because with a declarative</span><br><span style="color: hsl(120, 100%, 40%);">+ * pipeline, you can define the trigger in the pipeline file. This keeps</span><br><span style="color: hsl(120, 100%, 40%);">+ * everything in one place. We transition to scripted pipeline later on because</span><br><span style="color: hsl(120, 100%, 40%);">+ * we need to dynamically determine which docker image we're going to use and</span><br><span style="color: hsl(120, 100%, 40%);">+ * you can't do that in a delcarative pipeline.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+pipeline {</span><br><span style="color: hsl(120, 100%, 40%);">+ triggers {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This trigger will match either the "asterisk" or "Security-asterisk"</span><br><span style="color: hsl(120, 100%, 40%);">+ * projects. The branch is taken from the branch this job was created</span><br><span style="color: hsl(120, 100%, 40%);">+ * for.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ gerrit customUrl: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ commentTextParameterMode: 'PLAIN',</span><br><span style="color: hsl(120, 100%, 40%);">+ commitMessageParameterMode: 'PLAIN',</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildStartedVerifiedValue: 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildNotBuiltVerifiedValue: 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildSuccessfulVerifiedValue: 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildFailedVerifiedValue: -1,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritBuildUnstableVerifiedValue: -1,</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritProjects: [</span><br><span style="color: hsl(120, 100%, 40%);">+ [branches: [[compareType: 'PLAIN', pattern: "${BRANCH_NAME}"]],</span><br><span style="color: hsl(120, 100%, 40%);">+ compareType: 'REG_EXP',</span><br><span style="color: hsl(120, 100%, 40%);">+ disableStrictForbiddenFileVerification: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ pattern: '^(Security-)?asterisk.*'</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ silentMode: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ triggerOnEvents: [</span><br><span style="color: hsl(120, 100%, 40%);">+ commentAddedContains('^recheck$'),</span><br><span style="color: hsl(120, 100%, 40%);">+ patchsetCreated(excludeDrafts: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ excludeNoCodeChange: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ excludeTrivialRebase: false),</span><br><span style="color: hsl(120, 100%, 40%);">+ draftPublished()</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ skipVote: [</span><br><span style="color: hsl(120, 100%, 40%);">+ onFailed: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ onNotBuilt: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ onSuccessful: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ onUnstable: false</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ agent {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* All of the stages need to be performed on a docker host */</span><br><span style="color: hsl(120, 100%, 40%);">+ label "swdev-docker"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stages {</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ("Unit Tests-->") {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Jenkins will try to automatically rebuild this job when</span><br><span style="color: hsl(120, 100%, 40%);">+ * the jenkinsfile changes but since this job is dependent on</span><br><span style="color: hsl(120, 100%, 40%);">+ * Gerrit, we really don't want to do anything in that case.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ when {</span><br><span style="color: hsl(120, 100%, 40%);">+ not { environment name: 'GERRIT_CHANGE_NUMBER', value: '' }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ steps {</span><br><span style="color: hsl(120, 100%, 40%);">+ script {</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ("Checkout") {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Jenkins has already automatically checked out the base branch</span><br><span style="color: hsl(120, 100%, 40%);">+ * for this change but we now need to check out the change itself</span><br><span style="color: hsl(120, 100%, 40%);">+ * and rebase it on the current base branch. If the rebase fails,</span><br><span style="color: hsl(120, 100%, 40%);">+ * that's an indication to the user that they'll need to sort their</span><br><span style="color: hsl(120, 100%, 40%);">+ * change out.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * The Gerrit Trigger provides all the URLs and refspecs to</span><br><span style="color: hsl(120, 100%, 40%);">+ * check out the change.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ checkout scm: [$class: 'GitSCM',</span><br><span style="color: hsl(120, 100%, 40%);">+ branches: [[name: env.GERRIT_BRANCH ]],</span><br><span style="color: hsl(120, 100%, 40%);">+ extensions: [</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'CleanBeforeCheckout'],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'PreBuildMerge', options: [</span><br><span style="color: hsl(120, 100%, 40%);">+ mergeRemote: env.GERRIT_NAME,</span><br><span style="color: hsl(120, 100%, 40%);">+ mergeTarget: env.GERRIT_BRANCH ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'CloneOption',</span><br><span style="color: hsl(120, 100%, 40%);">+ noTags: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ depth: 10,</span><br><span style="color: hsl(120, 100%, 40%);">+ honorRefspec: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ shallow: true</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'BuildChooserSetting',</span><br><span style="color: hsl(120, 100%, 40%);">+ buildChooser: [$class: 'GerritTriggerBuildChooser']</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ userRemoteConfigs: [</span><br><span style="color: hsl(120, 100%, 40%);">+ [name: env.GERRIT_NAME, refspec: env.GERRIT_REFSPEC, url: env.GIT_URL ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ ]</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def images = env.DOCKER_IMAGES.split(' ')</span><br><span style="color: hsl(120, 100%, 40%);">+ def r = currentBuild.startTimeInMillis % images.length</span><br><span style="color: hsl(120, 100%, 40%);">+ def ri = images[(int)r]</span><br><span style="color: hsl(120, 100%, 40%);">+ def randomImage = env.DOCKER_REGISTRY + "/" + ri;</span><br><span style="color: hsl(120, 100%, 40%);">+ def dockerOptions =</span><br><span style="color: hsl(120, 100%, 40%);">+ "-v /srv/jenkins:/srv/jenkins:rw -v /srv/cache:/srv/cache:rw" +</span><br><span style="color: hsl(120, 100%, 40%);">+ " --entrypoint='' --name ${BUILD_TAG}-build"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ docker.image(randomImage).inside(dockerOptions) {</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ('Build') {</span><br><span style="color: hsl(120, 100%, 40%);">+ echo 'Building..'</span><br><span style="color: hsl(120, 100%, 40%);">+ sh './tests/CI/buildAsterisk.sh'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false,</span><br><span style="color: hsl(120, 100%, 40%);">+ artifacts: "tests/CI/output/*"</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ('Test') {</span><br><span style="color: hsl(120, 100%, 40%);">+ def outputdir = "tests/CI/output/UnitTests"</span><br><span style="color: hsl(120, 100%, 40%);">+ def outputfile = "${outputdir}/unittests-results.xml"</span><br><span style="color: hsl(120, 100%, 40%);">+ def testcmd = "test execute all"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sh 'sudo ./tests/CI/installAsterisk.sh'</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "tests/CI/runUnittests.sh --output-dir='${outputdir}' --output-xml='${outputfile}' --test-command='${testcmd}'"</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "tests/CI/runUnittests.sh --output-dir='${outputdir}' --output-xml='${outputfile}' --test-command='${testcmd}'"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: true,</span><br><span style="color: hsl(120, 100%, 40%);">+ artifacts: "${outputdir}/**"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ junit testResults: outputfile,</span><br><span style="color: hsl(120, 100%, 40%);">+ healthScaleFactor: 1.0,</span><br><span style="color: hsl(120, 100%, 40%);">+ keepLongStdio: true</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ('Cleanup') {</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "sudo make distclean || : "</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * The Gerrit Trigger will automatically post the "Verified" results back</span><br><span style="color: hsl(120, 100%, 40%);">+ * to Gerrit but the verification publisher publishes extra stuff in the</span><br><span style="color: hsl(120, 100%, 40%);">+ * "Code Review" section of the review.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ post {</span><br><span style="color: hsl(120, 100%, 40%);">+ success {</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritverificationpublisher verifyStatusValue: 1, verifyStatusCategory: 'Passed',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusURL: '', verifyStatusComment: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusName: '', verifyStatusReporter: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusRerun: 'recheck'</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ failure {</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritverificationpublisher verifyStatusValue: -1, verifyStatusCategory: 'Failed',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusURL: '', verifyStatusComment: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusName: '', verifyStatusReporter: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusRerun: 'recheck'</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ unstable {</span><br><span style="color: hsl(120, 100%, 40%);">+ gerritverificationpublisher verifyStatusValue: -1, verifyStatusCategory: 'Failed',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusURL: '', verifyStatusComment: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusName: '', verifyStatusReporter: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusRerun: 'recheck'</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9380">change 9380</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9380"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I9448065465e6de2b878634510ace8fd1ef378608 </div>
<div style="display:none"> Gerrit-Change-Number: 9380 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>