source: CIVL/doc/manual/part-tools.tex@ f65dbd0

1.23 2.0 main test-branch
Last change on this file since f65dbd0 was a9b64e6a, checked in by Andre Marianiello <andre.marianiello@…>, 12 years ago

boolea -> boolean

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1066 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 20.4 KB
Line 
1\part{Tools}
2\label{part:tools}
3
4\chapter{Tool Overview}
5
6\section{Symbolic execution}
7
8The tools currently in the CIVL tool kit all use \emph{symbolic
9 execution}. This is a technique in which variables are assigned
10symbolic rather than concrete values. In particular, input variables
11are assigned unique \emph{symbolic constants}, which are symbols such
12as $X$, $Y$, and so on. Operations produce symbolic expressions in
13those symbols, such as $(X+Y)/2$.
14
15\section{Commands}
16
17Current tools allow one to \emph{run} a CIVL program using random
18choice to resolve nondeterministic choices; \emph{verify} a program
19using model checking to explore all states of the program; and
20\emph{replay} a trace if an error is found. There are also commands
21to show the results just of preprocessing or parsing a file; as these
22are basically sub-tasks of the other tasks, they are used mainly for
23debugging.
24
25Each tool is launched from the command line by typing ``\texttt{civl}
26\textit{cmd} \ldots'', where \textit{cmd} is one of
27\begin{itemize}
28\item \ct{help} : print usage information
29\item \ct{run} : run the program using random simulation
30\item \ct{verify} : verify program
31\item \ct{replay} : replay trace for program
32\item \ct{parse} : show result of preprocessing and parsing file
33\item \ct{preprocess} : show result of preprocessing file only.
34\end{itemize}
35The additional arguments and options are described below and are also
36shown by the \ct{help} command.
37
38A number of properties are checked when running or verifying
39a CIVL program. These include the following:
40\begin{itemize}
41\item absence of deadlocks
42\item absence of assertion violations
43\item absence of division or modulus with denominator $0$
44\item absence of illegal pointer dereferences
45\item absence of out-of-bounds array indexes
46\item absence of invalid casts
47\item every object is defined (i.e., initialized) before
48 it is used.
49\end{itemize}
50
51
52\section{Options}
53
54The following command line options are available:
55
56\newenvironment{optionlist}{\begin{flushleft}}{\end{flushleft}}
57\newcommand{\option}[2]{#1\\[0mm]\makebox[5mm]{}#2\\[3mm]}
58\newcommand{\booloption}[3]{\option{\ct{-#1} or \ct{-#1=}\textit{boolean}
59 (default: \ct{#2})}{#3}}
60\newcommand{\intoption}[3]{\option{\ct{-#1=}\textit{integer}
61 (default: \ct{#2})}{#3}}
62\newcommand{\mapoption}[2]{\option{\ct{-#1}\textit{key}\ct{=}\textit{value}}{#2}}
63\newcommand{\stringoption}[3]{\option{\ct{-#1=}\textit{string}
64 (default: \ct{#2})}{#3}}
65
66\begin{optionlist}
67 \booloption{debug}{false}{debug mode: print very detailed information}
68 \booloption{echo}{false}{print the command line}
69 \booloption{enablePrintf}{true}{enable \texttt{printf} function}
70 \intoption{errorBound}{1}{stop after finding this many errors}
71 \booloption{guided}{false}{user guided simulation; applies only to
72 run, ignored for all other commands}
73 \intoption{id}{0}{ID number of trace to replay}
74 \mapoption{input}{initialize input variable \textit{key} to
75 \textit{value}}
76 \intoption{maxdepth}{2147483647}{bound on search depth}
77 \booloption{min}{false}{search for minimal counterexample}
78 \stringoption{por}{std}{partial order reduction (por) choices:
79 std (standard por) or scp (scoped por)}
80 \booloption{random}{varies}{select enabled transitions randomly;
81 default for \texttt{run}, ignored for all other commands}
82 \booloption{saveStates}{true}{save states during depth-first search}
83 \stringoption{seed}{none}{set the random seed; applies only to run}
84 \booloption{showAmpleSet}{false}{print the ample set of each state}
85 \booloption{showModel}{false}{print the model}
86 \booloption{showProverQueries}{false}{print theorem prover queries
87 only}
88 \booloption{showQueries}{false}{print all queries}
89 \booloption{showSavedStates}{false}{print saved states only}
90 \booloption{showStates}{false}{print all states}
91 \booloption{showTransitions}{false}{print transitions}
92 \booloption{simplify}{true}{simplify states?}
93 \booloption{solve}{false}{try to solve for concrete counterexample}
94 \stringoption{sysIncludePath}{}{set the system include path}
95 \stringoption{trace}{}{filename of trace to replay}
96 \stringoption{userIncludePath}{}{set the user include path}
97 \booloption{verbose}{false}{verbose mode}
98\end{optionlist}
99
100\section{Errors}
101\label{sec:errors}
102
103When a property violation occurs, either in \emph{verification} or
104\emph{run} mode, a brief report is written to the screen. In
105addition, a report may be \emph{logged} in the directory
106\texttt{CIVLREP}.
107
108The \emph{error bound} parameter determines how many errors can be
109encountered before a search terminates. By default, the error bound
110is 1, meaning a search will stop as soon as the first error is found.
111The error bound can be set to a higher number on the command line
112using option \emph{errorBound}.
113
114When the error bound is greater than one, the CIVL verifier continues
115searching after the first error is discovered. It first attempts to
116``recover'' from the error by adding to the path condition a clause
117which guarantees that the error cannot happen. For example, if the
118error was caused by a possible division by zero, $x/y$, where $y$ is
119an unconstrained real symbolic constant, CIVL will add to the path
120condition the predicate $y\neq 0$, and continue the search. In some
121cases, CIVL determines that the modified path condition is
122unsatisfiable, in which case the search will back-track in the usual
123symbolic execution way.
124
125In addition to the printed reports, errors are logged. However, CIVL
126follows a protocol aimed at limiting the number of reports of errors
127which are essentially the same. This protocol uses a simple
128equivalence relation on the set of errors. Two erroneous states are
129considered equivalent if the errors are of the same \emph{kind}
130(deadlock, division by zero, illegal pointer dereference, etc.) and
131every process is at the same location in both states. When an error
132is encountered, CIVL first checks to see if an earlier equivalent
133errors exists in the log. If so, the lengths of the traces leading to
134the two error states are compared. If the new trace is shorter, the
135old log entry is replaced with the new one. In this way, only the
136shortest representative error trace for each equivalence class of
137errors is recorded in the log.
138
139A log entry actually entails two things: first, a plain text entry
140similar to the one printed to the screen is made in a log file in
141\texttt{CIVLREP}. The name of this file is usually of the form
142\texttt{\textit{root}{\U}log.txt}, where \textit{root} is the root of
143the original file name, i.e., the substring of the file name that ends
144just before the first `\texttt{.}'. For example, if the file name is
145\texttt{diningBad.cvl}, the log file will be named
146\texttt{diningBad{\U}log.txt}. This is a plain text, human-readable
147file which summarizes the results of the verification run.
148
149In addition, each saved trace is stored in a separate file in
150\texttt{CIVLREP}. The names of these files have the form
151\texttt{\textit{root}{\U}\textit{id}.trace}, where \textit{id} is the
152error ID (reported when the error is printed and logged). This file
153is not intended to be human-readable. It contains a compressed
154representation of the trace, including all of the options and
155parameter values and choices made a nondeterministic points.
156This file is used by CIVL when replaying an error trace.
157
158As mentioned above, the CIVL \texttt{replay} command is used to play
159an earlier-saved error trace. When more than one trace has been
160saved, the \texttt{-id} command line option can be used to specify
161which one to play. (The default \emph{id} is 0).
162
163\chapter{Interpreting the Output}
164
165\section{Transitions}
166
167Transitions are printed during trace \texttt{replay}, in the course of
168a \texttt{run}, or during verification if option
169\emph{showTransitions} is selected. A typical transition is printed
170as follows:
171
172\begin{verbatim}
173State 6, proc 0:
174 44->49: LOOP_FALSE_BRANCH at f0:36.18-23 "i < n";
175 49->RET: return (init) at f0:37.0-1 "}";
176 7->8: i = 0 at f0:42.7-16 "int i = 0";
177--> State 74
178\end{verbatim}
179
180This means that the transition begins executing from the state with
181ID 6, and it is executed by the process with PID 0. The transition
182is executed in a sequence of atomic steps; in this case there the
183transition consists of three steps.
184
185Process 0 begins at location 44; this is a static location in the
186program graph of a function in the CIVL model. Details about the
187locations can be seen by printing the CIVL model. In executing the
188first step, control moves from location 44 to location 49. This first
189step is an edge in the program graph corresonding to the \emph{false}
190branch of a loop condition, i.e., the branch that exits the loop.
191
192The remainder of the line describing the step specifies the part of
193the original source code corresponding to this step. The source code
194fragment can be found in file \texttt{f0}. To save space and avoid
195constantly repeating long paths, all the source files involved in a
196program are printed once and assigned keys such as \texttt{f0},
197\texttt{f1}, etc. The legend is printed out once at the beginning of
198the run; in this case it is simply the following:
199\begin{verbatim}
200File name list:
201f0 : dining.cvl
202\end{verbatim}
203The source code fragment begins on character 18 of line 36 of
204\texttt{f0}, and extends to character 23 of that line. This range is
205inclusive on the left and exclusive on the right, so the total number
206of characters in this range is $23-18=5$. The five characters from
207the source code are printed next inside double quotes. For longer
208ranges, this excerpt will be abbreviated using an elipsis.
209
210The second step executes a \emph{return} statement, which results in
211popping the top activation frame from process 0's call stack. The
212function returning is \texttt{init}. Since the program counter for
213that frame disappears with the execution of this step, there is no
214final value for its new location; this is signified using the
215pseudo-location \texttt{RET}.
216
217In the new top frame, control is at location 7, and an assignment
218statement is executed, moving control to location 8. With this last
219step, the transition ends at State 74.
220
221Between transitions, processes can be renumbered. Hence a process
222with PID 0 in one state, may have a different PID in another state.
223The same is true for dynamic scope IDs. Within a single transition,
224however, these numbers will not change.
225
226\section{States}
227
228States are printed typically when a property is violated, at the
229initial or final points of a trace replay, or if the option
230\emph{showStates}, \emph{showSavedStates}, \emph{verbose}, or
231\emph{debug} is selected.
232
233\begin{figure}
234 \begin{small}
235\begin{verbatim}
236State 7
237| Path condition
238| | 0 <= SIZEOF(dynamicType<146>)+-1
239| Dynamic scopes
240| | dyscope d0 (id=0, parent=d0, static=0)
241| | | reachers = {0}
242| | | variables
243| | | | __atomic_lock_var = process<-1>
244| | | | __heap = NULL
245| | dyscope d1 (id=1, parent=d0, static=4)
246| | | reachers = {0}
247| | | variables
248| | | | __heap = $heap<(A[1][])<H_p0s1v0i0l0[0:=A<(H_p0s1v0i0l0[0].0)[0:=1, 1:=2, 2:=3],2>]>>
249| | | | a = &heapObject<d1,0,0>[0]
250| | | | b = &heapObject<d1,0,0>[0].a[2]
251| Process states
252| | process p0 (id=0)
253| | | atomicCount=0
254| | | call stack
255| | | | Frame[function=_CIVL_system, location=14, f0:25.2-9 "$assert", dyscope=d1]
256\end{verbatim}
257 \end{small}
258 \caption{Complete print-out of a state}
259 \label{fig:state-print}
260\end{figure}
261
262A complete print-out of a state can be seen in Figure
263\ref{fig:state-print}. The state is presented in hierarchical way.
264At the top-most level of this hierarchy, there are 3 main parts to the
265state:
266\begin{enumerate}
267\item the \emph{path condition}, i.e., the boolean-valued symbolic
268 expression used in symbolic execution to keep track of all
269 conditions on the input symbols which must hold in order for the
270 current path to have been followed;
271\item the \emph{dynamic scopes}, and
272\item the \emph{process states}.
273\end{enumerate}
274
275The dynamic scopes are numbered starting from 0. This numbering is
276arbitrary and is invisible to the program, i.e., there is no way for
277the program to obtain its dynamic scope ID. This allows the verifier
278to renumber dynamic scopes at will in order to transform a state into
279an equivalence canonical form.
280
281The print-out of each dynamic scope specifies the ID of the dyscope's
282parent in the dyscope tree. (The root dyscope shows $-1$ for the
283parent.) This specifies the complete tree structure of the dyscopes.
284Each dyscope is an instance of some static scope; the representation
285also shows the ID of this static scope.
286
287The next line in the representation of the dyscope shows a set of
288\emph{reachers}. These are the PIDs of the processes that can
289\emph{reach} this dyscope. A process can reach a dyscope if there is
290path in the dyscope tree that starts from a dyscope referenced by a
291frame on the process' call stack and follows the parent edges in the
292tree.
293
294The \emph{variables} section of the dyscope representation consists of
295one line for each variable in the static scope corresponding to the
296dyscope. There are also special hidden variables, such as the heap.
297In each case, the value assigned to the variable is shown. A value of
298\texttt{NULL} indicates that the variable is currently undefined. The format for the
299value of a pointer depends on the type of object being referenced, as
300follows:
301\begin{itemize}
302\item A variable: {\tt \&}\emph{variable} {\tt <}\emph{dyscope name}{\tt >}
303\item An element of an array: {\tt \&}\emph{array} {\tt <}\emph{dyscope name}{\tt >[}\emph{index}{\tt]}
304\item A struct field: {\tt \&}\emph{variable} {\tt <}\emph{dyscope name}{\tt >.}\emph{field}
305\item A heap cell: \emph{variable} {\tt <}\emph{dyscope name}{\tt,} \emph{malloc ID}{\tt,} \emph{malloc call number}{\tt >}
306\end{itemize}
307
308The process states section consists of one sub-section for each
309process currently in the state. Like the dynamic scopes, the
310processes are numbered in some arbitrary way. For each process, the
311value of the \emph{atomic count} is given. This is the nesting depth
312of the atomic blocks in which the process is currently located, i.e.,
313the number of times the process has entered an atomic block without
314exiting the block.
315
316The call stack of the process lists the activation frames on the stack
317from top to bottom. The frame at the top correspond to the function
318currently executing in that process. The name of the function, the
319value of the program counter (location), and the source code for that
320location, and the dyscope ID for the frame are shown.
321
322\section{Property Violations}
323
324As described in Section \ref{sec:errors}, an error report is printed
325whenever CIVL encounters an error. A typical error report appears as
326follows:
327\begin{small}
328\begin{verbatim}
329Error 0 encountered at depth 21:
330CIVL execution error (kind: DEADLOCK, certainty: PROVEABLE)
331A deadlock is possible:
332 Path condition: true
333 Enabling predicate: false
334ProcessState 0: terminated
335ProcessState 1: at location 25, f0:21.30-42 "forks[right]"
336 Enabling predicate: false
337ProcessState 2: at location 25, f0:21.30-42 "forks[right]"
338 Enabling predicate: false
339at f0:21.30-42 "forks[right]".
340\end{verbatim}
341\end{small}
342
343The report begins with ``Error 0''. The errors are numbered in the
344order they are discovered in this search; this indicates that this is
345the first (0th) error encountered. The depth refers to the length of
346the depth-first search stack when the error was encountered. In this
347case, the depth was 21, meaning that the trace leading to the
348erroneous state is a sequence of 21 states and 20 transitions.
349
350The errors are categorized by \emph{kind}. The error kinds include
351\emph{deadlock}, indicating that it is possible no transition is
352enabled in the state; \emph{assertion violation}, indicating an
353assertion may fail in the state; \emph{division by zero}; and
354\emph{out of bounds}, indicating an array index may be out of bounds,
355among many more.
356
357In addition to the brief report shown above, most error reports
358also include a complete print-out of the state at which the error
359occurred. They will also include additional information specific
360to the kind of error. For example, the deadlock error report shown
361above includes the following information:
362\begin{itemize}
363\item the value of the path condition;
364\item the \emph{enabling predicate}, which is the disjunction of the
365 guards associated to all transitions departing from the current
366 state. This is the predicate that CIVL has found to possibly be
367 unsatisfiable under the context of the path condition; and
368\item for each process, the current location of the process and the
369 enabling predicate for that process, i.e., the disjunction of the
370 guards associated to all transitions departing from the current
371 state in that process (CIVL has found that all of these may be
372 unsatisfiable).
373\end{itemize}
374
375Errors are also categorized as to their \emph{certainty}. CIVL is
376\emph{conservative}, meaning that if it not sure a property holds in a
377state, it will report it. This means that it may sometimes raise
378\emph{false alarms}, i.e., report a possible error even when none
379exists. The certainty measures how certain CIVL is that the error is
380real. The certainty levels, from most to least certain, are as
381follows:
382\begin{enumerate}
383\item \emph{concrete}: this indicates that CIVL has actually found
384 concrete
385 values for all input variables that are guaranteed to drive the
386 execution along the current trace and result in the error;
387\item \emph{proveable}: this indicates that a theorem prover (either
388 the external one or CIVL's built-in prover) has determined that
389 the error is feasible, which includes proving that the path condition
390 is satisfiable; however, it has not necessarily found concrete
391 values for the inputs;
392\item \emph{maybe}: this indicates the prover is not sure whether this
393 is an error; this could be due to the incompleteness of the decision
394 procecure, or it could be a real error;
395\item \emph{none}: probably an internal CIVL error: the theorem prover
396 has not said anything.
397\end{enumerate}
398
399\section{Statistics}
400
401\begin{itemize}
402\item \emph{validCalls}: the number of calls to the CIVL \emph{valid}
403 method, used to determine if a first-order formula is valid under
404 a given first-order context. Some of these queries are resolved
405 quickly by CIVL; when CIVL cannot resolve the query itself, it
406 calls a separate theorem prover (CVC3)
407\item \emph{proverCalls}: the number of calls to the separate theorem
408 prover's \emph{valid} method
409\item \emph{memory}: the total amount of memory, in bytes, consumed by
410 the Java virtual machine at the end of the search/run.
411\item \emph{time}: the total time, in seconds, used to perform the
412 CIVL operation
413\item \emph{maxProcs}: the maximum process count achieved, over all states
414 encountered in the search/run
415\item \emph{statesInstantiated}: the number of state objects
416 instantiated during the course of the verification/run
417\item \emph{statesSaved}: the number of states saved in the course
418 of a search
419\item \emph{statesSeen}: the number of states pushed onto the
420 depth-first search stack in the course of the search; note
421 that ``intermediate states'' created in the process of executing
422 a transition are not pushed onto the stack, only the final
423 state resulting from the transition is pushed
424\item \emph{statesMatched}: the number of times a state encountered
425 in the depth-first search was found to match a saved state seen
426 earlier in the search
427\item \emph{steps}: the total number of primitive steps executed
428 during the verification/run. A step is the smallest, atomic,
429 unit of execution; each transition is composed of one or more steps.
430 This number is a good measure for the total amount of ``work''
431 carried out by CIVL
432\item \emph{transitions}: the total number of transitions executed
433 during the verification/run. A transition is a coarser unit
434 of execution; each transition consists of one or more steps
435 executed from a single process, resulting in a state which is then
436 pushed onto the DFS stack.
437\end{itemize}
438
439\chapter{Emacs mode}
440
441A CIVL-C mode for the \texttt{emacs} text editor is available in
442directory \texttt{emacs} in the CIVL distribution. This provides
443syntax highlighting and automatic indentation for CIVL-C programs.
444
445To install this mode:
446\begin{enumerate}
447\item Copy file \texttt{civl-syntax.el} to \verb!~/.emacs.d/lisp! or another favorite location
448\item Include that path in your load path in \verb!.emacs!:
449\begin{verbatim}
450(add-to-list 'load-path "~/.emacs.d/lisp")
451\end{verbatim}
452\item Add the following lines to your \verb!~/.emacs! file:
453\begin{verbatim}
454(require 'civl-syntax)
455(civl-syntax)
456\end{verbatim}
457\end{enumerate}
458
459We are grateful to William Killian of the University of Delaware for
460writing this emacs module.
Note: See TracBrowser for help on using the repository browser.