#!/usr/bin/env bats
load helpers
# `radio` reads a fake sysfs, /dev, /proc and lock directory. USB devices are
# made under one root hub (usb1); a radio's serial chip and sound card sit
# behind its own hub, as they do in the real radios.
setup() {
setup_fake_home
export RADIO_SYSFS="$BATS_TEST_TMPDIR/sys"
export RADIO_DEV="$BATS_TEST_TMPDIR/dev"
export RADIO_PROC="$BATS_TEST_TMPDIR/proc"
export RADIO_LOCKDIR="$BATS_TEST_TMPDIR/lock"
export FAKE_RADIOS="$BATS_TEST_TMPDIR/radios"
ROOT_HUB="$RADIO_SYSFS/devices/pci0000:00/0000:00:14.0/usb1"
REAL_PYTHON3="$(command -v python3)"
export REAL_PYTHON3
unset XDG_DATA_HOME XDG_CONFIG_HOME UV_TOOL_DIR
# PipeWire's sources and sinks, as `pactl -f json list` prints them: none
# unless a test calls pipewire_card
stub pactl '[ -f "$FAKE_RADIOS/pw-$4" ] && cat "$FAKE_RADIOS/pw-$4" || echo "[]"'
mkdir -p "$ROOT_HUB" "$RADIO_SYSFS/class/tty" "$RADIO_SYSFS/class/sound" \
"$RADIO_DEV/serial/by-id" "$RADIO_PROC" "$RADIO_LOCKDIR" "$FAKE_RADIOS"
}
# usb PATH VID:PID [MANUFACTURER PRODUCT SERIAL]: a USB device under the root hub
usb() {
local dir="$ROOT_HUB/$1"
mkdir -p "$dir"
echo "${2%:*}" > "$dir/idVendor"
echo "${2#*:}" > "$dir/idProduct"
[ -z "${3:-}" ] || echo "$3" > "$dir/manufacturer"
[ -z "${4:-}" ] || echo "$4" > "$dir/product"
[ -z "${5:-}" ] || echo "$5" > "$dir/serial"
}
# port USBPATH TTY [BY-ID]: a serial port on interface N of the device, with a
# /dev/serial/by-id link if BY-ID is given
port() {
local iface="$ROOT_HUB/$1/${1##*/}:1.${4:-0}"
mkdir -p "$iface/$2/tty/$2" "$RADIO_SYSFS/class/tty/$2"
ln -s "$iface/$2" "$RADIO_SYSFS/class/tty/$2/device"
touch "$RADIO_DEV/$2"
[ -z "${3:-}" ] || ln -s "../../$2" "$RADIO_DEV/serial/by-id/$3"
}
# card USBPATH CARD ID: a sound card on the device
card() {
local iface="$ROOT_HUB/$1/${1##*/}:1.0"
mkdir -p "$iface/sound/$2" "$RADIO_SYSFS/class/sound/$2"
ln -s "$iface" "$RADIO_SYSFS/class/sound/$2/device"
echo "$3" > "$RADIO_SYSFS/class/sound/$2/id"
}
# A card's PCM devices: pcm CARD p|c..., playback and capture
pcm() {
local n="${1#card}" dir
shift
for dir; do mkdir -p "$RADIO_SYSFS/class/sound/pcmC${n}D0$dir"; done
}
# A hidraw device on a USB device, which you can open unless "locked", with
# udev's links in /dev/input if BY_ID is given: hidraw USBPATH HIDRAW [locked|open] [BY_ID]
hidraw() {
local iface="$ROOT_HUB/$1/${1##*/}:1.3"
mkdir -p "$iface/hidraw/$2" "$RADIO_SYSFS/class/hidraw/$2"
ln -s "$iface" "$RADIO_SYSFS/class/hidraw/$2/device"
touch "$RADIO_DEV/$2"
[ "${3:-}" != locked ] || chmod 000 "$RADIO_DEV/$2"
if [ -n "${4:-}" ]; then
mkdir -p "$RADIO_DEV/input/by-id" "$RADIO_DEV/input/by-path"
ln -sfn "../../$2" "$RADIO_DEV/input/by-id/$4-hidraw"
ln -s "../../$2" "$RADIO_DEV/input/by-path/pci-0000:00:14.0-usb-0:${1##*/}:1.3-hidraw"
fi
}
# A computer's own sound card, not on USB
onboard_card() {
mkdir -p "$RADIO_SYSFS/devices/pci0000:00/0000:00:1f.3/sound/card0" "$RADIO_SYSFS/class/sound/card0"
ln -s "$RADIO_SYSFS/devices/pci0000:00/0000:00:1f.3" "$RADIO_SYSFS/class/sound/card0/device"
echo PCH > "$RADIO_SYSFS/class/sound/card0/id"
}
ic7300() {
usb 1-2 10c4:0001
usb 1-2/1-2.1 10c4:ea60 "Silicon Labs" "CP2102 USB to UART Bridge Controller" "IC-7300 03001234"
port 1-2/1-2.1 ttyUSB0 usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0
usb 1-2/1-2.2 08bb:29c0 "Burr-Brown from TI" "USB Audio CODEC"
card 1-2/1-2.2 card1 CODEC
}
# A Yaesu: a CP2105 with two ports, and a sound card, behind its own hub
yaesu() {
usb "$1" 0424:2512
usb "$1/$1.1" 10c4:ea70 "Silicon Labs" "CP2105 Dual USB to UART Bridge Controller" "${2:-00A50791}"
port "$1/$1.1" "${3:-ttyUSB0}" "" 0
port "$1/$1.1" "${4:-ttyUSB1}" "" 1
usb "$1/$1.2" 08bb:2902 "Burr-Brown from TI" "USB Audio CODEC"
card "$1/$1.2" "${5:-card1}" "${6:-CODEC}"
}
# PipeWire lists ALSA card NUMBER as a USB codec, with a monitor source
# first, as PipeWire lists them: pipewire_card NUMBER [DESCRIPTION]
pipewire_card() {
local desc="${2:-USB Audio CODEC}"
jq -n --arg n "$1" --arg desc "$desc" '[
{name: "alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo.monitor", description: ("Monitor of " + $desc + " Analog Stereo"),
properties: {"alsa.card": $n, "device.class": "monitor"}},
{name: "alsa_input.pci-0000_00_1f.3.analog-stereo", description: "Built-in Audio Analog Stereo",
properties: {"alsa.card": "0", "device.class": "sound"}},
{name: "alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback", description: ($desc + " Mono"),
properties: {"alsa.card": $n, "device.class": "sound"}}]' > "$FAKE_RADIOS/pw-sources"
jq -n --arg n "$1" --arg desc "$desc" '[
{name: "alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo", description: ($desc + " Analog Stereo"),
properties: {"alsa.card": $n, "device.class": "sound"}}]' > "$FAKE_RADIOS/pw-sinks"
}
# The sound devices PortAudio lists: pa_devices NAME|INPUTS|OUTPUTS... Names
# with (hw:...) are ALSA's, as are pipewire and default; the rest are JACK's
pa_devices() {
local device name
for device; do
name="${device%%|*}"
case "$name" in
*"(hw:"* | pipewire | default) printf '%s\tALSA\t' "$name" ;;
*) printf '%s\tJACK Audio Connection Kit\t' "$name" ;;
esac
device="${device#*|}"
printf '%s\t%s\n' "${device%|*}" "${device#*|}"
done > "$FAKE_RADIOS/pa-devices"
}
# The radio on a port answers the probe with ANSWER ("38400 cat_id 0670")
answers() {
echo "$2" > "$FAKE_RADIOS/$1"
# The probe and PortAudio's device list are faked; other Python (QLog's
# log, Graywolf's settings) runs for real
stub python3 '
case "$3" in
*TIOCMBIC*) f="$FAKE_RADIOS/${4##*/}"; [ -f "$f" ] && cat "$f"; exit 0 ;;
*Pa_Initialize*) cat "$FAKE_RADIOS/pa-devices" 2> /dev/null; exit 0 ;;
esac
exec "$REAL_PYTHON3" "$@"'
}
@test "recognises an Icom by its USB serial number, with its port and sound card" {
onboard_card
ic7300
run bash "$REPO/radio"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[1]}" = " Serial port: /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0" ]
[ "${lines[2]}" = " Sound card: hw:CARD=CODEC (card1)" ]
[[ "${lines[3]}" == " USB: 10c4:ea60 Silicon Labs CP2102 USB to UART Bridge Controller, serial IC-7300 03001234" ]]
[ ${#lines[@]} -eq 4 ]
}
@test "doesn't talk to a radio it can't recognise unless asked to" {
yaesu 1-3
answers ttyUSB0 "38400 cat_id 0670"
run bash "$REPO/radio" detect
[ "$status" -eq 0 ]
[ "${lines[0]}" = "1. Unknown radio or interface" ]
[ "${lines[1]}" = " Serial port: /dev/ttyUSB0" ]
[ "${lines[2]}" = " Serial port: /dev/ttyUSB1" ]
[ "${lines[3]}" = " Sound card: hw:CARD=CODEC (card1)" ]
[[ "$output" == *"Run \`radio detect --probe\` to ask it what it is"* ]]
! grep -q python3 "$STUB_LOG"
}
@test "--probe asks each port until one answers, and marks it the CAT port" {
yaesu 1-3
answers ttyUSB1 "38400 cat_id 0670"
run bash "$REPO/radio" detect --probe
[ "$status" -eq 0 ]
[ "${lines[0]}" = "1. Yaesu FT-991A (Hamlib model 1035), answered on ttyUSB1 at 38400 baud" ]
[ "${lines[1]}" = " Serial port: /dev/ttyUSB0" ]
[ "${lines[2]}" = " CAT port: /dev/ttyUSB1" ]
[ "$(grep -c '^python3' "$STUB_LOG")" -eq 2 ]
}
@test "--probe recognises an Icom by its CI-V address" {
usb 1-4 0403:6001 FTDI "FT232R USB UART" A12345
port 1-4 ttyUSB0
answers ttyUSB0 "19200 civ 94"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), answered on ttyUSB0 at 19200 baud" ]
[ "${lines[2]}" = " Sound card: none found with it" ]
}
@test "lists every radio a reply could come from, when nothing narrows it" {
usb 1-4 0403:6001 FTDI "FT232R USB UART" A12345
port 1-4 ttyUSB0
answers ttyUSB0 "38400 cat_id 017"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "1. One of: Elecraft K3 (Hamlib model 2029), Elecraft K3S (Hamlib model 2043), Elecraft KX3 (Hamlib model 2045), Elecraft KX2 (Hamlib model 2044), Elecraft K4 (Hamlib model 2047), answered on ttyUSB0 at 38400 baud" ]
}
@test "says what answered when it doesn't know the radio" {
usb 1-4 0403:6001
port 1-4 ttyUSB0
answers ttyUSB0 "9600 civ 5E"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "1. An Icom radio at CI-V address 5E that radio doesn't know, answered on ttyUSB0 at 9600 baud" ]
}
@test "says when nothing answers" {
usb 1-4 0403:6001
port 1-4 ttyUSB0
answers ttyUSB1 "38400 cat_id 0670"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "1. Unknown radio or interface" ]
[[ "$output" == *"Nothing answered. If it's a radio, check it's switched on"* ]]
}
@test "won't probe a port another program has open or locked" {
yaesu 1-3
answers ttyUSB0 "38400 cat_id 0670"
mkdir -p "$RADIO_PROC/4242/fd"
echo rigctld > "$RADIO_PROC/4242/comm"
ln -s "$RADIO_DEV/ttyUSB0" "$RADIO_PROC/4242/fd/5"
touch "$RADIO_LOCKDIR/LCK..ttyUSB1"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "1. Unknown radio or interface" ]
[[ "$output" == *"Couldn't ask on ttyUSB0: $RADIO_DEV/ttyUSB0 is in use by rigctld (process 4242)"* ]]
[[ "$output" == *"Couldn't ask on ttyUSB1: $RADIO_DEV/ttyUSB1 is locked by another program"* ]]
[[ "$output" != *"Nothing answered"* ]]
! grep -q python3 "$STUB_LOG"
}
@test "pairs each radio with its own sound card" {
onboard_card
ic7300
yaesu 1-3 00B00001 ttyUSB1 ttyUSB2 card2 CODEC_1
run bash "$REPO/radio"
[ "$status" -eq 0 ]
# bats leaves the blank line between radios out of lines
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[2]}" = " Sound card: hw:CARD=CODEC (card1)" ]
[ "${lines[4]}" = "2. Unknown radio or interface" ]
[ "${lines[5]}" = " Serial port: /dev/ttyUSB1" ]
[ "${lines[6]}" = " Serial port: /dev/ttyUSB2" ]
[ "${lines[7]}" = " Sound card: hw:CARD=CODEC_1 (card2)" ]
}
@test "pairs a serial port and sound card that are one USB device" {
usb 1-5 0c26:0036 Icom "IC-705" "IC-705 12001234"
port 1-5 ttyACM0 "" 0
card 1-5 card1 IC705
run bash "$REPO/radio"
[ "${lines[0]}" = "1. Icom IC-705 (Hamlib model 3085), recognised by its USB serial number" ]
[ "${lines[2]}" = " Sound card: hw:CARD=IC705 (card1)" ]
}
@test "doesn't pair a port with a sound card on a hub with other things on it" {
usb 1-6 05e3:0610
usb 1-6/1-6.1 0403:6001 FTDI "FT232R USB UART" A12345
port 1-6/1-6.1 ttyUSB0
usb 1-6/1-6.2 0d8c:0012 C-Media "USB Audio Device"
card 1-6/1-6.2 card1 Device
usb 1-6/1-6.3 046d:c52b Logitech "USB Receiver"
run bash "$REPO/radio"
[ "${lines[2]}" = " Sound card: none found with it" ]
}
@test "doesn't pair a port with a sound card plugged straight into the computer" {
usb 1-4 0403:6001
port 1-4 ttyUSB0
usb 1-5 0d8c:0012 C-Media "USB Audio Device"
card 1-5 card1 Device
run bash "$REPO/radio"
[ "${lines[2]}" = " Sound card: none found with it" ]
}
@test "says when there's nothing plugged in" {
onboard_card
run bash "$REPO/radio"
[ "$status" -eq 1 ]
[ "$output" = "No USB serial ports found: is the radio plugged in and switched on?" ]
}
@test "probe asks one port" {
touch "$RADIO_DEV/ttyUSB3"
answers ttyUSB3 "4800 cat_id 024"
run bash "$REPO/radio" probe "$RADIO_DEV/ttyUSB3"
[ "$status" -eq 0 ]
[ "$output" = "Kenwood TS-890S (Hamlib model 2041), at 4800 baud" ]
}
@test "probe says how to get into the serial port's group" {
touch "$RADIO_DEV/ttyUSB3"
chmod 000 "$RADIO_DEV/ttyUSB3"
# Owned by uucp, as real serial ports are
local group=uucp
stub stat 'echo uucp'
run bash "$REPO/radio" probe "$RADIO_DEV/ttyUSB3"
[ "$status" -eq 1 ]
[[ "$output" == *"add yourself to the $group group with \`sudo usermod -aG $group $USER\`"* ]]
# In the group, but this login started before
echo "$group" > "$FAKE_GROUPS"
export FAKE_SESSION_GROUPS="$BATS_TEST_TMPDIR/session-groups"
: > "$FAKE_SESSION_GROUPS"
run bash "$REPO/radio" probe "$RADIO_DEV/ttyUSB3"
[[ "$output" == *"you can't open $RADIO_DEV/ttyUSB3 yet: log out and back in, so you're in the $group group"* ]]
}
@test "probe says why it can't open a port" {
run bash "$REPO/radio" probe "$RADIO_DEV/ttyUSB9"
[ "$status" -eq 1 ]
[[ "$output" == *"Can't ask: $RADIO_DEV/ttyUSB9 doesn't exist"* ]]
}
@test "unknown commands print usage" {
run bash "$REPO/radio" frobnicate
[ "$status" -eq 2 ]
[[ "$output" == *"Usage: radio"* ]]
}
# The real probe, talking to a fake radio on a pseudo-terminal
fake_radio() {
cat > "$BATS_TEST_TMPDIR/fake_radio.py" << 'EOF'
import os, select, sys, time, tty
master, slave = os.openpty()
tty.setraw(slave)
with open(sys.argv[1] + ".new", "w") as f:
f.write(os.ttyname(slave))
os.rename(sys.argv[1] + ".new", sys.argv[1])
civ_request = bytes.fromhex("fefe00e01900fd")
heard, end = b"", time.monotonic() + 20
while time.monotonic() < end:
if not select.select([master], [], [], 0.1)[0]:
continue
heard += os.read(master, 256)
if sys.argv[2] == "kenwood" and b"ID;" in heard:
os.write(master, b"ID0761;")
heard = b""
if sys.argv[2] == "elecraft" and b"ID;" in heard:
os.write(master, b"ID017;")
heard = b""
if sys.argv[2] == "elecraft" and b"OM;" in heard:
os.write(master, b"OM AP--------02;")
heard = b""
if sys.argv[2] == "icom" and civ_request in heard:
# With CI-V USB echo on, the radio echoes the request first
os.write(master, civ_request + bytes.fromhex("fefee0a41900a4fd"))
heard = b""
EOF
python3 "$BATS_TEST_TMPDIR/fake_radio.py" "$BATS_TEST_TMPDIR/pty" "$1" 3>&- &
FAKE_RADIO_PID=$!
local i
for i in $(seq 50); do
[ -f "$BATS_TEST_TMPDIR/pty" ] && break
sleep 0.1
done
PTY="$(cat "$BATS_TEST_TMPDIR/pty")"
}
teardown() {
[ -z "${FAKE_RADIO_PID:-}" ] || kill "$FAKE_RADIO_PID" 2> /dev/null || true
}
@test "probe hears a Kenwood-style answer from a real port" {
fake_radio kenwood
run bash "$REPO/radio" probe "$PTY"
[ "$status" -eq 0 ]
[ "$output" = "Yaesu FTDX10 (Hamlib model 1042), at 38400 baud" ]
}
@test "probe hears an Icom's answer over its echo, from a real port" {
fake_radio icom
run bash "$REPO/radio" probe "$PTY"
[ "$status" -eq 0 ]
[ "$output" = "Icom IC-705 (Hamlib model 3085), at 38400 baud" ]
}
@test "probe says when nothing answers on a real port" {
fake_radio silent
run bash "$REPO/radio" probe "$PTY"
[ "$status" -eq 1 ]
[ "$output" = "Nothing answered on $PTY at 38400 115200 19200 9600 4800 baud" ]
}
# --- radio configure ---
WSJTX_INI() { echo "$HOME/.var/app/io.sourceforge.wsjt.wsjtx/config/WSJT-X.ini"; }
PTT_CAT='PTTMethod=@Variant(\0\0\0\x7f\0\0\0\x1eTransceiverFactory::PTTMethod\0\0\0\0\xfPTT_method_CAT\0)'
# An IC-7300 that answers, with WSJT-X, JS8Call and Pat installed and none
# running. rigctld's service is running if $FAKE_RADIOS/rigctld-active exists;
# programs named in $FAKE_RUNNING are running
configurable() {
ic7300
answers ttyUSB0 "38400 civ 94"
touch "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx"
touch "$HOME/.local/bin/JS8Call"
chmod +x "$HOME/.local/bin/JS8Call"
stub pat 'exit 0'
stub pgrep '[[ " ${FAKE_RUNNING:-} " == *" $2 "* ]]'
stub systemctl '[ "$*" != "--user is-active --quiet hampack-rigctld" ] || [ -f "$FAKE_RADIOS/rigctld-active" ]'
mkdir -p "$HOME/.config/pat"
cat > "$HOME/.config/pat/config.json" << 'JSON'
{"mycall": "N0CALL", "hamlib_rigs": {}, "ardop": {"addr": "localhost:8515", "rig": ""},
"varahf": {"addr": "localhost:8300", "rig": "ft991"}, "varafm": {"addr": "localhost:8300", "rig": ""}}
JSON
chmod 600 "$HOME/.config/pat/config.json"
stub fldigi 'exit 0'
stub flrig 'exit 0'
mkdir -p "$HOME/.fldigi"
printf '\n\n\nN0CALL\n\n0\n\n0\n\n0\n\n/dev/rig\n\n\n' > "$HOME/.fldigi/fldigi_def.xml"
touch "$HOME/.local/bin/direwolf"
chmod +x "$HOME/.local/bin/direwolf"
mkdir -p "$HAMPACK_STATE/conf.d"
cp "$REPO/conf.d/direwolf.conf" "$HAMPACK_STATE/conf.d/"
touch "$HOME/.local/bin/not1mm"
chmod +x "$HOME/.local/bin/not1mm"
mkdir -p "$HOME/.config/not1mm"
echo '{"mycall": "N0CALL", "userigctld": false, "useflrig": false, "usetci": false, "CAT_ip": "127.0.0.1", "CAT_port": 12345, "sounddevice": "default"}' > "$HOME/.config/not1mm/not1mm.json"
pa_devices "HD-Audio Generic: ALC897 Analog (hw:0,0)|2|2" "USB Audio CODEC: USB Audio (hw:1,0)|1|2" "pipewire|64|64" "default|64|64"
touch "$FAKE_FLATPAKS/io.github.foldynl.QLog"
qlog_log
touch "$HOME/.local/bin/POTACAT.AppImage" "$HOME/.local/bin/graywolf"
chmod +x "$HOME/.local/bin/POTACAT.AppImage" "$HOME/.local/bin/graywolf"
mkdir -p "$HOME/.config/potacat"
echo '{"grid": "FN20jb", "catTarget": null, "firstRun": false}' > "$(POTACAT_JSON)"
graywolf_db 1:1
}
FLDIGI_XML() { echo "$HOME/.fldigi/fldigi_def.xml"; }
NOT1MM_JSON() { echo "$HOME/.config/not1mm/not1mm.json"; }
QLOG_DB() { echo "$HOME/.var/app/io.github.foldynl.QLog/data/hamradio/QLog/qlog.db"; }
# QLog's log, with rig_profiles as QLog 0.54 has it, and a QSO to show the
# rest of the log is untouched. qlog_log [old] leaves out the newest column
qlog_log() {
mkdir -p "$(dirname "$(QLOG_DB)")"
"$REAL_PYTHON3" -I - "$(QLOG_DB)" "${1:-}" << 'PY'
import sqlite3, sys
columns = ("profile_name TEXT PRIMARY KEY, model NUMBER NOT NULL, port_pathname TEXT, hostname TEXT, "
"netport NUMBER, baudrate NUMBER, databits NUMBER, stopbits REAL, flowcontrol TEXT, parity TEXT, "
"pollinterval INTEGER, txfreq_start REAL, txfreq_end REAL, get_freq INTEGER, get_mode INTEGER, "
"get_vfo INTEGER, get_pwr INTEGER, rit_offset REAL, xit_offset REAL, get_rit INTEGER, get_xit INTEGER, "
"get_ptt INTEGER DEFAULT 0, default_pwr REAL DEFAULT 100.0, qsy_wiping INTEGER DEFAULT 0, "
"get_key_speed INTEGER DEFAULT 1, assigned_cw_key TEXT DEFAULT ' ', key_speed_sync INTEGER DEFAULT 0, "
"dxspot2rig INTEGER DEFAULT 0, driver INTEGER DEFAULT 0, selected INTEGER, ptt_type TEXT, "
"ptt_port_pathname TEXT, rts TEXT, dtr TEXT, civaddr INTEGER, get_split INTEGER DEFAULT 0, "
"share_rigctld INTEGER DEFAULT 0, rigctld_port INTEGER DEFAULT 4532, rigctld_path TEXT, rigctld_args TEXT")
if sys.argv[2] != "old":
columns += ", cwkey_output INTEGER DEFAULT 0"
con = sqlite3.connect(sys.argv[1])
con.execute("PRAGMA journal_mode = WAL")
con.execute("CREATE TABLE rig_profiles (%s)" % columns)
con.execute("CREATE TABLE contacts (callsign TEXT)")
con.execute("INSERT INTO contacts VALUES ('W1AW')")
con.commit()
con.close()
PY
}
POTACAT_JSON() { echo "$HOME/.config/potacat/settings.json"; }
GRAYWOLF_DB() { echo "$HOME/.local/share/graywolf/graywolf.db"; }
# Graywolf's settings, with its channels and ptt_configs tables as 0.14.14
# has them: graywolf_db CHANNEL:OUTPUT_DEVICE... (0 is receive-only)
graywolf_db() {
mkdir -p "$(dirname "$(GRAYWOLF_DB)")"
"$REAL_PYTHON3" -I - "$(GRAYWOLF_DB)" "$@" << 'PY'
import sqlite3, sys
con = sqlite3.connect(sys.argv[1])
con.execute("PRAGMA journal_mode = WAL")
con.execute("CREATE TABLE audio_devices (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, direction TEXT NOT NULL DEFAULT 'input', "
"source_type TEXT NOT NULL, source_path TEXT, sample_rate INTEGER NOT NULL DEFAULT 48000, channels INTEGER NOT NULL DEFAULT 1, "
"format TEXT NOT NULL DEFAULT 's16le', gain_db REAL NOT NULL DEFAULT 0, created_at DATETIME, updated_at DATETIME)")
con.execute("CREATE TABLE channels (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, input_device_id INTEGER, "
"input_channel INTEGER NOT NULL DEFAULT 0, output_device_id INTEGER NOT NULL DEFAULT 0, output_channel INTEGER NOT NULL DEFAULT 0, "
"modem_type TEXT NOT NULL DEFAULT 'afsk', bit_rate INTEGER NOT NULL DEFAULT 1200, mode TEXT NOT NULL DEFAULT 'aprs', "
"created_at DATETIME, updated_at DATETIME, enabled NUMERIC NOT NULL DEFAULT true)")
con.execute("CREATE TABLE ptt_configs (id INTEGER PRIMARY KEY AUTOINCREMENT, channel_id INTEGER NOT NULL UNIQUE, "
"method TEXT NOT NULL DEFAULT 'none', device TEXT, gpio_pin INTEGER, ptt_method INTEGER NOT NULL DEFAULT 0, "
"gpio_line INTEGER NOT NULL DEFAULT 0, invert NUMERIC NOT NULL DEFAULT false, slot_time_ms INTEGER NOT NULL DEFAULT 10, "
"persist INTEGER NOT NULL DEFAULT 63, dwait_ms INTEGER NOT NULL DEFAULT 0, created_at DATETIME, updated_at DATETIME)")
for arg in sys.argv[2:]:
channel, output = arg.split(":")
con.execute("INSERT INTO channels (id, name, output_device_id) VALUES (?, ?, ?)", (int(channel), "ch" + channel, int(output)))
con.commit()
con.close()
PY
}
qlog_query() { "$REAL_PYTHON3" -I -c 'import sqlite3, sys
con = sqlite3.connect(sys.argv[1])
for row in con.execute(sys.argv[2]): print("|".join(map(str, row)))
con.commit()' "${2:-$(QLOG_DB)}" "$1"; }
DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
@test "configure runs rigctld for the radio on its stable port, at the rate it answered" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the Icom IC-7300 (Hamlib model 3073), on /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0 at 38400 baud" ]
local unit="$HOME/.config/systemd/user/hampack-rigctld.service"
grep -qx "ExecStart=/usr/bin/rigctld -m 3073 -r /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0 -s 38400 -T 127.0.0.1 -t 4532" "$unit"
grep -qx "systemctl --user reenable hampack-rigctld" "$STUB_LOG"
grep -qx "systemctl --user restart hampack-rigctld" "$STUB_LOG"
[[ "$output" == *"PipeWire didn't list the radio's sound card, hw:CARD=CODEC (\"USB Audio CODEC\"), so choose it yourself in WSJT-X, JS8Call and POTACAT."* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
grep -qx "card=hw:CARD=CODEC" "$HAMPACK_STATE/radio"
}
@test "configure stops its own rigctld to ask the radio, and starts it again if that fails" {
configurable
touch "$FAKE_RADIOS/rigctld-active"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
# Stopped before python3 asked the radio
local stopped asked
stopped="$(grep -n '^systemctl --user stop hampack-rigctld' "$STUB_LOG" | cut -d: -f1)"
asked="$(grep -n '^python3' "$STUB_LOG" | head -1 | cut -d: -f1)"
[ -n "$stopped" ] && [ "$stopped" -lt "$asked" ]
: > "$STUB_LOG"
rm "$FAKE_RADIOS/ttyUSB0"
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"Couldn't set it up: nothing answered on ttyUSB0."* ]]
grep -qx "systemctl --user start hampack-rigctld" "$STUB_LOG"
}
@test "configure sets up a new WSJT-X, and one with no rig, keeping its other settings" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: rig control through rigctld, PTT by CAT"* ]]
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
grep -qx "CATNetworkPort=127.0.0.1:4532" "$(WSJTX_INI)"
grep -qxF "$PTT_CAT" "$(WSJTX_INI)"
printf '[Configuration]\nMyCall=N0CALL\nRig=None\nPTTMethod=@Variant(\\0\\0\\0\\x7f\\0\\0\\0\\x1eTransceiverFactory::PTTMethod\\0\\0\\0\\0\\xfPTT_method_VOX\\0)\n\n[MultiSettings]\nOther\\Configuration\\Rig=Yaesu FT-991\n' > "$(WSJTX_INI)"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
grep -qx "MyCall=N0CALL" "$(WSJTX_INI)"
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
grep -qxF "$PTT_CAT" "$(WSJTX_INI)"
! grep -q "PTT_method_VOX" "$(WSJTX_INI)"
grep -qx 'Other\\Configuration\\Rig=Yaesu FT-991' "$(WSJTX_INI)"
[ "$(grep -c '^Rig=' "$(WSJTX_INI)")" -eq 1 ]
[[ "$output" == *"The settings were backed up first, to:"*"WSJT-X.ini.bak-"* ]]
ls "$(WSJTX_INI)".bak-* | grep -q .
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: already set up"* ]]
}
@test "configure leaves a rig you set yourself unless --force" {
configurable
printf '[Configuration]\nRig=Yaesu FT-991\nCATSerialPort=/dev/ttyUSB3\n' > "$(mkdir -p "$(dirname "$(WSJTX_INI)")"; WSJTX_INI)"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"WSJT-X: Left its rig (Yaesu FT-991) alone: \`radio configure --force\` replaces it"* ]]
grep -qx "Rig=Yaesu FT-991" "$(WSJTX_INI)"
run bash "$REPO/radio" configure --force
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
grep -qx "CATSerialPort=/dev/ttyUSB3" "$(WSJTX_INI)"
}
@test "configure skips programs that are running, and ones not installed" {
configurable
rm "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx"
export FAKE_RUNNING="JS8Call pat"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"WSJT-X: not installed"* ]]
[[ "$output" == *"JS8Call: skipped, because it's running"* ]]
[[ "$output" == *"Pat: skipped, because it's running"* ]]
[ ! -e "$HOME/.config/JS8Call.ini" ]
}
@test "configure sets up JS8Call like WSJT-X" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"JS8Call: rig control through rigctld, PTT by CAT"* ]]
grep -qx "Rig=Hamlib NET rigctl" "$HOME/.config/JS8Call.ini"
grep -qxF "$PTT_CAT" "$HOME/.config/JS8Call.ini"
}
@test "configure adds rigctld to Pat, for ARDOP and VARA where they had no rig" {
configurable
run bash "$REPO/radio" configure
local conf="$HOME/.config/pat/config.json"
[[ "$output" == *"Pat: rig \"hampack\" is rigctld"* ]]
[ "$(jq -c .hamlib_rigs.hampack "$conf")" = '{"address":"127.0.0.1:4532","network":"tcp"}' ]
[ "$(jq -r .ardop.rig "$conf")" = hampack ]
[ "$(jq -r .varahf.rig "$conf")" = ft991 ]
[ "$(jq -r .varafm.rig "$conf")" = hampack ]
[ "$(jq -r .mycall "$conf")" = N0CALL ]
[ "$(stat -c %a "$conf")" = 600 ]
run bash "$REPO/radio" configure
[[ "$output" == *"Pat: already set up"* ]]
run bash "$REPO/radio" configure --force
[ "$(jq -r .varahf.rig "$conf")" = hampack ]
}
@test "configure asks which radio when there's more than one" {
configurable
yaesu 1-3 00B00001 ttyUSB1 ttyUSB2 card2 CODEC_1
answers ttyUSB1 "38400 cat_id 0670"
run bash "$REPO/radio" configure
[ "$status" -eq 2 ]
[[ "$output" == *"There are 2 radios or interfaces plugged in"*"radio configure 2"* ]]
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
run bash "$REPO/radio" configure 2
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the Yaesu FT-991A (Hamlib model 1035), on /dev/ttyUSB1 at 38400 baud" ]
[[ "$output" == *"/dev/ttyUSB1 has no stable name"* ]]
run bash "$REPO/radio" configure 3
[ "$status" -eq 2 ]
[[ "$output" == *"There's no radio 3"* ]]
}
@test "configure needs --model for a radio it can't tell apart from others" {
configurable
answers ttyUSB0 "38400 cat_id 017"
# The IC-7300's USB serial number would say what it is; this radio's doesn't
echo 0001 > "$ROOT_HUB/1-2/1-2.1/serial"
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"Couldn't tell which radio it is: it's one of: Elecraft K3 (Hamlib model 2029), Elecraft K3S (Hamlib model 2043), Elecraft KX3"* ]]
[[ "$output" == *"radio configure --model 2045"* ]]
run bash "$REPO/radio" configure --model 2045
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the Elecraft KX3 (Hamlib model 2045), on /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0 at 38400 baud" ]
grep -q -- "-m 2045 " "$HOME/.config/systemd/user/hampack-rigctld.service"
}
@test "configure points fldigi at rigctld, keeping its other settings" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"fldigi: rig control through rigctld, PTT by Hamlib"* ]]
grep -qx "1" "$(FLDIGI_XML)"
grep -qx "2" "$(FLDIGI_XML)"
grep -qx "127.0.0.1:4532" "$(FLDIGI_XML)"
grep -qx "1" "$(FLDIGI_XML)"
grep -qx "0" "$(FLDIGI_XML)"
grep -qx "N0CALL" "$(FLDIGI_XML)"
grep -qx "" "$(FLDIGI_XML)"
[ "$(grep -c '' "$(FLDIGI_XML)")" -eq 1 ]
[ "$(tail -1 "$(FLDIGI_XML)")" = "" ]
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: already set up"* ]]
}
@test "configure leaves fldigi's own rig control alone unless --force" {
configurable
sed -i 's|0|1|' "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: sound card \"USB Audio CODEC: USB Audio (hw:1,0)\". Left its rig control alone"* ]]
grep -qx "0" "$(FLDIGI_XML)"
run bash "$REPO/radio" configure --force
grep -qx "1" "$(FLDIGI_XML)"
grep -qx "0" "$(FLDIGI_XML)"
}
@test "configure waits for fldigi to make its settings" {
configurable
rm "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: skipped: it has no settings yet. Run fldigi once"* ]]
[ ! -e "$(FLDIGI_XML)" ]
}
@test "configure gives Dire Wolf the radio's sound card and PTT through rigctld" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"Dire Wolf: sound card plughw:CARD=CODEC,DEV=0, PTT through rigctld"* ]]
[ "$(grep -E '^ADEVICE' "$(DIREWOLF_CONF)")" = "ADEVICE plughw:CARD=CODEC,DEV=0" ]
[ "$(grep -E '^PTT' "$(DIREWOLF_CONF)")" = "PTT RIG 2 127.0.0.1:4532" ]
grep -qx "MYCALL NOCALL" "$(DIREWOLF_CONF)"
# Only the settings changed, not the comments about them
[ "$(diff "$REPO/conf.d/direwolf.conf" "$(DIREWOLF_CONF)" | grep -c '^>')" -eq 2 ]
run bash "$REPO/radio" configure
[[ "$output" == *"Dire Wolf: already set up"* ]]
}
@test "configure leaves Dire Wolf settings you changed, unless --force" {
configurable
sed -i 's|^ADEVICE .*|ADEVICE plughw:2,0|' "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure
[[ "$output" == *"Dire Wolf: PTT through rigctld. Left your ADEVICE plughw:2,0 alone"* ]]
grep -qx "ADEVICE plughw:2,0" "$(DIREWOLF_CONF)"
grep -qx "PTT RIG 2 127.0.0.1:4532" "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure --force
grep -qx "ADEVICE plughw:CARD=CODEC,DEV=0" "$(DIREWOLF_CONF)"
}
@test "configure adds Dire Wolf's settings if they're missing, and needs a sound card for ADEVICE" {
configurable
sed -i '/^ADEVICE /d; /^PTT /d' "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure
[ "$(head -1 "$(DIREWOLF_CONF)")" = "ADEVICE plughw:CARD=CODEC,DEV=0" ]
[ "$(tail -1 "$(DIREWOLF_CONF)")" = "PTT RIG 2 127.0.0.1:4532" ]
# A radio with no sound card: PTT only
rm -r "$RADIO_SYSFS/class/sound/card1"
cp "$REPO/conf.d/direwolf.conf" "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure
[[ "$output" == *"Dire Wolf: PTT through rigctld"* ]]
grep -qx "ADEVICE plughw:0,0" "$(DIREWOLF_CONF)"
}
@test "configure points not1mm at rigctld" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"not1mm: rig control through rigctld"* ]]
[ "$(jq -c '[.userigctld, .useflrig, .usetci, .CAT_ip, .CAT_port, .mycall]' "$(NOT1MM_JSON)")" = '[true,false,false,"127.0.0.1",4532,"N0CALL"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: already set up"* ]]
}
@test "configure leaves not1mm on flrig unless --force, and skips it while it runs" {
configurable
jq '.useflrig = true' "$(NOT1MM_JSON)" > "$BATS_TEST_TMPDIR/n.json" && mv "$BATS_TEST_TMPDIR/n.json" "$(NOT1MM_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: voice keyer on \"USB Audio CODEC: USB Audio (hw:1,0)\". Left its rig control alone: \`radio configure --force\` replaces it"* ]]
[ "$(jq .useflrig "$(NOT1MM_JSON)")" = true ]
FAKE_RUNNING=not1mm run bash "$REPO/radio" configure --force
[[ "$output" == *"not1mm: skipped, because it's running"* ]]
[ "$(jq .useflrig "$(NOT1MM_JSON)")" = true ]
run bash "$REPO/radio" configure --force
[ "$(jq -c '[.userigctld, .useflrig]' "$(NOT1MM_JSON)")" = '[true,false]' ]
}
@test "configure adds and selects a rigctld profile in QLog, backing up the log first" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"QLog: rig profile \"HamPack\" is rigctld, and selected"* ]]
[ "$(qlog_query "SELECT profile_name, driver, model, hostname, netport, selected, get_freq, pollinterval FROM rig_profiles")" = "HamPack|1|2|127.0.0.1|4532|1|1|500" ]
[ "$(qlog_query "SELECT callsign FROM contacts")" = W1AW ]
# The backup is the log as it was
local backup
backup="$(ls "$(QLOG_DB)".bak-*)"
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles" "$backup")" = 0 ]
[ "$(qlog_query "SELECT callsign FROM contacts" "$backup")" = W1AW ]
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: already set up"* ]]
[ "$(ls "$(QLOG_DB)".bak-* | wc -l)" -eq 1 ]
}
@test "configure leaves QLog's own rig profiles unless --force, which selects its own" {
configurable
qlog_query "INSERT INTO rig_profiles (profile_name, model, driver, port_pathname, selected) VALUES ('IC-7300', 3073, 1, '/dev/ttyUSB0', 1)" > /dev/null
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: left alone: it has rig profiles already"* ]]
[ "$(qlog_query "SELECT profile_name FROM rig_profiles")" = "IC-7300" ]
! ls "$(QLOG_DB)".bak-* 2> /dev/null
run bash "$REPO/radio" configure --force
[ "$(qlog_query "SELECT profile_name, selected FROM rig_profiles ORDER BY profile_name")" = "$(printf 'HamPack|1\nIC-7300|0')" ]
}
@test "configure skips QLog when its log is missing, older than it knows, or QLog is running" {
configurable
rm "$(QLOG_DB)"
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: skipped: it has no log yet. Run QLog once"* ]]
qlog_log old
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: skipped: its log is older than this radio knows"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ]
rm "$(QLOG_DB)"*
qlog_log
FAKE_RUNNING=qlog run bash "$REPO/radio" configure
[[ "$output" == *"QLog: skipped, because it's running"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ]
}
@test "configure adds rigctld to POTACAT's rigs and makes it active" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"POTACAT: rig \"Icom IC-7300 (HamPack's rigctld)\" is rigctld, and active"* ]]
[ "$(jq -c '[.rigs, .activeRigId, .catTarget, .grid]' "$(POTACAT_JSON)")" = '[[{"id":"rig_hampack","name":"Icom IC-7300 (HamPack'"'"'s rigctld)","catTarget":{"type":"rigctldnet","host":"127.0.0.1","port":4532}}],"rig_hampack",{"type":"rigctldnet","host":"127.0.0.1","port":4532},"FN20jb"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
}
@test "configure puts POTACAT's connection in the operator's profile, where POTACAT keeps it" {
configurable
echo '{"activeProfile": "N0CALL", "rigs": []}' > "$(POTACAT_JSON)"
mkdir -p "$HOME/.config/potacat/profiles/N0CALL"
echo '{"myCallsign": "N0CALL", "catTarget": null}' > "$HOME/.config/potacat/profiles/N0CALL/settings.json"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ "$(jq -c '[.activeRigId, has("catTarget"), (.rigs | length)]' "$(POTACAT_JSON)")" = '["rig_hampack",false,1]' ]
[ "$(jq -c '[.catTarget.type, .myCallsign]' "$HOME/.config/potacat/profiles/N0CALL/settings.json")" = '["rigctldnet","N0CALL"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
}
@test "configure leaves POTACAT's own rig unless --force, which adds and selects its own" {
configurable
echo '{"rigs": [{"id": "rig_1", "name": "FT710", "catTarget": {"type": "serial", "path": "/dev/ttyUSB3"}}], "activeRigId": "rig_1", "catTarget": {"type": "serial", "path": "/dev/ttyUSB3"}}' > "$(POTACAT_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: Left its own radio alone: \`radio configure --force\` replaces it"* ]]
[ "$(jq -r .activeRigId "$(POTACAT_JSON)")" = rig_1 ]
FAKE_RUNNING=potacat run bash "$REPO/radio" configure --force
[[ "$output" == *"POTACAT: skipped, because it's running"* ]]
run bash "$REPO/radio" configure --force
[ "$(jq -c '[.activeRigId, [.rigs[].id], .catTarget.type]' "$(POTACAT_JSON)")" = '["rig_hampack",["rig_1","rig_hampack"],"rigctldnet"]' ]
}
@test "configure sets PTT to rigctld on Graywolf's transmitting channels, stopping it to do so" {
configurable
rm "$(GRAYWOLF_DB)"*
graywolf_db 1:1 2:1 3:0
"$REAL_PYTHON3" -I -c 'import sqlite3, sys
con = sqlite3.connect(sys.argv[1]); con.execute("INSERT INTO ptt_configs (channel_id, method) VALUES (2, \"none\")"); con.commit()' "$(GRAYWOLF_DB)"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"Graywolf: PTT through rigctld on 2 channels"* ]]
[ "$(qlog_query "SELECT channel_id, method, device, slot_time_ms, persist FROM ptt_configs ORDER BY channel_id" "$(GRAYWOLF_DB)")" = "$(printf '1|rigctld|127.0.0.1:4532|10|63\n2|rigctld|127.0.0.1:4532|10|63')" ]
grep -qx "systemctl stop graywolf" "$STUB_LOG"
grep -qx "systemctl start graywolf" "$STUB_LOG"
local backup
backup="$(ls "$(GRAYWOLF_DB)".bak-*)"
[ "$(qlog_query "SELECT COUNT(*) FROM ptt_configs WHERE method = 'rigctld'" "$backup")" = 0 ]
: > "$STUB_LOG"
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: already set up"* ]]
! grep -q "systemctl stop graywolf" "$STUB_LOG"
}
@test "configure leaves Graywolf's own PTT unless --force, and says when there's no channel" {
configurable
"$REAL_PYTHON3" -I -c 'import sqlite3, sys
con = sqlite3.connect(sys.argv[1]); con.execute("INSERT INTO ptt_configs (channel_id, method, device) VALUES (1, \"cm108\", \"/dev/hidraw0\")"); con.commit()' "$(GRAYWOLF_DB)"
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: Left 1 channel with PTT of its own alone"* ]]
! grep -q "systemctl stop graywolf" "$STUB_LOG"
run bash "$REPO/radio" configure --force
[ "$(qlog_query "SELECT method FROM ptt_configs" "$(GRAYWOLF_DB)")" = rigctld ]
rm "$(GRAYWOLF_DB)"*
graywolf_db 1:0
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: skipped: it has no channel that transmits yet. Add one in its web UI (http://localhost:8080) with PTT rigctld, 127.0.0.1:4532"* ]]
}
@test "configure tells you what to set in Graywolf when it can't stop it" {
configurable
stub sudo 'exit 1'
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: skipped: couldn't stop it to change its settings. Instead, in its web UI (http://localhost:8080), set each channel's PTT to rigctld, 127.0.0.1:4532"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM ptt_configs" "$(GRAYWOLF_DB)")" = 0 ]
}
# --- sound cards ---
@test "configure gives WSJT-X the radio's sound card as PipeWire names it" {
configurable
pipewire_card 1
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"WSJT-X: rig control through rigctld, PTT by CAT, sound card \"USB Audio CODEC Analog Stereo\""* ]]
grep -qx "SoundInName=alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback" "$(WSJTX_INI)"
grep -qx "SoundOutName=alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo" "$(WSJTX_INI)"
[[ "$output" == *"The radio's sound card is \"USB Audio CODEC Analog Stereo\" (hw:CARD=CODEC)."* ]]
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: already set up"* ]]
}
@test "configure gives JS8Call the sound card's PipeWire name and description, quoted as Qt would" {
configurable
pipewire_card 1 "Radio, USB"
run bash "$REPO/radio" configure
grep -qx "SoundInId=alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback" "$HOME/.config/JS8Call.ini"
grep -qx "SoundOutId=alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo" "$HOME/.config/JS8Call.ini"
grep -qx 'SoundInName="Radio, USB Mono"' "$HOME/.config/JS8Call.ini"
grep -qx 'SoundOutName="Radio, USB Analog Stereo"' "$HOME/.config/JS8Call.ini"
}
@test "configure replaces a default sound device, but not one you chose, unless --force" {
configurable
pipewire_card 1
mkdir -p "$(dirname "$(WSJTX_INI)")"
printf '[Configuration]\nSoundInName=pipewire\nSoundOutName=pipewire\n' > "$(WSJTX_INI)"
run bash "$REPO/radio" configure
grep -qx "SoundInName=alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback" "$(WSJTX_INI)"
printf '[Configuration]\nRig=Hamlib NET rigctl\nCATNetworkPort=127.0.0.1:4532\nSoundInName=alsa_input.usb-Other\nSoundOutName=alsa_output.usb-Other\n' > "$(WSJTX_INI)"
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: Left its sound card (alsa_input.usb-Other) alone: \`radio configure --force\` replaces it"* ]]
grep -qx "SoundInName=alsa_input.usb-Other" "$(WSJTX_INI)"
run bash "$REPO/radio" configure --force
grep -qx "SoundOutName=alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo" "$(WSJTX_INI)"
}
@test "configure leaves sound devices alone when PipeWire doesn't list the radio's card" {
configurable
pipewire_card 7
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: rig control through rigctld, PTT by CAT"$'\n'* ]]
! grep -q "^SoundInName=" "$(WSJTX_INI)"
[[ "$output" == *"PipeWire didn't list the radio's sound card"* ]]
}
@test "configure adds a Graywolf channel on the radio's sound card when it has none" {
configurable
rm "$(GRAYWOLF_DB)"*
graywolf_db
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"Graywolf: a channel on the radio's sound card (plughw:CARD=CODEC,DEV=0), 1200 baud APRS, PTT through rigctld"* ]]
[ "$(qlog_query "SELECT id, direction, source_type, source_path, sample_rate, channels FROM audio_devices ORDER BY id" "$(GRAYWOLF_DB)")" = "$(printf '1|input|soundcard|plughw:CARD=CODEC,DEV=0|48000|1\n2|output|soundcard|plughw:CARD=CODEC,DEV=0|48000|1')" ]
[ "$(qlog_query "SELECT name, input_device_id, output_device_id, modem_type, bit_rate, mode FROM channels" "$(GRAYWOLF_DB)")" = "Icom IC-7300|1|2|afsk|1200|aprs" ]
[ "$(qlog_query "SELECT channel_id, method, device FROM ptt_configs" "$(GRAYWOLF_DB)")" = "1|rigctld|127.0.0.1:4532" ]
grep -qx "systemctl stop graywolf" "$STUB_LOG"
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: already set up"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM channels" "$(GRAYWOLF_DB)")" = 1 ]
}
@test "configure doesn't add a Graywolf channel without a sound card, or beside channels you made" {
configurable
rm "$(GRAYWOLF_DB)"*
graywolf_db 1:0
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: skipped: it has no channel that transmits yet"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM channels" "$(GRAYWOLF_DB)")" = 1 ]
rm "$(GRAYWOLF_DB)"*
graywolf_db
rm -r "$RADIO_SYSFS/class/sound/card1"
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: skipped: it has no channel that transmits yet"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM channels" "$(GRAYWOLF_DB)")" = 0 ]
}
@test "configure gives not1mm's voice keyer the radio's sound card by PipeWire's name, which doesn't change" {
configurable
pipewire_card 1
pa_devices "USB Audio CODEC: USB Audio (hw:1,0)|1|2" "USB Audio CODEC Mono|1|0" "USB Audio CODEC Analog Stereo|2|2" "pipewire|64|64" "default|64|64"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: rig control through rigctld, voice keyer on \"USB Audio CODEC Analog Stereo\""* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC Analog Stereo" ]
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: already set up"* ]]
}
@test "configure gives not1mm ALSA's name for the card without PipeWire, or when two cards share its name" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"voice keyer on \"USB Audio CODEC: USB Audio (hw:1,0)\""* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC: USB Audio (hw:1,0)" ]
# Two radios with the same codec: PipeWire's name would match both
pipewire_card 1
pa_devices "USB Audio CODEC: USB Audio (hw:1,0)|1|2" "USB Audio CODEC Analog Stereo|2|2" "USB Audio CODEC: USB Audio (hw:2,0)|1|2" "USB Audio CODEC Analog Stereo|2|2"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: already set up"* ]]
}
@test "configure updates not1mm's card when its number changed, and leaves a card you chose unless --force" {
configurable
jq '.sounddevice = "USB Audio CODEC: USB Audio (hw:3,0)"' "$(NOT1MM_JSON)" > "$BATS_TEST_TMPDIR/n.json" && mv "$BATS_TEST_TMPDIR/n.json" "$(NOT1MM_JSON)"
run bash "$REPO/radio" configure
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC: USB Audio (hw:1,0)" ]
jq '.sounddevice = "HD-Audio Generic: ALC897 Analog (hw:0,0)"' "$(NOT1MM_JSON)" > "$BATS_TEST_TMPDIR/n.json" && mv "$BATS_TEST_TMPDIR/n.json" "$(NOT1MM_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: Left its sound card (HD-Audio Generic: ALC897 Analog (hw:0,0)) alone"* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "HD-Audio Generic: ALC897 Analog (hw:0,0)" ]
run bash "$REPO/radio" configure --force
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC: USB Audio (hw:1,0)" ]
}
@test "configure says when PortAudio doesn't list the radio's card for not1mm" {
configurable
pa_devices "HD-Audio Generic: ALC897 Analog (hw:0,0)|2|2" "pipewire|64|64" "default|64|64"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: rig control through rigctld, choose its sound card yourself: PortAudio doesn't list the radio's"* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = default ]
}
@test "configure gives fldigi the radio's sound card through PortAudio, by PipeWire's names" {
configurable
pipewire_card 1
pa_devices "USB Audio CODEC: USB Audio (hw:1,0)|1|2" "USB Audio CODEC Mono|1|0" "USB Audio CODEC Analog Stereo|2|2" "default|64|64"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: rig control through rigctld, PTT by Hamlib, sound card \"USB Audio CODEC Analog Stereo\""* ]]
grep -qx "1" "$(FLDIGI_XML)"
grep -qx "USB Audio CODEC Mono" "$(FLDIGI_XML)"
grep -qx "USB Audio CODEC Analog Stereo" "$(FLDIGI_XML)"
grep -qx "-1" "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: already set up"* ]]
}
@test "configure gives fldigi ALSA's names without PipeWire, and replaces defaults and old numbers only" {
configurable
sed -i 's||1\ndefault\nUSB Audio CODEC: USB Audio (hw:4,0)\n|' "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
grep -qx "USB Audio CODEC: USB Audio (hw:1,0)" "$(FLDIGI_XML)"
grep -qx "USB Audio CODEC: USB Audio (hw:1,0)" "$(FLDIGI_XML)"
[ "$(grep -c '' "$(FLDIGI_XML)")" -eq 1 ]
sed -i 's|.*|HD-Audio Generic: ALC897 Analog (hw:0,0)|' "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: Left its sound card alone"* ]]
grep -qx "HD-Audio Generic: ALC897 Analog (hw:0,0)" "$(FLDIGI_XML)"
run bash "$REPO/radio" configure --force
grep -qx "USB Audio CODEC: USB Audio (hw:1,0)" "$(FLDIGI_XML)"
}
@test "configure leaves fldigi on PulseAudio unless --force" {
configurable
sed -i 's||2\n|' "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: rig control through rigctld, PTT by Hamlib. Left its sound card alone"* ]]
grep -qx "2" "$(FLDIGI_XML)"
run bash "$REPO/radio" configure --force
grep -qx "1" "$(FLDIGI_XML)"
}
@test "the PortAudio device list runs against the real library" {
# Whatever devices this machine has (none, in CI), it lists them or fails cleanly
run bash -c 'source <(sed -n "/^portaudio_devices() {/,/^}/p" "$1"); portaudio_devices' _ "$REPO/radio"
[ "$status" -eq 0 ] || [ "$status" -eq 1 ]
[[ -z "$output" ]] || [[ "$(head -1 <<< "$output")" == *$'\t'*$'\t'*$'\t'* ]]
}
@test "configure gives POTACAT's rig the sound card by name, for POTACAT to find when it starts" {
configurable
pipewire_card 1
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: rig \"Icom IC-7300 (HamPack's rigctld)\" is rigctld, and active, sound card \"USB Audio CODEC Analog Stereo\", which POTACAT finds by name when it starts"* ]]
[ "$(jq -c '.rigs[0] | [.remoteAudioInput, .remoteAudioInputLabel, .remoteAudioOutput, .remoteAudioOutputLabel]' "$(POTACAT_JSON)")" = '["hampack:alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback","USB Audio CODEC Mono","hampack:alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo","USB Audio CODEC Analog Stereo"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
# POTACAT found the devices and stored their ids: still set up
jq '.rigs[0].remoteAudioInput = "4f3a9c" | .rigs[0].remoteAudioOutput = "9b21e0"' "$(POTACAT_JSON)" > "$BATS_TEST_TMPDIR/p.json" && mv "$BATS_TEST_TMPDIR/p.json" "$(POTACAT_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
[ "$(jq -r '.rigs[0].remoteAudioInput' "$(POTACAT_JSON)")" = 4f3a9c ]
}
@test "configure leaves a sound card you chose on POTACAT's rig, unless --force" {
configurable
pipewire_card 1
bash "$REPO/radio" configure > /dev/null
jq '.rigs[0] += {remoteAudioInput: "77aa", remoteAudioInputLabel: "Other Mono", remoteAudioOutput: "88bb", remoteAudioOutputLabel: "Other Analog Stereo"}' "$(POTACAT_JSON)" > "$BATS_TEST_TMPDIR/p.json" && mv "$BATS_TEST_TMPDIR/p.json" "$(POTACAT_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: Left its sound card alone"* ]]
[ "$(jq -r '.rigs[0].remoteAudioInput' "$(POTACAT_JSON)")" = 77aa ]
run bash "$REPO/radio" configure --force
[ "$(jq -r '.rigs[0].remoteAudioInputLabel' "$(POTACAT_JSON)")" = "USB Audio CODEC Mono" ]
[ "$(jq -r '.rigs[0].name' "$(POTACAT_JSON)")" = "Icom IC-7300 (HamPack's rigctld)" ]
}
@test "configure gives POTACAT no sound card for your own rig, or without PipeWire" {
configurable
pipewire_card 1
echo '{"rigs": [{"id": "rig_1", "name": "FT710", "catTarget": {"type": "serial", "path": "/dev/ttyUSB3"}}], "activeRigId": "rig_1", "catTarget": {"type": "serial", "path": "/dev/ttyUSB3"}}' > "$(POTACAT_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: Left its own radio alone"* ]]
[ "$(jq -c '.rigs[0] | has("remoteAudioInput")' "$(POTACAT_JSON)")" = false ]
rm "$FAKE_RADIOS"/pw-*
run bash "$REPO/radio" configure --force
[ "$(jq -c '.rigs[1] | [.id, has("remoteAudioInput")]' "$(POTACAT_JSON)")" = '["rig_hampack",false]' ]
}
# --- flrig ---
FLRIG_PREFS() { echo "$HOME/.flrig/${1:-flrig}.prefs"; }
IC7300_PORT=/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0
@test "configure leaves flrig alone, and says why, without --flrig" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"flrig: not set up: it and rigctld can't both use the radio's port. \`radio configure --flrig\` puts flrig in charge of the radio"* ]]
[ ! -e "$HOME/.flrig" ]
}
@test "configure --flrig puts flrig in charge of the radio, with rigctld passing everything to it" {
configurable
run bash "$REPO/radio" configure --flrig
[ "$status" -eq 0 ]
[[ "${lines[0]}" == *"at 38400 baud, through flrig" ]]
[[ "$output" == *"rigctld: runs as the hampack-rigctld user service, on 127.0.0.1:4532, and passes everything to flrig"* ]]
[[ "$output" == *"flrig: controls the IC-7300 on $IC7300_PORT at 38400 baud, PTT by CAT. It now starts when you log in; start it yourself this time, and leave it running"* ]]
grep -qx "ExecStart=/usr/bin/rigctld -m 4 -r 127.0.0.1:12345 -T 127.0.0.1 -t 4532" "$HOME/.config/systemd/user/hampack-rigctld.service"
# As FLTK writes it
[ "$(head -5 "$(FLRIG_PREFS)")" = "$(printf '; FLTK preferences file format 1.0\n; vendor: w1hkj.com\n; application: flrig\n\n[.]')" ]
grep -qx "xcvr_name:IC-7300" "$(FLRIG_PREFS)"
grep -qx "; application: IC-7300" "$(FLRIG_PREFS IC-7300)"
grep -qx "xcvr_serial_port:${IC7300_PORT:0:60}" "$(FLRIG_PREFS IC-7300)"
grep -qx "+${IC7300_PORT:60}" "$(FLRIG_PREFS IC-7300)"
grep -qx "serial_baudrate:7" "$(FLRIG_PREFS IC-7300)"
grep -qx "ptt_via_cat:1" "$(FLRIG_PREFS IC-7300)"
grep -q "^version:" "$(FLRIG_PREFS IC-7300)"
grep -qx "controller=flrig" "$HAMPACK_STATE/radio"
# The other programs still talk to rigctld
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
run bash "$REPO/radio" configure --flrig
[[ "$output" == *"flrig: already set up"* ]]
[ "$(grep -c '^xcvr_serial_port:' "$(FLRIG_PREFS IC-7300)")" -eq 1 ]
[ "$(grep -c '^+' "$(FLRIG_PREFS IC-7300)")" -eq 1 ]
# Back to rigctld on its own
run bash "$REPO/radio" configure
grep -q -- "-m 3073 -r $IC7300_PORT -s 38400" "$HOME/.config/systemd/user/hampack-rigctld.service"
grep -qx "controller=rigctld" "$HAMPACK_STATE/radio"
}
@test "configure --flrig keeps flrig's other settings, and uses its XML-RPC port" {
configurable
mkdir -p "$HOME/.flrig"
printf '; FLTK preferences file format 1.0\n; vendor: w1hkj.com\n; application: IC-7300\n\n[.]\n\nversion:2.0.12\nmainx:100\nxcvr_serial_port:NONE\nxmlport:12346\nlong:%s\n+%s\n' "$(printf 'a%.0s' {1..60})" "bcd" > "$(FLRIG_PREFS IC-7300)"
run bash "$REPO/radio" configure --flrig
[ "$status" -eq 0 ]
grep -qx "ExecStart=/usr/bin/rigctld -m 4 -r 127.0.0.1:12346 -T 127.0.0.1 -t 4532" "$HOME/.config/systemd/user/hampack-rigctld.service"
grep -qx "version:2.0.12" "$(FLRIG_PREFS IC-7300)"
grep -qx "mainx:100" "$(FLRIG_PREFS IC-7300)"
grep -qx "+bcd" "$(FLRIG_PREFS IC-7300)"
! grep -qx "xcvr_serial_port:NONE" "$(FLRIG_PREFS IC-7300)"
}
@test "configure --flrig leaves flrig on another radio or port unless --force" {
configurable
mkdir -p "$HOME/.flrig"
printf '; FLTK preferences file format 1.0\n; vendor: w1hkj.com\n; application: flrig\n\n[.]\n\nxcvr_name:FT-991A\n' > "$(FLRIG_PREFS)"
run bash "$REPO/radio" configure --flrig
[[ "$output" == *"flrig: It now starts when you log in; start it yourself this time. Left its radio (FT-991A) alone: \`radio configure --force\` replaces it"* ]]
grep -qx "xcvr_name:FT-991A" "$(FLRIG_PREFS)"
run bash "$REPO/radio" configure --flrig --force
grep -qx "xcvr_name:IC-7300" "$(FLRIG_PREFS)"
ls "$(FLRIG_PREFS)".bak-* > /dev/null
}
@test "configure --flrig needs flrig quit, and knowing the radio" {
configurable
FAKE_RUNNING=flrig run bash "$REPO/radio" configure --flrig
[ "$status" -eq 1 ]
[[ "$output" == *"Quit flrig first"* ]]
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
run bash "$REPO/radio" configure --flrig --model 2028
[ "$status" -eq 1 ]
[[ "$output" == *"radio doesn't know flrig's name for the Kenwood TS-480"* ]]
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
}
FLRIG_AUTOSTART() { echo "$HOME/.config/autostart/hampack-flrig.desktop"; }
@test "configure --flrig starts flrig when you log in, and stops that when rigctld takes the radio back" {
configurable
run bash "$REPO/radio" configure --flrig
grep -qx "Exec=flrig" "$(FLRIG_AUTOSTART)"
grep -qx "X-HamPack=radio configure --flrig" "$(FLRIG_AUTOSTART)"
run bash "$REPO/radio" configure --flrig
[[ "$output" == *"flrig: already set up. It starts when you log in, and leave it running"* ]]
run bash "$REPO/radio" configure
[[ "$output" == *"flrig: no longer starts when you log in, since rigctld has the radio's port again"* ]]
[ ! -e "$(FLRIG_AUTOSTART)" ]
run bash "$REPO/radio" configure
[[ "$output" == *"flrig: not set up: it and rigctld can't both use the radio's port"* ]]
}
@test "configure --flrig doesn't add a second autostart for flrig, or remove one that isn't HamPack's" {
configurable
mkdir -p "$HOME/.config/autostart"
printf '[Desktop Entry]\nType=Application\nName=My flrig\nExec=/usr/bin/flrig --debug-level 2\n' > "$HOME/.config/autostart/my-flrig.desktop"
run bash "$REPO/radio" configure --flrig
[[ "$output" == *"PTT by CAT. It starts when you log in, from my-flrig.desktop, and leave it running"* ]]
[ ! -e "$(FLRIG_AUTOSTART)" ]
# One of yours, under HamPack's name, without HamPack's mark
printf '[Desktop Entry]\nType=Application\nExec=flrig\n' > "$(FLRIG_AUTOSTART)"
run bash "$REPO/radio" configure
[ -e "$(FLRIG_AUTOSTART)" ]
[ -e "$HOME/.config/autostart/my-flrig.desktop" ]
}
# --- rigctld and the radio's port ---
@test "configure ties rigctld to the radio's port, so it runs when the radio is plugged in" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"rigctld: runs as the hampack-rigctld user service, on 127.0.0.1:4532, whenever the radio is plugged in and on"* ]]
local unit="$HOME/.config/systemd/user/hampack-rigctld.service" device
device="$(systemd-escape --path --suffix=device "$IC7300_PORT")"
[[ "$device" == dev-serial-by*id-usb*IC*7300*.device ]]
grep -qxF "BindsTo=$device" "$unit"
grep -qxF "After=$device" "$unit"
grep -qxF "WantedBy=$device" "$unit"
! grep -q "default.target" "$unit"
}
@test "configure --flrig starts rigctld at login, since flrig has the port" {
configurable
run bash "$REPO/radio" configure --flrig
local unit="$HOME/.config/systemd/user/hampack-rigctld.service"
grep -qx "WantedBy=default.target" "$unit"
! grep -q "^BindsTo=" "$unit"
}
@test "rigctld waits for a radio that isn't plugged in" {
export RADIO_DEV="$BATS_TEST_TMPDIR/dev"
run bash -c '
source <(sed -n "/^write_rigctld() {/,/^}/p" "$1")
RIGCTLD_UNIT="$HOME/.config/systemd/user/hampack-rigctld.service" RIGCTLD_ADDR=127.0.0.1:4532 DEVDIR="$RADIO_DEV"
write_rigctld "the Icom IC-7300" /dev/serial/by-id/usb-gone-if00-port0 -m 3073 -r /dev/serial/by-id/usb-gone-if00-port0 -s 38400
' _ "$REPO/radio"
[ "$status" -eq 0 ]
[ "$output" = waiting ]
grep -qx "systemctl --user reenable hampack-rigctld" "$STUB_LOG"
! grep -q "systemctl --user restart" "$STUB_LOG"
grep -qx "ExecStart=/usr/bin/rigctld -m 3073 -r /dev/serial/by-id/usb-gone-if00-port0 -s 38400 -T 127.0.0.1 -t 4532" "$HOME/.config/systemd/user/hampack-rigctld.service"
}
# --- sound cards with no serial port ---
@test "lists USB sound cards with no serial port, and how they key the radio" {
ic7300
pcm card1 p c
# An AIOC: a CM108-compatible sound card with no CAT
usb 1-3 1209:7388 "AIOC" "All-In-One-Cable"
card 1-3 card2 AIOC
pcm card2 p c
hidraw 1-3 hidraw2
# A SignaLink: a sound card keyed by VOX
usb 1-4 08bb:2904 "Burr-Brown from TI" "USB Audio CODEC"
card 1-4 card3 CODEC_1
pcm card3 p c
# A webcam's microphone: records, doesn't play
usb 1-5 046d:085e Logitech "BRIO"
card 1-5 card4 BRIO
pcm card4 c
run bash "$REPO/radio"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[4]}" = "USB sound cards with no serial port, for a radio keyed by VOX or a PTT line:" ]
[ "${lines[5]}" = "2. hw:CARD=AIOC (card2): AIOC All-In-One-Cable, 1209:7388. PTT through CM108 on /dev/hidraw2" ]
[ "${lines[6]}" = "3. hw:CARD=CODEC_1 (card3): Burr-Brown from TI USB Audio CODEC, 08bb:2904. PTT by VOX, or a line of its own" ]
[ ${#lines[@]} -eq 7 ]
# The radio sound card isn't listed again
[[ "$output" != *"(card1):"* ]]
}
@test "lists sound cards when there's no serial port at all" {
usb 1-4 08bb:2904 "Burr-Brown from TI" "USB Audio CODEC"
card 1-4 card1 CODEC
pcm card1 p c
run bash "$REPO/radio"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "USB sound cards with no serial port, for a radio keyed by VOX or a PTT line:" ]
[[ "$output" != *"No USB serial ports found"* ]]
# It can be set up: rigctld keys nothing, and the radio keys itself on the audio
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the radio on the Burr-Brown from TI USB Audio CODEC, with no CAT: PTT by VOX: the radio keys itself on the audio" ]
grep -qx "ExecStart=/usr/bin/rigctld -m 1 -T 127.0.0.1 -t 4532" "$HOME/.config/systemd/user/hampack-rigctld.service"
rm -r "$RADIO_SYSFS/class/sound/card1"
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"No USB serial ports or sound cards found"* ]]
}
@test "shows a radio's CM108 PTT, and says when you can't open it" {
# A Digirig: a CP2102 and a CM108B behind its own hub
usb 1-6 1a40:0101
usb 1-6/1-6.1 10c4:ea60 "Silicon Labs" "CP2102 USB to UART Bridge Controller" 0001
port 1-6/1-6.1 ttyUSB0
usb 1-6/1-6.2 0d8c:0012 "C-Media Electronics Inc." "USB Audio Device"
card 1-6/1-6.2 card1 Device
pcm card1 p c
hidraw 1-6/1-6.2 hidraw0 locked
run bash "$REPO/radio"
[ "${lines[2]}" = " Sound card: hw:CARD=Device (card1)" ]
[ "${lines[3]}" = " CM108 PTT: /dev/hidraw0, which you can't open yet: \`update\` installs HamPack's udev rule for it, which lets whoever is at the desktop use it" ]
[[ "$output" != *"USB sound cards with no serial port"* ]]
chmod 600 "$RADIO_DEV/hidraw0"
run bash "$REPO/radio"
[ "${lines[3]}" = " CM108 PTT: /dev/hidraw0" ]
}
@test "doesn't call other C-Media cards CM108-compatible" {
usb 1-4 0d8c:0014 "C-Media Electronics Inc." "USB Audio Device"
card 1-4 card1 Device
pcm card1 p c
hidraw 1-4 hidraw0
run bash "$REPO/radio"
[ "${lines[1]}" = "1. hw:CARD=Device (card1): C-Media Electronics Inc. USB Audio Device, 0d8c:0014. PTT by VOX, or a line of its own" ]
}
@test "radio's CM108 list is the udev rule's" {
local rule device vid pid
rule="$(grep -v '^#' "$REPO/udev/70-hampack-cm108.rules" | grep .)"
for device in 0d8c:0008 0d8c:000a 0d8c:000f 0d8c:0012 0d8c:0013 0d8c:0139 0d8c:013a 0d8c:013c 0c76:1605 0c76:1607 0c76:160b 1209:7388 0d8c:0014 0d8c:0001 0c76:1600 1209:0001; do
vid="${device%:*}" pid="${device#*:}"
mkdir -p "$BATS_TEST_TMPDIR/d/$device"
echo "$vid" > "$BATS_TEST_TMPDIR/d/$device/idVendor"
echo "$pid" > "$BATS_TEST_TMPDIR/d/$device/idProduct"
local in_radio=no in_rule=no pattern
bash -c 'source <(sed -n "/^attr() {/,/^}/p; /^cm108_compatible() {/,/^}/p" "$1"); cm108_compatible "$2"' _ "$REPO/radio" "$BATS_TEST_TMPDIR/d/$device" && in_radio=yes
for pattern in $(grep "idVendor}==\"$vid\"" <<< "$rule" | grep -oE 'idProduct}=="[^"]+"' | cut -d'"' -f2 | tr '|' ' '); do
# shellcheck disable=SC2053
[[ "$pid" == $pattern ]] && in_rule=yes
done
[ "$in_radio" = "$in_rule" ] || { echo "$device: radio $in_radio, rule $in_rule"; return 1; }
done
}
# --- Elecraft ---
@test "tells Elecraft radios apart by their option modules" {
usb 1-4 0403:6001 FTDI "FT232R USB UART" A12345
port 1-4 ttyUSB0
touch "$RADIO_DEV/ttyUSB0"
local options expected
for options in "AP--------02:Elecraft KX3 (Hamlib model 2045)" "----------01:Elecraft KX2 (Hamlib model 2044)" \
"AP-S----4---:Elecraft K4 (Hamlib model 2047)" "AP-S-R------:Elecraft K3S (Hamlib model 2043)" \
"AP-S--------:Elecraft K3 (Hamlib model 2029)"; do
expected="${options#*:}"
answers ttyUSB0 "38400 cat_id 017 ${options%%:*}"
run bash "$REPO/radio" probe "$RADIO_DEV/ttyUSB0"
[ "$output" = "$expected, at 38400 baud" ] || { echo "${options%%:*}: $output"; return 1; }
done
}
@test "configure sets up an Elecraft without --model, once its option modules say which" {
configurable
echo 0001 > "$ROOT_HUB/1-2/1-2.1/serial"
answers ttyUSB0 "38400 cat_id 017 AP--------01"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "${lines[0]}" == "Setting up the Elecraft KX2 (Hamlib model 2044), on "* ]]
grep -q -- "-m 2044 " "$HOME/.config/systemd/user/hampack-rigctld.service"
}
@test "probe asks a real Elecraft for its option modules" {
fake_radio elecraft
run bash "$REPO/radio" probe "$PTY"
[ "$status" -eq 0 ]
[ "$output" = "Elecraft KX3 (Hamlib model 2045), at 38400 baud" ]
}
# --- radios with no CAT ---
# An AIOC: a CM108-compatible sound card, with no serial port
aioc() {
usb 1-3 1209:7388 "AIOC" "All-In-One-Cable"
card 1-3 card2 AIOC
pcm card2 p c
hidraw 1-3 hidraw2 open usb-AIOC_All-In-One-Cable-if03
}
# A Digirig: a CP2102 and a CM108B behind its own hub, with a handheld that
# answers nothing on it
digirig() {
usb 1-6 1a40:0101
usb 1-6/1-6.1 10c4:ea60 "Silicon Labs" "CP2102 USB to UART Bridge Controller" 0001
port 1-6/1-6.1 ttyUSB0 usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0
usb 1-6/1-6.2 0d8c:0012 "C-Media Electronics Inc." "USB Audio Device"
card 1-6/1-6.2 card1 Device
pcm card1 p c
hidraw 1-6/1-6.2 hidraw0 open usb-C-Media_Electronics_Inc._USB_Audio_Device-if03
}
@test "configure sets up a sound card with a CM108 pin, with rigctld keying the radio through it" {
configurable
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
aioc
pipewire_card 2
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the radio on the AIOC All-In-One-Cable, with no CAT: PTT through its sound card's CM108 pin, /dev/input/by-id/usb-AIOC_All-In-One-Cable-if03-hidraw" ]
[[ "$output" == *"rigctld: runs as the hampack-rigctld user service, on 127.0.0.1:4532, and keys the radio when the programs transmit"* ]]
local unit="$HOME/.config/systemd/user/hampack-rigctld.service"
grep -qx "ExecStart=/usr/bin/rigctld -m 1 -p /dev/input/by-id/usb-AIOC_All-In-One-Cable-if03-hidraw -P CM108 -T 127.0.0.1 -t 4532" "$unit"
grep -qx "WantedBy=default.target" "$unit"
# The programs key it "by CAT", through rigctld, as for any radio
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
grep -qxF "$PTT_CAT" "$(WSJTX_INI)"
grep -qx "SoundInName=alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback" "$(WSJTX_INI)"
grep -qx "PTT RIG 2 127.0.0.1:4532" "$(DIREWOLF_CONF)"
grep -qx "ADEVICE plughw:CARD=AIOC,DEV=0" "$(DIREWOLF_CONF)"
grep -qx "ptt=cm108" "$HAMPACK_STATE/radio"
grep -qx "hamlib=1" "$HAMPACK_STATE/radio"
}
@test "configure finds a CM108 pin by its path when two cards of a kind share an id" {
configurable
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
aioc
usb 1-4 1209:7388 "AIOC" "All-In-One-Cable"
card 1-4 card3 AIOC_1
pcm card3 p c
hidraw 1-4 hidraw3 open usb-AIOC_All-In-One-Cable-if03
run bash "$REPO/radio" configure 1
[ "$status" -eq 0 ]
grep -q -- "-p /dev/input/by-path/pci-0000:00:14.0-usb-0:1-3:1.3-hidraw -P CM108" "$HOME/.config/systemd/user/hampack-rigctld.service"
}
@test "configure sets up a handheld on a Digirig with --no-cat and --ptt" {
configurable
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1" "$RADIO_DEV/serial/by-id/"* "$FAKE_RADIOS/ttyUSB0"
digirig
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"If the radio has no CAT, \`radio configure --no-cat --ptt HOW\` sets it up to be keyed."* ]]
run bash "$REPO/radio" configure --no-cat
[ "$status" -eq 2 ]
[[ "$output" == *"Give the way the interface keys the radio: --ptt rts or --ptt dtr"* ]]
local port=/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0 unit="$HOME/.config/systemd/user/hampack-rigctld.service"
run bash "$REPO/radio" configure --no-cat --ptt rts
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the radio on the CP2102 USB to UART Bridge Controller, with no CAT: PTT by RTS on $port" ]
grep -qx "ExecStart=/usr/bin/rigctld -m 1 -p $port -P RTS -T 127.0.0.1 -t 4532" "$unit"
grep -qxF "BindsTo=$(systemd-escape --path --suffix=device "$port")" "$unit"
run bash "$REPO/radio" configure --no-cat --ptt cm108
grep -q -- "-p /dev/input/by-id/usb-C-Media_Electronics_Inc._USB_Audio_Device-if03-hidraw -P CM108" "$unit"
}
@test "configure turns down options that don't fit a radio with no CAT" {
configurable
run bash "$REPO/radio" configure --ptt rts
[ "$status" -eq 2 ]
[[ "$output" == *"--ptt is for a radio with no CAT"* ]]
run bash "$REPO/radio" configure --no-cat --ptt rts --flrig
[ "$status" -eq 2 ]
[[ "$output" == *"flrig needs a radio with CAT"* ]]
run bash "$REPO/radio" configure --no-cat --ptt rts --model 3073
[ "$status" -eq 2 ]
[[ "$output" == *"--model doesn't apply"* ]]
run bash "$REPO/radio" configure --ptt sideways
[ "$status" -eq 2 ]
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
aioc
run bash "$REPO/radio" configure --ptt rts
[ "$status" -eq 2 ]
[[ "$output" == *"This sound card has no serial port for --ptt rts: use cm108 or vox."* ]]
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
# A VOX card can't be keyed through a CM108 pin it hasn't got
rm -r "$RADIO_SYSFS/class/sound/card2"
usb 1-4 08bb:2904 "Burr-Brown from TI" "USB Audio CODEC"
card 1-4 card3 CODEC
pcm card3 p c
run bash "$REPO/radio" configure --ptt cm108
[ "$status" -eq 1 ]
[[ "$output" == *"no CM108 PTT pin"* ]]
}
# --- setting up a radio when it's plugged in ---
# radio configure --auto, as the hampack-radio-plugged service runs it, with
# desktop notifications logged
auto() {
stub notify-send 'exit 0'
RADIO_AUTO_WAIT=0 run bash "$REPO/radio" configure --auto
}
@test "--auto sets up a radio it knows by its USB serial number, and says so" {
configurable
auto
[ "$status" -eq 0 ]
[[ "$output" == *"Setting up the Icom IC-7300 (Hamlib model 3073)"* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
grep -qx "systemctl --user restart hampack-rigctld" "$STUB_LOG"
grep -q "^notify-send --app-name=HamPack HamPack set up the Icom IC-7300 " "$STUB_LOG"
}
@test "--auto leaves Graywolf alone while it runs, rather than ask for sudo, and says what it skipped" {
configurable
FAKE_RUNNING=fldigi auto
[ "$status" -eq 0 ]
[[ "$output" == *"Graywolf: skipped: it's running, and stopping it to change its settings needs sudo. Run \`radio configure\` to set it up"* ]]
! grep -q "^sudo" "$STUB_LOG"
grep -q "^notify-send .* Skipped: fldigi, Graywolf. Run \`radio configure\` to see why" "$STUB_LOG"
}
@test "--auto doesn't ask a radio what it is" {
configurable
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
yaesu 1-3
answers ttyUSB0 "38400 cat_id 0670"
: > "$STUB_LOG"
auto
[ "$status" -eq 0 ]
[[ "$output" == "No radio that radio recognises by its USB serial number is plugged in"* ]]
! grep -q "^python3" "$STUB_LOG"
! grep -q "^notify-send" "$STUB_LOG"
[ ! -e "$HAMPACK_STATE/radio" ]
}
@test "--auto leaves the radio set up already, while it's plugged in" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
: > "$STUB_LOG"
auto
[ "$status" -eq 0 ]
[ "$output" = "The radio set up already, the Icom IC-7300, is plugged in, so it stays set up." ]
! grep -q "reenable" "$STUB_LOG"
! grep -q "^notify-send" "$STUB_LOG"
# A sound card with no serial port, set up with no CAT, counts while it's there
printf 'name=radio on the AIOC\nport=\ncard=hw:CARD=CODEC\n' > "$HAMPACK_STATE/radio"
auto
[[ "$output" == *"stays set up"* ]]
}
@test "--auto sets up a radio in place of one that isn't plugged in" {
configurable
mkdir -p "$HAMPACK_STATE"
printf 'name=Yaesu FT-991A\nport=/dev/serial/by-id/usb-gone-if00-port0\ncard=hw:CARD=Gone\n' > "$HAMPACK_STATE/radio"
auto
[ "$status" -eq 0 ]
grep -qx "name=Icom IC-7300" "$HAMPACK_STATE/radio"
}
@test "--auto leaves it to you when two radios it knows are plugged in" {
configurable
usb 1-5 10c4:ea60 "Silicon Labs" "CP2102 USB to UART Bridge Controller" "IC-705 12345678"
port 1-5 ttyUSB2
auto
[ "$status" -eq 0 ]
[ "$output" = "2 radios that radio recognises are plugged in: run \`radio configure N\` to set one up." ]
[ ! -e "$HAMPACK_STATE/radio" ]
}
@test "--auto says when it couldn't set the radio up" {
configurable
rm "$FAKE_RADIOS/ttyUSB0"
auto
[ "$status" -eq 1 ]
grep -qx "notify-send --app-name=HamPack HamPack couldn't set up the Icom IC-7300 Run \`radio configure\` to see why." "$STUB_LOG"
}
@test "--auto takes no other options" {
run bash "$REPO/radio" configure --auto --force
[ "$status" -eq 2 ]
}
# --- radio unconfigure ---
@test "unconfigure stops and removes rigctld and flrig's autostart, and stops --auto setting the radio up" {
configurable
run bash "$REPO/radio" configure --flrig
[ "$status" -eq 0 ]
: > "$STUB_LOG"
run bash "$REPO/radio" unconfigure < /dev/null
[ "$status" -eq 0 ]
[[ "$output" == *"rigctld: stopped, and the hampack-rigctld service removed"* ]]
[[ "$output" == *"flrig: no longer starts when you log in"* ]]
grep -qx "systemctl --user disable --now hampack-rigctld" "$STUB_LOG"
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
[ ! -e "$(FLRIG_AUTOSTART)" ]
[ ! -e "$HAMPACK_STATE/radio" ]
auto
[ "$status" -eq 0 ]
[[ "$output" == *"until you run \`radio configure\`"* ]]
! grep -q "reenable" "$STUB_LOG"
# radio configure turns --auto back on
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ ! -e "$HAMPACK_STATE/radio-unconfigured" ]
}
@test "unconfigure leaves an flrig autostart that isn't HamPack's" {
configurable
mkdir -p "$HOME/.config/autostart"
printf '[Desktop Entry]\nType=Application\nExec=flrig\n' > "$(FLRIG_AUTOSTART)"
run bash "$REPO/radio" unconfigure < /dev/null
[ -e "$(FLRIG_AUTOSTART)" ]
[[ "$output" == *"radio configure hasn't set anything up, so there's nothing to undo."* ]]
}
@test "unconfigure puts back the settings from before radio configure changed them, when you say yes" {
configurable
local pat="$HOME/.config/pat/config.json" pat_before contacts
pat_before="$(cat "$pat")"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
qlog_query "INSERT INTO contacts (callsign) VALUES ('K1ABC')"
run bash "$REPO/radio" unconfigure < <(yes y)
[ "$status" -eq 0 ]
[[ "$output" == *"Put back ~/.config/pat/config.json, as it was on "* ]]
[[ "$output" == *"Pat: put back. What was there is in $pat.bak-"* ]]
[ "$(cat "$pat")" = "$pat_before" ]
[ "$(stat -c %a "$pat")" = 600 ]
# QLog's log, through SQLite, with a warning about contacts logged since
[[ "$output" == *"QLog's log holds your contacts: any you've logged since "*" won't be in the log put back."* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ]
[ "$(qlog_query "SELECT callsign FROM contacts")" = W1AW ]
# ...and the log as it was is kept
contacts="$(for b in "$(QLOG_DB)".bak-*; do qlog_query "SELECT COUNT(*) FROM contacts" "$b"; done | sort | tail -1)"
[ "$contacts" = 2 ]
[[ "$output" != *"may still use rigctld"* ]]
}
@test "unconfigure puts back the oldest backup of each file, and leaves the ones you say no to" {
configurable
local pat="$HOME/.config/pat/config.json" fldigi pat_set fldigi_set
fldigi="$(FLDIGI_XML)"
run bash "$REPO/radio" configure
pat_set="$(cat "$pat")"
fldigi_set="$(cat "$fldigi")"
echo '{"mycall": "OLDEST"}' > "$pat.bak-20200101-000000"
# Not one of radio configure's
echo '{"mycall": "MINE"}' > "$pat.bak-mine"
run bash "$REPO/radio" unconfigure < /dev/null
[ "$status" -eq 0 ]
[ "$(cat "$pat")" = "$pat_set" ]
[ "$(cat "$fldigi")" = "$fldigi_set" ]
[[ "$output" == *"Put back ~/.config/pat/config.json, as it was on 2020-01-01 at 00:00? [y/N] "* ]]
[[ "$output" == *"Later backups radio configure made are still there"* ]]
[[ "$output" == *"fldigi, "*"Pat"*" may still use rigctld on 127.0.0.1:4532, which isn't running now"* ]]
run bash "$REPO/radio" unconfigure < <(yes y)
[ "$(jq -r .mycall "$pat")" = OLDEST ]
}
@test "unconfigure leaves programs that are running, and stops Graywolf to put it back" {
configurable
run bash "$REPO/radio" configure
local fldigi_set
fldigi_set="$(cat "$(FLDIGI_XML)")"
stub systemctl '[ "$*" != "--user is-active --quiet hampack-rigctld" ] && [ "$*" != "is-active --quiet graywolf" ] || [ -f "$FAKE_RADIOS/rigctld-active" ]'
touch "$FAKE_RADIOS/rigctld-active"
: > "$STUB_LOG"
FAKE_RUNNING=fldigi run bash "$REPO/radio" unconfigure < <(yes y)
[ "$status" -eq 0 ]
[[ "$output" == *"fldigi: left as it is, because it's running. Quit it and run \`radio unconfigure\` again"* ]]
[ "$(cat "$(FLDIGI_XML)")" = "$fldigi_set" ]
grep -qx "systemctl stop graywolf" "$STUB_LOG"
grep -qx "systemctl start graywolf" "$STUB_LOG"
[[ "$output" == *"Graywolf: put back"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM ptt_configs WHERE method = 'rigctld'" "$(GRAYWOLF_DB)")" = 0 ]
}
@test "unconfigure takes no options" {
run bash "$REPO/radio" unconfigure --force
[ "$status" -eq 2 ]
}