CIS 542 Embedded Systems Programming – Summer 2013 Lecture ...
CIS 542 Embedded Systems Programming – Summer 2013 Lecture ...
CIS 542 Embedded Systems Programming – Summer 2013 Lecture ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
A tool you can use to measure coverage is called “gcov”. To use gcov, run the following:<br />
gcc -fprofile-arcs -ftest-coverage myprog.c -o myprog<br />
./myprog (this creates myprog.gcda/data and myprog.gcno/graph)<br />
gcov myprog.c (this creates myprog.c.gcov)<br />
gcov -b myprog.c will also give branch coverage info<br />
Verification<br />
Testing is nice and easy but, as has been famously pointed out, “testing can only prove the existence of<br />
bugs, not their absence.” This is because, when we test, we pick representative inputs but we don't<br />
choose all possible inputs and/or all possible behaviors.<br />
It would be better to actually prove certain properties of the code. This is known as verification. In the<br />
systems we're interested in here, these are often referred to as safety properties: we want to be able to<br />
prove that there are certain bad things that can never happen.<br />
For instance, in this case we may want to prove that the speed is always less than or equal to 100. This<br />
can be done using a technique called model checking: we want to show that our code adheres to this<br />
“model of correctness”.<br />
Here is a piece of code that would use our control method:<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
10<br />
11<br />
12<br />
13<br />
14<br />
15<br />
16<br />
17<br />
18<br />
19<br />
drive_car() {<br />
}<br />
int speed;<br />
enum states state;<br />
while (1) { // keep looping and waiting for signal<br />
}<br />
// assume this is our interface with the hardware<br />
int signal = get_signal_from_driver();<br />
enum events event;<br />
if (signal == 0) event = brake;<br />
else if (signal == 1) event = accel;<br />
else continue; // illegal signal<br />
speed = control(speed, event, &state);<br />
To prove that the speed is always less than equal to 100, we can use a tool called BLAST. When using<br />
this tool, we attempt to show that the property can never be violated: that is, that it is impossible for the<br />
speed to go over 100.<br />
Here is an updated version of the code that could be used with BLAST: