-
Notifications
You must be signed in to change notification settings - Fork 4
/
L11-slides.tex
420 lines (349 loc) · 11.5 KB
/
L11-slides.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
\documentclass{beamer}
\usetheme{Boadilla}
%\includeonlyframes{current}
\usepackage{times}
\usefonttheme{structurebold}
\usepackage{listings}
\usepackage{ragged2e}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{alltt}
\usepackage[normalem]{ulem}
\usetikzlibrary{arrows}
\usetikzlibrary{automata}
\usetikzlibrary{shapes}
\usepackage{amsmath,amssymb}
\usepackage{rotating}
\usepackage{ulem}
\usepackage{listings}
\usepackage{enumerate}
\usepackage{tikz}
\tikzset{
every overlay node/.style={
draw=black,fill=white,rounded corners,anchor=north west,
},
}
\def\tikzoverlay{%
\tikz[baseline,overlay]\node[every overlay node]
}%
%\setbeamercovered{dynamic}
\setbeamertemplate{footline}[page number]{}
\setbeamertemplate{navigation symbols}{}
\usefonttheme{structurebold}
\title{Software Testing, Quality Assurance \& Maintenance---Lecture 11}
\author{Patrick Lam\\University of Waterloo}
\date{January 28, 2015}
\colorlet{redshaded}{red!25!bg}
\colorlet{shaded}{black!25!bg}
\colorlet{shadedshaded}{black!10!bg}
\colorlet{blackshaded}{black!40!bg}
\colorlet{darkred}{red!80!black}
\colorlet{darkblue}{blue!80!black}
\colorlet{darkgreen}{green!80!black}
\newcommand{\rot}[1]{\rotatebox{90}{\mbox{#1}}}
\newcommand{\gray}[1]{\mbox{#1}}
\newenvironment{changemargin}[1]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{1em}
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}
\lstset{ %
language=C++,
basicstyle=\ttfamily,commentstyle=\scriptsize\itshape,showstringspaces=false,breaklines=true}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\frametitle{Course roadmap}
\begin{changemargin}{2cm}
\begin{itemize}
\item $\checkmark$ Introduction (faults etc)
\item $\checkmark$ Graph coverage
\item $\Box$ \alert{Testing Concurrent Programs (wrap-up)}
\item $\Box$ Tools
\end{itemize}
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{Assertions}
\begin{changemargin}{2cm}
statements about the program state that are true, e.g.
\begin{center}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1cm,
semithick,initial text=]
\node[circle,draw,initial] (0) {};
\node[circle,draw] (1) [right of=0] {};
\path (0) edge [bend left] node {} (1)
(1) edge [bend left] node {} (0);
\end{tikzpicture}
\end{center}
doubly-linked list property: {\tt prev} is the inverse of {\tt next}
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{Assertions in This Course's Context}
\begin{changemargin}{2cm}
We also use assertions in unit tests \\
\hspace*{1cm}to say what's supposed to be true.\\[1em]
Plus, last time, we asserted about a lock being held\\
upon entry to a method. Or not.
\end{changemargin}
\end{frame}
\begin{frame}[fragile]
\frametitle{Preconditions, Postconditions}
\begin{changemargin}{2cm}
More generally, we can express\\[1em]
\begin{itemize}
\item what is supposed to be true upon entry \& exit from a method.
\end{itemize}
We saw this code in Linux.
\begin{lstlisting}
/* LOCKING: caller. */
void ata_dev_select(...) { ...}
\end{lstlisting}
= an assertion that the lock is held upon entry.
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{Assume/Guarantee Reasoning}
\begin{changemargin}{2cm}
Why would you use preconditions and postconditions?\\[1em]
When reasoning about the callee:\\
\hspace*{2em} assume the precondition holds upon entry;\\[2em]
When reasoning about the caller:\\
\hspace*{2em} guarantee the precondition holds before the call.\\[2em]
The reverse holds about the postcondition.
\end{changemargin}
\end{frame}
\begin{frame}[fragile]
\frametitle{What aComment actually does}
\begin{changemargin}{2cm}
\begin{itemize}
\item extract locking-related annotations from code;
\item extract locking-related annotations from comments;
\item propagate annotations to callers.
\end{itemize}
\end{changemargin}
\end{frame}
\part{Tools}
\frame{\partpage}
\begin{frame}[fragile]
\frametitle{OS X Mavericks goto fail bug}
\scriptsize
\begin{lstlisting}[language=C]
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail; /* MISTAKE! THIS LINE SHOULD NOT BE HERE */
if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
goto fail;
err = sslRawVerify(...);
fail:
return err;
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Source and writeup: goto fail}
\hspace*{3em}The bug:\\
{\scriptsize \url{opensource.apple.com/source/Security/Security-55471/libsecurity_ssl/lib/sslKeyExchange.c} }\\[2em]
\hspace*{3em}No bug:\\
{\scriptsize \url{www.opensource.apple.com/source/Security/Security-55179.13/libsecurity_ssl/lib/sslKeyExchange.c} }\\[2em]
\hspace*{3em} Writeup:\\ {\scriptsize \url{nakedsecurity.sophos.com/2014/02/24/anatomy-of-a-goto-fail-apples-ssl-bug-explained-plus-an-unofficial-patch/}}
\end{frame}
\begin{frame}
\frametitle{Detecting goto fail}
\begin{changemargin}{1cm}
In retrospect, a number of options:
\begin{itemize}
\item compiler {\tt -Wunreachable-code} option
\item PC-Lint:warning 539: Did not expect positive indentation
\item PVS-Studio:V640: Logic does not match formatting
\end{itemize}
~\\[1em]
\hfill \scriptsize [slide credit: contents from Sye Van De Veen]
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{Testing and Static Analysis Tools}
\begin{changemargin}{2cm}
The continuum:
\begin{itemize}
\item manual testing;
\item running a JUnit test suite, manually generated;
\item running automatically-generated tests;
\item running static analysis tools.
\end{itemize}
We'll examine several points on this continuum today.
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{Tools in Practice}
\begin{changemargin}{1.5cm}
More on this later (March), thanks to guest lecturer.
\begin{itemize}
\item Coverity---static analysis---used by 900+ companies, \\
including BlackBerry, Mozilla, etc.
\item Microsoft requires Windows device drivers \\
to pass the Static Driver Verifier for certification.
\end{itemize}
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{Tools you can Download}
\begin{changemargin}{2.5cm}
We'll survey some tools for:
\begin{itemize}
\item \alert{Java}
\item C/C++
\end{itemize}
(or, use e.g. a programming language \\ with stronger types!)
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{findbugs.sourceforge.net}
\includegraphics[height=4em]{L11/umdFindbugs.png}
\begin{changemargin}{2cm}
Open-source static bytecode analyzer for Java.\\
Finds bug patterns:
\begin{itemize}
\item off-by-one;
\item null pointer dereference;
\item ignored {\tt read()} return value;
\item ignored return value (immutable classes);
\item uninitialized read in constructor;
\item and more\ldots
\end{itemize}
FindBugs gives some false positives. \\[1em]
Some techniques to avoid them:\\
\end{changemargin}
\hspace*{1.5cm} \url{patricklam.ca/papers/14.msr.saa.pdf}
\end{frame}
\begin{frame}
\frametitle{Java Path Finder (JPF), NASA}
\includegraphics[height=4em]{L11/JPF.png} {\em Key Idea:}
\begin{changemargin}{2cm}
Implement a Java Virtual Machine,\\
but explore many thread interleavings,\\
looking for concurrency bugs.\\[2em]
``JPF is an explicit state software model checker for Java\texttrademark bytecode.''\\[1em]
JPF can also search for
\begin{itemize}
\item deadlocks and unhandled exceptions \\ \hspace*{2em} ({\tt NullPointerException},\\
\hspace*{2em}
{\tt AssertionError});
\item race conditions, heap bounds checks.
\end{itemize}
\url{javapathfinder.sourceforge.net}
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{Korat (University of Illinois)}
\includegraphics[height=2em]{L11/Korat.png} \hspace*{0.75cm}Key Idea:
\begin{changemargin}{2cm}
Generate Java objects from a representation invariant specification
written as a Java method.\\[1em]
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=1cm,
semithick,initial text=]
\node[circle,draw] (0) {};
\node[circle,draw] (1) [below left of=0] {};
\node[circle,draw] (2) [below right of=0] {};
\node[circle,draw] (3) [below left of=1] {};
\node[circle,draw] (4) [below right of=1] {};
\path (0) edge node {} (1)
(0) edge node {} (2)
(1) edge node {} (3)
(1) edge node {} (4);
\end{tikzpicture} \hspace*{2em} Binary Tree!\\[1em]
One characteristic of a Binary Tree:
\begin{itemize}
\item left \& right pointers don't refer to same node.
\end{itemize}
\end{changemargin}
\end{frame}
\begin{frame}[fragile]
\frametitle{Korat repOk for Binary Tree}
\tiny
\begin{changemargin}{1cm}
\begin{lstlisting}[language=Java]
boolean repOk() {
if (root == null) return size == 0; // empty tree has size 0
Set visited = new HashSet(); visited.add(root);
List workList = new LinkedList(); workList.add(root);
while (!workList.isEmpty()) {
Node current = (Node)workList.removeFirst();
if (current.left != null) {
if (!visited.add(current.left)) return false; // acyclicity
workList.add(current.left);
}
if (current.right != null) {
if (!visited.add(current.right)) return false; // acyclicity
workList.add(current.right);
}
}
if (visited.size() != size) return false; // consistency of size
return true;
}
\end{lstlisting}
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{What Korat Does}
\begin{changemargin}{2cm}
Generates all distinct (``non-isomorphic'') trees, \\
up to a given size (say 3).\\[1em]
Use these trees as inputs for testing \\
the {\tt add()} method of the tree.\\
(or for any other methods)\\[2em]
\end{changemargin}
\begin{center}
\url{korat.sourceforge.net/index.html}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Randoop (MIT)}
\includegraphics[height=2em]{L11/randoop.png} \hspace*{0.75cm}Key Idea:\\[1em]
\begin{changemargin}{2cm}
``Writing tests is a difficult and time-consuming activity, \\
and yet it is a crucial part of good software engineering. \\[1em]
Randoop automatically generates unit tests for Java classes.''
\end{changemargin}
\end{frame}
\begin{frame}
\frametitle{How Randoop Works}
\begin{changemargin}{1cm}
Generate random sequence of method calls, \\
looking for object contract violations.\\[1em]
Point it at a program \& let it run.\\[2em]
Discard bad method sequences \\
\hspace*{2em}(e.g. illegal argument exceptions).\\
Remember method sequences that create complex objects,\\
and sequences that result in object contract violations.\\[1em]
\end{changemargin}
\begin{center}
\url{code.google.com/p/randoop/}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{An Example Generated by Randoop}
\begin{changemargin}{1cm}
\begin{lstlisting}[language=Java]
public static void test1() {
LinkedList list = new LinkedList();
Object o1 = new Object();
list.addFirst(o1);
TreeSet t1 = new TreeSet(list);
Set s1 = Collections.synchronizedSet(t1);
// violated in the Java standard library!
Assert.assertTrue(s1.equals(s1));
}
\end{lstlisting}
\end{changemargin}
\end{frame}
\end{document}