source: CIVL/doc/manual/part-introduction.tex@ a82987f

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since a82987f was f4bf184, checked in by Stephen Siegel <siegel@…>, 12 years ago

Fixed svn:ignore in doc section, small updates to manual.

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

  • Property mode set to 100644
File size: 11.7 KB
Line 
1\part{Introduction}
2\label{part:intro}
3
4\chapter{Acknowledgement}
5
6The CIVL project is funded by the U.S.\ National Science Foundation
7under awards CCF-1346769 and CCF-1346756.
8
9\chapter{What is CIVL?}
10
11\textbf{CIVL} stands for \emph{Concurrency Intermediate Verification
12 Language}. The \emph{CIVL platform} encompasses:
13\begin{enumerate}
14\item the programming language \textbf{CIVL-C}, a dialect of C with
15 additional primitives supporting concurrency, specification, and modeling;
16\item verification and
17 analysis tools, including a symbolic execution-based model checker for
18 checking various properties of, or finding defects in, CIVL-C
19 programs; and
20\item tools that translate from many commonly used
21 languages/APIs to CIVL-C.
22\end{enumerate}
23
24The CIVL-C language is primarily intended to be an intermediate
25representation for verification. A C program using
26MPI~\cite{mpi-forum:2012:mpi30}, CUDA~\cite{cuda-programming-guide},
27OpenMP~\cite{openmp-standard}, OpenCL~\cite{opencl-standard}, or
28another API (or even some combination of APIs), will be automatically
29translated into CIVL-C and then verified. The advantages of such a
30framework are clear: the developer of a new verification technique
31could implement it for CIVL-C and then immediately see its impact
32across a broad range of concurrent programs. Likewise, when a new
33concurrency API is introduced, one only needs to implement a
34translator from it to CIVL-C in order to reap the benefits of all the
35verification tools in the platform. Programmers would have a valuable
36verification and debugging tool, while API designers could use CIVL as
37a ``sandbox'' to investigate possible API modifications, additions,
38and interactions.
39
40This manual covers all aspects of the CIVL framework, and is organized in parts
41as follows:
42\begin{enumerate}
43\item this introduction, including ``quick start'' instructions for
44 downloading and installing CIVL and several examples;
45\item a complete description of the CIVL-C language;
46\item a formal semantics for the language; and
47\item a description of the tools in the framework.
48\end{enumerate}
49
50\chapter{Installation and Quick Start}
51
52This chapter gives instructions for downloading and installing CIVL,
53and running the verification tool on an example.
54
55\textbf{Note.} The following instructions explain how to install CIVL
56under the directory \texttt{/opt}, which is the standard installation
57point. If you do not wish to install CIVL there (e.g., because you
58don't want to use \texttt{sudo}, or you want to install it in your
59home directory), you can just modify the instructions by replacing
60\texttt{/opt} with another directory. You will just need to edit the
61script file \texttt{civl} appropriately, replacing the default paths
62with your chosen paths.
63
64\begin{enumerate}
65\item Download and unpack the appropriate pre-compiled library of CIVL
66 dependencies from
67 \url{http://vsl.cis.udel.edu/tools/vsl_depend/}.
68 There are versions for Darwin (OS X), 32-bit Linux, and 64-bit Linux.
69 After unpacking, you should have a directory named \texttt{vsl}.
70\item If you do not already have a directory \texttt{/opt},
71 create it; use \texttt{sudo} as needed (\verb!sudo mkdir /opt!).
72\item Move the directory \texttt{vsl} into \texttt{/opt}
73 (\verb!mv vsl /opt!).
74\item Download and unpack the latest stable release of CIVL from
75 \url{http://vsl.cis.udel.edu/civl}. Again there are versions
76 for Darwin, 32-bit Linux, and 64-bit Linux.
77\item The resulting directory should be named
78 \texttt{CIVL-\textit{tag}} for some string \textit{tag} which
79 identifies the version of CIVL you downloaded. Move this directory
80 into \texttt{/opt} (\texttt{mv\ CIVL-\textit{tag}\ /opt}).
81\item There should now be an executable script at
82 \texttt{/opt/CIVL-\textit{tag}/bin/civl}. Move this script into
83 your path, or create a symlink from somewhere in your path to it, or
84 add the directory \texttt{/opt/CIVL-\textit{tag}/bin} to your path.
85\end{enumerate}
86
87From the command line, you should now be able to type \texttt{civl
88 help} and see a help message describing the command line syntax.
89
90Copy the file
91\texttt{CIVL-\textit{tag}/examples/concurrency/locksBad.cvl} to your
92working directory. Look at the program: it is a simple 2-process
93program with two shared variables used as locks. The 2 processes try
94to obtain the locks in opposite order, leading to a deadlock.
95
96Type
97\begin{verbatim}
98civl verify locksBad.cvl
99\end{verbatim}
100You should see some output culminating in a message
101\begin{verbatim}
102The program MAY NOT be correct. See CIVLREP/locksBad_log.txt
103\end{verbatim}
104
105Type
106\begin{verbatim}
107civl replay locksBad.cvl
108\end{verbatim}
109You should see a step-by-step account of how the program arrived
110at the deadlock.
111
112
113\chapter{Examples}
114
115In this section we show a few simple CIVL-C programs which illustrate
116some of the pertinent features of the language. We also show the results
117of running some of the tools on them.
118
119\section{Dining Philosophers}
120
121Dijkstra's well-known Dining Philosophers system can be encoded in
122CIVL-C as shown in Figure \ref{fig:dining}.
123
124\begin{figure}
125 \begin{small}
126\begin{verbatim}
127#include <civlc.h>
128
129$input int B; // upper bound on number of philosophers
130$input int n; // number of philosophers
131$assume 2<=n && n<=B;
132
133// Each fork will be on the table (0) or in a hand (1).
134_Bool forks[n];
135
136void dine(int id) {
137 int left = id;
138 int right = (id + 1) % n;
139
140 while (1) {
141 $when (forks[left] == 0) forks[left] = 1;
142 $when (forks[right] == 0) forks[right] = 1;
143 forks[right] = 0;
144 forks[left] = 0;
145 }
146}
147
148/* Put all forks on the table. */
149void init() {
150 for (int i = 0; i < n; i++) forks[i] = 0;
151}
152
153void main() {
154 init();
155 for (int i = 0; i < n; i++) $spawn dine(i);
156}
157\end{verbatim}
158 \end{small}
159 \caption{CIVL-C encoding of Dijkstra's Dining Philosophers}
160 \label{fig:dining}
161\end{figure}
162
163In this encoding, an upper bound \ct{B} is placed on the number of
164philosophers \ct{n}. When verifying this program, a concrete value
165will be specified for \ct{B}. Hence the result of verification will
166apply to all \ct{n} between $2$ and \ct{B}, inclusive.
167
168Both \ct{B} and \ct{n} are delcared as \emph{input} variables using
169the type qualifier \cinput. An input variable may be
170initialized with any valid value of its type. In contrast, non-input
171variables declared in file scope will be initialized with a
172special \emph{undefined} value; if such a variable is read before it
173is defined, an error will be reported. In addition, any input variable
174may have a concrete initial value specified on the command line. In
175this case, we will specify a concrete value for \ct{B} on the command
176line but leave \ct{n} unconstrained.
177
178An $\cassume$ statement restricts the set of executions of the program
179to include only those traces in which the assumptions hold. In
180contrast with an $\cassert$ statement, CIVL does not check that the
181assumed expression holds, and will not generate an error message if it
182fails to hold. Thus an $\cassume$ statement allows the programmer to
183say to CIVL ``assume that this is true,'' while an $\cassert$
184statement allows the programmer to say to CIVL ``check that this is
185true.''
186
187A $\cwhen$ statement encodes a \emph{guarded command}. The $\cwhen$
188statement includes a boolean expression called the \emph{guard} and a
189statement body. The $\cwhen$ statement is enabled if and only if the
190\emph{guard} evaluates to \emph{true}, in which case the body may be
191executed. The first atomic statement in the body executes atomically
192with the evaluation of the guard, so it is guaranteed that the guard
193will hold when this initial sub-statement executes. Since assignment
194statements are atomic in CIVL, in this example the bodiy of each
195$\cwhen$ statement executes atomically with the guard evaluation.
196
197The $\cspawn$ statement is very similar to a function call. The main
198difference is that the function called is invoked in a new process
199which runs concurrently with the existing processes. The $\cspawn$
200statement itself returns immediately.
201
202The program may be verified for an upper bound of $5$ by typing the
203following at the command line:
204\begin{verbatim}
205 civl verify -inputB=5 diningBad.cvl
206\end{verbatim}
207
208The output indicates that a deadlock has been found and a
209counterexample has been produced and saved. We can examine the
210counterexample, but it is more helpful to work with a \emph{minimal}
211counterexample, i.e., a deadlocking trace of minimal length. To find a
212minimal counterexample, we issue the command
213
214\begin{verbatim}
215 civl verify -inputB=5 -min diningBad.cvl
216\end{verbatim}
217
218\begin{figure}
219 \begin{small}
220\begin{verbatim}
221CIVL v0.7 of 2014-02-08 -- http://vsl.cis.udel.edu/civl
222Error 0 encountered at depth 136:
223...
224Error 25 encountered at depth 20:
225CIVL execution error (kind: DEADLOCK, certainty: PROVEABLE)
226A deadlock is possible:
227 Path condition: true
228 Enabling predicate: false
229ProcessState 0: at location 15, f0:40.4-9 "$wait"
230 Waiting on process 1
231ProcessState 1: at location 28, f0:22.31-43 "forks[right]"
232 Enabling predicate: false
233ProcessState 2: at location 28, f0:22.31-43 "forks[right]"
234 Enabling predicate: false
235at f0:40.4-9 "$wait".
236State 683
237| Path condition
238| | true
239| Dynamic scopes
240| | dyscope 0 (parent=-1, static=0)
241| | | reachers = {0,1,2}
242| | | variables
243| | | | __atomic_lock_var = process<-1>
244| | | | B = 5
245| | | | n = 2
246| | | | forks = X_s0v3[0:=1, 1:=1]
247...
248| Process states
249...
250| | process 2
251| | | atomicCount = 0
252| | | call stack
253| | | | Frame[function=dine, location=28, f0:22.31-43 "forks[right]", scope=5]
254...
255=================== Stats ===================
256 validCalls : 18874
257 proverCalls : 17
258 memory (bytes) : 163577856
259 time (s) : 6.22
260 maxProcs : 6
261 statesInstantiated : 9346
262 statesSaved : 684
263 statesSeen : 1782
264 statesMatched : 1178
265 steps : 3009
266 transitions : 2959
267
268The program MAY NOT be correct. See CIVLREP/diningBad_log.txt
269\end{verbatim}
270 \end{small}
271 \caption{Output from \texttt{civl verify -inputB=5 -min diningBad.cvl}}
272 \label{fig:diningOut}
273\end{figure}
274
275The result of this command is shown in Figure \ref{fig:diningOut}. The
276output indicates that a minimal counterexample has length 19, i.e.,
277involves 20 states and 19 transitions (the depth of 20 is one more
278than 19). It was the 26th and shortest trace found. It was deemed
279equivalent to the earlier traces and hence the earlier ones were
280discarded and only this one saved. We can replay the trace with the command
281\begin{verbatim}
282 civl replay diningBad.cvl
283\end{verbatim}
284
285\begin{figure}
286 \begin{small}
287\begin{verbatim}
288...
289Step 1: proc 0:
290 0->1: B = 5 at f0:9.0-12 "$input int B"
291Step 2: proc 0:
292 35->36: i = 0 at f0:30.7-16 "int i = 0"
293Step 3: proc 0:
294 36->38: LOOP_TRUE_BRANCH at f0:30.18-23 "i < n"
295Step 4: proc 0:
296 38->40: forks[i] = 0 at f0:30.30-42 "forks[i] = 0"
297...
298Step 17: proc 2:
299 21->25: LOOP_TRUE_BRANCH at f0:20.9-10 "1"
300Step 18: proc 1:
301 25->28: forks[left] = 1 at f0:21.30-45 "forks[left] = 1"
302Step 19: proc 2:
303 25->28: forks[left] = 1 at f0:21.30-45 "forks[left] = 1"
304...
305Violation of Deadlock found in State 20:
306A deadlock is possible:
307 Path condition: true
308 Enabling predicate: false
309ProcessState 0: at location 15, f0:40.4-9 "$wait"
310 Waiting on process 1
311ProcessState 1: at location 28, f0:22.31-43 "forks[right]"
312 Enabling predicate: false
313ProcessState 2: at location 28, f0:22.31-43 "forks[right]"
314 Enabling predicate: false
315...
316Trace ends after 19 steps.
317Violation(s) found.
318...
319\end{verbatim}
320 \end{small}
321 \caption{Output from \texttt{civl replay}}
322 \label{fig:diningReplay}
323\end{figure}
324
325The result of this command is shown in Figure \ref{fig:diningReplay}.
326The output indicates that a deadlock has been found involving 2
327philosophers. The trace has 19 steps; after the initialization
328sequence, each philosopher picks up her left fork.
329
Note: See TracBrowser for help on using the repository browser.