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 128<br />

approximation may prevent the SMT solver from producing a new path through the code, but<br />

strategies for achieving high coverage exist in this case, and are implemented by the above mentioned<br />

tools.<br />

To handle function calls, the mapping <strong>of</strong> actual parameters to formal parameters is handled like<br />

assignments. To handle function return values, a call is made so that the value can be remembered<br />

by the runtime, and then assigned at the call site.<br />

A loop is wrapped around each call <strong>of</strong> an autotest function. This loop noties the runtime<br />

when an autotest function is completed. If the runtime is able to produce an input that may<br />

explore a new path, the autotest function is called again. Otherwise, the loop terminates. This<br />

loop is constructed in the makeTestLoop function by way <strong>of</strong> an interpreted constructor.<br />

15.2.2 autotest Runtime<br />

The runtime library for this tutorial is divided into three parts. First, we maintain a symbolic<br />

memory that maps concrete addresses to expressions in terms <strong>of</strong> inputs. Second, at the end <strong>of</strong> an<br />

autotest function, we translate these expressions into expressions <strong>of</strong> the Yices SMT solver in order<br />

to obtain a path condition. Finally, we maintain a set <strong>of</strong> path conditions from which we may choose<br />

a path to modify for submission to Yices in the hope <strong>of</strong> obtaining inputs that will explore a new<br />

path. The source for the runtime library can be found in ciltut-lib/src/concolic. File names<br />

mentioned below are relative to this path.<br />

The le concolic exp.ml implements our internal expression representation. We dene our<br />

own type for expressions instead <strong>of</strong> translating directly to Yices expressions so that we leave open<br />

the possibility <strong>of</strong> using other SMT solvers in the future. The le concolic ctxt.ml implements the<br />

mapping from memory addresses to our symbolic expressions. It also maintains state for Yices, and<br />

includes a function yices <strong>of</strong> exp that translates our symbolic expressions into Yices expressions.<br />

In yices <strong>of</strong> exp the bit shifting operations are not translated into symbolic Yices expressions.<br />

This is because the Yices theory for bitvectors is only capable <strong>of</strong> reasoning about shifts by constant<br />

amounts. Therefore, yices <strong>of</strong> exp simply uses the concrete result <strong>of</strong> the operations.<br />

Finally, the le concolic paths.ml implements the path exploration algorithm. The global<br />

record pState maintains a list <strong>of</strong> already explored paths along with a list <strong>of</strong> conditions for the<br />

current path. It also maintains two mappings. The branchHT hash table maps branch identiers<br />

to the state <strong>of</strong> a branch. A branch identier is a combination <strong>of</strong> an id assigned at compile time to<br />

each conditional, and a count <strong>of</strong> the number <strong>of</strong> times a conditional has been executed on a single<br />

concrete run. The count is kept so that the possibly many executions <strong>of</strong> the same static conditional<br />

are not improperly conated by the path exploration algorithm. This is important, for example,<br />

so that each time a loop guard is executed, it is considered a dierent conditional. The state <strong>of</strong><br />

a branch is either NeitherTaken, TrueTaken, FalseTaken, or BothTaken. The second hash table,<br />

branchCounts, keeps track <strong>of</strong> how many times a conditional has been executed, so that branch id's<br />

may be properly assigned.<br />

When a conditional is executed, its id is determined by checking its static id and looking it up<br />

in branchCounts. Then, the condition is appended to pathCond. When an autotest function ends,<br />

the expressions in pathCond are translated to Yices expressions, and the resulting path condition is<br />

appended to paths, and branchHT is updated. Then, paths is searched for a path condition having

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

Saved successfully!

Ooh no, something went wrong!