Introduction Overview Static devices Dynamic behaviour Conclusion Capture and Replay Hardware behaviour for Regression Testing and Useful Bug Reports Martin Pitt <martin.pitt@ubuntu.com> Linux Plumbers Conference, September 2013
Introduction Overview Static devices Dynamic behaviour Conclusion Motivation From: Joe User < joe@random.com > 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 < hacker@freedesktop.org > 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 UMockdevTestbed ∗ t e s t b e d = umockdev testbed new ( ) ; 1 const char ∗ s y s b a t = umockdev testbed add device ( testbed , 2 ” power supply ” , ”fakeBAT0” , NULL, 3 / ∗ a t t r i b u t e s ∗ / 4 ” type ” , ” Battery ” , 5 ” s t a t u s ” , ” D i s c h a r g i n g ” , 6 ” e n e r g y f u l l ” , ”60000000” , 7 ” energy now ” , ”48000000” , 8 NULL, 9 / ∗ p r o p e r t i e s ∗ / 10 ”POWER SUPPLY ONLINE” , ”1” , 11 NULL ) ; 12 ) ; 13 14 / ∗ s t a r t GTestDBus and upowerd ∗ / 15 / ∗ c a l l upower − − dump or query over D − BUS ∗ / 16
Introduction Overview Static devices Dynamic behaviour Conclusion API usage: load device umockdev-record /sys/class/power supply/BAT0 > bat0.umockdev Load with: from g i . r e p o s i t o r y import UMockdev 1 t e s t b e d = UMockdev . Testbed . new ( ) 2 t e s t b e d . a d d f r o m f i l e ( testbed , ’ bat0 . umockdev ’ ) 3
Introduction Overview Static devices Dynamic behaviour Conclusion API usage: change device / ∗ change b a t t e r y charge ∗ / 1 u m o c k d e v t e s t b e d s e t a t t r i b u t e ( testbed , sys bat , 2 ” energy now ” , ”1500000” ) ; 3 / ∗ send uevent to n o t i f y upowerd ∗ / 4 umockdev testbed uevent ( testbed , sys bat , ” change ” ) ; 5 6 / ∗ c a l l upower − − dump or query over D − BUS ∗ / 7
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^@^@^@ GError ∗ e r r o r = NULL ; 1 u m o c k d e v t e s t b e d l o a d s c r i p t ( testbed , ”/ dev /ttyUSB0” , 2 ” huawei . s c r i p t ” , &e r r o r ) ; 3
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 GError ∗ e r r o r = NULL ; 1 u m o c k d e v t e s t b e d l o a d i o c t l ( testbed , ”/ dev / bus / usb /001/013” , 2 ”cam − import . i o c t l ” , &e r r o r ) ; 3
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, martin.pitt@ubuntu.com
Recommend
More recommend