<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9591">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Jenkins2: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">CI: Add Testsuite Unit Tests<br><br>Change-Id: I6a21b1d68f5669e8459d8dea21a83bb14556edbb<br>---<br>A CI/ci.functions<br>A CI/setupJenkinsEnvironment.sh<br>A CI/unittests.jenkinsfile<br>3 files changed, 222 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CI/ci.functions b/CI/ci.functions</span><br><span>new file mode 100644</span><br><span>index 0000000..67616c2</span><br><span>--- /dev/null</span><br><span>+++ b/CI/ci.functions</span><br><span>@@ -0,0 +1,30 @@</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%);">+declare -a POSITIONAL_ARGS</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%);">+ *)</span><br><span style="color: hsl(120, 100%, 40%);">+ POSITIONAL_ARGS+=($a)</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/CI/setupJenkinsEnvironment.sh b/CI/setupJenkinsEnvironment.sh</span><br><span>new file mode 100755</span><br><span>index 0000000..d97ad0a</span><br><span>--- /dev/null</span><br><span>+++ b/CI/setupJenkinsEnvironment.sh</span><br><span>@@ -0,0 +1,12 @@</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+mkdir -p /srv/cache/externals /srv/cache/sounds /srv/cache/ccache || :</span><br><span style="color: hsl(120, 100%, 40%);">+chown -R jenkins:users /srv/cache</span><br><span style="color: hsl(120, 100%, 40%);">+chmod g+rw /srv/cache/ccache</span><br><span style="color: hsl(120, 100%, 40%);">+chmod g+s /srv/cache/ccache</span><br><span style="color: hsl(120, 100%, 40%);">+if [ -n "${OUTPUT_DIR}" ] ; then</span><br><span style="color: hsl(120, 100%, 40%);">+ mkdir -p "${OUTPUT_DIR}" || :</span><br><span style="color: hsl(120, 100%, 40%);">+ chown -R jenkins:users "${OUTPUT_DIR}"</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span>diff --git a/CI/unittests.jenkinsfile b/CI/unittests.jenkinsfile</span><br><span>new file mode 100644</span><br><span>index 0000000..804e6c7</span><br><span>--- /dev/null</span><br><span>+++ b/CI/unittests.jenkinsfile</span><br><span>@@ -0,0 +1,180 @@</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 Testsuite Unit Tests multi-branch</span><br><span style="color: hsl(120, 100%, 40%);">+ * parent job. Jenkins will automatically scan the branches in the "testsuite"</span><br><span style="color: hsl(120, 100%, 40%);">+ * or "Security-testsuite" 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%);">+ 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-)?testsuite.*'</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 ("->") {</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%);">+ not { environment name: 'GERRIT_EVENT_ACCOUNT_NAME', value: 'Jenkins2' }</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%);">+ sh "sudo chown -R jenkins:users ."</span><br><span style="color: hsl(120, 100%, 40%);">+ env.GERRIT_PROJECT_URL = env.GERRIT_CHANGE_URL.replaceAll(/\/[0-9]+$/, "/${env.GERRIT_PROJECT}")</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "printenv | sort"</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%);">+ * 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: 'ScmName', name: env.GERRIT_NAME],</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%);">+ fastForwardMode: 'NO_FF',</span><br><span style="color: hsl(120, 100%, 40%);">+ mergeStrategy: 'RECURSIVE',</span><br><span style="color: hsl(120, 100%, 40%);">+ mergeTarget: env.GERRIT_BRANCH]],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'CloneOption',</span><br><span style="color: hsl(120, 100%, 40%);">+ honorRefspec: true,</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%);">+ shallow: true</span><br><span style="color: hsl(120, 100%, 40%);">+ ],</span><br><span style="color: hsl(120, 100%, 40%);">+ [$class: 'PruneStaleBranch'],</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.GERRIT_PROJECT_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%);">+ sh "sudo CI/setupJenkinsEnvironment.sh --output-dir=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%);">+ 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%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ def bt = env.BUILD_TAG.replaceAll(/[^a-zA-Z0-9_.-]/, '-')</span><br><span style="color: hsl(120, 100%, 40%);">+ def dockerOptions = "--ulimit core=0 --ulimit nofile=10240 " +</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 ${bt}-build"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ def img = docker.image(randomImage)</span><br><span style="color: hsl(120, 100%, 40%);">+ img.pull()</span><br><span style="color: hsl(120, 100%, 40%);">+ img.inside(dockerOptions) {</span><br><span style="color: hsl(120, 100%, 40%);">+ stage ('Test') {</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "./self_test"</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%);">+ post {</span><br><span style="color: hsl(120, 100%, 40%);">+ cleanup {</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "sudo make distclean 2&>/dev/null || : "</span><br><span style="color: hsl(120, 100%, 40%);">+ sh "sudo rm -rf CI/output 2&>/dev/null || : "</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%);">+ always {</span><br><span style="color: hsl(120, 100%, 40%);">+ script {</span><br><span style="color: hsl(120, 100%, 40%);">+ def cat</span><br><span style="color: hsl(120, 100%, 40%);">+ def comment</span><br><span style="color: hsl(120, 100%, 40%);">+ def rvalue</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (currentBuild.currentResult) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case ~/^SUCCESS$/:</span><br><span style="color: hsl(120, 100%, 40%);">+ cat = "Passed"</span><br><span style="color: hsl(120, 100%, 40%);">+ comment = ""</span><br><span style="color: hsl(120, 100%, 40%);">+ rvalue = 1</span><br><span style="color: hsl(120, 100%, 40%);">+ break</span><br><span style="color: hsl(120, 100%, 40%);">+ case ~/^FAILURE$/:</span><br><span style="color: hsl(120, 100%, 40%);">+ cat = "Failed"</span><br><span style="color: hsl(120, 100%, 40%);">+ comment = "Fatal Error"</span><br><span style="color: hsl(120, 100%, 40%);">+ rvalue = -1</span><br><span style="color: hsl(120, 100%, 40%);">+ break</span><br><span style="color: hsl(120, 100%, 40%);">+ case ~/^UNSTABLE$/:</span><br><span style="color: hsl(120, 100%, 40%);">+ cat = "Failed"</span><br><span style="color: hsl(120, 100%, 40%);">+ comment = "Tests Failed"</span><br><span style="color: hsl(120, 100%, 40%);">+ rvalue = -1</span><br><span style="color: hsl(120, 100%, 40%);">+ break</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%);">+ gerritverificationpublisher verifyStatusValue: rvalue,</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusCategory: cat, verifyStatusURL: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusComment: comment, verifyStatusName: '',</span><br><span style="color: hsl(120, 100%, 40%);">+ verifyStatusReporter: 'Jenkins2', verifyStatusRerun: 'regate'</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%);">+ success {</span><br><span style="color: hsl(120, 100%, 40%);">+ echo "Reporting ${currentBuild.currentResult} Passed"</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%);">+ echo "Reporting ${currentBuild.currentResult}: Failed: Fatal Error"</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%);">+ echo "Reporting ${currentBuild.currentResult}: Failed: Tests Failed"</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/9591">change 9591</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/9591"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I6a21b1d68f5669e8459d8dea21a83bb14556edbb </div>
<div style="display:none"> Gerrit-Change-Number: 9591 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>