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

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

started to fix the description of commands and options for the tool

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

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