bleneak
Posts: 1
Joined: Sun Dec 09, 2018 6:29 pm

Testing App Reading GPIO Pins

Sun Dec 09, 2018 7:25 pm

I will be writing a python app that will read some GPIO pins on a Raspberry Pi and store data on an Azure SQL server. On the field, the signals will come from switches in a factory. For testing the functionality, I want to write a unit/stress test app that will simulate these signals.

Since each pin has a global input/output mode, the test app cannot be setting the pins while the tested app will be reading them. The simplest method I could think of was to set a mirror set of pins to output mode, connect them to the input pins, and have the test app drive the output pins to simulate real world conditions. So as an example, say the actual app read pins 2-11. For testing, I would physically connect pins 2-11 to pins 12-21 (each over a 1K resistor just to be safe), and run a test app which sets pins 12-21 to output mode and drive them as needed for the test.

Is this a good way to test such apps? Or is there a better way to do this? A way to intercept GPIO.input calls in the actual app from the test app could be a better solution (as it doesn't include physical intervention), but is this easy to do in python, and will it correctly test all potential hardware problems? The answer probably exists in a guide, but i couldn't find it online so far. Thanks for any comments.

User avatar
davidcoton
Posts: 3780
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Testing App Reading GPIO Pins

Sun Dec 09, 2018 9:06 pm

If your code is written in a suitably modular style, possibly using the benefits of an object orientated design, it should be easy to add software input simulation to your GPIO reading routines (or to display the outputs of GPIO setting routines). That is useful for testing your logic and human interface layers, which may help in code development. It has some limitations for production testing:
  • There will always be some code that the software simulation bypasses, which will not be tested.
  • The hardware interface will not be tested.
So the ideal production test for your completed system will use a hardware simulator, which could well be another Pi programmed to simulate the factory switch conditions that you need to monitor. You can either interconnect the GPIOs just through resistors, or build something that simulates the actual factory signal levels so that you can test your interface circuits. In fact, if you use a pluggable interface to the Pi's GPIO, it should be possible to use the same test Pi and software with either style of hardware interface.

Key questions for you to consider:
  • What is the purpose of the tests?
  • What is the scope of the tests (software, Pi assembly, finished product)?
  • How many units need testing, and how often?
  • What is the cost of inadequately tested units being released?
Signature retired


Return to “Beginners”