GNU/Linux Hardware Emulation with Python
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Subtitle |
| |
Alternative Title |
| |
Title of Series | ||
Part Number | 72 | |
Number of Parts | 119 | |
Author | ||
License | CC Attribution 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor. | |
Identifiers | 10.5446/20048 (DOI) | |
Publisher | ||
Release Date | ||
Language | ||
Production Place | Berlin |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
| |
Keywords |
EuroPython 201472 / 119
1
2
9
10
11
13
15
17
22
23
24
27
28
41
44
46
49
56
78
79
80
81
84
97
98
99
101
102
104
105
107
109
110
111
112
113
116
118
119
00:00
Computer hardwareEmulatorSoftwareComputer hardwareComputer animationLecture/Conference
00:53
Computer networkSoftware protection dongleWeightOrdinary differential equationDesign of experimentsSoftwareComputer hardwareComputer animation
01:31
Boss CorporationConnected spaceFunctional (mathematics)System callSystem identificationComputerCodeAngleSoftware testingLecture/Conference
02:26
CAN busUsabilityComputer hardwareArc (geometry)DemonBus (computing)EmulationEmulatorInsertion lossFunctional (mathematics)Basis <Mathematik>Level (video gaming)Physical systemTheory of relativityTerm (mathematics)Cartesian coordinate systemVideo gameMessage passingGreatest elementPower (physics)SoftwareBus (computing)Kernel (computing)ComputerWell-formed formulaSpecies1 (number)Distribution (mathematics)Standard deviationLibrary (computing)InformationNP-hardData managementBoss CorporationDecision theoryComputer fileVariable (mathematics)Order (biology)Computer programmingEndliche ModelltheorieMathematical optimizationUtility softwareUniverse (mathematics)Reading (process)BlogClient (computing)Line (geometry)Service (economics)SimulationComputer hardwareComputer architectureSlide ruleSoftware testingSoftware protection dongleNetzwerkverwaltungTemplate (C++)DemonGame controllerComputer simulationReal numberDevice driverProjective planeEmulatorModule (mathematics)Computer animation
09:02
SummierbarkeitScalable Coherent InterfaceRadio-frequency identificationPerturbation theoryTrigonometric functionsFunctional (mathematics)Computer hardwarePhysical systemSpacetimeBoss CorporationOpen sourceMultiplication signDefault (computer science)Computer simulationData managementSpeciesView (database)Bus (computing)Computer fileGreatest elementSoftwareAtomic numberLatent heatKey (cryptography)Connected spaceVideo gamePower (physics)Uniform resource locatorRational numberVector spaceProcess (computing)Cellular automatonMassCuboidService (economics)Server (computing)Library (computing)IdentifiabilityVulnerability (computing)ACIDLogicPoint (geometry)Sign (mathematics)Utility softwareWordSoftware protection dongleDemonStandard deviationNetzwerkverwaltungLoop (music)VirtualizationState of matterComputer programmingSoftware testingHoaxRevision controlMereologySimulationEmulatorComputer animation
15:38
Digital librarySoftwareConnected spaceSubsetComputer programmingTheory of relativityExistenceField (computer science)Speech synthesisSoftware testingPhysical systemInterface (computing)Library (computing)VirtualizationCondition numberComputerForcing (mathematics)Data managementMessage passingCASE <Informatik>Range (statistics)Computer hardwareEmulatorLatent heatMereologyNetzwerkverwaltungBus (computing)Lecture/Conference
18:41
Bus (computing)Library (computing)Source codePower (physics)NetzwerkverwaltungComputer animation
19:21
Virtual machineLibrary (computing)Computer hardwareEvent horizonInteractive televisionProcess (computing)Multiplication signBlock (periodic table)WindowLecture/Conference
20:28
Googol
Transcript: English(auto-generated)
00:15
Well, I'm Stefano, and now I try to present to you how you can use Python to emulate hardware.
00:28
This is strange things for some of you, but in some ways this is possible, because with Linux, for example, it's possible to use software to emulate hardware in a very strange way, and so also with Python it's possible.
00:53
So, why do we have to emulate hardware? Why is this a necessity?
01:02
I'll be able to have this as a target, maybe because we have a software that we can test, but this software runs in a specific target, I work with an embedded, so if I wanted to test a software for an embedded target,
01:29
I have to emulate also the hardware of this embedded device. So, what I can do? I can, for example, for testing connection code in a desktop computer with a Wi-Fi or GSM network,
01:48
I have to buy an angle to have this functionality, but it's not a true way to do this. Why do I have to check if this connection code works?
02:01
Because it's powerful to have a connection code in an embedded device that works very well, because if you have some problem with this code, your device is an exuber. And also with the battery, how I can check if the battery is low?
02:23
I can pop up a notification to the user if the battery is low in my desktop computer, I can have any battery, so what I can check. And also, with other devices that can be connected to an embedded device,
02:43
or already present in an embedded device, like GPS, or like another tracker tools that are common, like some specific devices that are connected to your body.
03:02
And all this, you can test your software using Python, but in which way? The standard Linux architecture here is very simplified, but at the bottom you have the hardware that is connected to the kernel.
03:25
The kernel uses a functionality after 2.6 that is called inotify. Inotify is a module of the kernel that, thanks to this module,
03:43
is possible to connect, to check if something is connecting to the real computer, and get a notification immediately. Also with devices that are not real devices, like emulator 1. So when I connect a periphery, or I change a file of a system,
04:06
inotify can detect this, if you enable this functionality of the kernel. In the upper level, in the Unix system, in Linux system, you have some daemons that are running.
04:21
One of them is this dbus. dbus is used commonly to send messages from an application to another, but also by the system daemon, like upower. Upower is the daemon that generates all the signal from your battery to your system,
04:42
and dbus is the message bus that is used by this program. Also, udev is used when you connect a pen dongle to your computer. It generates a udev message that you run again on dbus.
05:01
On the top of this, you have your software to test. So you can emulate this hardware. The software to test is connected not to your real hardware, but bypassed by kernel. Other utilities I will show in the previous slide are dbus and udev.
05:27
But udev, you can emulate. Why? Because it's connected to dbus. So I can emulate udev behavior using dbus messages. So I can try to detect when the application wants to retrieve data
05:46
from a device using inotify, because inotify can permit me to say, OK, I'm reading from this file. This file is a device. The device is not present. I created this device. It's not a problem.
06:02
And then also upower generates the message from the batteries from your power supplier. OK, I can sniff this information for real hardware, a real battery, and then regenerate with dbus-mock. Dbus-mock is only a library that can help you
06:23
to create this simulation that are in higher level, because it's not a kernel driver emulation. It's only a software using dbus message. And so what are the libraries we can use in Python
06:42
to use this functionality for Linux? Sure, inotify is a library that is connected directly to this module of kernels. They are available in all Linux kernels to the 2.5,
07:01
and permits in a simple way to use inotify in an easy way. Then dbus-python that is abiding from library dbus, they are included in a lot of distribution, because a lot of program in a distribution of Linux
07:22
uses dbus-python to manage and create software that are based on. Python dbus-mock is a collection or template to generate emulated hardware. So inside of this library,
07:41
this is only a collector library on top of dbus, you have a network manager device that can create a wireless network, or a power template that can create a battery and power supply real simulator hardware.
08:05
And then pyudev. Pyudev, why? Because when you want to investigate how it works on real hardware, you have to sniff to monitor with udev. udev with pyudev, you can control udev with Python,
08:23
and then monitor each device. Why? Because an hardware uses to send messages to the system using udev. So with this, pyudev, you can see all messages that arrive from a device.
08:42
So when it's connected, when data reaches the system, and so on. And so this is the first dbus service. You can create in a few lines. This is only using dbus library, so the binding of dbus library included in dbus project.
09:05
So they are maintaining the same version. So with this library, you have no problem if dbuses are your version that you are binding. They are maintaining the same. And so what you can see,
09:21
you can create a test service using the session bus default that is for user. Choose session bus in dbus system and user. The default, if you run your program without any parameter,
09:42
it creates a bus in user space. And if you want to recreate a daemon like Upower, you have to remember that Upower creates a system service. So you have to use the dbus-like system.
10:02
And then you can create a service with your path. Dbus creates a path like Linux standard. So a folder with a service and a service name. And then there is a simple function, listen,
10:20
to create a loop to maintain this server. This is a dbus server, so it's like a daemon that listens for each request you receive. And then you have the function. So the function is test-service-hello that returns only the word hello world.
10:42
And this is what you can create with a template. So with dbus-mock, you have a template. We can join to dbus the functionality of what you want. So you can create a network manager device like this.
11:04
You can create a Wi-Fi adapter. So if you have a specification of an hardware, you can recreate with this library. So you can attach a virtual Wi-Fi adapter to a network manager.
11:29
And then at this point, if you want to try the scan, this is possible now, because you can recreate your Wi-Fi network
11:41
without a Wi-Fi dongle. This is very cool. Also, we can recreate the customer problem with a specific network, because you can create this network with the same key, the same protection, the same encryption, and then check if it is an adapter problem or a software problem,
12:04
a network manager, for example. And then you can create the connection. So with a simple command, you can establish the connection with your fake access point.
12:23
And so on. This is also useful for U-Power. With U-Power, you have the same mock. So you have the possibility to create a battery with the same specification. So we can check all the specifications of battery with the D-Bus monitor
12:40
and then recreate with all the specifications, so the duration of the battery, the state of power supply, whether it's connected or not connected, and so on. And what about iNotify?
13:00
Before I say that if a software checks a device, it attaches to a file, so it's open. And if you have something that checks that this file is open, I can run this simulation not always, but always is necessary.
13:23
Why this? Because if this works full of time, you can have some devices that are not present virtualized. They are always present in your system that is wrong. This iNotify prevents this.
13:42
So the devices are created each time the software is needed. So with iNotify, I can detect the part which is the device I can connect. So, for example, if you wanted to access to Boolans Air, I put here the part of Boolans Air,
14:03
and then recreate all my network on the fly with the mock before I show. And also for the battery, if I wanted to recreate some devices that are not present in a mock, I can create a mock myself,
14:20
because with SNF, you'd have monitor, iNotify monitor. Yes, with iNotify, I can read each request from a software, also by system, to a specific part. So I can show when a file is created, deleted, or modified.
14:44
And this is very powerful, because it's possible to have the same behavior of hardware device without anything, without anything else. So this is what you can do with hardware emulation in Python.
15:06
And this is a small example of what you can do. But the possibility is very, very, you can reach everything. So if you have a device that you cannot have,
15:25
but you have the specification, or you have only the data sheet, you can only recreate this also with Python. And this is very cool. Thank you.
15:44
Any questions? I'm having a DBUS message which claims there is an interface, and does not create the interface. So how does it help?
16:04
And in case of network, you can create a DBUS message and claim now you got connectivity, but you still don't have connectivity. The connectivity is not a problem. The network connectivity is not a problem,
16:20
because if your system is connected to Ethernet, you can use this network. This is only emulation of other devices that are not existent. But when you create a ping or whatever in your network, you go forward a real network.
16:41
So network manager is deviated by something, but in your program, in your emulation program, you can say, okay, we create all the network, but when we receive something request for a network connection, already added to a real one.
17:00
So it's not a real problem. I accept the answer. Are there any more questions?
17:22
If I understood you correctly, your main purpose was to test hardware parts that are not available, or that are rather hard to influence, that they have this condition that you actually want to check with your program. Therefore, your field was embedded, I assume, and using embedded Linux,
17:42
and using normal Linux to basically test the whole stuff. Is that correct? Yeah, yeah, yeah. This is used for testing software for embedded target. So we need to recreate some hardware specific in a desktop computer, so we recreate some hardware devices that are not possible to attach to a desktop computer.
18:12
Other question?
18:21
Do you also intend to build a virtual library for that, or a library of virtual devices? Yeah, it's possible. It would be very nice to have a range of devices virtualized. In this library, the bus market, there is a lot of examples, but yes, it's not very well documented.
18:46
Inside there is a network manager device, U-Power, and other system-based, recreateable devices, but yes, it's not very well documented.
19:03
But yes, it's possible to create some library. Maybe in future, yes. Any other questions? Then thanks a lot for your talk.
19:21
Oh, sorry. Have you tried to use this library when you interact with some proprietary hardware that runs only on Windows, and you have like VirtualBox or VMware, and would it be possible to sniff some of these events through this library?
19:46
Would it be useful? Yeah, if you use some emulation, it's not a problem, because in a VirtualBox, for example, if you attach a USB device, you can attach directly to the Virtual Machine. So you can sniff in a simple way.
20:05
Yeah, it's not a problem. Thank you. Okay. Thanks a lot for your talk.