2. 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”?
6. Introduction
Overview
Static devices
Dynamic behaviour
Conclusion
API usage: create device
1
2
3
4
5
6
7
8
9
10
11
12
13
UMockdevTestbed ∗ t e s t b e d = u m o c k d e v t e s t b e d n e w ( ) ;
const char ∗ sys bat = umockdev testbed add device ( testbed ,
” p o w e r s u p p l y ” , ” fakeBAT0 ” , NULL ,
/∗ a t t r i b u t e s ∗/
” type ” , ” Battery ” ,
” status ” , ” Discharging ” ,
” e n e r g y f u l l ” , ” 60000000 ” ,
” e n e r g y n o w ” , ” 48000000 ” ,
NULL ,
/∗ p r o p e r t i e s ∗/
”POWER SUPPLY ONLINE” , ” 1 ” ,
NULL ) ;
);
14
15
16
/∗ s t a r t GTestDBus and upowerd ∗/
/∗ c a l l upower −−dump o r q u e r y o v e r D−BUS ∗/
7. Introduction
Overview
Static devices
Dynamic behaviour
API usage: load device
umockdev-record /sys/class/power supply/BAT0 >
bat0.umockdev
Load with:
1
2
3
from g i . r e p o s i t o r y i m p o r t UMockdev
t e s t b e d = UMockdev . T e s t b e d . new ( )
t e s t b e d . a d d f r o m f i l e ( t e s t b e d , ’ b a t 0 . umockdev ’ )
Conclusion
8. Introduction
Overview
Static devices
Dynamic behaviour
API usage: change device
1
2
3
4
5
/∗ c h a n g e b a t t e r y c h a r g e ∗/
umockdev testbed set attribute ( testbed , sys bat ,
” e n e r g y n o w ” , ” 1500000 ” ) ;
/∗ s e n d u e v e n t t o n o t i f y upowerd ∗/
u m o c k d e v t e s t b e d u e v e n t ( t e s t b e d , s y s b a t , ” change ” ) ;
6
7
/∗ c a l l upower −−dump o r q u e r y o v e r D−BUS ∗/
Conclusion
11. Introduction
Overview
Static devices
Dynamic behaviour
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
2
3
G E r r o r ∗ e r r o r = NULL ;
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 ( t e s t b e d , ” / d e v / ttyUSB0 ” ,
” h u a w e i . s c r i p t ” , &e r r o r ) ;
Conclusion
12. 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
2
3
G E r r o r ∗ e r r o r = NULL ;
u m o c k d e v t e s t b e d l o a d i o c t l ( t e s t b e d , ” / d e v / b u s / u s b /001/013 ” ,
”cam−i m p o r t . i o c t l ” , &e r r o r ) ;
13. Introduction
Overview
Static devices
Dynamic behaviour
Conclusion
Summary
• successful for several packages
• 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
• testing against D-BUS services: python-dbusmock, Bendy Bus