taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

coverage.sh (5640B)


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