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

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

Simplified philosophers, working on manual updates.

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

  • Property mode set to 100644
File size: 11.6 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}[t]
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_Bool forks[n]; // Each fork will be on the table (0) or in a hand (1).
133
134void dine(int id) {
135 int left = id;
136 int right = (id + 1) % n;
137
138 while (1) {
139 $when (forks[left] == 0) forks[left] = 1;
140 $when (forks[right] == 0) forks[right] = 1;
141 forks[right] = 0;
142 forks[left] = 0;
143 }
144}
145
146void main() {
147 for (int i = 0; i < n; i++) forks[i] = 0;
148 for (int i = 0; i < n; i++) $spawn dine(i);
149}
150\end{verbatim}
151 \end{small}
152 \caption{CIVL-C encoding of Dijkstra's Dining Philosophers}
153 \label{fig:dining}
154\end{figure}
155
156In this encoding, an upper bound \ct{B} is placed on the number of
157philosophers \ct{n}. When verifying this program, a concrete value
158will be specified for \ct{B}. Hence the result of verification will
159apply to all \ct{n} between $2$ and \ct{B}, inclusive.
160
161Both \ct{B} and \ct{n} are delcared as \emph{input} variables using
162the type qualifier \cinput. An input variable may be
163initialized with any valid value of its type. In contrast, non-input
164variables declared in file scope will be initialized with a
165special \emph{undefined} value; if such a variable is read before it
166is defined, an error will be reported. In addition, any input variable
167may have a concrete initial value specified on the command line. In
168this case, we will specify a concrete value for \ct{B} on the command
169line but leave \ct{n} unconstrained.
170
171An $\cassume$ statement restricts the set of executions of the program
172to include only those traces in which the assumptions hold. In
173contrast with an $\cassert$ statement, CIVL does not check that the
174assumed expression holds, and will not generate an error message if it
175fails to hold. Thus an $\cassume$ statement allows the programmer to
176say to CIVL ``assume that this is true,'' while an $\cassert$
177statement allows the programmer to say to CIVL ``check that this is
178true.''
179
180A $\cwhen$ statement encodes a \emph{guarded command}. The $\cwhen$
181statement includes a boolean expression called the \emph{guard} and a
182statement body. The $\cwhen$ statement is enabled if and only if the
183\emph{guard} evaluates to \emph{true}, in which case the body may be
184executed. The first atomic statement in the body executes atomically
185with the evaluation of the guard, so it is guaranteed that the guard
186will hold when this initial sub-statement executes. Since assignment
187statements are atomic in CIVL, in this example the bodiy of each
188$\cwhen$ statement executes atomically with the guard evaluation.
189
190The $\cspawn$ statement is very similar to a function call. The main
191difference is that the function called is invoked in a new process
192which runs concurrently with the existing processes. The $\cspawn$
193statement itself returns immediately.
194
195The program may be verified for an upper bound of $5$ by typing the
196following at the command line:
197\begin{verbatim}
198 civl verify -inputB=5 diningBad.cvl
199\end{verbatim}
200
201The output indicates that a deadlock has been found and a
202counterexample has been produced and saved. We can examine the
203counterexample, but it is more helpful to work with a \emph{minimal}
204counterexample, i.e., a deadlocking trace of minimal length. To find a
205minimal counterexample, we issue the command
206
207\begin{verbatim}
208 civl verify -inputB=5 -min diningBad.cvl
209\end{verbatim}
210
211\begin{figure}[t]
212 \begin{small}
213\begin{verbatim}
214CIVL v0.7 of 2014-02-08 -- http://vsl.cis.udel.edu/civl
215Error 0 encountered at depth 136:
216...
217Error 25 encountered at depth 20:
218CIVL execution error (kind: DEADLOCK, certainty: PROVEABLE)
219A deadlock is possible:
220 Path condition: true
221 Enabling predicate: false
222ProcessState 0: at location 15, f0:40.4-9 "$wait"
223 Waiting on process 1
224ProcessState 1: at location 28, f0:22.31-43 "forks[right]"
225 Enabling predicate: false
226ProcessState 2: at location 28, f0:22.31-43 "forks[right]"
227 Enabling predicate: false
228at f0:40.4-9 "$wait".
229State 683
230| Path condition
231| | true
232| Dynamic scopes
233| | dyscope 0 (parent=-1, static=0)
234| | | reachers = {0,1,2}
235| | | variables
236| | | | __atomic_lock_var = process<-1>
237| | | | B = 5
238| | | | n = 2
239| | | | forks = X_s0v3[0:=1, 1:=1]
240...
241| Process states
242...
243| | process 2
244| | | atomicCount = 0
245| | | call stack
246| | | | Frame[function=dine, location=28, f0:22.31-43 "forks[right]", scope=5]
247...
248=================== Stats ===================
249 validCalls : 18874
250 proverCalls : 17
251 memory (bytes) : 163577856
252 time (s) : 6.22
253 maxProcs : 6
254 statesInstantiated : 9346
255 statesSaved : 684
256 statesSeen : 1782
257 statesMatched : 1178
258 steps : 3009
259 transitions : 2959
260
261The program MAY NOT be correct. See CIVLREP/diningBad_log.txt
262\end{verbatim}
263 \end{small}
264 \caption{Output from \texttt{civl verify -inputB=5 -min diningBad.cvl}}
265 \label{fig:diningOut}
266\end{figure}
267
268The result of this command is shown in Figure \ref{fig:diningOut}. The
269output indicates that a minimal counterexample has length 19, i.e.,
270involves 20 states and 19 transitions (the depth of 20 is one more
271than 19). It was the 26th and shortest trace found. It was deemed
272equivalent to the earlier traces and hence the earlier ones were
273discarded and only this one saved. We can replay the trace with the command
274\begin{verbatim}
275 civl replay diningBad.cvl
276\end{verbatim}
277
278\begin{figure}
279 \begin{small}
280\begin{verbatim}
281...
282Step 1: proc 0:
283 0->1: B = 5 at f0:9.0-12 "$input int B"
284Step 2: proc 0:
285 35->36: i = 0 at f0:30.7-16 "int i = 0"
286Step 3: proc 0:
287 36->38: LOOP_TRUE_BRANCH at f0:30.18-23 "i < n"
288Step 4: proc 0:
289 38->40: forks[i] = 0 at f0:30.30-42 "forks[i] = 0"
290...
291Step 17: proc 2:
292 21->25: LOOP_TRUE_BRANCH at f0:20.9-10 "1"
293Step 18: proc 1:
294 25->28: forks[left] = 1 at f0:21.30-45 "forks[left] = 1"
295Step 19: proc 2:
296 25->28: forks[left] = 1 at f0:21.30-45 "forks[left] = 1"
297...
298Violation of Deadlock found in State 20:
299A deadlock is possible:
300 Path condition: true
301 Enabling predicate: false
302ProcessState 0: at location 15, f0:40.4-9 "$wait"
303 Waiting on process 1
304ProcessState 1: at location 28, f0:22.31-43 "forks[right]"
305 Enabling predicate: false
306ProcessState 2: at location 28, f0:22.31-43 "forks[right]"
307 Enabling predicate: false
308...
309Trace ends after 19 steps.
310Violation(s) found.
311...
312\end{verbatim}
313 \end{small}
314 \caption{Output from \texttt{civl replay}}
315 \label{fig:diningReplay}
316\end{figure}
317
318The result of this command is shown in Figure \ref{fig:diningReplay}.
319The output indicates that a deadlock has been found involving 2
320philosophers. The trace has 19 steps; after the initialization
321sequence, each philosopher picks up her left fork.
Note: See TracBrowser for help on using the repository browser.