Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GNU Linux Hardware Emulation with Python

GNU Linux Hardware Emulation with Python

Talk: https://www.youtube.com/watch?v=UhLP0TJg5T8

With the kernel inotify feature, the D-Bus mocker library and the udev monitoring we try to detect the different events that occours when you're using a specific set of connected devices.

Then we try to mimic these devices investigating also the kernel drivers if necessary.

At the end we're ready to connect the simulation routines to our testing procedure.

Stefano Cotta Ramusino

July 22, 2014
Tweet

More Decks by Stefano Cotta Ramusino

Other Decks in Programming

Transcript

  1. GNU/LINUX HARDWARE EMULATION

    WITH PYTHON
    Stefano Cotta Ramusino !

    22 . 07 . 2014

    View full-size slide

  2. 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

    View full-size slide

  3. 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

    View full-size slide

  4. 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

    View full-size slide

  5. YOU’RE MY SALVATION
    No problem


    you can emulate all these hardware with


    Python !
    Stefano Cotta Ramusino
    Page 4/10

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. 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

    View full-size slide

  10. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide