coverage.sh (5614B)
1 #!/bin/bash 2 # Coverage for lcov.taler.net. 3 # 4 # The site serves a directory of HTML per repository; for the C codebases that 5 # directory comes from lcov's `genhtml`. Nothing on the receiving end needs 6 # lcov's own format, so this ships JaCoCo's report, which is the same thing for 7 # the JVM: a source-annotated page per class, green and red down the gutter. 8 # 9 # What runs here is every JVM unit test in the repository. The *integration* 10 # suites -- pos-simulator/, which drives the merchant terminal in an emulator, 11 # and wallet-simulator/, which drives the wallet against a local Taler stack 12 # -- are not run by this job, and the reason is a hard one: an Android 13 # emulator needs /dev/kvm, a container only gets it if the host passes the 14 # device *and* the CI user may open it, and even accelerated each of those 15 # suites is hours rather than minutes -- the POS one measured 103.7 s per 16 # scenario over 57 runs, and the wallet's is of the same order with a hundred 17 # scenarios of its own. Those are nightlies on a KVM-capable worker 18 # (6-simulator-pos and 7-simulator-wallet), not jobs that run on every push. 19 # 20 # Either nightly feeds its result back here rather than raising a report of 21 # its own: drop the `.ec` files a simulator run produced into 22 # /inputs/emulator-coverage (or point EMULATOR_EC_DIR at them) and they are 23 # merged in. That is also why the variants below are the `sim` ones -- JaCoCo 24 # matches execution data to classes by a checksum of the class file, so the 25 # unit tests have to be reported against the same build type the emulator ran. 26 set -exuo pipefail 27 28 REPO_NAME=taler-android 29 ARTIFACT_PATH="/artifacts/${REPO_NAME}/lcov/${CI_COMMIT_REF}/${REPO_NAME}" 30 WORK="${PWD}/build/coverage" 31 JACOCO_VERSION="${JACOCO_VERSION:-0.8.14}" 32 CLI="${WORK}/org.jacoco.cli-${JACOCO_VERSION}-nodeps.jar" 33 EMULATOR_EC_DIR="${EMULATOR_EC_DIR:-/inputs/emulator-coverage}" 34 35 mkdir -p "${WORK}" "${ARTIFACT_PATH}" 36 37 # Every module that has unit tests and switches `enableUnitTestCoverage` on. 38 # `cashier` and `donau-verificator` carry none, so asking for them would only 39 # fail the job for an empty result. 40 ./gradlew --no-daemon \ 41 :taler-kotlin-android:testDebugUnitTest \ 42 :merchant-lib:testDebugUnitTest \ 43 :merchant-terminal:testSimUnitTest \ 44 :wallet:testFdroidSimUnitTest 45 46 if [ ! -s "${CLI}" ]; then 47 curl -sSfL -o "${CLI}" \ 48 "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/${JACOCO_VERSION}/org.jacoco.cli-${JACOCO_VERSION}-nodeps.jar" 49 fi 50 51 # Unit-test execution data, plus anything an emulator run left for us. 52 EXEC_FILES=() 53 while IFS= read -r f; do EXEC_FILES+=("${f}"); done < <( 54 find . -path '*/outputs/unit_test_code_coverage/*' -name '*.exec' | sort) 55 if [ -d "${EMULATOR_EC_DIR}" ]; then 56 while IFS= read -r f; do EXEC_FILES+=("${f}"); done < <( 57 find "${EMULATOR_EC_DIR}" -name '*.ec' | sort) 58 fi 59 if [ "${#EXEC_FILES[@]}" -eq 0 ]; then 60 echo "no execution data; did the tests run?" >&2 61 exit 1 62 fi 63 64 MERGED="${WORK}/merged.exec" 65 rm -f "${MERGED}" 66 java -jar "${CLI}" merge "${EXEC_FILES[@]}" --destfile "${MERGED}" 67 68 # Kotlin and Java classes live in separate trees per module and variant, and 69 # both have to be the *uninstrumented* ones. 70 CLASS_ARGS=() 71 SOURCE_ARGS=() 72 add_module() { # add_module <module> <variant> 73 local m="${1}" v="${2}" 74 for d in "${m}/build/tmp/kotlin-classes/${v}" \ 75 "${m}/build/intermediates/javac/${v}/classes"; do 76 [ -d "${d}" ] && CLASS_ARGS+=(--classfiles "${d}") 77 done 78 [ -d "${m}/src/main/java" ] && SOURCE_ARGS+=(--sourcefiles "${m}/src/main/java") 79 } 80 add_module taler-kotlin-android debug 81 add_module merchant-lib debug 82 add_module merchant-terminal sim 83 add_module wallet fdroidSim 84 85 [ "${#CLASS_ARGS[@]}" -gt 0 ] || { echo "no class files to report on" >&2; exit 1; } 86 87 java -jar "${CLI}" report "${MERGED}" \ 88 "${CLASS_ARGS[@]}" "${SOURCE_ARGS[@]}" \ 89 --html "${ARTIFACT_PATH}/html" \ 90 --xml "${WORK}/coverage.xml" \ 91 --name "GNU Taler ${REPO_NAME} coverage report" 92 93 # A landing page over the top, saying which lines no build of this type could 94 # ever reach and what produced the figures. Never fatal: the report above is 95 # the deliverable. 96 cp "${WORK}/coverage.xml" "${ARTIFACT_PATH}/coverage.xml" || true 97 # JaCoCo's own report goes under html/, the landing page sits at the top of 98 # the artifact and links into it -- otherwise the two would both want to be 99 # index.html and the summary would clobber the report. 100 # --also-gaps: the page discounts lines no `sim` build could ever enter, and 101 # each simulator knows that about its own app -- the terminal's screenshot-only 102 # composables on one side, the wallet's @Preview bodies (27 % of everything the 103 # wallet half of this report calls "missed") on the other. Without the second 104 # module the repo-wide figure would call the wallet's preview functions 105 # uncovered work. 106 python3 pos-simulator/coverage/summary_html.py "${ARTIFACT_PATH}" \ 107 "${EMULATOR_EC_DIR}" --title "GNU Taler ${REPO_NAME}" \ 108 --also-gaps wallet-simulator/coverage \ 109 || echo "summary page not written" >&2 110 111 chmod -R a+rX "${ARTIFACT_PATH}" 112 113 # A local run has no route to the artifact host; PUBLISH=0 stops there with 114 # the report on disk, which is what you want when testing the job itself. 115 if [ "${PUBLISH:-1}" = "0" ]; then 116 echo "PUBLISH=0: report left at ${ARTIFACT_PATH}, not uploaded" >&2 117 exit 0 118 fi 119 120 RSYNC_HOST="taler.host.internal" 121 RSYNC_PORT=424243 122 RSYNC_PATH="incoming_taler/" 123 RSYNC_DEST="rsync://${RSYNC_HOST}/${RSYNC_PATH}" 124 125 rsync -rvP --port "${RSYNC_PORT}" "${ARTIFACT_PATH}" "${RSYNC_DEST}"