Files
infix/test/console
T
Joachim Wiberg 5386ec9a3a test,doc,board: Infamy Made Easy
As of 4768cae6, we can use conserver/telnet to connect to the docker0
bridge IP:90XX, where XX is DUTXX.  This was a great UX improvement
and this patch set aims to further the experience by:

 - allow running Infamy (infix-test container) completely rootless¹
 - reduce the expsed port range 50->10 (can be improved further)
 - use 'podman --publish-all' ports, which allocates ten random
   ports for the exposed Qemu telnet ports
 - add Quick Start Guide to doc/testing.md

This restores the possiblity of running multiple "make test-sh"
instances, e.g., when multiple users share the same server.

The 'console' script included in this commit uses 'podman inspect' to
find the port number for a given DUT, and optional instance.  It takes
either the console/dut number (1-N), or the dut name from the topology.

Also in this commit:
 - set hostname for easy identification (for console script)
 - set conatainer --name to hostname
 - adjust workdir from buildroot to infix/test
 - simplify PS1 and add time to prompt (when did the test finish?)

When running 'make test-sh' the prompt now tells you which instance you
are running, e.g., infmay10.  Calling 'console 1 infamy10' connects to
console 1 (port 9001) on the infamy10 instance.

For more information, see the Quick Start Guide in doc/testing.md.  It
shows how to use the new helper scripts: console and shell.

Fix #227

_______
¹) devs using podman, instead of docker, with slirp4netns installed, can
   run the infix-test container completely rootless.  We like this, and
   as of today podman is our recommendation.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2024-02-25 19:49:27 +01:00

87 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Attach to console of a Qemu device (DUT) running in Infamy
#
# You can override Ctrl-] in your ~/.telnetrc
#
# DEFAULT
# environ define USER root
# set escape "^X"
#
# If you're unhappy with your telnet experience, Debian/Ubuntu
# systems have two telnet packages, Netkit and GNU Inetutils.
#
testdir=$(dirname "$(readlink -f "$0")")
. "$testdir/.env"
usage()
{
echo "Usage:"
echo " console DUT [SYSTEM]"
echo "Example:"
echo " console 1 # attach to DUT1 on infamy0"
echo " console dut3 infamy1 # attach to 'dut2' on infamy1"
echo " console cisco2 infamy2 # attach to DUT 'cisco2' on infamy2"
exit 1
}
topo()
{
dir=$(podman inspect "$1" 2>/dev/null | jq -re '.[].Args | index("-q") as $index | .[$index+1]')
dot="$dir/topology.dot.in"
[ -f "$dot" ] && echo "$dot"
}
list()
{
dot=$(topo "$1")
if [ -z "$dot" ]; then
echo ", cannot even find $1"
return
fi
echo ", available DUTs:"
gvpr 'N [$.qn_console] { print($.name); }' "$dot"
}
find()
{
dot=$(topo "$2")
[ -n "$dot" ] || return
gvpr '
N [$.name == "'"$1"'"] {
printf("%s\n", $.qn_console);
}
' "$dot"
}
dut=$1
if [ -z "$dut" ]; then
usage
exit 1
fi
sys=$2
[ -n "$sys" ] || sys=$(infamy)
if test "$dut" -eq "$dut" 2>/dev/null; then
port=$((9000 + dut))
else
port=$(find "$dut" "$sys")
if [ -z "$port" ]; then
printf "Cannot find port for %s on %s" "$dut" "$sys"
list "$sys"
exit 1
fi
fi
portmap=$($(runner) port "$sys" $port)
port=${portmap#0.0.0.0:}
if [ -z "$port" ]; then
echo "Cannot find DUT$dut telnet port $port on $sys (port map $portmap)"
exit 1
fi
telnet 127.0.0.1 "$port"