Files
makronix/mobile/tools/userland-test.sh
T
lotherkandClaude Sonnet 5.5 73c9de51a6 licence: the CNCL line in every file Makronix wrote (tools, docs, www, mobile, top level)
consmirror.c: the BSD notice is replaced (Makronix's own file).  Files with
changes of other sessions pending are left for their commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:50:26 +00:00

48 lines
1.9 KiB
Bash

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# Run a port's test (mobile/userland/<prog>/test.sh) on the phone
# (docs/NETBSD-USERLAND.md, A8). The program, the test and the test data
# of NetBSD's own test (src/tests/<MX_SRCDIR>, if it exists) are copied to
# /tmp/userland-test/<prog> on the phone and run there; nothing goes to
# /system, the image's own program of that name is not touched.
#
# Usage: userland-test.sh DEVICEDIR PROG [--qemu]
# --qemu run on the host under qemu-aarch64 with the sysroot instead
set -eu
. "$(dirname "$0")/lib.sh"
[ $# -ge 2 ] || { echo "usage: $0 DEVICEDIR PROG [--qemu]" >&2; exit 2; }
load_device "$1"
prog=$2 mode=${3:-phone}
dev=$(basename "$DEVDIR")
port=$ROOT/userland/$prog
[ -f "$port/test.sh" ] || die "no $port/test.sh"
srcdir=$(sed -n 's/^MX_SRCDIR=[[:space:]]*//p' "$port/Makefile")
local=$(sed -n 's/^MX_LOCALSRC=[[:space:]]*//p' "$port/Makefile")
[ -n "$srcdir$local" ] || die "no MX_SRCDIR or MX_LOCALSRC in $port/Makefile"
destdir=$ROOT/build/userland/$dev/destdir
bin=$(cd "$destdir" && find usr -type f -name "$prog" -perm -u+x | head -n 1)
[ -n "$bin" ] || die "$prog is not installed in $destdir (make userland PROG=$prog)"
tests=
[ -z "$srcdir" ] || [ ! -d "$ROOT/../src/tests/$srcdir" ] ||
tests=$ROOT/../src/tests/$srcdir
case $mode in
--qemu)
sh "$port/test.sh" "qemu-aarch64 -L $ROOT/build/sysroot-$dev $destdir/$bin" \
"${tests:-/nonexistent}"
;;
phone)
a=$(phone_addr) || die "phone not reachable"
r=/tmp/userland-test/$prog
phone_ssh "$a" "rm -rf $r && mkdir -p $r/data"
tar -C "$destdir" -cf - "$bin" | phone_ssh "$a" "tar -C $r -xf -"
tar -C "$port" -cf - test.sh | phone_ssh "$a" "tar -C $r -xf -"
[ -z "$tests" ] || tar -C "$tests" -cf - . | phone_ssh "$a" "tar -C $r/data -xf -"
phone_ssh "$a" "cd $r && sh test.sh $r/$bin $r/data"
;;
*) die "unknown mode $mode" ;;
esac