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

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

Adding the parts of the manual.

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

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