29.01.2014 Views

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 15. AUTOMATED TEST GENERATION 130<br />

../test/tut15.c<br />

uint64_t (autotest f)(int input a, int input b)<br />

{<br />

if ((a * b) - (a + b) == 14862436) {<br />

return 1;<br />

}<br />

else return 0;<br />

}<br />

The function g compares the string given by its argument with the string "autotest". The type<br />

<strong>of</strong> the argument s has the annotation inputnt indicating that it is a null-terminated array. This<br />

indicates to the test generation runtime that it must generate valid null-terminated strings when<br />

concocting new inputs for g.<br />

../test/tut15.c<br />

uint64_t (autotest g)(char *inputnt s)<br />

{<br />

return string_compare(s, "autotest");<br />

}<br />

int main ()<br />

{<br />

uint64_t res;<br />

char cheese[1024] = "cheese";<br />

res = f(0,0);<br />

res = g(cheese);<br />

}<br />

return res;<br />

This example can be compiled by invoking the following command:<br />

$ ciltutcc --enable-tut15 -o tut15 test/tut15.c<br />

Then invoking the resulting program, tut15, produces the following output:<br />

autotest f:<br />

a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!