How can I fake a linux character device with D? -


i fake led (character device) of embedded linux board (beaglebone black) in user space library written in d.

via command line led driver represented user space "device file" (e.g. led "user leds d2 0"):

debian@beaglebone:/sys/class/leds/beaglebone:green:usr0$ tree . ├── brightness ├── device -> ../../../leds ├── invert ├── max_brightness ├── power │   ├── async │   ├── autosuspend_delay_ms │   ├── control │   ├── runtime_active_kids │   ├── runtime_active_time │   ├── runtime_enabled │   ├── runtime_status │   ├── runtime_suspended_time │   └── runtime_usage ├── subsystem -> ../../../../../class/leds ├── trigger └── uevent 

via command line single entities e.g. brightness (turn on , off) can written , read files:

cd /sys/class/leds/beaglebone:green:usr0 echo none > trigger echo 1 > brightness echo 0 > brightness 

i consider reasonable abstract whole device interface , implement production class , test class (hand-made fake object) implements interface. client code of library use either production code or fake class injected using dependency injection.

could mock framework https://github.com/qaston/dmocks-revived provide functionality use fake driver in client code out of box instead of using handmade fake led driver described above? (i guess fake more complicated character devices necessary "hand-implement" anyway.)

or there better approaches fake character device (e.g. make production class require root path of driver when creating instance via "constructor injection")?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -