source: CIVL/mods/dev.civl.com/doc/manual/part-tools.tex@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was aad342c, checked in by Stephen Siegel <siegel@…>, 3 years ago

Performing huge refactor to incorporate ABC, GMC, and SARL into CIVL repo and use Java modules.

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

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