Capture and Replay Hardware Behaviour for Regression Testing and Useful Bug Reports
Total Page:16
File Type:pdf, Size:1020Kb
Introduction Overview Static devices Dynamic behaviour Conclusion Capture and Replay Hardware behaviour for Regression Testing and Useful Bug Reports Martin Pitt <[email protected]> Linux Plumbers Conference, September 2013 Introduction Overview Static devices Dynamic behaviour Conclusion Motivation From: Joe User <[email protected]> Subject: eye phone 17 doesn't work after Ubuntu upgrade My eye phone 17 has worked fine in Ubuntu 12.04 LTS, but under 13.04 Rhythmbox doesn't do anything any more when I plug it in. From: Jack Developer <[email protected]> Subject: Re: eye phone 17 doesn't work after Ubuntu upgrade Sorry, I don't have this device. It works fine with my phone and media player. Can you please attach the output of "rhythmbox {debug"? Introduction Overview Static devices Dynamic behaviour Conclusion Structure • umockdev-record /dev/ttyUSB0 • UMockdevTestbed GObject class API • umockdev-run --device 3g-usbstick.umockdev --script /dev/ttyUSB0=connect.script ModemManager Introduction Overview Static devices Dynamic behaviour Conclusion How does it look like? Live demo, brace for impact! Introduction Overview Static devices Dynamic behaviour Conclusion Device detection only • program only uses sysfs, udev properties, and uevents • no /dev access • power supply devices (upower), lsusb, DMI, rfkill, /sys/class/drm/ Introduction Overview Static devices Dynamic behaviour Conclusion API usage: create device 1 UMockdevTestbed ∗ testbed = umockdev testbed new ( ) ; 2 c o n s t char ∗ s y s bat = umockdev t e s t b e d a d d device (testbed , 3 "power s u p p l y","fakeBAT0" , NULL , 4 /∗ a t t r i b u t e s ∗/ 5 "type","Battery", 6 "status","Discharging", 7 "energy f u l l","60000000", 8 "energy now","48000000", 9 NULL , 10 /∗ p r o p e r t i e s ∗/ 11 "POWER SUPPLY ONLINE","1", 12 NULL ) ; 13 ); 14 15 /∗ s t a r t GTestDBus and upowerd ∗/ 16 /∗ c a l l upower −−dump or query overD −BUS ∗/ Introduction Overview Static devices Dynamic behaviour Conclusion API usage: load device umockdev-record /sys/class/power supply/BAT0 > bat0.umockdev Load with: 1 from gi.repository import UMockdev 2 testbed = UMockdev.Testbed.new() 3 testbed.add f r o m file(testbed ,'bat0. umockdev') Introduction Overview Static devices Dynamic behaviour Conclusion API usage: change device 1 /∗ change battery charge ∗/ 2 u m o c k d e v t e s t b e d s e t attribute (testbed , sys b a t , 3 "energy now","1500000"); 4 /∗ send uevent to notify upowerd ∗/ 5 u m o c k d e v t e s t b e d uevent (testbed , sys b a t ,"change"); 6 7 /∗ c a l l upower −−dump or query overD −BUS ∗/ Introduction Overview Static devices Dynamic behaviour Conclusion Implementation: preload library $ umockdev-wrapper ./my-test-suite or $ LD PRELOAD=libumockdev-preload.so ./my-test-suite Introduction Overview Static devices Dynamic behaviour Conclusion /dev emulation $UMOCKDEV DIR/dev/* Common cases: • char device (tty, ModemManager, evdev events): read(), write() • socket (Android rild): send(), recv() • ioctl (usbdevfs, evdev properties) • block device Introduction Overview Static devices Dynamic behaviour Conclusion read/write scripts w 0 ATZ^J r 200 OK^J w 350 ATI0^J r 10 Huawei X1234^Jcaps:^I2G 3G 4G^J [...] f 5 - w 50 ^@jf9j#2j(*J^@^@^@ 1 GError ∗ error = NULL; 2 u m o c k d e v t e s t b e d l o a d script(testbed ,"/dev/ttyUSB0", 3 "huawei.script", &error); Introduction Overview Static devices Dynamic behaviour Conclusion ioctl emulation USBDEVFS_CONNECTINFO 0 0B00000000000000 USBDEVFS_REAPURB 0 1 2 0 0 8 8 0 0001020304050607 USBDEVFS_REAPURB 0 1 129 0 0 15 6 0 DEADBEEF0042 USBDEVFS_REAPURB 0 1 129 0 0 15 7 0 10090807060504 USBDEVFS_REAPURB 0 1 129 -5 0 15 5 0 1010101010 EVIOCGBIT(3) 8 0300001100806002 1 GError ∗ error = NULL; 2 u m o c k d e v t e s t b e d l o a d ioctl(testbed ,"/dev/bus/usb/001/013", 3 "cam−import.ioctl", &error); Introduction Overview Static devices Dynamic behaviour Conclusion Summary • Limited to recorded use cases, without much deviation • use case driven, especially ioctls • specific to /sys and /dev • other kinds of devices: scsi debug, veth, mac80211 hwsim Introduction Overview Static devices Dynamic behaviour Conclusion EOF Thank you for your attention! Q & A, other use cases, discussion https://github.com/martinpitt/umockdev/ pitti on Freenode, [email protected].