DF-5253 / cycle.py
#!/usr/bin/env python3 """Cycle the emulated USB audio device (unplug/replug) while the guest hammer runs, driving uaudio detach/attach -> pcm mixer_uninit frees the mixer lock while uaudio mixer sysctls are still registered.""" import socket, time, sys sock = "dfbsd-qemu/boot-mon.sock" cycles = int(sys.argv[1]) if len(sys.argv) > 1 else 40 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(sock) time.sleep(0.2); s.recv(65536) def mon(cmd, wait=0.4): s.send((cmd + "\n").encode()); time.sleep(wait) try: d = s.recv(1 << 20).decode(errors="replace") except Exception: d = "" return d for n in range(cycles): r1 = mon("device_del usbaud0", 1.2) r2 = mon("device_add usb-audio,bus=uhci0.0,audiodev=snd0,id=usbaud0", 1.8) print("cycle %d: del=%s add=%s" % (n, r1.strip().splitlines()[-1:] , r2.strip().splitlines()[-1:]), flush=True) # wait for guest re-attach time.sleep(0.8) s.close() |