taler-android

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

simulator.sh (4308B)


      1 #!/bin/bash
      2 # Nightly: drive the merchant terminal in a real emulator, and fold what that
      3 # reached into the coverage report.
      4 #
      5 # This is the integration half of `5-coverage`.  That job runs every JVM unit
      6 # test and says in its own header why the emulator suites are not part of it:
      7 # about three hours of emulator time has no business on every push.  So they
      8 # live here instead, this job runs only from the nightly scheduler
      9 # (`RUN_ON = nightly` in config.ini), and when the suite is done it hands its
     10 # execution data to 5-coverage's script through EMULATOR_EC_DIR -- the hook
     11 # that script already documents -- rather than growing a second report that
     12 # would disagree with the first.
     13 #
     14 # One emulator, deliberately.  The harness can drive five side by side, which
     15 # takes the suite from about three hours to about forty minutes, but the
     16 # container worker is shared with every other repository's CI and a nightly is
     17 # in no hurry.  POS_WORKER therefore stays 0.
     18 set -exuo pipefail
     19 
     20 REPO_ROOT="${PWD}"
     21 export POS_SIM_ROOT="${POS_SIM_ROOT:-${REPO_ROOT}/build/pos-sim}"
     22 export POS_WORKER=0
     23 # Deliberately word-split: these are arguments to suite.py, not one argument.
     24 read -r -a SUITE_ARGS <<< "${POS_SUITE_ARGS:---all}"
     25 
     26 # The terminal builds every merchant URL with a hard-coded `https://`, so a
     27 # backend the harness controls has to answer TLS, and the `sim` build type
     28 # carries the simulator's CA as an extra trust anchor.  That CA's private key
     29 # is deliberately not in git (see pos-simulator/tls/README.md): a certificate
     30 # without its key authorises nobody, which is what makes shipping ca.crt in a
     31 # never-published build type safe.  A CI checkout therefore has the
     32 # certificates and none of the keys, and has to generate its own set -- which
     33 # means rebuilding the APK, because the anchor is compiled into it.  Hence
     34 # before the build below, and not after.
     35 TLS=pos-simulator/tls
     36 if [ ! -r "${TLS}/ca.key" ]; then
     37     openssl req -x509 -newkey rsa:2048 -nodes \
     38         -keyout "${TLS}/ca.key" -out "${TLS}/ca.crt" -days 3650 \
     39         -subj '/CN=Taler POS simulator CA/O=GNU Taler/OU=pos-simulator' \
     40         -addext 'basicConstraints=critical,CA:TRUE' \
     41         -addext 'keyUsage=critical,keyCertSign,cRLSign'
     42     openssl req -newkey rsa:2048 -nodes \
     43         -keyout "${TLS}/srv.key" -out "${TLS}/srv.csr" -subj '/CN=localhost'
     44     openssl x509 -req -in "${TLS}/srv.csr" -CA "${TLS}/ca.crt" \
     45         -CAkey "${TLS}/ca.key" -CAcreateserial -out "${TLS}/srv.crt" \
     46         -days 3650 -extfile "${TLS}/srv.ext"
     47     cp "${TLS}/ca.crt" merchant-terminal/src/sim/res/raw/sim_ca.crt
     48 fi
     49 
     50 # The `sim` build type is `debug` plus the JaCoCo agent, the PosSimHooks
     51 # receiver the driver needs for the three things adb cannot do, and the trust
     52 # anchor above.  It is what the simulator drives; a plain debug APK would run
     53 # but report no coverage.
     54 ./gradlew --no-daemon :merchant-terminal:assembleSim
     55 APK=merchant-terminal/build/outputs/apk/sim/merchant-terminal-sim.apk
     56 test -s "${APK}"
     57 
     58 # The harness resolves tls/ and backend/ relative to its own file, not to
     59 # POS_SIM_ROOT, so the tree is copied whole instead of being run from the
     60 # checkout -- the same shape the README's rsync produces on a dedicated host.
     61 rm -rf "${POS_SIM_ROOT}"
     62 mkdir -p "${POS_SIM_ROOT}/apk"
     63 cp -a pos-simulator/. "${POS_SIM_ROOT}/"
     64 cp "${APK}" "${POS_SIM_ROOT}/apk/pos.apk"
     65 cd "${POS_SIM_ROOT}"
     66 . ./env.sh
     67 
     68 # Unconditional on the way out: an emulator that outlives the job keeps its
     69 # AVD lock files, and the next night's boot dies on them rather than on
     70 # anything to do with that night's code.
     71 trap '"${POS_SIM_ROOT}"/emu/emu.sh kill "${POS_WORKER}" || true' EXIT
     72 emu/emu.sh create  "${POS_WORKER}"
     73 emu/emu.sh boot    "${POS_WORKER}"
     74 emu/emu.sh prepare "${POS_WORKER}"
     75 
     76 # suite.py exits non-zero only for harness errors.  A scenario that finds
     77 # something wrong with the app still reports `ok`, because the finding *is*
     78 # the result -- so a failure here means the harness itself could not run,
     79 # which is what config.ini's advisory flags are calibrated for.
     80 cd driver
     81 python3 suite.py "${SUITE_ARGS[@]}"
     82 cd "${REPO_ROOT}"
     83 
     84 # Not `exec`: the trap above has to survive to shut the emulator down.
     85 EC_DIR="${POS_SIM_ROOT}/run/coverage"
     86 ls -l "${EC_DIR}" || true
     87 EMULATOR_EC_DIR="${EC_DIR}" contrib/ci/jobs/5-coverage/job.sh