I'm working on a project using GPIOs. I struggle to write some automated testing code.

I would like to emulate activity on /sys/class/gpio/X/{direction,value}. Is there a way to achieve this?

GPIO's trigger interrupts, which are polled using the POLLPRI flag. I need a way to re-create this behavior in full software, so I can test my code against different "physical input" automatically.

Any idea?


1 Answer 1


I'm assuming you want to do this without external hardware connected to the gpios.

Have your test code alter the level of the gpios you want to test.

There are multiple ways.

  • least intrusive, add an internal pull-up or pull-down to the gpio.
  • write 0 or 1 to the gpio.
  • generate PWM on the gpio to force constant level changes.

You haven't said anything which precludes this simple solution.

  • Yes, I'd like to do this w/o any hardware. Writing to the GPIO doesn't seem to work (permission denied, probably because the pins are in interrupt mode.
    – Xaqq
    Sep 22, 2014 at 7:41
  • Use a library to access the gpios directly so bypassing the sys interface. I've used the same technique to time Linux interrupt latency. Set up a sysfs interrupt then use library software to toggle the gpio level.
    – joan
    Sep 22, 2014 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.