taler-android

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

commit 89c4cc999e125ed16c82f6769290fa55c3b38749
parent 282d5bb40ac63fb79da4391e803ddf6066371550
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 10 Nov 2026 01:53:40 +0100

[all] contrib/ci: a nightly job that drives the POS terminal in an emulator

The suite takes about three hours serially, so it runs from the nightly
scheduler rather than on every push, and folds its execution data into
5-coverage's report instead of growing a second one.

Diffstat:
Mcontrib/ci/Containerfile | 8+++++++-
Acontrib/ci/jobs/6-simulator-pos/README.md | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontrib/ci/jobs/6-simulator-pos/config.ini | 8++++++++
Acontrib/ci/jobs/6-simulator-pos/job.sh | 6++++++
Acontrib/ci/jobs/6-simulator-pos/simulator.sh | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 190 insertions(+), 1 deletion(-)

diff --git a/contrib/ci/Containerfile b/contrib/ci/Containerfile @@ -16,7 +16,12 @@ ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 ENV PATH="${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:/root/.local/bin" # Base tools: what the jobs themselves shell out to, plus fdroidserver's and -# the coverage job's Python. +# the coverage job's Python. procps is for the emulator teardown: emu.sh +# falls back to `pgrep -f -- "-port <console>"` when `adb emu kill` leaves the +# process behind, and without it that fallback fails with "pgrep: command not +# found" -- quietly, because the teardown is deliberately non-fatal. An +# emulator that survives a job keeps its AVD lock files and the *next* run +# fails to boot on them. RUN apt-get update && apt-get -qy install --no-install-recommends \ bash \ ca-certificates \ @@ -24,6 +29,7 @@ RUN apt-get update && apt-get -qy install --no-install-recommends \ git \ openssh-client \ pipx \ + procps \ python3 \ python3-pip \ python3-setuptools \ diff --git a/contrib/ci/jobs/6-simulator-pos/README.md b/contrib/ci/jobs/6-simulator-pos/README.md @@ -0,0 +1,82 @@ +<!-- + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +--> + +# `6-simulator` — the terminal, driven in an emulator, nightly + +```bash +contrib/ci/ci.sh 6-simulator # as the buildbot runs it +PUBLISH=0 contrib/ci/jobs/6-simulator/job.sh # locally, report on disk +POS_SUITE_ARGS='--tag mock' \ + PUBLISH=0 contrib/ci/jobs/6-simulator/job.sh # a subset, while iterating +``` + +This is the integration half of [`5-coverage`](../5-coverage/README.md). That +job runs every JVM unit test; this one boots an Android emulator, installs the +`sim` build of `merchant-terminal`, walks all 103 scenarios in +`pos-simulator/driver/suite.py`, and then calls 5-coverage's own script with +`EMULATOR_EC_DIR` pointed at the execution data the run produced. There is one +report, not two, and it is the merged one. + +## Why it is nightly and not per-push + +Measured over 57 real scenario runs the mean scenario is 103.7 s, so the suite +is about **three hours serially**. The harness can drive five emulators side by +side and finish in about forty minutes, and this job deliberately does not: the +container worker is shared with every other repository's CI, and a nightly has +nowhere to be. `POS_WORKER` stays `0`. + +`config.ini` carries `RUN_ON = nightly`, which the buildmaster honours by +skipping the stage in push builds. Stages are discovered by listing this +directory, so without that key the job would run on every push — three hours of +emulator time holding the worker, which is worse than a job that fails, because +a failure at least gets noticed. + +## Why it is advisory + +`HALT_ON_FAILURE = False` with `WARN_ON_FAILURE = True`, as the deploy jobs +have. 87 of the 103 scenarios need the public `demo.taler.net` deployment — +backend, exchange and bank — and that tracks master and is redeployed without +reference to this repository. An outage there is not a defect here, so the job +warns and the build stays green. + +That is safe because of how `suite.py` reports: it exits non-zero **only** for +harness errors. A scenario that finds something wrong with the app still exits +`ok`, because the finding is the result rather than a crash. So a failure of +this job means the harness could not run at all. + +## The TLS wrinkle + +`ConfigFragment.sanitizeMerchantUrlAndUpdateFields` and +`MainActivity.handleSetupIntent` both hard-code `https://`, so the harness's own +backend has to answer TLS, and the `sim` build type compiles the simulator's CA +in as an extra trust anchor. + +The CA's private key is **not** in git, deliberately — see +[`pos-simulator/tls/README.md`](../../../../pos-simulator/tls/README.md). A CI +checkout has `ca.crt` and `srv.crt` and neither key, so the job generates its +own set and copies the new `ca.crt` over +`merchant-terminal/src/sim/res/raw/sim_ca.crt` **before** building the APK: the +anchor is compiled in, so a new CA means a new build. On a host that already +has `ca.key` — a dedicated simulator box — nothing is regenerated. + +## What it needs from the image + +All of it is already in `contrib/ci/Containerfile`: the emulator and the +`android-36;google_apis;x86_64` system image, `taler-wallet-cli` for the 13 +`pay` scenarios, `taler-twister` for the 15 `fault` ones, `openssl`, and a +`python3` — the driver is pure standard library. It also needs `/dev/kvm`, +which the buildmaster passes to every container unconditionally; without +acceleration the suite is a day rather than three hours. diff --git a/contrib/ci/jobs/6-simulator-pos/config.ini b/contrib/ci/jobs/6-simulator-pos/config.ini @@ -0,0 +1,7 @@ +[build] +HALT_ON_FAILURE = False +WARN_ON_FAILURE = True +CONTAINER_BUILD = True +CONTAINER_NAME = localhost/taler-android +CONTAINER_ARCH = amd64 +RUN_ON = nightly +\ No newline at end of file diff --git a/contrib/ci/jobs/6-simulator-pos/job.sh b/contrib/ci/jobs/6-simulator-pos/job.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -exuo pipefail + +job_dir=$(dirname "${BASH_SOURCE[0]}") + +"${job_dir}"/simulator.sh diff --git a/contrib/ci/jobs/6-simulator-pos/simulator.sh b/contrib/ci/jobs/6-simulator-pos/simulator.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# Nightly: drive the merchant terminal in a real emulator, and fold what that +# reached into the coverage report. +# +# This is the integration half of `5-coverage`. That job runs every JVM unit +# test and says in its own header why the emulator suites are not part of it: +# about three hours of emulator time has no business on every push. So they +# live here instead, this job runs only from the nightly scheduler +# (`RUN_ON = nightly` in config.ini), and when the suite is done it hands its +# execution data to 5-coverage's script through EMULATOR_EC_DIR -- the hook +# that script already documents -- rather than growing a second report that +# would disagree with the first. +# +# One emulator, deliberately. The harness can drive five side by side, which +# takes the suite from about three hours to about forty minutes, but the +# container worker is shared with every other repository's CI and a nightly is +# in no hurry. POS_WORKER therefore stays 0. +set -exuo pipefail + +REPO_ROOT="${PWD}" +export POS_SIM_ROOT="${POS_SIM_ROOT:-${REPO_ROOT}/build/pos-sim}" +export POS_WORKER=0 +# Deliberately word-split: these are arguments to suite.py, not one argument. +read -r -a SUITE_ARGS <<< "${POS_SUITE_ARGS:---all}" + +# The terminal builds every merchant URL with a hard-coded `https://`, so a +# backend the harness controls has to answer TLS, and the `sim` build type +# carries the simulator's CA as an extra trust anchor. That CA's private key +# is deliberately not in git (see pos-simulator/tls/README.md): a certificate +# without its key authorises nobody, which is what makes shipping ca.crt in a +# never-published build type safe. A CI checkout therefore has the +# certificates and none of the keys, and has to generate its own set -- which +# means rebuilding the APK, because the anchor is compiled into it. Hence +# before the build below, and not after. +TLS=pos-simulator/tls +if [ ! -r "${TLS}/ca.key" ]; then + openssl req -x509 -newkey rsa:2048 -nodes \ + -keyout "${TLS}/ca.key" -out "${TLS}/ca.crt" -days 3650 \ + -subj '/CN=Taler POS simulator CA/O=GNU Taler/OU=pos-simulator' \ + -addext 'basicConstraints=critical,CA:TRUE' \ + -addext 'keyUsage=critical,keyCertSign,cRLSign' + openssl req -newkey rsa:2048 -nodes \ + -keyout "${TLS}/srv.key" -out "${TLS}/srv.csr" -subj '/CN=localhost' + openssl x509 -req -in "${TLS}/srv.csr" -CA "${TLS}/ca.crt" \ + -CAkey "${TLS}/ca.key" -CAcreateserial -out "${TLS}/srv.crt" \ + -days 3650 -extfile "${TLS}/srv.ext" + cp "${TLS}/ca.crt" merchant-terminal/src/sim/res/raw/sim_ca.crt +fi + +# The `sim` build type is `debug` plus the JaCoCo agent, the PosSimHooks +# receiver the driver needs for the three things adb cannot do, and the trust +# anchor above. It is what the simulator drives; a plain debug APK would run +# but report no coverage. +./gradlew --no-daemon :merchant-terminal:assembleSim +APK=merchant-terminal/build/outputs/apk/sim/merchant-terminal-sim.apk +test -s "${APK}" + +# The harness resolves tls/ and backend/ relative to its own file, not to +# POS_SIM_ROOT, so the tree is copied whole instead of being run from the +# checkout -- the same shape the README's rsync produces on a dedicated host. +rm -rf "${POS_SIM_ROOT}" +mkdir -p "${POS_SIM_ROOT}/apk" +cp -a pos-simulator/. "${POS_SIM_ROOT}/" +cp "${APK}" "${POS_SIM_ROOT}/apk/pos.apk" +cd "${POS_SIM_ROOT}" +. ./env.sh + +# Unconditional on the way out: an emulator that outlives the job keeps its +# AVD lock files, and the next night's boot dies on them rather than on +# anything to do with that night's code. +trap '"${POS_SIM_ROOT}"/emu/emu.sh kill "${POS_WORKER}" || true' EXIT +emu/emu.sh create "${POS_WORKER}" +emu/emu.sh boot "${POS_WORKER}" +emu/emu.sh prepare "${POS_WORKER}" + +# suite.py exits non-zero only for harness errors. A scenario that finds +# something wrong with the app still reports `ok`, because the finding *is* +# the result -- so a failure here means the harness itself could not run, +# which is what config.ini's advisory flags are calibrated for. +cd driver +python3 suite.py "${SUITE_ARGS[@]}" +cd "${REPO_ROOT}" + +# Not `exec`: the trap above has to survive to shut the emulator down. +EC_DIR="${POS_SIM_ROOT}/run/coverage" +ls -l "${EC_DIR}" || true +EMULATOR_EC_DIR="${EC_DIR}" contrib/ci/jobs/5-coverage/job.sh