Slide 1

Slide 1 text

GNU/LINUX HARDWARE EMULATION
 WITH PYTHON Stefano Cotta Ramusino ! 
 22 . 07 . 2014

Slide 2

Slide 2 text

OH NO!! WHAT CAN I DO? Do want to test your connection code
 with a WiFi/GSM network
 …
 but you haven’t any dongle? Stefano Cotta Ramusino Page 1/10

Slide 3

Slide 3 text

OH NO!! WHAT CAN I DO? Do you want to check your software notification when battery is low
 …
 but you’re testing your application
 on your desktop? Stefano Cotta Ramusino Page 2/10

Slide 4

Slide 4 text

OH NO!! WHAT CAN I DO? Do you want to manipulate the data coming from a device
 …
 but you’ve lend it to someone else? Stefano Cotta Ramusino Page 3/10

Slide 5

Slide 5 text

YOU’RE MY SALVATION No problem
 
 you can emulate all these hardware with
 
 Python ! Stefano Cotta Ramusino Page 4/10

Slide 6

Slide 6 text

GNU/LINUX ARCHITECTURE Kernel Stefano Cotta Ramusino Page 5/10 D-Bus Daemon udev Hardware inotify Software to Test

Slide 7

Slide 7 text

HARDWARE EMULATION Stefano Cotta Ramusino Page 6/10 Kernel D-Bus Daemon inotify D-Bus Mock Emulated Hardware Software to Test

Slide 8

Slide 8 text

LIBRARIES pyinotify! dbus-python! python-dbusmock! pyudev Stefano Cotta Ramusino Page 7/10

Slide 9

Slide 9 text

D-BUS SERVICE class DBusService(dbus.service.Object):
 def __init__(self):
 name = dbus.service.BusName('test.service', bus = dbus.SessionBus())
 dbus.service.Object.__init__(self, bus_name, '/test/service')
 
 @dbus.service.method('test.service')
 def hello(self):
 return 'Hello World!' Stefano Cotta Ramusino Page 7/10

Slide 10

Slide 10 text

D-BUS MOCK wifi = dbusmock.AddWiFiDevice('MyWiFi', 'wlan0', DeviceState.ACTIVATED)! dbusmock.AddAccessPoint(wifi, 'MyAcccessPoint', 'MyAP', '00:11:22:33:44:55', …)! dbusmock.AddWiFiConnection(wifi, 'MyConnection', 'MyAP', …) Stefano Cotta Ramusino Page 8/10

Slide 11

Slide 11 text

INOTIFY wm = pyinotify.WatchManager()! wm.add_watch(path, pyinotify.IN_OPEN | pyinotify.IN_CLOSE_WRITE) Stefano Cotta Ramusino Page 9/10

Slide 12

Slide 12 text

CONTACT Stefano Cotta Ramusino! [email protected]! @stefano_cotta Stefano Cotta Ramusino Page 10/10