SPB Git

Repository Public

run-scenarios.sh 4.0 KB 98 lines shellscript

1#!/bin/bash2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : KA Maps Engine8# File             : sdk/ios/Scripts/run-scenarios.sh9# Module           : sdk10# Repository       : https://git.spboucher.ai/ka-maps-engine11# Created          : 2026-12-0112# Last Modified    : 2026-12-0113#14# Author           : Simon-Pierre Boucher15# Position         : Professor of Finance16# Institution      : Université du Québec en Outaouais (UQO)17# Organization     : SP Boucher18# Website          : https://spboucher.ai19# Git              : https://git.spboucher.ai20#21# Preferred Contact: support@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin   : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# License          : None specified (no license file in this repository)32#33# Do not embed credentials, private keys, access tokens,34# certificates or confidential personal information.35#36# =============================================================================37# END OF SP BOUCHER SOURCE HEADER38# =============================================================================3940# Lance des scénarios de l'application d'exemple sur un simulateur DÉJÀ démarré, sans fenêtre41# (jamais d'ouverture de Simulator.app), photographie l'écran à chaque point de capture et rapatrie42# les résultats JSON.43#44# Usage : run-scenarios.sh <udid> <dossier-de-sortie> <scénarios séparés par des virgules | all> [arguments de lancement…]45# Variables : KAMAPS_APP (chemin du .app ; défaut : DerivedData /tmp/kamaps-dd), KAMAPS_TIMEOUT (s, défaut 600),46#             KAMAPS_ENV="CLE=valeur CLE2=valeur" (environnement du processus, ex. MTL_DEBUG_LAYER=1).47set -euo pipefail48UDID="$1"; OUT="$2"; SCEN="$3"; shift 349BUNDLE=com.spboucher.kamaps.example50APP="${KAMAPS_APP:-/tmp/kamaps-dd/Build/Products/Debug-iphonesimulator/KAMapsExample.app}"51TIMEOUT="${KAMAPS_TIMEOUT:-600}"52mkdir -p "$OUT/shots" "$OUT/results"5354xcrun simctl terminate "$UDID" "$BUNDLE" >/dev/null 2>&1 || true55xcrun simctl install "$UDID" "$APP"56DATA="$(xcrun simctl get_app_container "$UDID" "$BUNDLE" data)"57rm -f "$DATA/Documents/done.txt" "$DATA/Documents/checkpoint.txt"58rm -rf "$DATA/Documents/results"5960ENVV=()61for kv in ${KAMAPS_ENV:-}; do ENVV+=("SIMCTL_CHILD_$kv"); done62LOG="$OUT/console-$(echo "$SCEN" | tr ',' '-').log"63env "${ENVV[@]+"${ENVV[@]}"}" xcrun simctl launch --console-pty "$UDID" "$BUNDLE" -scenario "$SCEN" "$@" >"$LOG" 2>&1 &64LAUNCH=$!6566last=""67t0=$(date +%s)68status=169while :; do70  if [ -f "$DATA/Documents/checkpoint.txt" ]; then71    cp="$(cat "$DATA/Documents/checkpoint.txt" 2>/dev/null || true)"72    if [ -n "$cp" ] && [ "$cp" != "$last" ]; then73      last="$cp"74      name="${cp#* }"75      xcrun simctl io "$UDID" screenshot --type=png "$OUT/shots/$name.png" >/dev/null 2>&1 || true76    fi77  fi78  if [ -f "$DATA/Documents/done.txt" ]; then79    echo "== $(cat "$DATA/Documents/done.txt")"80    grep -q "^DONE ok" "$DATA/Documents/done.txt" && status=081    break82  fi83  if ! kill -0 "$LAUNCH" 2>/dev/null; then84    echo "== l'application s'est arrêtée avant la fin (voir $LOG)"; break85  fi86  if [ $(( $(date +%s) - t0 )) -gt "$TIMEOUT" ]; then87    echo "== délai dépassé ($TIMEOUT s)"; break88  fi89  sleep 0.1590done91cp "$DATA/Documents/results/"*.json "$OUT/results/" 2>/dev/null || true92xcrun simctl terminate "$UDID" "$BUNDLE" >/dev/null 2>&1 || true93kill "$LAUNCH" 2>/dev/null || true94for f in "$OUT/results/"*.json; do95  [ -f "$f" ] && python3 -c "import json,sys; d=json.load(open(sys.argv[1])); print(('OK  ' if d['ok'] else 'FAIL'), d['scenario'], d['seconds'], 's', '' if d['ok'] else d['error'])" "$f"96done97exit $status98
Files main
Menu

Theme