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

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 93acf35 was 93acf35, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

cleaned up language and tools description of the manual

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

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