preparation ------------ change /etc/locale.conf to en_US.UTF-8 run lxpolkit remove ZE WIFI connection from NM virsh net-destroy cockpit1 rmmod iwldvm iwlwifi (NOT killswitch) cd ~martin/Dokumente/computer/talks/simulated-hardware sudo -i mkdir -p /run/udev/rules.d/ cd ~martin/Dokumente/computer/talks/simulated-hardware start gnome-disks on another desktop other term: journalctl --lines=0 -f connect phone, enable MTP; verify mtp-detect increase font size; clear intro (2') ---------- comparison to rocket launching for longest time: fix production with an update getting better with CI; but one area which is particularly tricky is hardware access on the plumbing layer udisks, upower, NetworkManager, modemmanager, rfkill, libmtp, libinput show how to simulate various kinds of hardware for testing and interactive debugging disks (6') ---------- simple cases: loop devices; don't feel/smell like real HD partitions are tricky (kpartx), no fault injection, no device types, don't scale well more powerful: scsi_debug kmod simple: modprobe scsi_debug dev_size_mb=100 create GPT partitioning and partition in Disks, mount it simulate pulling an USB stick or CD drive: echo 1 > /sys/block/sdb/device/delete → disappears, journal says "Cleaning up mount point" mount | grep sdb lots of devices: rmmod scsi_debug modprobe scsi_debug add_host=100 CD: rmmod scsi_debug modprobe scsi_debug ptype=5 rmmod scsi_debug errors: medium error in sector 0x1234 modprobe scsi_debug opts=2 dd if=/dev/zero of=/dev/sdb rmmod scsi_debug doc: http://sg.danny.cz/sg/sdebug26.html example: https://github.com/storaged-project/udisks/blob/master/src/tests/integration-test ethernet (4.5') --------------- veth: kernel virtual net driver, symmetric pair; consider "local" end (test with NM), and "remote" end (set up as router with known good tool, e. g. dnsmasq) vim veth.sh show nm-applet: not connected to anything nmcli g filter out some log noise: journalctl -f -ocat -t NetworkManager ./veth.sh nm-applet right-click connection info (nmcli g) doc: man ip-link Debian/Ubuntu autopkgtests for NetworkManager and netplan, upstream systemd networkd wifi (5') --------- mac80211_hwsim kmod: real wifi driver for userspace; again a symmetric connected pair vim wifi.sh NM blacklisting: opposite, don't interfere with router end new thing: hostapd for wifi router stack; real thing journalctl -f -ocat -t NetworkManager ./wifi.sh click on nm-applet to connect nmcli d Debian/Ubuntu autopkgtests for NetworkManager and netplan https://www.kernel.org/doc/Documentation/networking/mac80211_hwsim/ generic devices (5') -------------------- block and network are rather special; most Linux devices/drivers are much simpler (char dev, read/write, ioctl) umockdev: mock /sys, /dev, /proc, redirects to temp dir via preload lib emulate uevents by redirecting netlink socket C library, GI bindings, CLI tools needs no privileges → make check close root shell empty by default: umockdev-run -- ls -l /sys API or udevadm dump like text files: cat foo.umockdev similar to udevadm info --export-db: name, devnode, udev props; but with sysfs attributes umockdev-run -d foo.umockdev bash tree -l /sys cat /sys/devices/foo/mode ls -l /dev/foo ls -l $UMOCKDEV_DIR/dev/foo exit examples: upower test suite (UPS, batteries), input devs (lid, touch screen) https://github.com/martinpitt/umockdev packages in all major distros Device behaviour ---------------- record/replay reads/writes to device with correct timing → 3G modems record/replay evdev ioctls → wacom tablets record URB; gphoto, MTP lsusb umockdev-record /dev/bus/usb/002/020 > /tmp/sony.umockdev less /tmp/sony.umockdev umockdev-record -i /dev/bus/usb/002/020=/tmp/sony.ioctl mtp-detect less /tmp/sony.ioctl disconnect mobile umockdev-run -d /tmp/sony.umockdev lsusb umockdev-run -d /tmp/sony.umockdev mtp-detect umockdev-run -d /tmp/sony.umockdev -i /dev/bus/usb/002/020=/tmp/sony.ioctl mtp-detect Disclaimer: URB slightly broken right now; used to work with gphoto, shotwell, etc.; but URB structure apparently got more flexible now evdev ioctls work quite nicely (Wacom or other exotic devices); supports outputting to evemu format can record and replay (with correct timing) raw reads/writes to devices; used for testing modems (3G/4G sticks)