repro_qr_tab_crash.py (3216B)
1 # This file is part of GNU Taler 2 # (C) 2026 Taler Systems S.A. 3 # 4 # GNU Taler is free software; you can redistribute it and/or modify it under the 5 # terms of the GNU General Public License as published by the Free Software 6 # Foundation; either version 3, or (at your option) any later version. 7 # 8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License along with 13 # GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 14 """Selecting the QR configuration tab crashes the terminal. 15 16 Four steps from a fresh install: open the app with no configuration, tap 17 "QR config", wait for the camera's first frame, and the process is gone. 18 19 cd /tmp/taler-pos-sim/driver && . ../env.sh 20 python3 ../findings/repro_qr_tab_crash.py 21 22 Exits 0 when the crash reproduces, 1 when it does not. 23 """ 24 25 import os 26 import re 27 import subprocess 28 import sys 29 import time 30 from pathlib import Path 31 32 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) 33 34 from device import ADB, PKG, Device, serial_for 35 from pos import Pos 36 37 SERIAL = serial_for() 38 39 40 def main() -> int: 41 dev = Device(SERIAL) 42 app = Pos(dev) 43 44 print("1. a terminal with no configuration") 45 dev.stop() 46 dev.clear_data() 47 dev.grant_camera() 48 dev.launch() 49 screen = dev.wait_for(r"Merchant portal URL", timeout=90) 50 assert screen.find(r"^QR config$"), f"no QR tab: {screen.texts()}" 51 52 print("2. clearing the log so the crash cannot be confused with an older one") 53 dev.logcat(clear=True) 54 time.sleep(1) 55 56 print("3. tapping 'QR config'") 57 node = screen.find(r"^QR config$") 58 dev.tap_node(node, screen) 59 60 print("4. waiting for the camera's first frame") 61 time.sleep(10) 62 63 after = dev.dump() 64 # The default buffer set, not "-b crash": the crash buffer is empty on the 65 # emulator images this runs on, and naming it explicitly returns nothing at 66 # all -- which reads as "the app did not crash" while the launcher is on 67 # screen because it did. 68 log = subprocess.run([ADB, "-s", SERIAL, "logcat", "-d"], 69 capture_output=True, text=True).stdout 70 lines = log.splitlines() 71 crash = "" 72 for i, line in enumerate(lines): 73 if "FATAL EXCEPTION" in line: 74 block = "\n".join(lines[i:i + 16]) 75 if PKG in block: 76 crash = block 77 break 78 79 print() 80 print(f"activity now: {after.activity}") 81 print(f"screen now: {after.texts()[:8]}") 82 if crash: 83 print() 84 print(crash) 85 print() 86 print("REPRODUCED: the QR configuration tab crashed the terminal.") 87 return 0 88 print() 89 print("not reproduced: the terminal survived the QR tab. Either this is a " 90 "patched build, or this device's camera reports a rotation of 0 or " 91 "180 degrees -- check " 92 "'logcat -d | grep rotationDegrees' and the AVD's hw.camera.back.") 93 return 1 94 95 96 if __name__ == "__main__": 97 sys.exit(main())