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

1.23 2.0 main test-branch
Last change on this file since bfebb46 was f5aed1c, checked in by Stephen Siegel <siegel@…>, 12 years ago

Added chapter on emacs mode.

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

  • Property mode set to 100644
File size: 20.3 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 84
237| Path condition
238| | true
239| Dynamic scopes
240| | dyscope 0 (parent=-1, static=0)
241| | | reachers = {1,2}
242| | | variables
243| | | | __atomic_lock_var = process<-1>
244| | | | __heap = NULL
245| | | | BOUND = 3
246| | | | n = 2
247| | | | forks = X_s0v4[0:=0, 1:=-1]
248| | dyscope 1 (parent=2, static=5)
249| | | reachers = {1}
250| | | variables
251| | | | __heap = NULL
252| | | | left = 0
253| | | | right = 1
254| | dyscope 2 (parent=0, static=1)
255| | | reachers = {1}
256| | | variables
257| | | | id = 0
258| | | | __heap = NULL
259| | dyscope 3 (parent=4, static=5)
260| | | reachers = {2}
261| | | variables
262| | | | __heap = NULL
263| | | | left = 1
264| | | | right = 0
265| | dyscope 4 (parent=0, static=1)
266| | | reachers = {2}
267| | | variables
268| | | | id = 1
269| | | | __heap = NULL
270| Process states
271| | process 0
272| | | atomicCount = 0
273| | | call stack
274| | process 1
275| | | atomicCount = 0
276| | | call stack
277| | | | Frame[function=dine, location=25, f0:22.32-44 "forks[right]", scope=1]
278| | process 2
279| | | atomicCount = 0
280| | | call stack
281| | | | Frame[function=dine, location=33, f0:26.32-44 "forks[right]", scope=3]
282\end{verbatim}
283 \end{small}
284 \caption{Complete print-out of a state}
285 \label{fig:state-print}
286\end{figure}
287
288A complete print-out of a state can be seen in Figure
289\ref{fig:state-print}. The state is presented in hierarchical way.
290At the top-most level of this hierarchy, there are 3 main parts to the
291state:
292\begin{enumerate}
293\item the \emph{path condition}, i.e., the boolea-valued symbolic
294 expression used in symbolic execution to keep track of all
295 conditions on the input symbols which must hold in order for the
296 current path to have been followed;
297\item the \emph{dynamic scopes}, and
298\item the \emph{process states}.
299\end{enumerate}
300
301The dynamic scopes are numbered starting from 0. This numbering is
302arbitrary and is invisible to the program, i.e., there is no way for
303the program to obtain its dynamic scope ID. This allows the verifier
304to renumber dynamic scopes at will in order to transform a state into
305an equivalence canonical form.
306
307The print-out of each dynamic scope specifies the ID of the dyscope's
308parent in the dyscope tree. (The root dyscope shows $-1$ for the
309parent.) This specifies the complete tree structure of the dyscopes.
310Each dyscope is an instance of some static scope; the representation
311also shows the ID of this static scope.
312
313The next line in the representation of the dyscope shows a set of
314\emph{reachers}. These are the PIDs of the processes that can
315\emph{reach} this dyscope. A process can reach a dyscope if there is
316path in the dyscope tree that starts from a dyscope referenced by a
317frame on the process' call stack and follows the parent edges in the
318tree.
319
320The \emph{variables} section of the dyscope representation consists of
321one line for each variable in the static scope corresponding to the
322dyscope. There are also special hidden variables, such as the heap.
323In each case, the value assigned to the variable is shown. A value of
324\texttt{NULL} indicates that the variable is currently undefined.
325
326The process states section consists of one sub-section for each
327process currently in the state. Like the dynamic scopes, the
328processes are numbered in some arbitrary way. For each process, the
329value of the \emph{atomic count} is given. This is the nesting depth
330of the atomic blocks in which the process is currently located, i.e.,
331the number of times the process has entered an atomic block without
332exiting the block.
333
334The call stack of the process lists the activation frames on the stack
335from top to bottom. The frame at the top correspond to the function
336currently executing in that process. The name of the function, the
337value of the program counter (location), and the source code for that
338location, and the dyscope ID for the frame are shown.
339
340\section{Property Violations}
341
342As described in Section \ref{sec:errors}, an error report is printed
343whenever CIVL encounters an error. A typical error report appears as
344follows:
345\begin{small}
346\begin{verbatim}
347Error 0 encountered at depth 21:
348CIVL execution error (kind: DEADLOCK, certainty: PROVEABLE)
349A deadlock is possible:
350 Path condition: true
351 Enabling predicate: false
352ProcessState 0: terminated
353ProcessState 1: at location 25, f0:21.30-42 "forks[right]"
354 Enabling predicate: false
355ProcessState 2: at location 25, f0:21.30-42 "forks[right]"
356 Enabling predicate: false
357at f0:21.30-42 "forks[right]".
358\end{verbatim}
359\end{small}
360
361The report begins with ``Error 0''. The errors are numbered in the
362order they are discovered in this search; this indicates that this is
363the first (0th) error encountered. The depth refers to the length of
364the depth-first search stack when the error was encountered. In this
365case, the depth was 21, meaning that the trace leading to the
366erroneous state is a sequence of 21 states and 20 transitions.
367
368The errors are categorized by \emph{kind}. The error kinds include
369\emph{deadlock}, indicating that it is possible no transition is
370enabled in the state; \emph{assertion violation}, indicating an
371assertion may fail in the state; \emph{division by zero}; and
372\emph{out of bounds}, indicating an array index may be out of bounds,
373among many more.
374
375In addition to the brief report shown above, most error reports
376also include a complete print-out of the state at which the error
377occurred. They will also include additional information specific
378to the kind of error. For example, the deadlock error report shown
379above includes the following information:
380\begin{itemize}
381\item the value of the path condition;
382\item the \emph{enabling predicate}, which is the disjunction of the
383 guards associated to all transitions departing from the current
384 state. This is the predicate that CIVL has found to possibly be
385 unsatisfiable under the context of the path condition; and
386\item for each process, the current location of the process and the
387 enabling predicate for that process, i.e., the disjunction of the
388 guards associated to all transitions departing from the current
389 state in that process (CIVL has found that all of these may be
390 unsatisfiable).
391\end{itemize}
392
393Errors are also categorized as to their \emph{certainty}. CIVL is
394\emph{conservative}, meaning that if it not sure a property holds in a
395state, it will report it. This means that it may sometimes raise
396\emph{false alarms}, i.e., report a possible error even when none
397exists. The certainty measures how certain CIVL is that the error is
398real. The certainty levels, from most to least certain, are as
399follows:
400\begin{enumerate}
401\item \emph{concrete}: this indicates that CIVL has actually found
402 concrete
403 values for all input variables that are guaranteed to drive the
404 execution along the current trace and result in the error;
405\item \emph{proveable}: this indicates that a theorem prover (either
406 the external one or CIVL's built-in prover) has determined that
407 the error is feasible, which includes proving that the path condition
408 is satisfiable; however, it has not necessarily found concrete
409 values for the inputs;
410\item \emph{maybe}: this indicates the prover is not sure whether this
411 is an error; this could be due to the incompleteness of the decision
412 procecure, or it could be a real error;
413\item \emph{none}: probably an internal CIVL error: the theorem prover
414 has not said anything.
415\end{enumerate}
416
417\section{Statistics}
418
419\begin{itemize}
420\item \emph{validCalls}: the number of calls to the CIVL \emph{valid}
421 method, used to determine if a first-order formula is valid under
422 a given first-order context. Some of these queries are resolved
423 quickly by CIVL; when CIVL cannot resolve the query itself, it
424 calls a separate theorem prover (CVC3)
425\item \emph{proverCalls}: the number of calls to the separate theorem
426 prover's \emph{valid} method
427\item \emph{memory}: the total amount of memory, in bytes, consumed by
428 the Java virtual machine at the end of the search/run.
429\item \emph{time}: the total time, in seconds, used to perform the
430 CIVL operation
431\item \emph{maxProcs}: the maximum process count achieved, over all states
432 encountered in the search/run
433\item \emph{statesInstantiated}: the number of state objects
434 instantiated during the course of the verification/run
435\item \emph{statesSaved}: the number of states saved in the course
436 of a search
437\item \emph{statesSeen}: the number of states pushed onto the
438 depth-first search stack in the course of the search; note
439 that ``intermediate states'' created in the process of executing
440 a transition are not pushed onto the stack, only the final
441 state resulting from the transition is pushed
442\item \emph{statesMatched}: the number of times a state encountered
443 in the depth-first search was found to match a saved state seen
444 earlier in the search
445\item \emph{steps}: the total number of primitive steps executed
446 during the verification/run. A step is the smallest, atomic,
447 unit of execution; each transition is composed of one or more steps.
448 This number is a good measure for the total amount of ``work''
449 carried out by CIVL
450\item \emph{transitions}: the total number of transitions executed
451 during the verification/run. A transition is a coarser unit
452 of execution; each transition consists of one or more steps
453 executed from a single process, resulting in a state which is then
454 pushed onto the DFS stack.
455\end{itemize}
456
457\chapter{Emacs mode}
458
459A CIVL-C mode for the \texttt{emacs} text editor is available in
460directory \texttt{emacs} in the CIVL distribution. This provides
461syntax highlighting and automatic indentation for CIVL-C programs.
462
463To install this mode:
464\begin{enumerate}
465\item Copy file \texttt{civl-syntax.el} to \verb!~/.emacs.d/lisp! or another favorite location
466\item Include that path in your load path in \verb!.emacs!:
467\begin{verbatim}
468(add-to-list 'load-path "~/.emacs.d/lisp")
469\end{verbatim}
470\item Add the following lines to your \verb!~/.emacs! file:
471\begin{verbatim}
472(require 'civl-syntax)
473(civl-syntax)
474\end{verbatim}
475\end{enumerate}
476
477We are grateful to William Killian of the University of Delaware for
478writing this emacs module.
Note: See TracBrowser for help on using the repository browser.